OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef SerializedScriptValue_h | 31 #ifndef SerializedScriptValue_h |
32 #define SerializedScriptValue_h | 32 #define SerializedScriptValue_h |
33 | 33 |
34 #include "bindings/v8/ScriptValue.h" | 34 #include "bindings/v8/ScriptValue.h" |
35 | 35 |
36 #include "wtf/HashMap.h" | |
36 #include "wtf/ThreadSafeRefCounted.h" | 37 #include "wtf/ThreadSafeRefCounted.h" |
37 #include <v8.h> | 38 #include <v8.h> |
38 | 39 |
39 namespace WTF { | 40 namespace WTF { |
40 | 41 |
41 class ArrayBuffer; | 42 class ArrayBuffer; |
42 class ArrayBufferContents; | 43 class ArrayBufferContents; |
43 | 44 |
44 } | 45 } |
45 | 46 |
46 namespace WebCore { | 47 namespace WebCore { |
47 | 48 |
49 class BlobDataHandle; | |
48 class MessagePort; | 50 class MessagePort; |
49 | 51 |
50 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 52 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; |
51 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 53 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; |
54 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; | |
52 | 55 |
53 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue> { | 56 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue> { |
54 public: | 57 public: |
55 // Increment this for each incompatible change to the wire format. | 58 // Increment this for each incompatible change to the wire format. |
56 // Version 2: Added StringUCharTag for UChar v8 strings. | 59 // Version 2: Added StringUCharTag for UChar v8 strings. |
57 static const uint32_t wireFormatVersion = 2; | 60 // Version 3: Switched to using uuids as blob data identifiers. |
61 static const uint32_t wireFormatVersion = 3; | |
58 | 62 |
59 virtual ~SerializedScriptValue(); | 63 virtual ~SerializedScriptValue(); |
60 | 64 |
61 // If a serialization error occurs (e.g., cyclic input value) this | 65 // If a serialization error occurs (e.g., cyclic input value) this |
62 // function returns an empty representation, schedules a V8 exception to | 66 // function returns an empty representation, schedules a V8 exception to |
63 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 67 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
64 // the caller must not invoke any V8 operations until control returns to | 68 // the caller must not invoke any V8 operations until control returns to |
65 // V8. When serialization is successful, |didThrow| is false. | 69 // V8. When serialization is successful, |didThrow| is false. |
66 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*); | 70 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*); |
67 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, v8::I solate*); | 71 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, v8::I solate*); |
(...skipping 20 matching lines...) Expand all Loading... | |
88 String toWireString() const { return m_data; } | 92 String toWireString() const { return m_data; } |
89 void toWireBytes(Vector<char>&) const; | 93 void toWireBytes(Vector<char>&) const; |
90 | 94 |
91 // Deserializes the value (in the current context). Returns a null value in | 95 // Deserializes the value (in the current context). Returns a null value in |
92 // case of failure. | 96 // case of failure. |
93 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); | 97 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); |
94 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); | 98 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); |
95 | 99 |
96 ScriptValue deserializeForInspector(ScriptState*); | 100 ScriptValue deserializeForInspector(ScriptState*); |
97 | 101 |
98 const Vector<String>& blobURLs() const { return m_blobURLs; } | 102 // Only reflects the truth if the SSV was created by walking a v8 value, not reliable |
jsbell
2013/10/02 22:24:41
I think the only callers of this basically do:
SS
| |
103 // if the SSV was created createdFromWire(data). | |
104 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); } | |
99 | 105 |
100 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute | 106 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute |
101 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. | 107 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. |
102 // Ok to invoke multiple times (only adds memory once). | 108 // Ok to invoke multiple times (only adds memory once). |
103 // The memory registration is revoked automatically in destructor. | 109 // The memory registration is revoked automatically in destructor. |
104 void registerMemoryAllocatedWithCurrentScriptContext(); | 110 void registerMemoryAllocatedWithCurrentScriptContext(); |
105 | 111 |
106 private: | 112 private: |
107 enum StringDataMode { | 113 enum StringDataMode { |
108 StringValue, | 114 StringValue, |
109 WireData | 115 WireData |
110 }; | 116 }; |
111 enum ExceptionPolicy { | 117 enum ExceptionPolicy { |
112 ThrowExceptions, | 118 ThrowExceptions, |
113 DoNotThrowExceptions | 119 DoNotThrowExceptions |
114 }; | 120 }; |
115 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 121 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
116 | 122 |
117 SerializedScriptValue(); | 123 SerializedScriptValue(); |
118 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowExceptions); | 124 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowExceptions); |
119 explicit SerializedScriptValue(const String& wireData); | 125 explicit SerializedScriptValue(const String& wireData); |
120 | 126 |
121 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*); | 127 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*); |
122 | 128 |
123 String m_data; | 129 String m_data; |
124 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 130 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
125 Vector<String> m_blobURLs; | 131 BlobDataHandleMap m_blobDataHandles; |
126 intptr_t m_externallyAllocatedMemory; | 132 intptr_t m_externallyAllocatedMemory; |
127 }; | 133 }; |
128 | 134 |
129 } // namespace WebCore | 135 } // namespace WebCore |
130 | 136 |
131 #endif // SerializedScriptValue_h | 137 #endif // SerializedScriptValue_h |
OLD | NEW |