| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ | 5 #ifndef CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ |
| 6 #define CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ | 6 #define CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ |
| 7 | 7 |
| 8 #include "content/common/content_export.h" | 8 #include "content/common/content_export.h" |
| 9 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 class Value; | 12 class Value; |
| 13 } | 13 } |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 // Converts between v8::Value (JavaScript values in the v8 heap) and Chrome's | 17 // Converts between v8::Value (JavaScript values in the v8 heap) and Chrome's |
| 18 // values (from base/values.h). Lists and dictionaries are converted | 18 // values (from base/values.h). Lists and dictionaries are converted |
| 19 // recursively. | 19 // recursively. |
| 20 // | 20 // |
| 21 // Only the JSON types (null, boolean, string, number, array, and object) are | 21 // The JSON types (null, boolean, string, number, array, and object) as well as |
| 22 // supported. | 22 // binary values are supported. For binary values, we convert to WebKit |
| 23 // ArrayBuffers, and support converting from an ArrayBuffer or any of the |
| 24 // ArrayBufferView subclasses (Uint8Array, etc.). |
| 23 class CONTENT_EXPORT V8ValueConverter { | 25 class CONTENT_EXPORT V8ValueConverter { |
| 24 public: | 26 public: |
| 25 static V8ValueConverter* create(); | 27 static V8ValueConverter* create(); |
| 26 | 28 |
| 27 virtual ~V8ValueConverter() {} | 29 virtual ~V8ValueConverter() {} |
| 28 | 30 |
| 29 // Converts Value to v8::Value. Unsupported types are replaced with null. | 31 // Converts Value to v8::Value. Unsupported types are replaced with null. |
| 30 // If an array or object throws while setting a value, that property or item | 32 // If an array or object throws while setting a value, that property or item |
| 31 // is skipped, leaving a hole in the case of arrays. | 33 // is skipped, leaving a hole in the case of arrays. |
| 32 virtual v8::Handle<v8::Value> ToV8Value( | 34 virtual v8::Handle<v8::Value> ToV8Value( |
| 33 const base::Value* value, | 35 const base::Value* value, |
| 34 v8::Handle<v8::Context> context) const = 0; | 36 v8::Handle<v8::Context> context) const = 0; |
| 35 | 37 |
| 36 // Converts v8::Value to Value. Unsupported types are replaced with null. | 38 // Converts v8::Value to Value. Unsupported types are replaced with null. |
| 37 // If an array or object throws while getting a value, that property or item | 39 // If an array or object throws while getting a value, that property or item |
| 38 // is replaced with null. | 40 // is replaced with null. |
| 39 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, | 41 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, |
| 40 v8::Handle<v8::Context> context) const = 0; | 42 v8::Handle<v8::Context> context) const = 0; |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 } // namespace content | 45 } // namespace content |
| 44 | 46 |
| 45 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ | 47 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ |
| OLD | NEW |