| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_RENDERER_V8_VALUE_CONVERTER_H_ | 5 #ifndef CHROME_RENDERER_V8_VALUE_CONVERTER_H_ |
| 6 #define CHROME_RENDERER_V8_VALUE_CONVERTER_H_ | 6 #define CHROME_RENDERER_V8_VALUE_CONVERTER_H_ |
| 7 | 7 |
| 8 #include "v8/include/v8.h" | 8 #include "v8/include/v8.h" |
| 9 | 9 |
| 10 namespace base { |
| 11 class DictionaryValue; |
| 12 class ListValue; |
| 10 class Value; | 13 class Value; |
| 11 class ListValue; | 14 } |
| 12 class DictionaryValue; | |
| 13 | 15 |
| 14 // Converts between v8::Value (JavaScript values in the v8 heap) and Chrome's | 16 // Converts between v8::Value (JavaScript values in the v8 heap) and Chrome's |
| 15 // values (from base/values.h). Lists and dictionaries are converted | 17 // values (from base/values.h). Lists and dictionaries are converted |
| 16 // recursively. | 18 // recursively. |
| 17 // | 19 // |
| 18 // Only the JSON types (null, boolean, string, number, array, and object) are | 20 // Only the JSON types (null, boolean, string, number, array, and object) are |
| 19 // supported by default. Additional types can be allowed with e.g. | 21 // supported by default. Additional types can be allowed with e.g. |
| 20 // set_allow_date(), set_allow_regexp(). | 22 // set_allow_date(), set_allow_regexp(). |
| 21 class V8ValueConverter { | 23 class V8ValueConverter { |
| 22 public: | 24 public: |
| 23 V8ValueConverter(); | 25 V8ValueConverter(); |
| 24 | 26 |
| 25 bool allow_undefined() const { return allow_undefined_; } | 27 bool allow_undefined() const { return allow_undefined_; } |
| 26 void set_allow_undefined(bool val) { allow_undefined_ = val; } | 28 void set_allow_undefined(bool val) { allow_undefined_ = val; } |
| 27 | 29 |
| 28 bool allow_date() const { return allow_date_; } | 30 bool allow_date() const { return allow_date_; } |
| 29 void set_allow_date(bool val) { allow_date_ = val; } | 31 void set_allow_date(bool val) { allow_date_ = val; } |
| 30 | 32 |
| 31 bool allow_regexp() const { return allow_regexp_; } | 33 bool allow_regexp() const { return allow_regexp_; } |
| 32 void set_allow_regexp(bool val) { allow_regexp_ = val; } | 34 void set_allow_regexp(bool val) { allow_regexp_ = val; } |
| 33 | 35 |
| 34 // Converts Value to v8::Value. Unsupported types are replaced with null. | 36 // Converts Value to v8::Value. Unsupported types are replaced with null. |
| 35 // If an array or object throws while setting a value, that property or item | 37 // If an array or object throws while setting a value, that property or item |
| 36 // is skipped, leaving a hole in the case of arrays. | 38 // is skipped, leaving a hole in the case of arrays. |
| 37 v8::Handle<v8::Value> ToV8Value(Value* value, | 39 v8::Handle<v8::Value> ToV8Value(base::Value* value, |
| 38 v8::Handle<v8::Context> context) const; | 40 v8::Handle<v8::Context> context) const; |
| 39 | 41 |
| 40 // Converts v8::Value to Value. Unsupported types are replaced with null. | 42 // Converts v8::Value to Value. Unsupported types are replaced with null. |
| 41 // If an array or object throws while getting a value, that property or item | 43 // If an array or object throws while getting a value, that property or item |
| 42 // is replaced with null. | 44 // is replaced with null. |
| 43 Value* FromV8Value(v8::Handle<v8::Value> value, | 45 base::Value* FromV8Value(v8::Handle<v8::Value> value, |
| 44 v8::Handle<v8::Context> context) const; | 46 v8::Handle<v8::Context> context) const; |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 v8::Handle<v8::Value> ToV8ValueImpl(Value* value) const; | 49 v8::Handle<v8::Value> ToV8ValueImpl(base::Value* value) const; |
| 48 v8::Handle<v8::Value> ToV8Array(ListValue* list) const; | 50 v8::Handle<v8::Value> ToV8Array(base::ListValue* list) const; |
| 49 v8::Handle<v8::Value> ToV8Object(DictionaryValue* dictionary) const; | 51 v8::Handle<v8::Value> ToV8Object(base::DictionaryValue* dictionary) const; |
| 50 | 52 |
| 51 Value* FromV8ValueImpl(v8::Handle<v8::Value> value) const; | 53 base::Value* FromV8ValueImpl(v8::Handle<v8::Value> value) const; |
| 52 ListValue* FromV8Array(v8::Handle<v8::Array> array) const; | 54 base::ListValue* FromV8Array(v8::Handle<v8::Array> array) const; |
| 53 DictionaryValue* FromV8Object(v8::Handle<v8::Object> object) const; | 55 base::DictionaryValue* FromV8Object(v8::Handle<v8::Object> object) const; |
| 54 | 56 |
| 55 // If true, we will convert undefined JavaScript values to null. | 57 // If true, we will convert undefined JavaScript values to null. |
| 56 bool allow_undefined_; | 58 bool allow_undefined_; |
| 57 | 59 |
| 58 // If true, we will convert Date JavaScript objects to doubles. | 60 // If true, we will convert Date JavaScript objects to doubles. |
| 59 bool allow_date_; | 61 bool allow_date_; |
| 60 | 62 |
| 61 // If true, we will convet RegExp JavaScript objects to string. | 63 // If true, we will convet RegExp JavaScript objects to string. |
| 62 bool allow_regexp_; | 64 bool allow_regexp_; |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 #endif // CHROME_RENDERER_V8_VALUE_CONVERTER_H_ | 67 #endif // CHROME_RENDERER_V8_VALUE_CONVERTER_H_ |
| OLD | NEW |