 Chromium Code Reviews
 Chromium Code Reviews Issue 1862033002:
  Make OffscreenCanvas Transferable  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1862033002:
  Make OffscreenCanvas Transferable  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..2e3ae4dfb7f328e936781015c3b6cef11600f4bc 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 { | 
| @@ -50,6 +52,33 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create | 
| return createFromWire(wireData); | 
| } | 
| +void SerializedScriptValueForModulesFactory::transferData(SerializedScriptValue* serializedValue, SerializedScriptValueWriter& writer, Transferables* transferables, ExceptionState& exceptionState, v8::Isolate* isolate) | 
| +{ | 
| + 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(serializedValue, writer, transferables, exceptionState, isolate); | 
| +} | 
| + | 
| 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 i) | 
| 
haraken
2016/04/21 00:29:03
i => index
 
xidachen
2016/04/21 15:32:48
Done.
 | 
| +{ | 
| + if (SerializedScriptValueFactory::extractTransferables(isolate, transferables, exceptionState, transferableObject, i)) | 
| + 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(i) + " is a duplicate of an earlier OffscreenCanvas."); | 
| + return false; | 
| + } | 
| + offscreenCanvases.append(offscreenCanvas); | 
| + return true; | 
| + } | 
| + return false; | 
| +} | 
| + | 
| } // namespace blink |