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 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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/core/v8/ScriptValue.h" | 34 #include "bindings/core/v8/ScriptValue.h" |
35 #include "bindings/core/v8/Transferable.h" | 35 #include "bindings/core/v8/Transferables.h" |
36 #include "core/CoreExport.h" | 36 #include "core/CoreExport.h" |
37 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
38 #include "wtf/ThreadSafeRefCounted.h" | 38 #include "wtf/ThreadSafeRefCounted.h" |
39 #include <v8.h> | 39 #include <v8.h> |
40 | 40 |
41 namespace WTF { | 41 namespace WTF { |
42 | 42 |
43 class ArrayBufferContents; | 43 class ArrayBufferContents; |
44 | 44 |
45 } | 45 } |
46 | 46 |
47 namespace blink { | 47 namespace blink { |
48 | 48 |
49 class BlobDataHandle; | 49 class BlobDataHandle; |
| 50 class Transferables; |
50 class ExceptionState; | 51 class ExceptionState; |
51 class StaticBitmapImage; | 52 class StaticBitmapImage; |
52 class TransferableArrayBuffer; | |
53 class TransferableImageBitmap; | |
54 class MessagePort; | |
55 class WebBlobInfo; | 53 class WebBlobInfo; |
56 | 54 |
57 typedef HeapVector<Member<MessagePort>, 1> MessagePortArray; | |
58 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap; | 55 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap; |
59 typedef Vector<WebBlobInfo> WebBlobInfoArray; | 56 typedef Vector<WebBlobInfo> WebBlobInfoArray; |
60 typedef HeapVector<Member<Transferable>> TransferableArray; | |
61 | 57 |
62 class CORE_EXPORT SerializedScriptValue : public ThreadSafeRefCounted<Serialized
ScriptValue> { | 58 class CORE_EXPORT SerializedScriptValue : public ThreadSafeRefCounted<Serialized
ScriptValue> { |
63 public: | 59 public: |
64 // Increment this for each incompatible change to the wire format. | 60 // Increment this for each incompatible change to the wire format. |
65 // Version 2: Added StringUCharTag for UChar v8 strings. | 61 // Version 2: Added StringUCharTag for UChar v8 strings. |
66 // Version 3: Switched to using uuids as blob data identifiers. | 62 // Version 3: Switched to using uuids as blob data identifiers. |
67 // Version 4: Extended File serialization to be complete. | 63 // Version 4: Extended File serialization to be complete. |
68 // Version 5: Added CryptoKeyTag for Key objects. | 64 // Version 5: Added CryptoKeyTag for Key objects. |
69 // Version 6: Added indexed serialization for File, Blob, and FileList. | 65 // Version 6: Added indexed serialization for File, Blob, and FileList. |
70 // Version 7: Extended File serialization with user visibility. | 66 // Version 7: Extended File serialization with user visibility. |
(...skipping 14 matching lines...) Expand all Loading... |
85 | 81 |
86 // Deserializes the value (in the current context). Returns a null value in | 82 // Deserializes the value (in the current context). Returns a null value in |
87 // case of failure. | 83 // case of failure. |
88 v8::Local<v8::Value> deserialize(MessagePortArray* = 0); | 84 v8::Local<v8::Value> deserialize(MessagePortArray* = 0); |
89 v8::Local<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const
WebBlobInfoArray* = 0); | 85 v8::Local<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const
WebBlobInfoArray* = 0); |
90 | 86 |
91 // Helper function which pulls the values out of a JS sequence and into a Me
ssagePortArray. | 87 // Helper function which pulls the values out of a JS sequence and into a Me
ssagePortArray. |
92 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL
spec and section 8.3.3 | 88 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL
spec and section 8.3.3 |
93 // of the HTML5 spec and generates exceptions as appropriate. | 89 // of the HTML5 spec and generates exceptions as appropriate. |
94 // Returns true if the array was filled, or false if the passed value was no
t of an appropriate type. | 90 // Returns true if the array was filled, or false if the passed value was no
t of an appropriate type. |
95 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Tr
ansferableArray&, ExceptionState&); | 91 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Tr
ansferables&, ExceptionState&); |
96 | 92 |
97 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute | 93 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute |
98 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. | 94 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. |
99 // Ok to invoke multiple times (only adds memory once). | 95 // Ok to invoke multiple times (only adds memory once). |
100 // The memory registration is revoked automatically in destructor. | 96 // The memory registration is revoked automatically in destructor. |
101 void registerMemoryAllocatedWithCurrentScriptContext(); | 97 void registerMemoryAllocatedWithCurrentScriptContext(); |
102 | 98 |
103 // Returns true if the value contains a transferable ArrayBuffer. | 99 // Returns true if the value contains a transferable ArrayBuffer. |
104 bool containsTransferableArrayBuffer() const; | 100 bool containsTransferableArrayBuffer() const; |
105 | 101 |
106 private: | 102 private: |
107 // The followings are private, but used by SerializedScriptValueFactory. | 103 // The followings are private, but used by SerializedScriptValueFactory. |
108 enum StringDataMode { | 104 enum StringDataMode { |
109 StringValue, | 105 StringValue, |
110 WireData | 106 WireData |
111 }; | 107 }; |
112 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 108 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
113 typedef Vector<RefPtr<StaticBitmapImage>, 1> ImageBitmapContentsArray; | 109 typedef Vector<RefPtr<StaticBitmapImage>, 1> ImageBitmapContentsArray; |
114 | 110 |
115 SerializedScriptValue(); | 111 SerializedScriptValue(); |
116 explicit SerializedScriptValue(const String& wireData); | 112 explicit SerializedScriptValue(const String& wireData); |
117 | 113 |
118 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } | 114 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } |
119 String& data() { return m_data; } | 115 String& data() { return m_data; } |
120 void setData(const String& data) { m_data = data; } | 116 void setData(const String& data) { m_data = data; } |
121 void transferArrayBuffers(v8::Isolate*, TransferableArrayBuffer*, ExceptionS
tate&); | 117 void transferArrayBuffers(v8::Isolate*, const ArrayBufferArray&, ExceptionSt
ate&); |
122 void transferImageBitmaps(v8::Isolate*, TransferableImageBitmap*, ExceptionS
tate&); | 118 void transferImageBitmaps(v8::Isolate*, const ImageBitmapArray&, ExceptionSt
ate&); |
123 ArrayBufferContentsArray* getArrayBufferContentsArray() { return m_arrayBuff
erContentsArray.get(); } | 119 ArrayBufferContentsArray* getArrayBufferContentsArray() { return m_arrayBuff
erContentsArray.get(); } |
124 ImageBitmapContentsArray* getImageBitmapContentsArray() { return m_imageBitm
apContentsArray.get(); } | 120 ImageBitmapContentsArray* getImageBitmapContentsArray() { return m_imageBitm
apContentsArray.get(); } |
125 | 121 |
126 static PassOwnPtr<ArrayBufferContentsArray> createArrayBuffers(v8::Isolate*,
TransferableArrayBuffer*, ExceptionState&); | |
127 static PassOwnPtr<ImageBitmapContentsArray> createImageBitmaps(v8::Isolate*,
TransferableImageBitmap*, ExceptionState&); | |
128 | |
129 private: | 122 private: |
130 String m_data; | 123 String m_data; |
131 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 124 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
132 OwnPtr<ImageBitmapContentsArray> m_imageBitmapContentsArray; | 125 OwnPtr<ImageBitmapContentsArray> m_imageBitmapContentsArray; |
133 BlobDataHandleMap m_blobDataHandles; | 126 BlobDataHandleMap m_blobDataHandles; |
134 intptr_t m_externallyAllocatedMemory; | 127 intptr_t m_externallyAllocatedMemory; |
135 | 128 |
136 friend class SerializedScriptValueFactory; | 129 friend class SerializedScriptValueFactory; |
137 }; | 130 }; |
138 | 131 |
139 } // namespace blink | 132 } // namespace blink |
140 | 133 |
141 #endif // SerializedScriptValue_h | 134 #endif // SerializedScriptValue_h |
OLD | NEW |