[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 | |
John Abd-El-Malek | 312a30bb | 2017-10-23 19:51:52 | [diff] [blame^] | 5 | #ifndef CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |
| 6 | #define CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 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] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 56b8d5c | 2011-10-07 00:28:34 | [diff] [blame] | 12 | #include "content/common/content_export.h" |
John Abd-El-Malek | 312a30bb | 2017-10-23 19:51:52 | [diff] [blame^] | 13 | #include "content/public/renderer/v8_value_converter.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 14 | |
[email protected] | 040b785 | 2011-11-09 03:51:09 | [diff] [blame] | 15 | namespace base { |
| 16 | class DictionaryValue; |
| 17 | class ListValue; |
| 18 | class Value; |
| 19 | } |
| 20 | |
[email protected] | 3827e970 | 2012-10-23 06:19:28 | [diff] [blame] | 21 | namespace content { |
| 22 | |
| 23 | class CONTENT_EXPORT V8ValueConverterImpl : public V8ValueConverter { |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 24 | public: |
| 25 | V8ValueConverterImpl(); |
| 26 | |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 27 | // V8ValueConverter implementation. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 28 | void SetDateAllowed(bool val) override; |
| 29 | void SetRegExpAllowed(bool val) override; |
| 30 | void SetFunctionAllowed(bool val) override; |
| 31 | void SetStripNullFromObjects(bool val) override; |
rdevlin.cronin | f88f9bc2 | 2017-02-24 17:09:30 | [diff] [blame] | 32 | void SetConvertNegativeZeroToInt(bool val) override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 33 | void SetStrategy(Strategy* strategy) override; |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 34 | v8::Local<v8::Value> ToV8Value( |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 35 | const base::Value* value, |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 36 | v8::Local<v8::Context> context) const override; |
dcheng | 0232f57 | 2016-05-27 17:47:44 | [diff] [blame] | 37 | std::unique_ptr<base::Value> FromV8Value( |
| 38 | v8::Local<v8::Value> value, |
| 39 | v8::Local<v8::Context> context) const override; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 40 | |
| 41 | private: |
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 42 | friend class ScopedAvoidIdentityHashForTesting; |
[email protected] | 195487f | 2013-06-10 14:20:41 | [diff] [blame] | 43 | |
| 44 | class FromV8ValueState; |
lazyboy | 275ec3e | 2016-05-04 18:04:24 | [diff] [blame] | 45 | class ScopedUniquenessGuard; |
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 46 | |
[email protected] | 5f042ee | 2013-11-29 20:12:01 | [diff] [blame] | 47 | v8::Local<v8::Value> ToV8ValueImpl(v8::Isolate* isolate, |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 48 | v8::Local<v8::Object> creation_context, |
[email protected] | e086cfc | 2014-06-11 12:15:48 | [diff] [blame] | 49 | const base::Value* value) const; |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 50 | v8::Local<v8::Value> ToV8Array(v8::Isolate* isolate, |
| 51 | v8::Local<v8::Object> creation_context, |
[email protected] | 5f042ee | 2013-11-29 20:12:01 | [diff] [blame] | 52 | const base::ListValue* list) const; |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 53 | v8::Local<v8::Value> ToV8Object( |
[email protected] | 5f042ee | 2013-11-29 20:12:01 | [diff] [blame] | 54 | v8::Isolate* isolate, |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 55 | v8::Local<v8::Object> creation_context, |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 56 | const base::DictionaryValue* dictionary) const; |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 57 | v8::Local<v8::Value> ToArrayBuffer(v8::Isolate* isolate, |
jdoerrie | 14b25da | 2017-04-11 07:45:50 | [diff] [blame] | 58 | v8::Local<v8::Object> creation_context, |
| 59 | const base::Value* value) const; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 60 | |
dcheng | 0232f57 | 2016-05-27 17:47:44 | [diff] [blame] | 61 | std::unique_ptr<base::Value> FromV8ValueImpl(FromV8ValueState* state, |
| 62 | v8::Local<v8::Value> value, |
| 63 | v8::Isolate* isolate) const; |
| 64 | std::unique_ptr<base::Value> FromV8Array(v8::Local<v8::Array> array, |
| 65 | FromV8ValueState* state, |
| 66 | v8::Isolate* isolate) const; |
[email protected] | 2d58238b | 2012-05-09 20:30:19 | [diff] [blame] | 67 | |
| 68 | // This will convert objects of type ArrayBuffer or any of the |
[email protected] | 551b864 | 2014-04-25 09:07:07 | [diff] [blame] | 69 | // ArrayBufferView subclasses. |
dcheng | 0232f57 | 2016-05-27 17:47:44 | [diff] [blame] | 70 | std::unique_ptr<base::Value> FromV8ArrayBuffer(v8::Local<v8::Object> val, |
| 71 | v8::Isolate* isolate) const; |
[email protected] | 2d58238b | 2012-05-09 20:30:19 | [diff] [blame] | 72 | |
dcheng | 0232f57 | 2016-05-27 17:47:44 | [diff] [blame] | 73 | std::unique_ptr<base::Value> FromV8Object(v8::Local<v8::Object> object, |
| 74 | FromV8ValueState* state, |
| 75 | v8::Isolate* isolate) const; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 76 | |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 77 | // If true, we will convert Date JavaScript objects to doubles. |
[email protected] | 3de391e8 | 2012-05-16 17:50:51 | [diff] [blame] | 78 | bool date_allowed_; |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 79 | |
[email protected] | e0658bc | 2012-09-17 04:05:24 | [diff] [blame] | 80 | // If true, we will convert RegExp JavaScript objects to string. |
| 81 | bool reg_exp_allowed_; |
| 82 | |
| 83 | // If true, we will convert Function JavaScript objects to dictionaries. |
| 84 | bool function_allowed_; |
[email protected] | 2a52184 | 2012-05-30 09:17:06 | [diff] [blame] | 85 | |
| 86 | // If true, undefined and null values are ignored when converting v8 objects |
| 87 | // into Values. |
| 88 | bool strip_null_from_objects_; |
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 89 | |
rdevlin.cronin | f88f9bc2 | 2017-02-24 17:09:30 | [diff] [blame] | 90 | // If true, convert -0 to an integer value (instead of a double). |
| 91 | bool convert_negative_zero_to_int_; |
| 92 | |
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 93 | bool avoid_identity_hash_for_testing_; |
| 94 | |
[email protected] | d754cbb0 | 2013-08-12 17:51:36 | [diff] [blame] | 95 | // Strategy object that changes the converter's behavior. |
| 96 | Strategy* strategy_; |
| 97 | |
[email protected] | 6a9b737 | 2013-03-20 15:35:20 | [diff] [blame] | 98 | DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl); |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 99 | }; |
| 100 | |
[email protected] | 3827e970 | 2012-10-23 06:19:28 | [diff] [blame] | 101 | } // namespace content |
| 102 | |
John Abd-El-Malek | 312a30bb | 2017-10-23 19:51:52 | [diff] [blame^] | 103 | #endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |