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