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

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

Issue 1917733004: Reland of: Make OffscreenCanvas Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: works! 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 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 22 matching lines...) Expand all
33 #include "bindings/core/v8/DOMDataStore.h" 33 #include "bindings/core/v8/DOMDataStore.h"
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ExceptionState.h" 35 #include "bindings/core/v8/ExceptionState.h"
36 #include "bindings/core/v8/ScriptState.h" 36 #include "bindings/core/v8/ScriptState.h"
37 #include "bindings/core/v8/ScriptValueSerializer.h" 37 #include "bindings/core/v8/ScriptValueSerializer.h"
38 #include "bindings/core/v8/SerializedScriptValueFactory.h" 38 #include "bindings/core/v8/SerializedScriptValueFactory.h"
39 #include "bindings/core/v8/Transferables.h" 39 #include "bindings/core/v8/Transferables.h"
40 #include "bindings/core/v8/V8ArrayBuffer.h" 40 #include "bindings/core/v8/V8ArrayBuffer.h"
41 #include "bindings/core/v8/V8ImageBitmap.h" 41 #include "bindings/core/v8/V8ImageBitmap.h"
42 #include "bindings/core/v8/V8MessagePort.h" 42 #include "bindings/core/v8/V8MessagePort.h"
43 #include "bindings/core/v8/V8OffscreenCanvas.h"
43 #include "bindings/core/v8/V8SharedArrayBuffer.h" 44 #include "bindings/core/v8/V8SharedArrayBuffer.h"
44 #include "core/dom/DOMArrayBuffer.h" 45 #include "core/dom/DOMArrayBuffer.h"
45 #include "core/dom/DOMSharedArrayBuffer.h" 46 #include "core/dom/DOMSharedArrayBuffer.h"
46 #include "core/dom/ExceptionCode.h" 47 #include "core/dom/ExceptionCode.h"
47 #include "core/dom/MessagePort.h" 48 #include "core/dom/MessagePort.h"
48 #include "core/frame/ImageBitmap.h" 49 #include "core/frame/ImageBitmap.h"
49 #include "platform/SharedBuffer.h" 50 #include "platform/SharedBuffer.h"
50 #include "platform/blob/BlobData.h" 51 #include "platform/blob/BlobData.h"
51 #include "platform/heap/Handle.h" 52 #include "platform/heap/Handle.h"
52 #include "wtf/Assertions.h" 53 #include "wtf/Assertions.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 HeapHashSet<Member<ImageBitmap>> visited; 134 HeapHashSet<Member<ImageBitmap>> visited;
134 for (size_t i = 0; i < imageBitmaps.size(); ++i) { 135 for (size_t i = 0; i < imageBitmaps.size(); ++i) {
135 if (visited.contains(imageBitmaps[i])) 136 if (visited.contains(imageBitmaps[i]))
136 continue; 137 continue;
137 visited.add(imageBitmaps[i]); 138 visited.add(imageBitmaps[i]);
138 contents->append(imageBitmaps[i]->transfer()); 139 contents->append(imageBitmaps[i]->transfer());
139 } 140 }
140 m_imageBitmapContentsArray = contents.release(); 141 m_imageBitmapContentsArray = contents.release();
141 } 142 }
142 143
144 void SerializedScriptValue::transferOffscreenCanvas(v8::Isolate* isolate, const OffscreenCanvasArray& offscreenCanvases, ExceptionState& exceptionState)
145 {
146 if (!offscreenCanvases.size())
147 return;
148
149 HeapHashSet<Member<OffscreenCanvas>> visited;
150 for (size_t i = 0; i < offscreenCanvases.size(); i++) {
151 if (offscreenCanvases[i]->isNeutered()) {
152 exceptionState.throwDOMException(DataCloneError, "OffscreenCanvas at index " + String::number(i) + " is already neutered.");
153 return;
154 }
155 if (offscreenCanvases[i]->renderingContext()) {
156 exceptionState.throwDOMException(DataCloneError, "OffscreenCanvas at index " + String::number(i) + " has an associated context.");
157 return;
158 }
159 if (visited.contains(offscreenCanvases[i].get()))
sof 2016/04/26 19:37:15 If it really is legal/expected to have duplicates
xidachen 2016/04/26 20:40:59 Done.
160 continue;
161 visited.add(offscreenCanvases[i].get());
162 offscreenCanvases[i].get()->setNeutered();
163 }
164 }
143 165
144 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, const Arr ayBufferArray& arrayBuffers, ExceptionState& exceptionState) 166 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, const Arr ayBufferArray& arrayBuffers, ExceptionState& exceptionState)
145 { 167 {
146 if (!arrayBuffers.size()) 168 if (!arrayBuffers.size())
147 return; 169 return;
148 170
149 for (size_t i = 0; i < arrayBuffers.size(); ++i) { 171 for (size_t i = 0; i < arrayBuffers.size(); ++i) {
150 if (arrayBuffers[i]->isNeutered()) { 172 if (arrayBuffers[i]->isNeutered()) {
151 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); 173 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered.");
152 return; 174 return;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return false; 281 return false;
260 } 282 }
261 transferables.arrayBuffers.append(sharedArrayBuffer); 283 transferables.arrayBuffers.append(sharedArrayBuffer);
262 } else if (V8ImageBitmap::hasInstance(transferableObject, isolate)) { 284 } else if (V8ImageBitmap::hasInstance(transferableObject, isolate)) {
263 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl(v8::Local<v8::Objec t>::Cast(transferableObject)); 285 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl(v8::Local<v8::Objec t>::Cast(transferableObject));
264 if (transferables.imageBitmaps.contains(imageBitmap)) { 286 if (transferables.imageBitmaps.contains(imageBitmap)) {
265 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at index " + String::number(i) + " is a duplicate of an earlier ImageBitmap."); 287 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at index " + String::number(i) + " is a duplicate of an earlier ImageBitmap.");
266 return false; 288 return false;
267 } 289 }
268 transferables.imageBitmaps.append(imageBitmap); 290 transferables.imageBitmaps.append(imageBitmap);
291 } else if (V8OffscreenCanvas::hasInstance(transferableObject, isolate)) {
292 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl(v8::Loc al<v8::Object>::Cast(transferableObject));
293 if (transferables.offscreenCanvases.contains(offscreenCanvas)) {
294 exceptionState.throwDOMException(DataCloneError, "OffscreenCanva s at index " + String::number(i) + " is a duplicate of an earlier OffscreenCanva s.");
295 return false;
296 }
297 transferables.offscreenCanvases.append(offscreenCanvas);
269 } else { 298 } else {
270 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type."); 299 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type.");
271 return false; 300 return false;
272 } 301 }
273 } 302 }
274 return true; 303 return true;
275 } 304 }
276 305
277 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() 306 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext()
278 { 307 {
279 if (m_externallyAllocatedMemory) 308 if (m_externallyAllocatedMemory)
280 return; 309 return;
281 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); 310 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length());
282 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall yAllocatedMemory); 311 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall yAllocatedMemory);
283 } 312 }
284 313
285 bool SerializedScriptValue::containsTransferableArrayBuffer() const 314 bool SerializedScriptValue::containsTransferableArrayBuffer() const
286 { 315 {
287 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty(); 316 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty();
288 } 317 }
289 318
290 } // namespace blink 319 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698