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

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

Issue 18590006: Blob support for IDB [Blink] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: small cleanup Created 7 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 | 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
40 namespace WTF { 39 namespace WTF {
41 40
42 class ArrayBuffer; 41 class ArrayBuffer;
43 class ArrayBufferContents; 42 class ArrayBufferContents;
44 43
45 } 44 }
46 45
47 namespace WebCore { 46 namespace WebCore {
48 47
49 class BlobDataHandle; 48 class BlobDataHandle;
49 class BlobInfo;
50 class MessagePort; 50 class MessagePort;
51 51
52 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; 52 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
53 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; 53 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray;
54 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; 54 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap;
55 55
56 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript Value> { 56 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript Value> {
57 public: 57 public:
58 // Increment this for each incompatible change to the wire format. 58 // Increment this for each incompatible change to the wire format.
59 // Version 2: Added StringUCharTag for UChar v8 strings. 59 // Version 2: Added StringUCharTag for UChar v8 strings.
60 // Version 3: Switched to using uuids as blob data identifiers. 60 // Version 3: Switched to using uuids as blob data identifiers.
61 static const uint32_t wireFormatVersion = 3; 61 static const uint32_t wireFormatVersion = 3;
62 62
63 ~SerializedScriptValue(); 63 ~SerializedScriptValue();
64 64
65 // If a serialization error occurs (e.g., cyclic input value) this 65 // If a serialization error occurs (e.g., cyclic input value) this
66 // function returns an empty representation, schedules a V8 exception to 66 // function returns an empty representation, schedules a V8 exception to
67 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case 67 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case
68 // 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
69 // V8. When serialization is successful, |didThrow| is false. 69 // V8. When serialization is successful, |didThrow| is false.
70 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*); 70 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*);
71 static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa gePortArray*, ArrayBufferArray*, Vector<BlobInfo>*, bool& didThrow, v8::Isolate* );
71 static PassRefPtr<SerializedScriptValue> createFromWire(const String&); 72 static PassRefPtr<SerializedScriptValue> createFromWire(const String&);
72 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&); 73 static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui nt8_t>&);
73 static PassRefPtr<SerializedScriptValue> create(const String&); 74 static PassRefPtr<SerializedScriptValue> create(const String&);
74 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ; 75 static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*) ;
75 static PassRefPtr<SerializedScriptValue> create(); 76 static PassRefPtr<SerializedScriptValue> create();
76 77 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, Vector<B lobInfo>*, bool& didThrow, ScriptState*);
77 static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, bool& di dThrow, ScriptState*);
78 78
79 // Never throws exceptions. 79 // Never throws exceptions.
80 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*); 80 static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand le<v8::Value>, v8::Isolate*);
81 81
82 static PassRefPtr<SerializedScriptValue> nullValue(); 82 static PassRefPtr<SerializedScriptValue> nullValue();
83 static PassRefPtr<SerializedScriptValue> nullValue(v8::Isolate*); 83 static PassRefPtr<SerializedScriptValue> nullValue(v8::Isolate*);
84 84
85 String toWireString() const { return m_data; } 85 String toWireString() const { return m_data; }
86 void toWireBytes(Vector<char>&) const; 86 void toWireBytes(Vector<char>&) const;
87 87
88 // Deserializes the value (in the current context). Returns a null value in 88 // Deserializes the value (in the current context). Returns a null value in
89 // case of failure. 89 // case of failure.
90 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0); 90 v8::Handle<v8::Value> deserialize(MessagePortArray* = 0);
91 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0); 91 v8::Handle<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const
92 92 Vector<BlobInfo>* = 0);
93 // Only reflects the truth if the SSV was created by walking a v8 value, not reliable
94 // if the SSV was created createdFromWire(data).
95 bool containsBlobs() const { return !m_blobDataHandles.isEmpty(); }
96 93
97 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute 94 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute
98 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. 95 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM.
99 // Ok to invoke multiple times (only adds memory once). 96 // Ok to invoke multiple times (only adds memory once).
100 // The memory registration is revoked automatically in destructor. 97 // The memory registration is revoked automatically in destructor.
101 void registerMemoryAllocatedWithCurrentScriptContext(); 98 void registerMemoryAllocatedWithCurrentScriptContext();
102 99
103 private: 100 private:
104 enum StringDataMode { 101 enum StringDataMode {
105 StringValue, 102 StringValue,
106 WireData 103 WireData
107 }; 104 };
108 enum ExceptionPolicy { 105 enum ExceptionPolicy {
109 ThrowExceptions, 106 ThrowExceptions,
110 DoNotThrowExceptions 107 DoNotThrowExceptions
111 }; 108 };
112 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; 109 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
113 110
114 SerializedScriptValue(); 111 SerializedScriptValue();
115 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowExceptions); 112 SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA rray*, Vector<BlobInfo>*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowE xceptions);
116 explicit SerializedScriptValue(const String& wireData); 113 explicit SerializedScriptValue(const String& wireData);
117 114
118 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*); 115 static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer Array&, bool& didThrow, v8::Isolate*);
119 116
120 String m_data; 117 String m_data;
121 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; 118 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
122 BlobDataHandleMap m_blobDataHandles; 119 BlobDataHandleMap m_blobDataHandles;
123 intptr_t m_externallyAllocatedMemory; 120 intptr_t m_externallyAllocatedMemory;
124 }; 121 };
125 122
126 } // namespace WebCore 123 } // namespace WebCore
127 124
128 #endif // SerializedScriptValue_h 125 #endif // SerializedScriptValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698