blob: a6ae3c7785425805b2038c3ca59b7792e68c5188 [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;
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:4934 v8::Local<v8::Value> ToV8Value(const base::Value* value,
35 v8::Local<v8::Context> context) override;
dcheng0232f572016-05-27 17:47:4436 std::unique_ptr<base::Value> FromV8Value(
37 v8::Local<v8::Value> value,
Lucas Furukawa Gadanid51ff5d62018-12-07 21:26:4938 v8::Local<v8::Context> context) override;
[email protected]8d86f13d2011-10-04 17:01:1939
40 private:
[email protected]6a9b7372013-03-20 15:35:2041 friend class ScopedAvoidIdentityHashForTesting;
[email protected]195487f2013-06-10 14:20:4142
43 class FromV8ValueState;
lazyboy275ec3e2016-05-04 18:04:2444 class ScopedUniquenessGuard;
[email protected]6a9b7372013-03-20 15:35:2045
[email protected]5f042ee2013-11-29 20:12:0146 v8::Local<v8::Value> ToV8ValueImpl(v8::Isolate* isolate,
deepak.s750d68f2015-04-30 07:32:4147 v8::Local<v8::Object> creation_context,
[email protected]e086cfc2014-06-11 12:15:4848 const base::Value* value) const;
deepak.s750d68f2015-04-30 07:32:4149 v8::Local<v8::Value> ToV8Array(v8::Isolate* isolate,
50 v8::Local<v8::Object> creation_context,
[email protected]5f042ee2013-11-29 20:12:0151 const base::ListValue* list) const;
deepak.s750d68f2015-04-30 07:32:4152 v8::Local<v8::Value> ToV8Object(
[email protected]5f042ee2013-11-29 20:12:0153 v8::Isolate* isolate,
deepak.s750d68f2015-04-30 07:32:4154 v8::Local<v8::Object> creation_context,
[email protected]83820d42011-11-12 22:03:1155 const base::DictionaryValue* dictionary) const;
deepak.s750d68f2015-04-30 07:32:4156 v8::Local<v8::Value> ToArrayBuffer(v8::Isolate* isolate,
jdoerrie14b25da2017-04-11 07:45:5057 v8::Local<v8::Object> creation_context,
58 const base::Value* value) const;
[email protected]8d86f13d2011-10-04 17:01:1959
dcheng0232f572016-05-27 17:47:4460 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]2d58238b2012-05-09 20:30:1966
67 // This will convert objects of type ArrayBuffer or any of the
[email protected]551b8642014-04-25 09:07:0768 // ArrayBufferView subclasses.
dcheng0232f572016-05-27 17:47:4469 std::unique_ptr<base::Value> FromV8ArrayBuffer(v8::Local<v8::Object> val,
70 v8::Isolate* isolate) const;
[email protected]2d58238b2012-05-09 20:30:1971
dcheng0232f572016-05-27 17:47:4472 std::unique_ptr<base::Value> FromV8Object(v8::Local<v8::Object> object,
73 FromV8ValueState* state,
74 v8::Isolate* isolate) const;
[email protected]8d86f13d2011-10-04 17:01:1975
[email protected]8d86f13d2011-10-04 17:01:1976 // If true, we will convert Date JavaScript objects to doubles.
[email protected]3de391e82012-05-16 17:50:5177 bool date_allowed_;
[email protected]8d86f13d2011-10-04 17:01:1978
[email protected]e0658bc2012-09-17 04:05:2479 // 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]2a521842012-05-30 09:17:0684
85 // If true, undefined and null values are ignored when converting v8 objects
86 // into Values.
87 bool strip_null_from_objects_;
[email protected]6a9b7372013-03-20 15:35:2088
rdevlin.croninf88f9bc22017-02-24 17:09:3089 // If true, convert -0 to an integer value (instead of a double).
90 bool convert_negative_zero_to_int_;
91
[email protected]6a9b7372013-03-20 15:35:2092 bool avoid_identity_hash_for_testing_;
93
[email protected]d754cbb02013-08-12 17:51:3694 // Strategy object that changes the converter's behavior.
95 Strategy* strategy_;
96
[email protected]6a9b7372013-03-20 15:35:2097 DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl);
[email protected]8d86f13d2011-10-04 17:01:1998};
99
[email protected]3827e9702012-10-23 06:19:28100} // namespace content
101
John Abd-El-Malek312a30bb2017-10-23 19:51:52102#endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_