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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValueFactory.cpp

Issue 1862033002: Make OffscreenCanvas Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address haraken's comments, need bots to test Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/core/v8/SerializedScriptValueFactory.h" 5 #include "bindings/core/v8/SerializedScriptValueFactory.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptValueSerializer.h" 8 #include "bindings/core/v8/ScriptValueSerializer.h"
9 #include "bindings/core/v8/Transferables.h" 9 #include "bindings/core/v8/Transferables.h"
10 #include "bindings/core/v8/V8ArrayBuffer.h"
11 #include "bindings/core/v8/V8ImageBitmap.h"
12 #include "bindings/core/v8/V8MessagePort.h"
13 #include "bindings/core/v8/V8SharedArrayBuffer.h"
10 #include "core/dom/DOMArrayBuffer.h" 14 #include "core/dom/DOMArrayBuffer.h"
11 #include "core/dom/MessagePort.h" 15 #include "core/dom/MessagePort.h"
12 #include "core/frame/ImageBitmap.h" 16 #include "core/frame/ImageBitmap.h"
13 #include "wtf/ByteOrder.h" 17 #include "wtf/ByteOrder.h"
14 #include "wtf/text/StringBuffer.h" 18 #include "wtf/text/StringBuffer.h"
15 19
16 namespace blink { 20 namespace blink {
17 21
18 SerializedScriptValueFactory* SerializedScriptValueFactory::m_instance = 0; 22 SerializedScriptValueFactory* SerializedScriptValueFactory::m_instance = 0;
19 23
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // information stored in m_data isn't even encoded in UTF-16. Instead, 152 // information stored in m_data isn't even encoded in UTF-16. Instead,
149 // unicode characters are encoded as UTF-8 with two code units per UChar. 153 // unicode characters are encoded as UTF-8 with two code units per UChar.
150 SerializedScriptValueReader reader(reinterpret_cast<const uint8_t*>(data.imp l()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, ScriptState: :current(isolate)); 154 SerializedScriptValueReader reader(reinterpret_cast<const uint8_t*>(data.imp l()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, ScriptState: :current(isolate));
151 ScriptValueDeserializer deserializer(reader, messagePorts, arrayBufferConten tsArray, imageBitmapContentsArray); 155 ScriptValueDeserializer deserializer(reader, messagePorts, arrayBufferConten tsArray, imageBitmapContentsArray);
152 156
153 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. 157 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed.
154 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. 158 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation.
155 return deserializer.deserialize(); 159 return deserializer.deserialize();
156 } 160 }
157 161
162 bool SerializedScriptValueFactory::extractTransferables(v8::Isolate* isolate, Tr ansferables& transferables, ExceptionState& exceptionState, v8::Local<v8::Value> & transferableObject, unsigned i)
163 {
164 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15.
165 if (V8MessagePort::hasInstance(transferableObject, isolate)) {
166 MessagePort* port = V8MessagePort::toImpl(v8::Local<v8::Object>::Cast(tr ansferableObject));
167 // Check for duplicate MessagePorts.
168 if (transferables.messagePorts.contains(port)) {
169 exceptionState.throwDOMException(DataCloneError, "Message port at in dex " + String::number(i) + " is a duplicate of an earlier port.");
170 return false;
171 }
172 transferables.messagePorts.append(port);
173 return true;
174 }
175 if (V8ArrayBuffer::hasInstance(transferableObject, isolate)) {
176 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Local<v8::Object >::Cast(transferableObject));
177 if (transferables.arrayBuffers.contains(arrayBuffer)) {
178 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is a duplicate of an earlier ArrayBuffer.");
179 return false;
180 }
181 transferables.arrayBuffers.append(arrayBuffer);
182 return true;
183 }
184 if (V8SharedArrayBuffer::hasInstance(transferableObject, isolate)) {
185 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl(v8 ::Local<v8::Object>::Cast(transferableObject));
186 if (transferables.arrayBuffers.contains(sharedArrayBuffer)) {
187 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuffer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayBuffe r.");
188 return false;
189 }
190 transferables.arrayBuffers.append(sharedArrayBuffer);
191 return true;
192 }
193 if (V8ImageBitmap::hasInstance(transferableObject, isolate)) {
194 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl(v8::Local<v8::Object>:: Cast(transferableObject));
195 if (transferables.imageBitmaps.contains(imageBitmap)) {
196 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at ind ex " + String::number(i) + " is a duplicate of an earlier ImageBitmap.");
197 return false;
198 }
199 transferables.imageBitmaps.append(imageBitmap);
200 return true;
201 }
202 return false;
203 }
158 204
159 } // namespace blink 205 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698