Chromium Code Reviews| 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 50182cdafc96e88d8c8c48ca0e9efe4fc1c7c6b7..28146e94260f029eb7e90378690ddf18b4eecc15 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,28 @@ 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) |
|
haraken
2016/04/19 00:48:10
Why do you need this helper method? Can't you simp
xidachen
2016/04/19 15:29:50
Simplified. This helper function is now removed.
|
| +{ |
| + 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, const Transferables* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptState) |
| +ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScriptValueWriter& writer, Transferables* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptState) |
| : ScriptValueSerializer(writer, transferables, blobInfo, blobDataHandles, tryCatch, scriptState) |
| + , m_writer(writer) |
| { |
| + ASSERT(!tryCatch.HasCaught()); |
| + v8::Local<v8::Object> creationContext = scriptState->context()->Global(); |
| + auto& offscreenCanvases = static_cast<TransferableOffscreenCanvas*>(transferables)->offscreenCanvases; |
| + for (size_t i = 0; i < offscreenCanvases.size(); i++) { |
| + v8::Local<v8::Object> v8OffscreenCanvas = toV8Object(offscreenCanvases[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 +126,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 +335,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 +372,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 +685,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); |
|
haraken
2016/04/19 00:48:10
Where are the appended results used?
xidachen
2016/04/19 15:29:50
Turns out m_offscreenCanvases isn't needed, remove
|
| + *object = result; |
| + return true; |
| +} |
| + |
| bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) |
| { |
| return toSerializedScriptValueReaderForModules(reader()).read(value, *this); |