[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] | 56b8d5c | 2011-10-07 00:28:34 | [diff] [blame^] | 12 | class CONTENT_EXPORT V8ValueConverterImpl : public content::V8ValueConverter { |
[email protected] | 8d86f13d | 2011-10-04 17:01:19 | [diff] [blame] | 13 | public: |
| 14 | V8ValueConverterImpl(); |
| 15 | |
| 16 | // Use the following setters to support additional types other than the |
| 17 | // default ones. |
| 18 | bool allow_undefined() const { return allow_undefined_; } |
| 19 | void set_allow_undefined(bool val) { allow_undefined_ = val; } |
| 20 | |
| 21 | bool allow_date() const { return allow_date_; } |
| 22 | void set_allow_date(bool val) { allow_date_ = val; } |
| 23 | |
| 24 | bool allow_regexp() const { return allow_regexp_; } |
| 25 | void set_allow_regexp(bool val) { allow_regexp_ = val; } |
| 26 | |
| 27 | // V8ValueConverter implementation. |
| 28 | virtual v8::Handle<v8::Value> ToV8Value( |
| 29 | base::Value* value, |
| 30 | v8::Handle<v8::Context> context) const OVERRIDE; |
| 31 | virtual base::Value* FromV8Value( |
| 32 | v8::Handle<v8::Value> value, |
| 33 | v8::Handle<v8::Context> context) const OVERRIDE; |
| 34 | |
| 35 | private: |
| 36 | v8::Handle<v8::Value> ToV8ValueImpl(base::Value* value) const; |
| 37 | v8::Handle<v8::Value> ToV8Array(base::ListValue* list) const; |
| 38 | v8::Handle<v8::Value> ToV8Object(base::DictionaryValue* dictionary) const; |
| 39 | |
| 40 | base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value) const; |
| 41 | base::ListValue* FromV8Array(v8::Handle<v8::Array> array) const; |
| 42 | base::DictionaryValue* FromV8Object(v8::Handle<v8::Object> object) const; |
| 43 | |
| 44 | // If true, we will convert undefined JavaScript values to null. |
| 45 | bool allow_undefined_; |
| 46 | |
| 47 | // If true, we will convert Date JavaScript objects to doubles. |
| 48 | bool allow_date_; |
| 49 | |
| 50 | // If true, we will convet RegExp JavaScript objects to string. |
| 51 | bool allow_regexp_; |
| 52 | }; |
| 53 | |
| 54 | #endif // CONTENT_RENDERER_V8_VALUE_CONVERTER_IMPL_H_ |