OLD | NEW |
---|---|
1 // Copyright (c) 2012 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 // Extends the default behaviour of V8ValueConverter. | |
18 class CONTENT_EXPORT V8ValueConverterStrategy { | |
19 public: | |
20 // If false is returned, V8ValueConverter proceeds with the default behavior. | |
21 virtual bool ToV8Value(const base::Value* value, | |
22 v8::Handle<v8::Value>* out) const = 0; | |
23 // If false is returned, V8ValueConverter proceeds with the default behavior. | |
24 virtual bool FromV8Value(v8::Handle<v8::Value> value, | |
25 base::Value** out) const = 0; | |
not at google - send to devlin
2013/07/22 21:44:57
make this a member class of Strategy of V8ValueCon
pmarch
2013/07/22 23:06:55
Done.
| |
26 }; | |
27 | |
17 // Converts between v8::Value (JavaScript values in the v8 heap) and Chrome's | 28 // Converts between v8::Value (JavaScript values in the v8 heap) and Chrome's |
18 // values (from base/values.h). Lists and dictionaries are converted | 29 // values (from base/values.h). Lists and dictionaries are converted |
19 // recursively. | 30 // recursively. |
20 // | 31 // |
21 // The JSON types (null, boolean, string, number, array, and object) as well as | 32 // The JSON types (null, boolean, string, number, array, and object) as well as |
22 // binary values are supported. For binary values, we convert to WebKit | 33 // binary values are supported. For binary values, we convert to WebKit |
23 // ArrayBuffers, and support converting from an ArrayBuffer or any of the | 34 // ArrayBuffers, and support converting from an ArrayBuffer or any of the |
24 // ArrayBufferView subclasses (Uint8Array, etc.). | 35 // ArrayBufferView subclasses (Uint8Array, etc.). |
25 class CONTENT_EXPORT V8ValueConverter { | 36 class CONTENT_EXPORT V8ValueConverter { |
26 public: | 37 public: |
(...skipping 18 matching lines...) Expand all Loading... | |
45 // If true, Function objects are converted into DictionaryValues with whatever | 56 // If true, Function objects are converted into DictionaryValues with whatever |
46 // additional properties has been set on them. | 57 // additional properties has been set on them. |
47 // | 58 // |
48 // Otherwise they are treated as unsupported, see FromV8Value. | 59 // Otherwise they are treated as unsupported, see FromV8Value. |
49 virtual void SetFunctionAllowed(bool val) = 0; | 60 virtual void SetFunctionAllowed(bool val) = 0; |
50 | 61 |
51 // If true, null values are stripped from objects. This is often useful when | 62 // If true, null values are stripped from objects. This is often useful when |
52 // converting arguments to extension APIs. | 63 // converting arguments to extension APIs. |
53 virtual void SetStripNullFromObjects(bool val) = 0; | 64 virtual void SetStripNullFromObjects(bool val) = 0; |
54 | 65 |
66 // Extend default behavior of V8ValueConverter. | |
67 virtual void SetStrategy(V8ValueConverterStrategy* strategy) = 0; | |
68 | |
55 // Converts a base::Value to a v8::Value. | 69 // Converts a base::Value to a v8::Value. |
56 // | 70 // |
57 // Unsupported types are replaced with null. If an array or object throws | 71 // Unsupported types are replaced with null. If an array or object throws |
58 // while setting a value, that property or item is skipped, leaving a hole in | 72 // while setting a value, that property or item is skipped, leaving a hole in |
59 // the case of arrays. | 73 // the case of arrays. |
60 virtual v8::Handle<v8::Value> ToV8Value( | 74 virtual v8::Handle<v8::Value> ToV8Value( |
61 const base::Value* value, | 75 const base::Value* value, |
62 v8::Handle<v8::Context> context) const = 0; | 76 v8::Handle<v8::Context> context) const = 0; |
63 | 77 |
64 // Converts a v8::Value to base::Value. | 78 // Converts a v8::Value to base::Value. |
65 // | 79 // |
66 // Unsupported types (unless explicitly configured) are not converted, so | 80 // Unsupported types (unless explicitly configured) are not converted, so |
67 // this method may return NULL -- the exception is when converting arrays, | 81 // this method may return NULL -- the exception is when converting arrays, |
68 // where unsupported types are converted to Value(TYPE_NULL). | 82 // where unsupported types are converted to Value(TYPE_NULL). |
69 // | 83 // |
70 // Likewise, if an object throws while converting a property it will not be | 84 // Likewise, if an object throws while converting a property it will not be |
71 // converted, whereas if an array throws while converting an item it will be | 85 // converted, whereas if an array throws while converting an item it will be |
72 // converted to Value(TYPE_NULL). | 86 // converted to Value(TYPE_NULL). |
73 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, | 87 virtual base::Value* FromV8Value(v8::Handle<v8::Value> value, |
74 v8::Handle<v8::Context> context) const = 0; | 88 v8::Handle<v8::Context> context) const = 0; |
75 }; | 89 }; |
76 | 90 |
77 } // namespace content | 91 } // namespace content |
78 | 92 |
79 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ | 93 #endif // CONTENT_PUBLIC_RENDERER_V8_VALUE_CONVERTER_H_ |
OLD | NEW |