Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: WebCore/bindings/v8/SerializedScriptValue.h

Issue 11192017: ********** WebCore blob hacking (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/Source/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 15 matching lines...) Expand all
70 String toWireString() const { return m_data; } 73 String toWireString() const { return m_data; }
71 74
72 // Deserializes the value (in the current context). Returns a null value in 75 // Deserializes the value (in the current context). Returns a null value in
73 // case of failure. 76 // case of failure.
74 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0, v8::Isolate* = 0); 77 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0, v8::Isolate* = 0);
75 78
76 #if ENABLE(INSPECTOR) 79 #if ENABLE(INSPECTOR)
77 ScriptValue deserializeForInspector(ScriptState*, v8::Isolate* = 0); 80 ScriptValue deserializeForInspector(ScriptState*, v8::Isolate* = 0);
78 #endif 81 #endif
79 82
80 const Vector<String>& blobURLs() const { return m_blobURLs; } 83 // Only reflects the truth if the SSV was created by walking a v8 value. The class
84 // does not know about blobs potentially contained the data string when its its
85 // been createdFromWire(data).
86 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); }
81 87
82 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute 88 // 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. 89 // 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). 90 // Ok to invoke multiple times (only adds memory once).
85 // The memory registration is revoked automatically in destructor. 91 // The memory registration is revoked automatically in destructor.
86 void registerMemoryAllocatedWithCurrentScriptContext(); 92 void registerMemoryAllocatedWithCurrentScriptContext();
87 93
88 private: 94 private:
89 enum StringDataMode {
90 StringValue,
91 WireData
92 };
93 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; 95 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
94 96
95 SerializedScriptValue(); 97 SerializedScriptValue();
96 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, bool& didThrow, v8::Isolate*); 98 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, bool& didThrow, v8::Isolate*);
97 explicit SerializedScriptValue(const String& wireData); 99 explicit SerializedScriptValue(const String& wireData);
98 100
99 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*); 101 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*);
100 102
101 String m_data; 103 String m_data;
102 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; 104 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
103 Vector<String> m_blobURLs; 105 BlobDataHandleMap m_blobDataHandles;
104 intptr_t m_externallyAllocatedMemory; 106 intptr_t m_externallyAllocatedMemory;
105 }; 107 };
106 108
107 } // namespace WebCore 109 } // namespace WebCore
108 110
109 #endif // SerializedScriptValue_h 111 #endif // SerializedScriptValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698