Chromium Code Reviews| 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/v8/ScriptValue.h" | 34 #include "bindings/v8/ScriptValue.h" |
| 35 | |
| 36 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
| 37 #include "wtf/ThreadSafeRefCounted.h" | 36 #include "wtf/ThreadSafeRefCounted.h" |
| 38 #include <v8.h> | 37 #include <v8.h> |
| 39 | 38 |
| 39 namespace blink { | |
| 40 | |
| 41 class WebBlobInfo; | |
| 42 | |
| 43 } | |
| 44 | |
| 40 namespace WTF { | 45 namespace WTF { |
| 41 | 46 |
| 42 class ArrayBuffer; | 47 class ArrayBuffer; |
| 43 class ArrayBufferContents; | 48 class ArrayBufferContents; |
| 44 | 49 |
| 45 } | 50 } |
| 46 | 51 |
| 47 namespace WebCore { | 52 namespace WebCore { |
| 48 | 53 |
| 49 class BlobDataHandle; | 54 class BlobDataHandle; |
| 50 class ExceptionState; | 55 class ExceptionState; |
| 51 class MessagePort; | 56 class MessagePort; |
| 52 | 57 |
| 53 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 58 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; |
| 54 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 59 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; |
| 55 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; | 60 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; |
|
jsbell
2014/04/03 18:16:33
Add a WebBlobInfoArray typedef?
ericu
2014/04/07 23:14:20
Done.
| |
| 56 | 61 |
| 57 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript Value> { | 62 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript Value> { |
| 58 public: | 63 public: |
| 59 // Increment this for each incompatible change to the wire format. | 64 // Increment this for each incompatible change to the wire format. |
| 60 // Version 2: Added StringUCharTag for UChar v8 strings. | 65 // Version 2: Added StringUCharTag for UChar v8 strings. |
| 61 // Version 3: Switched to using uuids as blob data identifiers. | 66 // Version 3: Switched to using uuids as blob data identifiers. |
| 62 // Version 4: Extended File serialization to be complete. | 67 // Version 4: Extended File serialization to be complete. |
| 63 // Version 5: Added CryptoKeyTag for Key objects. | 68 // Version 5: Added CryptoKeyTag for Key objects. |
| 64 static const uint32_t wireFormatVersion = 5; | 69 static const uint32_t wireFormatVersion = 5; |
| 65 | 70 |
| 66 ~SerializedScriptValue(); | 71 ~SerializedScriptValue(); |
| 67 | 72 |
| 68 // If a serialization error occurs (e.g., cyclic input value) this | 73 // If a serialization error occurs (e.g., cyclic input value) this |
| 69 // function returns an empty representation, schedules a V8 exception to | 74 // function returns an empty representation, schedules a V8 exception to |
| 70 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 75 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
| 71 // the caller must not invoke any V8 operations until control returns to | 76 // the caller must not invoke any V8 operations until control returns to |
| 72 // V8. When serialization is successful, |didThrow| is false. | 77 // V8. When serialization is successful, |didThrow| is false. |
| 73 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*); | 78 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*); |
| 74 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); | 79 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); |
| 75 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&); | 80 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&); |
| 76 static PassRefPtr<SerializedScriptValue> create(const String&); | 81 static PassRefPtr<SerializedScriptValue> create(const String&); |
| 77 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ; | 82 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ; |
| 78 static PassRefPtr<SerializedScriptValue> create(); | 83 static PassRefPtr<SerializedScriptValue> create(); |
| 79 | 84 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, Vector<b link::WebBlobInfo>*, ExceptionState&, ScriptState*); |
| 80 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, Exceptio nState&, ScriptState*); | |
| 81 | 85 |
| 82 // Never throws exceptions. | 86 // Never throws exceptions. |
| 83 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*); | 87 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*); |
| 84 | 88 |
| 85 static PassRefPtr<SerializedScriptValue> nullValue(); | 89 static PassRefPtr<SerializedScriptValue> nullValue(); |
| 86 | 90 |
| 87 String toWireString() const { return m_data; } | 91 String toWireString() const { return m_data; } |
| 88 void toWireBytes(Vector<char>&) const; | 92 void toWireBytes(Vector<char>&) const; |
| 89 | 93 |
| 90 // Deserializes the value (in the current context). Returns a null value in | 94 // Deserializes the value (in the current context). Returns a null value in |
| 91 // case of failure. | 95 // case of failure. |
| 92 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); | 96 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); |
| 93 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); | 97 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const |
| 98 Vector<blink::WebBlobInfo>* = 0); | |
| 94 | 99 |
| 95 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray. | 100 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray. |
| 96 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 | 101 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 |
| 97 // of the HTML5 spec and generates exceptions as appropriate. | 102 // of the HTML5 spec and generates exceptions as appropriate. |
| 98 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type. | 103 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type. |
| 99 static bool extractTransferables(v8::Local<v8::Value>, int, MessagePortArray &, ArrayBufferArray&, ExceptionState&, v8::Isolate*); | 104 static bool extractTransferables(v8::Local<v8::Value>, int, MessagePortArray &, ArrayBufferArray&, ExceptionState&, v8::Isolate*); |
| 100 | 105 |
| 101 // Only reflects the truth if the SSV was created by walking a v8 value, not reliable | 106 // Only reflects the truth if the SSV was created by walking a v8 value, not reliable |
| 102 // if the SSV was created createdFromWire(data). | 107 // if the SSV was created createdFromWire(data). |
| 103 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); } | 108 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); } |
| 104 | 109 |
| 105 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute | 110 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute |
| 106 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. | 111 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. |
| 107 // Ok to invoke multiple times (only adds memory once). | 112 // Ok to invoke multiple times (only adds memory once). |
| 108 // The memory registration is revoked automatically in destructor. | 113 // The memory registration is revoked automatically in destructor. |
| 109 void registerMemoryAllocatedWithCurrentScriptContext(); | 114 void registerMemoryAllocatedWithCurrentScriptContext(); |
| 110 | 115 |
| 111 private: | 116 private: |
| 112 enum StringDataMode { | 117 enum StringDataMode { |
| 113 StringValue, | 118 StringValue, |
| 114 WireData | 119 WireData |
| 115 }; | 120 }; |
| 116 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 121 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
| 117 | 122 |
| 118 SerializedScriptValue(); | 123 SerializedScriptValue(); |
| 119 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, ExceptionState&, v8::Isolate*); | 124 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, Vector<blink::WebBlobInfo>*, ExceptionState&, v8::Isolate*); |
| 120 explicit SerializedScriptValue(const String& wireData); | 125 explicit SerializedScriptValue(const String& wireData); |
| 121 | 126 |
| 122 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, ExceptionState&, v8::Isolate*); | 127 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, ExceptionState&, v8::Isolate*); |
| 123 | 128 |
| 124 String m_data; | 129 String m_data; |
| 125 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 130 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 126 BlobDataHandleMap m_blobDataHandles; | 131 BlobDataHandleMap m_blobDataHandles; |
| 127 intptr_t m_externallyAllocatedMemory; | 132 intptr_t m_externallyAllocatedMemory; |
| 128 }; | 133 }; |
| 129 | 134 |
| 130 } // namespace WebCore | 135 } // namespace WebCore |
| 131 | 136 |
| 132 #endif // SerializedScriptValue_h | 137 #endif // SerializedScriptValue_h |
| OLD | NEW |