• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
6 #define CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
7 
8 #include <map>
9 
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "content/common/content_export.h"
13 #include "content/public/renderer/v8_value_converter.h"
14 
15 namespace base {
16 class BinaryValue;
17 class DictionaryValue;
18 class ListValue;
19 class Value;
20 }
21 
22 namespace content {
23 
24 class CONTENT_EXPORT V8ValueConverterImpl : public V8ValueConverter {
25  public:
26   V8ValueConverterImpl();
27 
28   // V8ValueConverter implementation.
29   virtual void SetDateAllowed(bool val) OVERRIDE;
30   virtual void SetRegExpAllowed(bool val) OVERRIDE;
31   virtual void SetFunctionAllowed(bool val) OVERRIDE;
32   virtual void SetStripNullFromObjects(bool val) OVERRIDE;
33   virtual void SetStrategy(Strategy* strategy) OVERRIDE;
34   virtual v8::Handle<v8::Value> ToV8Value(
35       const base::Value* value,
36       v8::Handle<v8::Context> context) const OVERRIDE;
37   virtual base::Value* FromV8Value(
38       v8::Handle<v8::Value> value,
39       v8::Handle<v8::Context> context) const OVERRIDE;
40 
41  private:
42   friend class ScopedAvoidIdentityHashForTesting;
43 
44   class FromV8ValueState;
45 
46   v8::Local<v8::Value> ToV8ValueImpl(v8::Isolate* isolate,
47                                       const base::Value* value) const;
48   v8::Handle<v8::Value> ToV8Array(v8::Isolate* isolate,
49                                   const base::ListValue* list) const;
50   v8::Handle<v8::Value> ToV8Object(
51       v8::Isolate* isolate,
52       const base::DictionaryValue* dictionary) const;
53   v8::Handle<v8::Value> ToArrayBuffer(const base::BinaryValue* value) const;
54 
55   base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value,
56                                FromV8ValueState* state,
57                                v8::Isolate* isolate) const;
58   base::Value* FromV8Array(v8::Handle<v8::Array> array,
59                            FromV8ValueState* state,
60                            v8::Isolate* isolate) const;
61 
62   // This will convert objects of type ArrayBuffer or any of the
63   // ArrayBufferView subclasses. The return value will be NULL if |value| is
64   // not one of these types.
65   base::BinaryValue* FromV8Buffer(v8::Handle<v8::Value> value) const;
66 
67   base::Value* FromV8Object(v8::Handle<v8::Object> object,
68                             FromV8ValueState* state,
69                             v8::Isolate* isolate) const;
70 
71   // If true, we will convert Date JavaScript objects to doubles.
72   bool date_allowed_;
73 
74   // If true, we will convert RegExp JavaScript objects to string.
75   bool reg_exp_allowed_;
76 
77   // If true, we will convert Function JavaScript objects to dictionaries.
78   bool function_allowed_;
79 
80   // If true, undefined and null values are ignored when converting v8 objects
81   // into Values.
82   bool strip_null_from_objects_;
83 
84   bool avoid_identity_hash_for_testing_;
85 
86   // Strategy object that changes the converter's behavior.
87   Strategy* strategy_;
88 
89   DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl);
90 };
91 
92 }  // namespace content
93 
94 #endif  // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
95