| Index: third_party/WebKit/Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp
|
| diff --git a/third_party/WebKit/Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp b/third_party/WebKit/Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp
|
| index 5a54a8efe235e23bbd6ec051493dd6ad07c8f948..197028f60ec818ad656dcb8f06d7efd943f451c7 100644
|
| --- a/third_party/WebKit/Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp
|
| +++ b/third_party/WebKit/Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp
|
| @@ -6,8 +6,10 @@
|
|
|
| #include "bindings/core/v8/SerializationTag.h"
|
| #include "bindings/core/v8/V8Binding.h"
|
| +#include "bindings/modules/v8/TransferableOffscreenCanvas.h"
|
| #include "bindings/modules/v8/V8CryptoKey.h"
|
| #include "bindings/modules/v8/V8DOMFileSystem.h"
|
| +#include "bindings/modules/v8/V8OffscreenCanvas.h"
|
| #include "modules/filesystem/DOMFileSystem.h"
|
| #include "public/platform/Platform.h"
|
|
|
| @@ -72,10 +74,31 @@ enum AssymetricCryptoKeyType {
|
| // Maximum allowed value is 2^32-1
|
| };
|
|
|
| +static v8::Local<v8::Object> toV8Object(OffscreenCanvas* impl, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
|
| +{
|
| + if (!impl)
|
| + return v8::Local<v8::Object>();
|
| + v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate);
|
| + if (wrapper.IsEmpty())
|
| + return v8::Local<v8::Object>();
|
| + return wrapper.As<v8::Object>();
|
| +}
|
|
|
| ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScriptValueWriter& writer, MessagePortArray* messagePorts, TransferableArray* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptState)
|
| : ScriptValueSerializer(writer, messagePorts, transferables, blobInfo, blobDataHandles, tryCatch, scriptState)
|
| + , m_writer(writer)
|
| {
|
| + ASSERT(!tryCatch.HasCaught());
|
| + v8::Local<v8::Object> creationContext = scriptState->context()->Global();
|
| + if (!transferables)
|
| + return;
|
| + if (auto* offscreenCanvases = TransferableOffscreenCanvas::get(*transferables)) {
|
| + for (size_t i = 0; i < offscreenCanvases->getArray().size(); i++) {
|
| + v8::Local<v8::Object> v8OffscreenCanvas = toV8Object(offscreenCanvases->getArray().at(i).get(), creationContext, isolate());
|
| + if (!m_transferredOffscreenCanvas.contains(v8OffscreenCanvas))
|
| + m_transferredOffscreenCanvas.set(v8OffscreenCanvas, i);
|
| + }
|
| + }
|
| }
|
|
|
| ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileSystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next)
|
| @@ -106,6 +129,15 @@ void SerializedScriptValueWriterForModules::writeDOMFileSystem(int type, const S
|
| doWriteWebCoreString(url);
|
| }
|
|
|
| +void SerializedScriptValueWriterForModules::writeTransferredOffscreenCanvas(uint32_t index, uint32_t width, uint32_t height, uint32_t id)
|
| +{
|
| + append(OffscreenCanvasTransferTag);
|
| + doWriteUint32(index);
|
| + doWriteUint32(width);
|
| + doWriteUint32(height);
|
| + doWriteUint32(id);
|
| +}
|
| +
|
| bool SerializedScriptValueWriterForModules::writeCryptoKey(const WebCryptoKey& key)
|
| {
|
| append(static_cast<uint8_t>(CryptoKeyTag));
|
| @@ -306,9 +338,27 @@ ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::doSerializeVa
|
| return handleError(DataCloneError, "Couldn't serialize key data", next);
|
| return 0;
|
| }
|
| + v8::Local<v8::Object> jsObject = value.As<v8::Object>();
|
| + uint32_t offscreenCanvasIndex;
|
| + if (V8OffscreenCanvas::hasInstance(value, isolate()) && m_transferredOffscreenCanvas.tryGet(jsObject, &offscreenCanvasIndex)) {
|
| + return writeTransferredOffscreenCanvas(value, offscreenCanvasIndex, next);
|
| + }
|
| return ScriptValueSerializer::doSerializeValue(value, next);
|
| }
|
|
|
| +ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeTransferredOffscreenCanvas(v8::Local<v8::Value> value, uint32_t index, ScriptValueSerializer::StateBase* next)
|
| +{
|
| + OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl(value.As<v8::Object>());
|
| + if (!offscreenCanvas)
|
| + return 0;
|
| + if (offscreenCanvas->isNeutered())
|
| + return handleError(DataCloneError, "An OffscreenCanvas is neutered and could not be cloned.", next);
|
| + if (offscreenCanvas->renderingContext())
|
| + return handleError(DataCloneError, "An OffscreenCanvas with a context could not be cloned.", next);
|
| + m_writer.writeTransferredOffscreenCanvas(index, offscreenCanvas->width(), offscreenCanvas->height(), offscreenCanvas->getAssociatedCanvasId());
|
| + return 0;
|
| +}
|
| +
|
| bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, ScriptValueCompositeCreator& creator)
|
| {
|
| SerializationTag tag;
|
| @@ -325,6 +375,19 @@ bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, Sc
|
| return false;
|
| creator.pushObjectReference(*value);
|
| break;
|
| + case OffscreenCanvasTransferTag:
|
| + uint32_t index, width, height, id;
|
| + if (!doReadUint32(&index))
|
| + return false;
|
| + if (!doReadUint32(&width))
|
| + return false;
|
| + if (!doReadUint32(&height))
|
| + return false;
|
| + if (!doReadUint32(&id))
|
| + return false;
|
| + if (!creator.tryGetTransferredOffscreenCanvas(index, width, height, id, value))
|
| + return false;
|
| + break;
|
| default:
|
| return SerializedScriptValueReader::readWithTag(tag, value, creator);
|
| }
|
| @@ -625,9 +688,27 @@ bool SerializedScriptValueReaderForModules::doReadKeyUsages(WebCryptoKeyUsageMas
|
|
|
| ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedScriptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferContentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents)
|
| : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBitmapContents)
|
| + , m_offscreenCanvases(0)
|
| + , m_reader(reader)
|
| {
|
| }
|
|
|
| +bool ScriptValueDeserializerForModules::tryGetTransferredOffscreenCanvas(uint32_t index, uint32_t width, uint32_t height, uint32_t id, v8::Local<v8::Value>* object)
|
| +{
|
| + v8::Local<v8::Value> result;
|
| + OffscreenCanvas* offscreenCanvas = OffscreenCanvas::create(width, height);
|
| + offscreenCanvas->setAssociatedCanvasId(id);
|
| + v8::Isolate* isolate = m_reader.getScriptState()->isolate();
|
| + v8::Local<v8::Object> creationContext = m_reader.getScriptState()->context()->Global();
|
| + result = toV8(offscreenCanvas, creationContext, isolate);
|
| + if (result.IsEmpty()) {
|
| + return false;
|
| + }
|
| + m_offscreenCanvases.append(result);
|
| + *object = result;
|
| + return true;
|
| +}
|
| +
|
| bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value)
|
| {
|
| return toSerializedScriptValueReaderForModules(reader()).read(value, *this);
|
|
|