[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 1 | // 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] | 56b8d5c | 2011-10-07 00:28:34 | [diff] [blame] | 9 | #include "content/common/content_export.h" |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 10 | #include "content/public/renderer/v8_value_converter.h" |
| 11 | |
[email protected] | 040b785 | 2011-11-09 03:51:09 | [diff] [blame^] | 12 | namespace base { |
| 13 | class DictionaryValue; |
| 14 | class ListValue; |
| 15 | class Value; |
| 16 | } |
| 17 | |
[email protected] | 56b8d5c | 2011-10-07 00:28:34 | [diff] [blame] | 18 | class CONTENT_EXPORT V8ValueConverterImpl : public content::V8ValueConverter { |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 19 | 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] | 040b785 | 2011-11-09 03:51:09 | [diff] [blame^] | 60 | #endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |