blob: f5ad10a4b81476d240ff5f74561c460fdb755fb6 [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
5#ifndef CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
6#define CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_
7
[email protected]6a9b7372013-03-20 15:35:208#include <map>
[email protected]217d9562012-07-16 21:57:379
[email protected]6a9b7372013-03-20 15:35:2010#include "base/basictypes.h"
[email protected]8d86f13d2011-10-04 17:01:1911#include "base/compiler_specific.h"
[email protected]56b8d5c2011-10-07 00:28:3412#include "content/common/content_export.h"
[email protected]8d86f13d2011-10-04 17:01:1913#include "content/public/renderer/v8_value_converter.h"
14
[email protected]040b7852011-11-09 03:51:0915namespace base {
[email protected]2d58238b2012-05-09 20:30:1916class BinaryValue;
[email protected]040b7852011-11-09 03:51:0917class DictionaryValue;
18class ListValue;
19class Value;
20}
21
[email protected]3827e9702012-10-23 06:19:2822namespace content {
23
24class CONTENT_EXPORT V8ValueConverterImpl : public V8ValueConverter {
[email protected]8d86f13d2011-10-04 17:01:1925 public:
26 V8ValueConverterImpl();
27
[email protected]8d86f13d2011-10-04 17:01:1928 // V8ValueConverter implementation.
[email protected]3de391e82012-05-16 17:50:5129 virtual void SetDateAllowed(bool val) OVERRIDE;
[email protected]e0658bc2012-09-17 04:05:2430 virtual void SetRegExpAllowed(bool val) OVERRIDE;
31 virtual void SetFunctionAllowed(bool val) OVERRIDE;
[email protected]2a521842012-05-30 09:17:0632 virtual void SetStripNullFromObjects(bool val) OVERRIDE;
[email protected]8d86f13d2011-10-04 17:01:1933 virtual v8::Handle<v8::Value> ToV8Value(
[email protected]83820d42011-11-12 22:03:1134 const base::Value* value,
[email protected]8d86f13d2011-10-04 17:01:1935 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]6a9b7372013-03-20 15:35:2041 friend class ScopedAvoidIdentityHashForTesting;
[email protected]195487f2013-06-10 14:20:4142
43 class FromV8ValueState;
[email protected]6a9b7372013-03-20 15:35:2044
[email protected]83820d42011-11-12 22:03:1145 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]2d58238b2012-05-09 20:30:1949 v8::Handle<v8::Value> ToArrayBuffer(const base::BinaryValue* value) const;
[email protected]8d86f13d2011-10-04 17:01:1950
[email protected]217d9562012-07-16 21:57:3751 base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value,
[email protected]195487f2013-06-10 14:20:4152 FromV8ValueState* state) const;
[email protected]217d9562012-07-16 21:57:3753 base::Value* FromV8Array(v8::Handle<v8::Array> array,
[email protected]195487f2013-06-10 14:20:4154 FromV8ValueState* state) const;
[email protected]2d58238b2012-05-09 20:30:1955
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]217d9562012-07-16 21:57:3761 base::Value* FromV8Object(v8::Handle<v8::Object> object,
[email protected]195487f2013-06-10 14:20:4162 FromV8ValueState* state) const;
[email protected]8d86f13d2011-10-04 17:01:1963
[email protected]8d86f13d2011-10-04 17:01:1964 // If true, we will convert Date JavaScript objects to doubles.
[email protected]3de391e82012-05-16 17:50:5165 bool date_allowed_;
[email protected]8d86f13d2011-10-04 17:01:1966
[email protected]e0658bc2012-09-17 04:05:2467 // 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]2a521842012-05-30 09:17:0672
73 // If true, undefined and null values are ignored when converting v8 objects
74 // into Values.
75 bool strip_null_from_objects_;
[email protected]6a9b7372013-03-20 15:35:2076
77 bool avoid_identity_hash_for_testing_;
78
79 DISALLOW_COPY_AND_ASSIGN(V8ValueConverterImpl);
[email protected]8d86f13d2011-10-04 17:01:1980};
81
[email protected]3827e9702012-10-23 06:19:2882} // namespace content
83
[email protected]040b7852011-11-09 03:51:0984#endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_