[email protected] | 2d58238b | 2012-05-09 20:30:19 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 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 | |||||
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 8 | #include <map> |
[email protected] | 217d956 | 2012-07-16 21:57:37 | [diff] [blame] | 9 | |
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | 56b8d5c | 2011-10-07 00:28:34 | [diff] [blame] | 12 | #include "content/common/content_export.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 13 | #include "content/public/renderer/v8_value_converter.h" |
14 | |||||
[email protected] | 040b785 | 2011-11-09 03:51:09 | [diff] [blame] | 15 | namespace base { |
[email protected] | 2d58238b | 2012-05-09 20:30:19 | [diff] [blame] | 16 | class BinaryValue; |
[email protected] | 040b785 | 2011-11-09 03:51:09 | [diff] [blame] | 17 | class DictionaryValue; |
18 | class ListValue; | ||||
19 | class Value; | ||||
20 | } | ||||
21 | |||||
[email protected] | 3827e970 | 2012-10-23 06:19:28 | [diff] [blame] | 22 | namespace content { |
23 | |||||
24 | class CONTENT_EXPORT V8ValueConverterImpl : public V8ValueConverter { | ||||
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 25 | public: |
26 | V8ValueConverterImpl(); | ||||
27 | |||||
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 28 | // V8ValueConverter implementation. |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 29 | virtual void SetDateAllowed(bool val) OVERRIDE; |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 30 | virtual void SetRegExpAllowed(bool val) OVERRIDE; |
31 | virtual void SetFunctionAllowed(bool val) OVERRIDE; | ||||
[email protected] | 2a52184 | 2012-05-30 09:17:06 | [diff] [blame] | 32 | virtual void SetStripNullFromObjects(bool val) OVERRIDE; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 33 | virtual v8::Handle<v8::Value> ToV8Value( |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 34 | const base::Value* value, |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 35 | v8::Handle<v8::Context> context) const OVERRIDE; |
36 | virtual base::Value* FromV8Value( | ||||
37 | v8::Handle<v8::Value> value, | ||||
38 | v8::Handle<v8::Context> context) const OVERRIDE; | ||||
39 | |||||
40 | private: | ||||
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 41 | friend class ScopedAvoidIdentityHashForTesting; |
[email protected] | 195487f | 2013-06-10 14:20:41 | [diff] [blame^] | 42 | |
43 | class FromV8ValueState; | ||||
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 44 | |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 45 | v8::Handle<v8::Value> ToV8ValueImpl(const base::Value* value) const; |
46 | v8::Handle<v8::Value> ToV8Array(const base::ListValue* list) const; | ||||
47 | v8::Handle<v8::Value> ToV8Object( | ||||
48 | const base::DictionaryValue* dictionary) const; | ||||
[email protected] | 2d58238b | 2012-05-09 20:30:19 | [diff] [blame] | 49 | v8::Handle<v8::Value> ToArrayBuffer(const base::BinaryValue* value) const; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 50 | |
[email protected] | 217d956 | 2012-07-16 21:57:37 | [diff] [blame] | 51 | base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value, |
[email protected] | 195487f | 2013-06-10 14:20:41 | [diff] [blame^] | 52 | FromV8ValueState* state) const; |
[email protected] | 217d956 | 2012-07-16 21:57:37 | [diff] [blame] | 53 | base::Value* FromV8Array(v8::Handle<v8::Array> array, |
[email protected] | 195487f | 2013-06-10 14:20:41 | [diff] [blame^] | 54 | FromV8ValueState* state) const; |
[email protected] | 2d58238b | 2012-05-09 20:30:19 | [diff] [blame] | 55 | |
56 | // This will convert objects of type ArrayBuffer or any of the | ||||
57 | // ArrayBufferView subclasses. The return value will be NULL if |value| is | ||||
58 | // not one of these types. | ||||
59 | base::BinaryValue* FromV8Buffer(v8::Handle<v8::Value> value) const; | ||||
60 | |||||
[email protected] | 217d956 | 2012-07-16 21:57:37 | [diff] [blame] | 61 | base::Value* FromV8Object(v8::Handle<v8::Object> object, |
[email protected] | 195487f | 2013-06-10 14:20:41 | [diff] [blame^] | 62 | FromV8ValueState* state) const; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 63 | |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 64 | // If true, we will convert Date JavaScript objects to doubles. |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 65 | bool date_allowed_; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 66 | |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 67 | // If true, we will convert RegExp JavaScript objects to string. |
68 | bool reg_exp_allowed_; | ||||
69 | |||||
70 | // If true, we will convert Function JavaScript objects to dictionaries. | ||||
71 | bool function_allowed_; | ||||
[email protected] | 2a52184 | 2012-05-30 09:17:06 | [diff] [blame] | 72 | |
73 | // If true, undefined and null values are ignored when converting v8 objects | ||||
74 | // into Values. | ||||
75 | bool strip_null_from_objects_; | ||||
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 76 | |
77 | bool avoid_identity_hash_for_testing_; | ||||
78 | |||||
79 | DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl); | ||||
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 80 | }; |
81 | |||||
[email protected] | 3827e970 | 2012-10-23 06:19:28 | [diff] [blame] | 82 | } // namespace content |
83 | |||||
[email protected] | 040b785 | 2011-11-09 03:51:09 | [diff] [blame] | 84 | #endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |