blob: 16d19a5f410858cdc7986eeedcf589169cbb7168 [file] [log] [blame]
[email protected]2d58238b2012-05-09 20:30:191// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8d86f13d2011-10-04 17:01:192// 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-Malek312a30bb2017-10-23 19:51:525#ifndef CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
6#define CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
[email protected]8d86f13d2011-10-04 17:01:197
[email protected]6a9b7372013-03-20 15:35:208#include <map>
[email protected]217d9562012-07-16 21:57:379
[email protected]8d86f13d2011-10-04 17:01:1910#include "base/compiler_specific.h"
avi66a07722015-12-25 23:38:1211#include "base/macros.h"
[email protected]56b8d5c2011-10-07 00:28:3412#include "content/common/content_export.h"
John Abd-El-Malek312a30bb2017-10-23 19:51:5213#include "content/public/renderer/v8_value_converter.h"
[email protected]8d86f13d2011-10-04 17:01:1914
[email protected]040b7852011-11-09 03:51:0915namespace base {
16class DictionaryValue;
17class ListValue;
18class Value;
19}
20
[email protected]3827e9702012-10-23 06:19:2821namespace content {
22
23class CONTENT_EXPORT V8ValueConverterImpl : public V8ValueConverter {
[email protected]8d86f13d2011-10-04 17:01:1924 public:
25 V8ValueConverterImpl();
26
[email protected]8d86f13d2011-10-04 17:01:1927 // V8ValueConverter implementation.
dcheng6d18e402014-10-21 12:32:5228 void SetDateAllowed(bool val) override;
29 void SetRegExpAllowed(bool val) override;
30 void SetFunctionAllowed(bool val) override;
31 void SetStripNullFromObjects(bool val) override;
rdevlin.croninf88f9bc22017-02-24 17:09:3032 void SetConvertNegativeZeroToInt(bool val) override;
dcheng6d18e402014-10-21 12:32:5233 void SetStrategy(Strategy* strategy) override;
deepak.s750d68f2015-04-30 07:32:4134 v8::Local<v8::Value> ToV8Value(
[email protected]83820d42011-11-12 22:03:1135 const base::Value* value,
deepak.s750d68f2015-04-30 07:32:4136 v8::Local<v8::Context> context) const override;
dcheng0232f572016-05-27 17:47:4437 std::unique_ptr<base::Value> FromV8Value(
38 v8::Local<v8::Value> value,
39 v8::Local<v8::Context> context) const override;
[email protected]8d86f13d2011-10-04 17:01:1940
41 private:
[email protected]6a9b7372013-03-20 15:35:2042 friend class ScopedAvoidIdentityHashForTesting;
[email protected]195487f2013-06-10 14:20:4143
44 class FromV8ValueState;
lazyboy275ec3e2016-05-04 18:04:2445 class ScopedUniquenessGuard;
[email protected]6a9b7372013-03-20 15:35:2046
[email protected]5f042ee2013-11-29 20:12:0147 v8::Local<v8::Value> ToV8ValueImpl(v8::Isolate* isolate,
deepak.s750d68f2015-04-30 07:32:4148 v8::Local<v8::Object> creation_context,
[email protected]e086cfc2014-06-11 12:15:4849 const base::Value* value) const;
deepak.s750d68f2015-04-30 07:32:4150 v8::Local<v8::Value> ToV8Array(v8::Isolate* isolate,
51 v8::Local<v8::Object> creation_context,
[email protected]5f042ee2013-11-29 20:12:0152 const base::ListValue* list) const;
deepak.s750d68f2015-04-30 07:32:4153 v8::Local<v8::Value> ToV8Object(
[email protected]5f042ee2013-11-29 20:12:0154 v8::Isolate* isolate,
deepak.s750d68f2015-04-30 07:32:4155 v8::Local<v8::Object> creation_context,
[email protected]83820d42011-11-12 22:03:1156 const base::DictionaryValue* dictionary) const;
deepak.s750d68f2015-04-30 07:32:4157 v8::Local<v8::Value> ToArrayBuffer(v8::Isolate* isolate,
jdoerrie14b25da2017-04-11 07:45:5058 v8::Local<v8::Object> creation_context,
59 const base::Value* value) const;
[email protected]8d86f13d2011-10-04 17:01:1960
dcheng0232f572016-05-27 17:47:4461 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]2d58238b2012-05-09 20:30:1967
68 // This will convert objects of type ArrayBuffer or any of the
[email protected]551b8642014-04-25 09:07:0769 // ArrayBufferView subclasses.
dcheng0232f572016-05-27 17:47:4470 std::unique_ptr<base::Value> FromV8ArrayBuffer(v8::Local<v8::Object> val,
71 v8::Isolate* isolate) const;
[email protected]2d58238b2012-05-09 20:30:1972
dcheng0232f572016-05-27 17:47:4473 std::unique_ptr<base::Value> FromV8Object(v8::Local<v8::Object> object,
74 FromV8ValueState* state,
75 v8::Isolate* isolate) const;
[email protected]8d86f13d2011-10-04 17:01:1976
[email protected]8d86f13d2011-10-04 17:01:1977 // If true, we will convert Date JavaScript objects to doubles.
[email protected]3de391e82012-05-16 17:50:5178 bool date_allowed_;
[email protected]8d86f13d2011-10-04 17:01:1979
[email protected]e0658bc2012-09-17 04:05:2480 // 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]2a521842012-05-30 09:17:0685
86 // If true, undefined and null values are ignored when converting v8 objects
87 // into Values.
88 bool strip_null_from_objects_;
[email protected]6a9b7372013-03-20 15:35:2089
rdevlin.croninf88f9bc22017-02-24 17:09:3090 // If true, convert -0 to an integer value (instead of a double).
91 bool convert_negative_zero_to_int_;
92
[email protected]6a9b7372013-03-20 15:35:2093 bool avoid_identity_hash_for_testing_;
94
[email protected]d754cbb02013-08-12 17:51:3695 // Strategy object that changes the converter's behavior.
96 Strategy* strategy_;
97
[email protected]6a9b7372013-03-20 15:35:2098 DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl);
[email protected]8d86f13d2011-10-04 17:01:1999};
100
[email protected]3827e9702012-10-23 06:19:28101} // namespace content
102
John Abd-El-Malek312a30bb2017-10-23 19:51:52103#endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_