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

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

Issue 223123002: Add blob serialization support [currently unused] to SerializedScriptValue. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaseline crypto tests Created 6 years, 8 months 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 | Annotate | Revision Log
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 14 matching lines...) Expand all
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;
61 typedef Vector<blink::WebBlobInfo> WebBlobInfoArray;
56 62
57 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript Value> { 63 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript Value> {
58 public: 64 public:
59 // Increment this for each incompatible change to the wire format. 65 // Increment this for each incompatible change to the wire format.
60 // Version 2: Added StringUCharTag for UChar v8 strings. 66 // Version 2: Added StringUCharTag for UChar v8 strings.
61 // Version 3: Switched to using uuids as blob data identifiers. 67 // Version 3: Switched to using uuids as blob data identifiers.
62 // Version 4: Extended File serialization to be complete. 68 // Version 4: Extended File serialization to be complete.
63 // Version 5: Added CryptoKeyTag for Key objects. 69 // Version 5: Added CryptoKeyTag for Key objects.
64 static const uint32_t wireFormatVersion = 5; 70 // Version 6: Added indexed serialization for File, Blob, and FileList.
71 static const uint32_t wireFormatVersion = 6;
65 72
66 ~SerializedScriptValue(); 73 ~SerializedScriptValue();
67 74
68 // If a serialization error occurs (e.g., cyclic input value) this 75 // If a serialization error occurs (e.g., cyclic input value) this
69 // function returns an empty representation, schedules a V8 exception to 76 // function returns an empty representation, schedules a V8 exception to
70 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case 77 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case
71 // the caller must not invoke any V8 operations until control returns to 78 // the caller must not invoke any V8 operations until control returns to
72 // V8. When serialization is successful, |didThrow| is false. 79 // V8. When serialization is successful, |didThrow| is false.
73 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*); 80 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*);
74 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); 81 static PassRefPtr<SerializedScriptValue> createFromWire(const String&);
75 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&); 82 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&);
76 static PassRefPtr<SerializedScriptValue> create(const String&); 83 static PassRefPtr<SerializedScriptValue> create(const String&);
77 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ; 84 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ;
78 static PassRefPtr<SerializedScriptValue> create(); 85 static PassRefPtr<SerializedScriptValue> create();
79 86 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, WebBlobI nfoArray*, ExceptionState&, ScriptState*);
80 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, Exceptio nState&, ScriptState*);
81 87
82 // Never throws exceptions. 88 // Never throws exceptions.
83 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*); 89 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*);
84 90
85 static PassRefPtr<SerializedScriptValue> nullValue(); 91 static PassRefPtr<SerializedScriptValue> nullValue();
86 92
87 String toWireString() const { return m_data; } 93 String toWireString() const { return m_data; }
88 void toWireBytes(Vector<char>&) const; 94 void toWireBytes(Vector<char>&) const;
89 95
90 // Deserializes the value (in the current context). Returns a null value in 96 // Deserializes the value (in the current context). Returns a null value in
91 // case of failure. 97 // case of failure.
92 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); 98 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0);
93 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); 99 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const WebBlobInfoArray* = 0);
94 100
95 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray. 101 // 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 102 // 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. 103 // 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. 104 // 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*); 105 static bool extractTransferables(v8::Local<v8::Value>, int, MessagePortArray &, ArrayBufferArray&, ExceptionState&, v8::Isolate*);
100 106
101 // Only reflects the truth if the SSV was created by walking a v8 value, not reliable 107 // Only reflects the truth if the SSV was created by walking a v8 value, not reliable
102 // if the SSV was created createdFromWire(data). 108 // if the SSV was created createdFromWire(data).
103 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); } 109 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); }
104 110
105 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute 111 // 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. 112 // 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). 113 // Ok to invoke multiple times (only adds memory once).
108 // The memory registration is revoked automatically in destructor. 114 // The memory registration is revoked automatically in destructor.
109 void registerMemoryAllocatedWithCurrentScriptContext(); 115 void registerMemoryAllocatedWithCurrentScriptContext();
110 116
111 private: 117 private:
112 enum StringDataMode { 118 enum StringDataMode {
113 StringValue, 119 StringValue,
114 WireData 120 WireData
115 }; 121 };
116 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; 122 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
117 123
118 SerializedScriptValue(); 124 SerializedScriptValue();
119 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, ExceptionState&, v8::Isolate*); 125 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, WebBlobInfoArray*, ExceptionState&, v8::Isolate*);
120 explicit SerializedScriptValue(const String& wireData); 126 explicit SerializedScriptValue(const String& wireData);
121 127
122 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, ExceptionState&, v8::Isolate*); 128 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, ExceptionState&, v8::Isolate*);
123 129
124 String m_data; 130 String m_data;
125 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; 131 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
126 BlobDataHandleMap m_blobDataHandles; 132 BlobDataHandleMap m_blobDataHandles;
127 intptr_t m_externallyAllocatedMemory; 133 intptr_t m_externallyAllocatedMemory;
128 }; 134 };
129 135
130 } // namespace WebCore 136 } // namespace WebCore
131 137
132 #endif // SerializedScriptValue_h 138 #endif // SerializedScriptValue_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/IDBBindingUtilities.cpp ('k') | Source/bindings/v8/SerializedScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698