| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |
| 6 #define CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ | 6 #define CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 virtual void SetStripNullFromObjects(bool val) OVERRIDE; | 32 virtual void SetStripNullFromObjects(bool val) OVERRIDE; |
| 33 virtual v8::Handle<v8::Value> ToV8Value( | 33 virtual v8::Handle<v8::Value> ToV8Value( |
| 34 const base::Value* value, | 34 const base::Value* value, |
| 35 v8::Handle<v8::Context> context) const OVERRIDE; | 35 v8::Handle<v8::Context> context) const OVERRIDE; |
| 36 virtual base::Value* FromV8Value( | 36 virtual base::Value* FromV8Value( |
| 37 v8::Handle<v8::Value> value, | 37 v8::Handle<v8::Value> value, |
| 38 v8::Handle<v8::Context> context) const OVERRIDE; | 38 v8::Handle<v8::Context> context) const OVERRIDE; |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 friend class ScopedAvoidIdentityHashForTesting; | 41 friend class ScopedAvoidIdentityHashForTesting; |
| 42 typedef std::multimap<int, v8::Handle<v8::Object> > HashToHandleMap; | 42 |
| 43 class FromV8ValueState; |
| 43 | 44 |
| 44 v8::Handle<v8::Value> ToV8ValueImpl(const base::Value* value) const; | 45 v8::Handle<v8::Value> ToV8ValueImpl(const base::Value* value) const; |
| 45 v8::Handle<v8::Value> ToV8Array(const base::ListValue* list) const; | 46 v8::Handle<v8::Value> ToV8Array(const base::ListValue* list) const; |
| 46 v8::Handle<v8::Value> ToV8Object( | 47 v8::Handle<v8::Value> ToV8Object( |
| 47 const base::DictionaryValue* dictionary) const; | 48 const base::DictionaryValue* dictionary) const; |
| 48 v8::Handle<v8::Value> ToArrayBuffer(const base::BinaryValue* value) const; | 49 v8::Handle<v8::Value> ToArrayBuffer(const base::BinaryValue* value) const; |
| 49 | 50 |
| 50 base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value, | 51 base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value, |
| 51 HashToHandleMap* unique_map) const; | 52 FromV8ValueState* state) const; |
| 52 base::Value* FromV8Array(v8::Handle<v8::Array> array, | 53 base::Value* FromV8Array(v8::Handle<v8::Array> array, |
| 53 HashToHandleMap* unique_map) const; | 54 FromV8ValueState* state) const; |
| 54 | 55 |
| 55 // This will convert objects of type ArrayBuffer or any of the | 56 // This will convert objects of type ArrayBuffer or any of the |
| 56 // ArrayBufferView subclasses. The return value will be NULL if |value| is | 57 // ArrayBufferView subclasses. The return value will be NULL if |value| is |
| 57 // not one of these types. | 58 // not one of these types. |
| 58 base::BinaryValue* FromV8Buffer(v8::Handle<v8::Value> value) const; | 59 base::BinaryValue* FromV8Buffer(v8::Handle<v8::Value> value) const; |
| 59 | 60 |
| 60 base::Value* FromV8Object(v8::Handle<v8::Object> object, | 61 base::Value* FromV8Object(v8::Handle<v8::Object> object, |
| 61 HashToHandleMap* unique_map) const; | 62 FromV8ValueState* state) const; |
| 62 | |
| 63 // If |handle| is not in |map|, then add it to |map| and return true. | |
| 64 // Otherwise do nothing and return false. Here "A is unique" means that no | |
| 65 // other handle B in the map points to the same object as A. Note that A can | |
| 66 // be unique even if there already is another handle with the same identity | |
| 67 // hash (key) in the map, because two objects can have the same hash. | |
| 68 bool UpdateAndCheckUniqueness(HashToHandleMap* map, | |
| 69 v8::Handle<v8::Object> handle) const; | |
| 70 | 63 |
| 71 // If true, we will convert Date JavaScript objects to doubles. | 64 // If true, we will convert Date JavaScript objects to doubles. |
| 72 bool date_allowed_; | 65 bool date_allowed_; |
| 73 | 66 |
| 74 // If true, we will convert RegExp JavaScript objects to string. | 67 // If true, we will convert RegExp JavaScript objects to string. |
| 75 bool reg_exp_allowed_; | 68 bool reg_exp_allowed_; |
| 76 | 69 |
| 77 // If true, we will convert Function JavaScript objects to dictionaries. | 70 // If true, we will convert Function JavaScript objects to dictionaries. |
| 78 bool function_allowed_; | 71 bool function_allowed_; |
| 79 | 72 |
| 80 // If true, undefined and null values are ignored when converting v8 objects | 73 // If true, undefined and null values are ignored when converting v8 objects |
| 81 // into Values. | 74 // into Values. |
| 82 bool strip_null_from_objects_; | 75 bool strip_null_from_objects_; |
| 83 | 76 |
| 84 bool avoid_identity_hash_for_testing_; | 77 bool avoid_identity_hash_for_testing_; |
| 85 | 78 |
| 86 DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl); | 79 DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl); |
| 87 }; | 80 }; |
| 88 | 81 |
| 89 } // namespace content | 82 } // namespace content |
| 90 | 83 |
| 91 #endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ | 84 #endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |
| OLD | NEW |