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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 class DOMArrayBuffer; | 49 class DOMArrayBuffer; |
50 class ExceptionState; | 50 class ExceptionState; |
51 class MessagePort; | 51 class MessagePort; |
52 class WebBlobInfo; | 52 class WebBlobInfo; |
53 | 53 |
54 typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray; | 54 typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray; |
55 typedef Vector<RefPtr<DOMArrayBuffer>, 1> ArrayBufferArray; | 55 typedef Vector<RefPtr<DOMArrayBuffer>, 1> ArrayBufferArray; |
56 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; | 56 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; |
57 typedef Vector<blink::WebBlobInfo> WebBlobInfoArray; | 57 typedef Vector<blink::WebBlobInfo> WebBlobInfoArray; |
58 | 58 |
59 class SerializedScriptValue final : public ThreadSafeRefCounted<SerializedScript Value> { | 59 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue> { |
tasak
2014/11/14 08:07:39
Remove "final", because SerializedScriptValueForMo
| |
60 public: | 60 public: |
61 // Increment this for each incompatible change to the wire format. | 61 // Increment this for each incompatible change to the wire format. |
62 // Version 2: Added StringUCharTag for UChar v8 strings. | 62 // Version 2: Added StringUCharTag for UChar v8 strings. |
63 // Version 3: Switched to using uuids as blob data identifiers. | 63 // Version 3: Switched to using uuids as blob data identifiers. |
64 // Version 4: Extended File serialization to be complete. | 64 // Version 4: Extended File serialization to be complete. |
65 // Version 5: Added CryptoKeyTag for Key objects. | 65 // Version 5: Added CryptoKeyTag for Key objects. |
66 // Version 6: Added indexed serialization for File, Blob, and FileList. | 66 // Version 6: Added indexed serialization for File, Blob, and FileList. |
67 // Version 7: Extended File serialization with user visibility. | 67 // Version 7: Extended File serialization with user visibility. |
68 static const uint32_t wireFormatVersion = 7; | 68 static const uint32_t wireFormatVersion = 7; |
69 | 69 |
70 ~SerializedScriptValue(); | |
71 | |
72 // VarInt encoding constants. | 70 // VarInt encoding constants. |
73 static const int varIntShift = 7; | 71 static const int varIntShift = 7; |
74 static const int varIntMask = (1 << varIntShift) - 1; | 72 static const int varIntMask = (1 << varIntShift) - 1; |
75 | 73 |
76 // If a serialization error occurs (e.g., cyclic input value) this | 74 virtual ~SerializedScriptValue(); |
77 // function returns an empty representation, schedules a V8 exception to | |
78 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | |
79 // the caller must not invoke any V8 operations until control returns to | |
80 // V8. When serialization is successful, |didThrow| is false. | |
81 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*); | |
82 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); | |
83 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&); | |
84 static PassRefPtr<SerializedScriptValue> create(const String&); | |
85 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ; | |
86 static PassRefPtr<SerializedScriptValue> create(); | |
87 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, WebBlobI nfoArray*, ExceptionState&, v8::Isolate*); | |
88 | |
89 // Never throws exceptions. | |
90 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Isol ate*, v8::Handle<v8::Value>); | |
91 | 75 |
92 static PassRefPtr<SerializedScriptValue> nullValue(); | 76 static PassRefPtr<SerializedScriptValue> nullValue(); |
93 | 77 |
94 String toWireString() const { return m_data; } | 78 String toWireString() const { return m_data; } |
95 void toWireBytes(Vector<char>&) const; | 79 void toWireBytes(Vector<char>&) const; |
96 | 80 |
97 // Deserializes the value (in the current context). Returns a null value in | 81 // Deserializes the value (in the current context). Returns a null value in |
98 // case of failure. | 82 // case of failure. |
99 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); | 83 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); |
100 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const WebBlobInfoArray* = 0); | 84 virtual v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const WebBlobInfoArray* = 0); |
101 | 85 |
102 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray. | 86 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray. |
103 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 | 87 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 |
104 // of the HTML5 spec and generates exceptions as appropriate. | 88 // of the HTML5 spec and generates exceptions as appropriate. |
105 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type. | 89 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type. |
106 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Me ssagePortArray&, ArrayBufferArray&, ExceptionState&); | 90 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Me ssagePortArray&, ArrayBufferArray&, ExceptionState&); |
107 | 91 |
108 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute | 92 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute |
109 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. | 93 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. |
110 // Ok to invoke multiple times (only adds memory once). | 94 // Ok to invoke multiple times (only adds memory once). |
111 // The memory registration is revoked automatically in destructor. | 95 // The memory registration is revoked automatically in destructor. |
112 void registerMemoryAllocatedWithCurrentScriptContext(); | 96 void registerMemoryAllocatedWithCurrentScriptContext(); |
113 | 97 |
114 private: | 98 protected: |
115 enum StringDataMode { | 99 enum StringDataMode { |
116 StringValue, | 100 StringValue, |
117 WireData | 101 WireData |
118 }; | 102 }; |
119 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 103 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
120 | 104 |
121 SerializedScriptValue(); | 105 SerializedScriptValue(); |
122 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, WebBlobInfoArray*, ExceptionState&, v8::Isolate*); | 106 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, WebBlobInfoArray*, ExceptionState&, v8::Isolate*); |
123 explicit SerializedScriptValue(const String& wireData); | 107 explicit SerializedScriptValue(const String& wireData); |
124 | 108 |
125 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(v8::Isolate *, ArrayBufferArray&, ExceptionState&); | 109 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } |
110 String& data() { return m_data; } | |
111 void setData(const String& data) { m_data = data; } | |
112 void transferArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&); | |
113 ArrayBufferContentsArray* arrayBufferContentsArray() { return m_arrayBufferC ontentsArray.get(); } | |
114 | |
115 private: | |
116 static PassOwnPtr<ArrayBufferContentsArray> createArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&); | |
126 | 117 |
127 String m_data; | 118 String m_data; |
128 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 119 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
129 BlobDataHandleMap m_blobDataHandles; | 120 BlobDataHandleMap m_blobDataHandles; |
130 intptr_t m_externallyAllocatedMemory; | 121 intptr_t m_externallyAllocatedMemory; |
122 | |
123 friend class SerializedScriptValueFactory; | |
tasak
2014/11/14 08:07:39
Make it possible for factory class to create Seria
| |
131 }; | 124 }; |
132 | 125 |
133 } // namespace blink | 126 } // namespace blink |
134 | 127 |
135 #endif // SerializedScriptValue_h | 128 #endif // SerializedScriptValue_h |
OLD | NEW |