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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.h

Issue 1423513005: Reland of: Make Imagebitmap Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 15 matching lines...) Expand all
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/core/v8/ScriptValue.h" 34 #include "bindings/core/v8/ScriptValue.h"
35 #include "core/CoreExport.h" 35 #include "core/CoreExport.h"
36 #include "third_party/skia/include/core/SkImage.h"
36 #include "wtf/HashMap.h" 37 #include "wtf/HashMap.h"
37 #include "wtf/ThreadSafeRefCounted.h" 38 #include "wtf/ThreadSafeRefCounted.h"
38 #include <v8.h> 39 #include <v8.h>
39 40
40 namespace WTF { 41 namespace WTF {
41 42
42 class ArrayBufferContents; 43 class ArrayBufferContents;
43 44
44 } 45 }
45 46
46 namespace blink { 47 namespace blink {
47 48
48 class BlobDataHandle; 49 class BlobDataHandle;
49 class DOMArrayBufferBase; 50 class DOMArrayBufferBase;
50 class ExceptionState; 51 class ExceptionState;
52 class ImageBitmap;
51 class MessagePort; 53 class MessagePort;
52 class WebBlobInfo; 54 class WebBlobInfo;
53 55
54 typedef HeapVector<Member<MessagePort>, 1> MessagePortArray; 56 typedef HeapVector<Member<MessagePort>, 1> MessagePortArray;
55 typedef Vector<RefPtr<DOMArrayBufferBase>, 1> ArrayBufferArray; 57 typedef Vector<RefPtr<DOMArrayBufferBase>, 1> ArrayBufferArray;
56 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap; 58 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap;
57 typedef Vector<WebBlobInfo> WebBlobInfoArray; 59 typedef Vector<WebBlobInfo> WebBlobInfoArray;
60 typedef WillBeHeapVector<RefPtrWillBeMember<ImageBitmap>, 1> ImageBitmapArray;
58 61
59 class CORE_EXPORT SerializedScriptValue : public ThreadSafeRefCounted<Serialized ScriptValue> { 62 class CORE_EXPORT SerializedScriptValue : public ThreadSafeRefCounted<Serialized ScriptValue> {
60 public: 63 public:
61 // Increment this for each incompatible change to the wire format. 64 // Increment this for each incompatible change to the wire format.
62 // Version 2: Added StringUCharTag for UChar v8 strings. 65 // Version 2: Added StringUCharTag for UChar v8 strings.
63 // Version 3: Switched to using uuids as blob data identifiers. 66 // Version 3: Switched to using uuids as blob data identifiers.
64 // Version 4: Extended File serialization to be complete. 67 // Version 4: Extended File serialization to be complete.
65 // Version 5: Added CryptoKeyTag for Key objects. 68 // Version 5: Added CryptoKeyTag for Key objects.
66 // Version 6: Added indexed serialization for File, Blob, and FileList. 69 // Version 6: Added indexed serialization for File, Blob, and FileList.
67 // Version 7: Extended File serialization with user visibility. 70 // Version 7: Extended File serialization with user visibility.
(...skipping 14 matching lines...) Expand all
82 85
83 // Deserializes the value (in the current context). Returns a null value in 86 // Deserializes the value (in the current context). Returns a null value in
84 // case of failure. 87 // case of failure.
85 v8::Local<v8::Value> deserialize(MessagePortArray* = 0); 88 v8::Local<v8::Value> deserialize(MessagePortArray* = 0);
86 v8::Local<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const WebBlobInfoArray* = 0); 89 v8::Local<v8::Value> deserialize(v8::Isolate*, MessagePortArray* = 0, const WebBlobInfoArray* = 0);
87 90
88 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray. 91 // Helper function which pulls the values out of a JS sequence and into a Me ssagePortArray.
89 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 92 // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3
90 // of the HTML5 spec and generates exceptions as appropriate. 93 // of the HTML5 spec and generates exceptions as appropriate.
91 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type. 94 // Returns true if the array was filled, or false if the passed value was no t of an appropriate type.
92 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Me ssagePortArray&, ArrayBufferArray&, ExceptionState&); 95 static bool extractTransferables(v8::Isolate*, v8::Local<v8::Value>, int, Me ssagePortArray&, ArrayBufferArray&, ImageBitmapArray&, ExceptionState&);
93 96
94 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute 97 // Informs the V8 about external memory allocated and owned by this object. Large values should contribute
95 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM. 98 // to GC counters to eventually trigger a GC, otherwise flood of postMessage () can cause OOM.
96 // Ok to invoke multiple times (only adds memory once). 99 // Ok to invoke multiple times (only adds memory once).
97 // The memory registration is revoked automatically in destructor. 100 // The memory registration is revoked automatically in destructor.
98 void registerMemoryAllocatedWithCurrentScriptContext(); 101 void registerMemoryAllocatedWithCurrentScriptContext();
99 102
100 // Returns true if the value contains a transferable ArrayBuffer. 103 // Returns true if the value contains a transferable ArrayBuffer.
101 bool containsTransferableArrayBuffer() const; 104 bool containsTransferableArrayBuffer() const;
102 105
103 private: 106 private:
104 // The followings are private, but used by SerializedScriptValueFactory. 107 // The followings are private, but used by SerializedScriptValueFactory.
105 enum StringDataMode { 108 enum StringDataMode {
106 StringValue, 109 StringValue,
107 WireData 110 WireData
108 }; 111 };
109 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; 112 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
113 typedef Vector<RefPtr<SkImage>, 1> ImageBitmapContentsArray;
110 114
111 SerializedScriptValue(); 115 SerializedScriptValue();
112 explicit SerializedScriptValue(const String& wireData); 116 explicit SerializedScriptValue(const String& wireData);
113 117
114 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } 118 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; }
115 String& data() { return m_data; } 119 String& data() { return m_data; }
116 void setData(const String& data) { m_data = data; } 120 void setData(const String& data) { m_data = data; }
117 void transferArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&); 121 void transferArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&);
122 void transferImageBitmaps(v8::Isolate*, ImageBitmapArray&, ExceptionState&);
118 ArrayBufferContentsArray* arrayBufferContentsArray() { return m_arrayBufferC ontentsArray.get(); } 123 ArrayBufferContentsArray* arrayBufferContentsArray() { return m_arrayBufferC ontentsArray.get(); }
124 ImageBitmapContentsArray* imageBitmapContentsArray() { return m_imageBitmapC ontentsArray.get(); }
119 125
120 static PassOwnPtr<ArrayBufferContentsArray> createArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&); 126 static PassOwnPtr<ArrayBufferContentsArray> createArrayBuffers(v8::Isolate*, ArrayBufferArray&, ExceptionState&);
127 static PassOwnPtr<ImageBitmapContentsArray> createImageBitmaps(v8::Isolate*, ImageBitmapArray&, ExceptionState&);
121 128
122 private: 129 private:
123 String m_data; 130 String m_data;
124 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; 131 OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray;
132 OwnPtr<ImageBitmapContentsArray> m_imageBitmapContentsArray;
125 BlobDataHandleMap m_blobDataHandles; 133 BlobDataHandleMap m_blobDataHandles;
126 intptr_t m_externallyAllocatedMemory; 134 intptr_t m_externallyAllocatedMemory;
127 135
128 friend class SerializedScriptValueFactory; 136 friend class SerializedScriptValueFactory;
129 }; 137 };
130 138
131 } // namespace blink 139 } // namespace blink
132 140
133 #endif // SerializedScriptValue_h 141 #endif // SerializedScriptValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698