| 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 28 matching lines...) Expand all Loading... |
| 39 namespace WTF { | 39 namespace WTF { |
| 40 | 40 |
| 41 class ArrayBuffer; | 41 class ArrayBuffer; |
| 42 class ArrayBufferContents; | 42 class ArrayBufferContents; |
| 43 | 43 |
| 44 } | 44 } |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 class ExceptionState; | 48 class ExceptionState; |
| 49 class MessagePort; | |
| 50 | 49 |
| 51 typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray; | |
| 52 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 50 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; |
| 53 | 51 |
| 54 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript
Value> { | 52 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript
Value> { |
| 55 public: | 53 public: |
| 56 // Increment this for each incompatible change to the wire format. | 54 // Increment this for each incompatible change to the wire format. |
| 57 // Version 2: Added StringUCharTag for UChar v8 strings. | 55 // Version 2: Added StringUCharTag for UChar v8 strings. |
| 58 // Version 3: Switched to using uuids as blob data identifiers. | 56 // Version 3: Switched to using uuids as blob data identifiers. |
| 59 // Version 4: Extended File serialization to be complete. | 57 // Version 4: Extended File serialization to be complete. |
| 60 // Version 5: Added CryptoKeyTag for Key objects. | 58 // Version 5: Added CryptoKeyTag for Key objects. |
| 61 // Version 6: Added indexed serialization for File, Blob, and FileList. | 59 // Version 6: Added indexed serialization for File, Blob, and FileList. |
| 62 // Version 7: Extended File serialization with user visibility. | 60 // Version 7: Extended File serialization with user visibility. |
| 63 static const uint32_t wireFormatVersion = 7; | 61 static const uint32_t wireFormatVersion = 7; |
| 64 | 62 |
| 65 ~SerializedScriptValue(); | 63 ~SerializedScriptValue(); |
| 66 | 64 |
| 67 // If a serialization error occurs (e.g., cyclic input value) this | 65 // If a serialization error occurs (e.g., cyclic input value) this |
| 68 // function returns an empty representation, schedules a V8 exception to | 66 // function returns an empty representation, schedules a V8 exception to |
| 69 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 67 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
| 70 // 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 |
| 71 // V8. When serialization is successful, |didThrow| is false. | 69 // V8. When serialization is successful, |didThrow| is false. |
| 72 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa
gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*); | 70 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Array
BufferArray*, ExceptionState&, v8::Isolate*); |
| 73 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); | 71 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); |
| 74 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui
nt8_t>&); | 72 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui
nt8_t>&); |
| 75 static PassRefPtr<SerializedScriptValue> create(const String&); | 73 static PassRefPtr<SerializedScriptValue> create(const String&); |
| 76 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*)
; | 74 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*)
; |
| 77 static PassRefPtr<SerializedScriptValue> create(); | 75 static PassRefPtr<SerializedScriptValue> create(); |
| 78 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, Exceptio
nState&, v8::Isolate*); | 76 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, Exceptio
nState&, v8::Isolate*); |
| 79 | 77 |
| 80 // Never throws exceptions. | 78 // Never throws exceptions. |
| 81 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand
le<v8::Value>, v8::Isolate*); | 79 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand
le<v8::Value>, v8::Isolate*); |
| 82 | 80 |
| 83 static PassRefPtr<SerializedScriptValue> nullValue(); | 81 static PassRefPtr<SerializedScriptValue> nullValue(); |
| 84 | 82 |
| 85 String toWireString() const { return m_data; } | 83 String toWireString() const { return m_data; } |
| 86 void toWireBytes(Vector<char>&) const; | 84 void toWireBytes(Vector<char>&) const; |
| 87 | 85 |
| 88 // Deserializes the value (in the current context). Returns a null value in | 86 // Deserializes the value (in the current context). Returns a null value in |
| 89 // case of failure. | 87 // case of failure. |
| 90 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); | 88 v8::Handle<v8::Value> deserialize(); |
| 91 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); | 89 v8::Handle<v8::Value> deserialize(v8::Isolate*); |
| 92 | |
| 93 // Helper function which pulls the values out of a JS sequence and into a Me
ssagePortArray. | |
| 94 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL
spec and section 8.3.3 | |
| 95 // of the HTML5 spec and generates exceptions as appropriate. | |
| 96 // Returns true if the array was filled, or false if the passed value was no
t of an appropriate type. | |
| 97 static bool extractTransferables(v8::Local<v8::Value>, int, MessagePortArray
&, ArrayBufferArray&, ExceptionState&, v8::Isolate*); | |
| 98 | |
| 99 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute | |
| 100 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. | |
| 101 // Ok to invoke multiple times (only adds memory once). | |
| 102 // The memory registration is revoked automatically in destructor. | |
| 103 void registerMemoryAllocatedWithCurrentScriptContext(); | |
| 104 | 90 |
| 105 private: | 91 private: |
| 106 enum StringDataMode { | 92 enum StringDataMode { |
| 107 StringValue, | 93 StringValue, |
| 108 WireData | 94 WireData |
| 109 }; | 95 }; |
| 110 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 96 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
| 111 | 97 |
| 112 SerializedScriptValue(); | 98 SerializedScriptValue(); |
| 113 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA
rray*, ExceptionState&, v8::Isolate*); | 99 SerializedScriptValue(v8::Handle<v8::Value>, ArrayBufferArray*, ExceptionSta
te&, v8::Isolate*); |
| 114 explicit SerializedScriptValue(const String& wireData); | 100 explicit SerializedScriptValue(const String& wireData); |
| 115 | 101 |
| 116 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
Array&, ExceptionState&, v8::Isolate*); | 102 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
Array&, ExceptionState&, v8::Isolate*); |
| 117 | 103 |
| 118 String m_data; | 104 String m_data; |
| 119 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 105 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 120 intptr_t m_externallyAllocatedMemory; | 106 intptr_t m_externallyAllocatedMemory; |
| 121 }; | 107 }; |
| 122 | 108 |
| 123 } // namespace blink | 109 } // namespace blink |
| 124 | 110 |
| 125 #endif // SerializedScriptValue_h | 111 #endif // SerializedScriptValue_h |
| OLD | NEW |