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

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

Issue 1862033002: Make OffscreenCanvas Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no need to register, taking the same approach as extractTransferables 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/SerializedScriptValueForModulesFactory.cpp
diff --git a/third_party/WebKit/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp b/third_party/WebKit/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp
index bafa2c93bb6ca9d27d78816fd336e5b080bb6385..b0ddba22ed801e541426a4402204982d004bc84d 100644
--- a/third_party/WebKit/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp
+++ b/third_party/WebKit/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp
@@ -7,6 +7,8 @@
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/SerializedScriptValue.h"
#include "bindings/modules/v8/ScriptValueSerializerForModules.h"
+#include "bindings/modules/v8/TransferablesForModules.h"
+#include "bindings/modules/v8/V8OffscreenCanvas.h"
#include "core/dom/ExceptionCode.h"
namespace blink {
@@ -32,7 +34,7 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
exceptionState.throwDOMException(DataCloneError, errorMessage);
return serializedValue.release();
case ScriptValueSerializer::Success:
- transferData(serializedValue.get(), writer, transferables, exceptionState, isolate);
+ transferData(isolate, transferables, exceptionState, serializedValue.get(), writer);
return serializedValue.release();
case ScriptValueSerializer::JSException:
ASSERT_NOT_REACHED();
@@ -50,6 +52,33 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
return createFromWire(wireData);
}
+void SerializedScriptValueForModulesFactory::transferData(v8::Isolate* isolate, Transferables* transferables, ExceptionState& exceptionState, SerializedScriptValue* serializedValue, SerializedScriptValueWriter& writer)
+{
+ serializedValue->setData(writer.takeWireString());
+ ASSERT(serializedValue->data().impl()->hasOneRef());
+ if (!transferables)
+ return;
+ auto& offscreenCanvases = static_cast<TransferablesForModules*>(transferables)->offscreenCanvases;
+ if (offscreenCanvases.size()) {
+ HeapHashSet<Member<OffscreenCanvas>> visited;
+ for (size_t i = 0; i < offscreenCanvases.size(); i++) {
+ if (offscreenCanvases[i]->isNeutered()) {
+ exceptionState.throwDOMException(DataCloneError, "OffscreenCanvas at index " + String::number(i) + " is already neutered.");
+ return;
+ }
+ if (offscreenCanvases[i]->renderingContext()) {
+ exceptionState.throwDOMException(DataCloneError, "OffscreenCanvas at index " + String::number(i) + " has an associated context.");
+ return;
+ }
+ if (visited.contains(offscreenCanvases[i].get()))
+ continue;
+ visited.add(offscreenCanvases[i].get());
+ offscreenCanvases[i].get()->setNeutered();
+ }
+ }
+ SerializedScriptValueFactory::transferData(isolate, transferables, exceptionState, serializedValue, writer);
+}
+
ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerialize(v8::Local<v8::Value> value, SerializedScriptValueWriter& writer, Transferables* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessage, v8::Isolate* isolate)
{
ScriptValueSerializerForModules serializer(writer, transferables, blobInfo, blobDataHandles, tryCatch, ScriptState::current(isolate));
@@ -73,5 +102,22 @@ v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String&
return deserializer.deserialize();
}
+bool SerializedScriptValueForModulesFactory::extractTransferables(v8::Isolate* isolate, Transferables& transferables, ExceptionState& exceptionState, v8::Local<v8::Value>& transferableObject, unsigned index)
+{
+ if (SerializedScriptValueFactory::extractTransferables(isolate, transferables, exceptionState, transferableObject, index))
+ return true;
+ if (V8OffscreenCanvas::hasInstance(transferableObject, isolate)) {
+ OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl(v8::Local<v8::Object>::Cast(transferableObject));
+ auto& offscreenCanvases = static_cast<TransferablesForModules*>(&transferables)->offscreenCanvases;
+ if (offscreenCanvases.contains(offscreenCanvas)) {
+ exceptionState.throwDOMException(DataCloneError, "OffscreenCanvas at index " + String::number(index) + " is a duplicate of an earlier OffscreenCanvas.");
+ return false;
+ }
+ offscreenCanvases.append(offscreenCanvas);
+ return true;
+ }
+ return false;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698