| 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 20 matching lines...) Expand all Loading... |
| 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/Threading.h> | 37 #include <wtf/Threading.h> |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 class BlobDataHandle; |
| 41 class MessagePort; | 42 class MessagePort; |
| 42 | 43 |
| 43 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 44 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; |
| 44 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 45 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; |
| 46 typedef Vector<RefPtr<BlobDataHandle>, 1> BlobDataHandleArray; |
| 45 | 47 |
| 46 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue>
{ | 48 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue>
{ |
| 47 public: | 49 public: |
| 48 virtual ~SerializedScriptValue(); | 50 virtual ~SerializedScriptValue(); |
| 49 | 51 |
| 50 // If a serialization error occurs (e.g., cyclic input value) this | 52 // If a serialization error occurs (e.g., cyclic input value) this |
| 51 // function returns an empty representation, schedules a V8 exception to | 53 // function returns an empty representation, schedules a V8 exception to |
| 52 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 54 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
| 53 // the caller must not invoke any V8 operations until control returns to | 55 // the caller must not invoke any V8 operations until control returns to |
| 54 // V8. When serialization is successful, |didThrow| is false. | 56 // V8. When serialization is successful, |didThrow| is false. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 String toWireString() const { return m_data; } | 72 String toWireString() const { return m_data; } |
| 71 | 73 |
| 72 // Deserializes the value (in the current context). Returns a null value in | 74 // Deserializes the value (in the current context). Returns a null value in |
| 73 // case of failure. | 75 // case of failure. |
| 74 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0, v8::Isolate* = 0); | 76 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0, v8::Isolate* = 0); |
| 75 | 77 |
| 76 #if ENABLE(INSPECTOR) | 78 #if ENABLE(INSPECTOR) |
| 77 ScriptValue deserializeForInspector(ScriptState*, v8::Isolate* = 0); | 79 ScriptValue deserializeForInspector(ScriptState*, v8::Isolate* = 0); |
| 78 #endif | 80 #endif |
| 79 | 81 |
| 80 const Vector<String>& blobURLs() const { return m_blobURLs; } | 82 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); } |
| 81 | 83 |
| 82 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute | 84 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute |
| 83 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. | 85 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. |
| 84 // Ok to invoke multiple times (only adds memory once). | 86 // Ok to invoke multiple times (only adds memory once). |
| 85 // The memory registration is revoked automatically in destructor. | 87 // The memory registration is revoked automatically in destructor. |
| 86 void registerMemoryAllocatedWithCurrentScriptContext(); | 88 void registerMemoryAllocatedWithCurrentScriptContext(); |
| 87 | 89 |
| 88 private: | 90 private: |
| 89 enum StringDataMode { | |
| 90 StringValue, | |
| 91 WireData | |
| 92 }; | |
| 93 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 91 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
| 94 | 92 |
| 95 SerializedScriptValue(); | 93 SerializedScriptValue(); |
| 96 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA
rray*, bool& didThrow, v8::Isolate*); | 94 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA
rray*, bool& didThrow, v8::Isolate*); |
| 97 explicit SerializedScriptValue(const String& wireData); | 95 explicit SerializedScriptValue(const String& wireData); |
| 98 | 96 |
| 99 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
Array&, bool& didThrow, v8::Isolate*); | 97 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
Array&, bool& didThrow, v8::Isolate*); |
| 100 | 98 |
| 101 String m_data; | 99 String m_data; |
| 102 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 100 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 103 Vector<String> m_blobURLs; | 101 BlobDataHandleArray m_blobDataHandles; // TODO: Does this generalize better
? SerializedScriptValue::ExtraData?? |
| 104 intptr_t m_externallyAllocatedMemory; | 102 intptr_t m_externallyAllocatedMemory; |
| 105 }; | 103 }; |
| 106 | 104 |
| 107 } // namespace WebCore | 105 } // namespace WebCore |
| 108 | 106 |
| 109 #endif // SerializedScriptValue_h | 107 #endif // SerializedScriptValue_h |
| OLD | NEW |