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

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

Issue 2541683002: Make ImageBitmap transfers work in cases that require serialization (Closed)
Patch Set: Created 4 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
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); 201 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper));
202 } 202 }
203 } else { 203 } else {
204 v8::Local<v8::Object> wrapper = 204 v8::Local<v8::Object> wrapper =
205 DOMWrapperWorld::current(isolate).domDataStore().get(object, isolate); 205 DOMWrapperWorld::current(isolate).domDataStore().get(object, isolate);
206 if (!wrapper.IsEmpty()) 206 if (!wrapper.IsEmpty())
207 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); 207 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper));
208 } 208 }
209 } 209 }
210 210
211 void SerializedScriptValue::transferImageBitmaps( 211 std::unique_ptr<ImageBitmapContentsArray>
212 SerializedScriptValue::transferImageBitmapContents(
212 v8::Isolate* isolate, 213 v8::Isolate* isolate,
213 const ImageBitmapArray& imageBitmaps, 214 const ImageBitmapArray& imageBitmaps,
214 ExceptionState& exceptionState) { 215 ExceptionState& exceptionState) {
215 if (!imageBitmaps.size()) 216 if (!imageBitmaps.size())
216 return; 217 return nullptr;
217 218
218 for (size_t i = 0; i < imageBitmaps.size(); ++i) { 219 for (size_t i = 0; i < imageBitmaps.size(); ++i) {
219 if (imageBitmaps[i]->isNeutered()) { 220 if (imageBitmaps[i]->isNeutered()) {
220 exceptionState.throwDOMException( 221 exceptionState.throwDOMException(
221 DataCloneError, "ImageBitmap at index " + String::number(i) + 222 DataCloneError, "ImageBitmap at index " + String::number(i) +
222 " is already detached."); 223 " is already detached.");
223 return; 224 return nullptr;
224 } 225 }
225 } 226 }
226 227
227 std::unique_ptr<ImageBitmapContentsArray> contents = 228 std::unique_ptr<ImageBitmapContentsArray> contents =
228 wrapUnique(new ImageBitmapContentsArray); 229 wrapUnique(new ImageBitmapContentsArray);
229 HeapHashSet<Member<ImageBitmap>> visited; 230 HeapHashSet<Member<ImageBitmap>> visited;
230 for (size_t i = 0; i < imageBitmaps.size(); ++i) { 231 for (size_t i = 0; i < imageBitmaps.size(); ++i) {
231 if (visited.contains(imageBitmaps[i])) 232 if (visited.contains(imageBitmaps[i]))
232 continue; 233 continue;
233 visited.add(imageBitmaps[i]); 234 visited.add(imageBitmaps[i]);
234 contents->append(imageBitmaps[i]->transfer()); 235 contents->append(imageBitmaps[i]->transfer());
235 } 236 }
237 return contents;
238 }
239
240 void SerializedScriptValue::transferImageBitmaps(
241 v8::Isolate* isolate,
242 const ImageBitmapArray& imageBitmaps,
243 ExceptionState& exceptionState) {
244 std::unique_ptr<ImageBitmapContentsArray> contents =
245 transferImageBitmapContents(isolate, imageBitmaps, exceptionState);
236 m_imageBitmapContentsArray = std::move(contents); 246 m_imageBitmapContentsArray = std::move(contents);
237 } 247 }
238 248
239 void SerializedScriptValue::transferOffscreenCanvas( 249 void SerializedScriptValue::transferOffscreenCanvas(
240 v8::Isolate* isolate, 250 v8::Isolate* isolate,
241 const OffscreenCanvasArray& offscreenCanvases, 251 const OffscreenCanvasArray& offscreenCanvases,
242 ExceptionState& exceptionState) { 252 ExceptionState& exceptionState) {
243 if (!offscreenCanvases.size()) 253 if (!offscreenCanvases.size())
244 return; 254 return;
245 255
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { 465 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() {
456 if (m_externallyAllocatedMemory) 466 if (m_externallyAllocatedMemory)
457 return; 467 return;
458 468
459 m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); 469 m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes());
460 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( 470 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
461 m_externallyAllocatedMemory); 471 m_externallyAllocatedMemory);
462 } 472 }
463 473
464 } // namespace blink 474 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698