Index: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
index bc1e32f4a090fdb4f9d5092eab00f52cbc79609f..79af5805b6c48eb96b565987d076dc260cc8b4bd 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp |
@@ -38,6 +38,7 @@ |
#include "bindings/core/v8/ScriptValueSerializer.h" |
#include "bindings/core/v8/SerializedScriptValueFactory.h" |
#include "bindings/core/v8/V8ArrayBuffer.h" |
+#include "bindings/core/v8/V8ImageBitmap.h" |
#include "bindings/core/v8/V8MessagePort.h" |
#include "bindings/core/v8/V8SharedArrayBuffer.h" |
#include "core/dom/ExceptionCode.h" |
@@ -101,6 +102,31 @@ static void acculumateArrayBuffersForAllWorlds(v8::Isolate* isolate, DOMArrayBuf |
} |
} |
+PassOwnPtr<SerializedScriptValue::ImageBitmapContentsArray> SerializedScriptValue::createImageBitmaps(v8::Isolate* isolate, ImageBitmapArray& imageBitmaps, ExceptionState& exceptionState) |
+{ |
+ ASSERT(imageBitmaps.size()); |
+ |
+ for (size_t i = 0; i < imageBitmaps.size(); i++) { |
+ if (imageBitmaps[i]->isNeutered()) { |
+ exceptionState.throwDOMException(DataCloneError, "ImageBitmap at index " + String::number(i) + " is already neutered."); |
+ return nullptr; |
+ } |
+ } |
+ |
+ OwnPtr<ImageBitmapContentsArray> contents = adoptPtr(new ImageBitmapContentsArray(imageBitmaps.size())); |
+ WillBeHeapHashSet<RawPtrWillBeMember<ImageBitmap>> visited; |
+ int validIdx = 0; |
+ for (size_t i = 0; i < imageBitmaps.size(); i++) { |
sof
2015/11/16 19:22:34
The code here works fine, but I wonder if we can s
xidachen
2015/11/16 20:15:50
Thank you for the comments. I think you made a goo
|
+ if (visited.contains(imageBitmaps[i].get())) |
+ continue; |
+ visited.add(imageBitmaps[i].get()); |
+ contents->at(validIdx++) = imageBitmaps[i]->transfer(); |
+ } |
+ contents.get()->remove(validIdx, imageBitmaps.size()-validIdx); |
+ return contents.release(); |
+} |
+ |
+ |
PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValue::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState) |
{ |
ASSERT(arrayBuffers.size()); |
@@ -169,11 +195,12 @@ v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me |
return SerializedScriptValueFactory::instance().deserialize(this, isolate, messagePorts, blobInfo); |
} |
-bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState) |
+bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ImageBitmapArray& imageBitmaps, ExceptionState& exceptionState) |
{ |
if (isUndefinedOrNull(value)) { |
ports.resize(0); |
arrayBuffers.resize(0); |
+ imageBitmaps.resize(0); |
return true; |
} |
@@ -222,6 +249,13 @@ bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local |
return false; |
} |
arrayBuffers.append(sharedArrayBuffer.release()); |
+ } else if (V8ImageBitmap::hasInstance(transferrable, isolate)) { |
+ RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = V8ImageBitmap::toImpl(v8::Local<v8::Object>::Cast(transferrable)); |
+ if (imageBitmaps.contains(imageBitmap)) { |
+ exceptionState.throwDOMException(DataCloneError, "ImageBitmap at index " + String::number(i) + " is a duplicate of an earlier ImageBitmap."); |
+ return false; |
+ } |
+ imageBitmaps.append(imageBitmap.release()); |
} else { |
exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type."); |
return false; |
@@ -259,4 +293,9 @@ void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff |
m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, exceptionState); |
} |
+void SerializedScriptValue::transferImageBitmaps(v8::Isolate* isolate, ImageBitmapArray& imageBitmaps, ExceptionState& exceptionState) |
+{ |
+ m_imageBitmapContentsArray = createImageBitmaps(isolate, imageBitmaps, exceptionState); |
+} |
+ |
} // namespace blink |