| 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 16 matching lines...) Expand all Loading... |
| 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 "ScriptValue.h" | 34 #include "ScriptValue.h" |
| 35 #include <v8.h> | 35 #include <v8.h> |
| 36 #include <wtf/ArrayBuffer.h> | 36 #include <wtf/ArrayBuffer.h> |
| 37 #include <wtf/HashMap.h> |
| 37 #include <wtf/Threading.h> | 38 #include <wtf/Threading.h> |
| 38 | 39 |
| 39 namespace WebCore { | 40 namespace WebCore { |
| 40 | 41 |
| 42 class BlobDataHandle; |
| 41 class MessagePort; | 43 class MessagePort; |
| 42 | 44 |
| 43 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 45 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; |
| 44 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 46 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; |
| 47 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; |
| 45 | 48 |
| 46 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue>
{ | 49 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue>
{ |
| 47 public: | 50 public: |
| 48 virtual ~SerializedScriptValue(); | 51 virtual ~SerializedScriptValue(); |
| 49 | 52 |
| 50 // If a serialization error occurs (e.g., cyclic input value) this | 53 // If a serialization error occurs (e.g., cyclic input value) this |
| 51 // function returns an empty representation, schedules a V8 exception to | 54 // function returns an empty representation, schedules a V8 exception to |
| 52 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 55 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
| 53 // the caller must not invoke any V8 operations until control returns to | 56 // the caller must not invoke any V8 operations until control returns to |
| 54 // V8. When serialization is successful, |didThrow| is false. | 57 // V8. When serialization is successful, |didThrow| is false. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 80 | 83 |
| 81 // Deserializes the value (in the current context). Returns a null value in | 84 // Deserializes the value (in the current context). Returns a null value in |
| 82 // case of failure. | 85 // case of failure. |
| 83 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); | 86 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); |
| 84 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); | 87 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); |
| 85 | 88 |
| 86 #if ENABLE(INSPECTOR) | 89 #if ENABLE(INSPECTOR) |
| 87 ScriptValue deserializeForInspector(ScriptState*); | 90 ScriptValue deserializeForInspector(ScriptState*); |
| 88 #endif | 91 #endif |
| 89 | 92 |
| 90 const Vector<String>& blobURLs() const { return m_blobURLs; } | 93 // Only reflects the truth if the SSV was created by walking a v8 value. The
class |
| 94 // does not know about blobs potentially contained the data string when its
its |
| 95 // been createdFromWire(data). |
| 96 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); } |
| 91 | 97 |
| 92 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute | 98 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute |
| 93 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. | 99 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. |
| 94 // Ok to invoke multiple times (only adds memory once). | 100 // Ok to invoke multiple times (only adds memory once). |
| 95 // The memory registration is revoked automatically in destructor. | 101 // The memory registration is revoked automatically in destructor. |
| 96 void registerMemoryAllocatedWithCurrentScriptContext(); | 102 void registerMemoryAllocatedWithCurrentScriptContext(); |
| 97 | 103 |
| 98 private: | 104 private: |
| 99 enum StringDataMode { | |
| 100 StringValue, | |
| 101 WireData | |
| 102 }; | |
| 103 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 105 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
| 104 | 106 |
| 105 SerializedScriptValue(); | 107 SerializedScriptValue(); |
| 106 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA
rray*, bool& didThrow, v8::Isolate*); | 108 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA
rray*, bool& didThrow, v8::Isolate*); |
| 107 explicit SerializedScriptValue(const String& wireData); | 109 explicit SerializedScriptValue(const String& wireData); |
| 108 | 110 |
| 109 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
Array&, bool& didThrow, v8::Isolate*); | 111 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
Array&, bool& didThrow, v8::Isolate*); |
| 110 | 112 |
| 111 String m_data; | 113 String m_data; |
| 112 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 114 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 113 Vector<String> m_blobURLs; | 115 BlobDataHandleMap m_blobDataHandles; |
| 114 intptr_t m_externallyAllocatedMemory; | 116 intptr_t m_externallyAllocatedMemory; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 } // namespace WebCore | 119 } // namespace WebCore |
| 118 | 120 |
| 119 #endif // SerializedScriptValue_h | 121 #endif // SerializedScriptValue_h |
| OLD | NEW |