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

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: no need to register, taking the same approach as extractTransferables 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 11 matching lines...) Expand all
31 exceptionState.rethrowV8Exception(tryCatch.Exception()); 35 exceptionState.rethrowV8Exception(tryCatch.Exception());
32 return serializedValue.release(); 36 return serializedValue.release();
33 } 37 }
34 } 38 }
35 switch (status) { 39 switch (status) {
36 case ScriptValueSerializer::InputError: 40 case ScriptValueSerializer::InputError:
37 case ScriptValueSerializer::DataCloneError: 41 case ScriptValueSerializer::DataCloneError:
38 exceptionState.throwDOMException(ScriptValueSerializer::DataCloneError, errorMessage); 42 exceptionState.throwDOMException(ScriptValueSerializer::DataCloneError, errorMessage);
39 return serializedValue.release(); 43 return serializedValue.release();
40 case ScriptValueSerializer::Success: 44 case ScriptValueSerializer::Success:
41 transferData(serializedValue.get(), writer, transferables, exceptionStat e, isolate); 45 transferData(isolate, transferables, exceptionState, serializedValue.get (), writer);
42 return serializedValue.release(); 46 return serializedValue.release();
43 case ScriptValueSerializer::JSException: 47 case ScriptValueSerializer::JSException:
44 ASSERT_NOT_REACHED(); 48 ASSERT_NOT_REACHED();
45 break; 49 break;
46 } 50 }
47 ASSERT_NOT_REACHED(); 51 ASSERT_NOT_REACHED();
48 return serializedValue.release(); 52 return serializedValue.release();
49 } 53 }
50 54
51 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Isola te* isolate, v8::Local<v8::Value> value, Transferables* transferables, Exception State& exceptionState) 55 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Isola te* isolate, v8::Local<v8::Value> value, Transferables* transferables, Exception State& exceptionState)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 writer.writeWebCoreString(data); 100 writer.writeWebCoreString(data);
97 String wireData = writer.takeWireString(); 101 String wireData = writer.takeWireString();
98 return createFromWire(wireData); 102 return createFromWire(wireData);
99 } 103 }
100 104
101 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create() 105 PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create()
102 { 106 {
103 return adoptRef(new SerializedScriptValue()); 107 return adoptRef(new SerializedScriptValue());
104 } 108 }
105 109
106 void SerializedScriptValueFactory::transferData(SerializedScriptValue* serialize dValue, SerializedScriptValueWriter& writer, Transferables* transferables, Excep tionState& exceptionState, v8::Isolate* isolate) 110 void SerializedScriptValueFactory::transferData(v8::Isolate* isolate, Transferab les* transferables, ExceptionState& exceptionState, SerializedScriptValue* seria lizedValue, SerializedScriptValueWriter& writer)
107 { 111 {
108 serializedValue->setData(writer.takeWireString()); 112 serializedValue->setData(writer.takeWireString());
109 ASSERT(serializedValue->data().impl()->hasOneRef()); 113 ASSERT(serializedValue->data().impl()->hasOneRef());
110 if (!transferables) 114 if (!transferables)
111 return; 115 return;
112 116
113 serializedValue->transferImageBitmaps(isolate, transferables->imageBitmaps, exceptionState); 117 serializedValue->transferImageBitmaps(isolate, transferables->imageBitmaps, exceptionState);
114 if (exceptionState.hadException()) 118 if (exceptionState.hadException())
115 return; 119 return;
116 serializedValue->transferArrayBuffers(isolate, transferables->arrayBuffers, exceptionState); 120 serializedValue->transferArrayBuffers(isolate, transferables->arrayBuffers, exceptionState);
(...skipping 31 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 index)
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(index) + " 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(index) + " 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(index) + " is a duplicate of an earlier SharedArrayB uffer.");
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(index) + " 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