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

Unified Diff: third_party/WebKit/Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp

Issue 1862033002: Make OffscreenCanvas Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address haraken's comments, need bots to test 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 side-by-side diff with in-line comments
Download patch
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..61424bc9e6d64ef03791decc79076ba4e52038a6 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/TransferablesForModules.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,25 @@ enum AssymetricCryptoKeyType {
// Maximum allowed value is 2^32-1
};
-
-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();
+ if (!transferables)
+ return;
+ auto& offscreenCanvases = static_cast<TransferablesForModules*>(transferables)->offscreenCanvases;
+ for (size_t i = 0; i < offscreenCanvases.size(); i++) {
+ v8::Local<v8::Object> v8OffscreenCanvas = v8::Local<v8::Object>();
haraken 2016/04/21 00:29:03 ' = v8::Local<v8::Object>()' is not needed.
xidachen 2016/04/21 15:32:48 Done.
+ if (offscreenCanvases[i].get()) {
+ v8::Local<v8::Value> wrapper = toV8(offscreenCanvases[i].get(), creationContext, isolate());
haraken 2016/04/21 00:29:02 You can use: toV8(offscreenCanvases[i].get(), s
xidachen 2016/04/21 15:32:48 Done.
+ if (!wrapper.IsEmpty())
+ v8OffscreenCanvas = wrapper.As<v8::Object>();
haraken 2016/04/21 00:29:03 if (wrapper.IsEmpty()) { v8OffscreenCanvas = wra
xidachen 2016/04/21 15:32:48 Done.
+ }
+ if (!m_transferredOffscreenCanvas.contains(v8OffscreenCanvas))
+ m_transferredOffscreenCanvas.set(v8OffscreenCanvas, i);
+ }
}
ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileSystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next)
@@ -106,6 +123,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 +332,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;
haraken 2016/04/21 00:29:02 nullptr
xidachen 2016/04/21 15:32:48 Done.
+ 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;
haraken 2016/04/21 00:29:02 nullptr
xidachen 2016/04/21 15:32:48 Done.
+}
+
bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, ScriptValueCompositeCreator& creator)
{
SerializationTag tag;
@@ -325,6 +369,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 +682,25 @@ bool SerializedScriptValueReaderForModules::doReadKeyUsages(WebCryptoKeyUsageMas
ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedScriptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferContentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents)
: ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBitmapContents)
+ , 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);
haraken 2016/04/21 00:29:03 Use: toV8(offscreenCanvas, scriptState);
xidachen 2016/04/21 15:32:48 Done.
+ if (result.IsEmpty()) {
+ return false;
+ }
+ *object = result;
haraken 2016/04/21 00:29:03 *object = toV8(...) would be enough. result won't
xidachen 2016/04/21 15:32:48 Done.
+ return true;
+}
+
bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value)
{
return toSerializedScriptValueReaderForModules(reader()).read(value, *this);

Powered by Google App Engine
This is Rietveld 408576698