blob: 9639e423ed0976175e6c0be21a27292b6cf0eb01 [file] [log] [blame]
[email protected]8d86f13d2011-10-04 17:01:191// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// 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
8#include "base/compiler_specific.h"
[email protected]56b8d5c2011-10-07 00:28:349#include "content/common/content_export.h"
[email protected]8d86f13d2011-10-04 17:01:1910#include "content/public/renderer/v8_value_converter.h"
11
[email protected]040b7852011-11-09 03:51:0912namespace base {
13class DictionaryValue;
14class ListValue;
15class Value;
16}
17
[email protected]56b8d5c2011-10-07 00:28:3418class CONTENT_EXPORT V8ValueConverterImpl : public content::V8ValueConverter {
[email protected]8d86f13d2011-10-04 17:01:1919 public:
20 V8ValueConverterImpl();
21
22 // Use the following setters to support additional types other than the
23 // default ones.
24 bool allow_undefined() const { return allow_undefined_; }
25 void set_allow_undefined(bool val) { allow_undefined_ = val; }
26
27 bool allow_date() const { return allow_date_; }
28 void set_allow_date(bool val) { allow_date_ = val; }
29
30 bool allow_regexp() const { return allow_regexp_; }
31 void set_allow_regexp(bool val) { allow_regexp_ = val; }
32
33 // V8ValueConverter implementation.
34 virtual v8::Handle<v8::Value> ToV8Value(
35 base::Value* value,
36 v8::Handle<v8::Context> context) const OVERRIDE;
37 virtual base::Value* FromV8Value(
38 v8::Handle<v8::Value> value,
39 v8::Handle<v8::Context> context) const OVERRIDE;
40
41 private:
42 v8::Handle<v8::Value> ToV8ValueImpl(base::Value* value) const;
43 v8::Handle<v8::Value> ToV8Array(base::ListValue* list) const;
44 v8::Handle<v8::Value> ToV8Object(base::DictionaryValue* dictionary) const;
45
46 base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value) const;
47 base::ListValue* FromV8Array(v8::Handle<v8::Array> array) const;
48 base::DictionaryValue* FromV8Object(v8::Handle<v8::Object> object) const;
49
50 // If true, we will convert undefined JavaScript values to null.
51 bool allow_undefined_;
52
53 // If true, we will convert Date JavaScript objects to doubles.
54 bool allow_date_;
55
56 // If true, we will convet RegExp JavaScript objects to string.
57 bool allow_regexp_;
58};
59
[email protected]040b7852011-11-09 03:51:0960#endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_