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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" 5 #include "bindings/modules/v8/ScriptValueSerializerForModules.h"
6 6
7 #include "bindings/core/v8/SerializationTag.h" 7 #include "bindings/core/v8/SerializationTag.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/modules/v8/TransferablesForModules.h"
9 #include "bindings/modules/v8/V8CryptoKey.h" 10 #include "bindings/modules/v8/V8CryptoKey.h"
10 #include "bindings/modules/v8/V8DOMFileSystem.h" 11 #include "bindings/modules/v8/V8DOMFileSystem.h"
12 #include "bindings/modules/v8/V8OffscreenCanvas.h"
11 #include "modules/filesystem/DOMFileSystem.h" 13 #include "modules/filesystem/DOMFileSystem.h"
12 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
13 15
14 namespace blink { 16 namespace blink {
15 17
16 enum CryptoKeyAlgorithmTag { 18 enum CryptoKeyAlgorithmTag {
17 AesCbcTag = 1, 19 AesCbcTag = 1,
18 HmacTag = 2, 20 HmacTag = 2,
19 RsaSsaPkcs1v1_5Tag = 3, 21 RsaSsaPkcs1v1_5Tag = 3,
20 // ID 4 was used by RsaEs, while still behind experimental flag. 22 // ID 4 was used by RsaEs, while still behind experimental flag.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 NoParamsKeyTag = 6, 67 NoParamsKeyTag = 6,
66 // Maximum allowed value is 255 68 // Maximum allowed value is 255
67 }; 69 };
68 70
69 enum AssymetricCryptoKeyType { 71 enum AssymetricCryptoKeyType {
70 PublicKeyType = 1, 72 PublicKeyType = 1,
71 PrivateKeyType = 2, 73 PrivateKeyType = 2,
72 // Maximum allowed value is 2^32-1 74 // Maximum allowed value is 2^32-1
73 }; 75 };
74 76
75 77 ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScrip tValueWriter& writer, Transferables* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptS tate)
76 ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScrip tValueWriter& writer, const Transferables* transferables, WebBlobInfoArray* blob Info, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* s criptState)
77 : ScriptValueSerializer(writer, transferables, blobInfo, blobDataHandles, tr yCatch, scriptState) 78 : ScriptValueSerializer(writer, transferables, blobInfo, blobDataHandles, tr yCatch, scriptState)
79 , m_writer(writer)
78 { 80 {
81 ASSERT(!tryCatch.HasCaught());
82 if (!transferables)
83 return;
84 auto& offscreenCanvases = static_cast<TransferablesForModules*>(transferable s)->offscreenCanvases;
85 for (size_t i = 0; i < offscreenCanvases.size(); i++) {
86 v8::Local<v8::Object> v8OffscreenCanvas;
87 if (offscreenCanvases[i].get()) {
88 v8::Local<v8::Value> wrapper = toV8(offscreenCanvases[i].get(), scri ptState);
89 if (!wrapper.IsEmpty()) {
90 v8OffscreenCanvas = wrapper.As<v8::Object>();
91 if (!m_transferredOffscreenCanvas.contains(v8OffscreenCanvas))
92 m_transferredOffscreenCanvas.set(v8OffscreenCanvas, i);
93 }
94 }
95 }
79 } 96 }
80 97
81 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileS ystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next) 98 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileS ystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next)
82 { 99 {
83 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>()); 100 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>());
84 if (!fs) 101 if (!fs)
85 return 0; 102 return 0;
86 if (!fs->clonable()) 103 if (!fs->clonable())
87 return handleError(DataCloneError, "A FileSystem object could not be clo ned.", next); 104 return handleError(DataCloneError, "A FileSystem object could not be clo ned.", next);
88 105
(...skipping 10 matching lines...) Expand all
99 } 116 }
100 117
101 void SerializedScriptValueWriterForModules::writeDOMFileSystem(int type, const S tring& name, const String& url) 118 void SerializedScriptValueWriterForModules::writeDOMFileSystem(int type, const S tring& name, const String& url)
102 { 119 {
103 append(DOMFileSystemTag); 120 append(DOMFileSystemTag);
104 doWriteUint32(type); 121 doWriteUint32(type);
105 doWriteWebCoreString(name); 122 doWriteWebCoreString(name);
106 doWriteWebCoreString(url); 123 doWriteWebCoreString(url);
107 } 124 }
108 125
126 void SerializedScriptValueWriterForModules::writeTransferredOffscreenCanvas(uint 32_t index, uint32_t width, uint32_t height, uint32_t id)
127 {
128 append(OffscreenCanvasTransferTag);
129 doWriteUint32(index);
130 doWriteUint32(width);
131 doWriteUint32(height);
132 doWriteUint32(id);
133 }
134
109 bool SerializedScriptValueWriterForModules::writeCryptoKey(const WebCryptoKey& k ey) 135 bool SerializedScriptValueWriterForModules::writeCryptoKey(const WebCryptoKey& k ey)
110 { 136 {
111 append(static_cast<uint8_t>(CryptoKeyTag)); 137 append(static_cast<uint8_t>(CryptoKeyTag));
112 138
113 switch (key.algorithm().paramsType()) { 139 switch (key.algorithm().paramsType()) {
114 case WebCryptoKeyAlgorithmParamsTypeAes: 140 case WebCryptoKeyAlgorithmParamsTypeAes:
115 doWriteAesKey(key); 141 doWriteAesKey(key);
116 break; 142 break;
117 case WebCryptoKeyAlgorithmParamsTypeHmac: 143 case WebCryptoKeyAlgorithmParamsTypeHmac:
118 doWriteHmacKey(key); 144 doWriteHmacKey(key);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return handleError(DataCloneError, "An object could not be cloned.", next); 325 return handleError(DataCloneError, "An object could not be cloned.", next);
300 greyObject(jsObject); 326 greyObject(jsObject);
301 327
302 if (isDOMFileSystem) 328 if (isDOMFileSystem)
303 return writeDOMFileSystem(value, next); 329 return writeDOMFileSystem(value, next);
304 330
305 if (!writeCryptoKey(value)) 331 if (!writeCryptoKey(value))
306 return handleError(DataCloneError, "Couldn't serialize key data", ne xt); 332 return handleError(DataCloneError, "Couldn't serialize key data", ne xt);
307 return 0; 333 return 0;
308 } 334 }
335 v8::Local<v8::Object> jsObject = value.As<v8::Object>();
336 uint32_t offscreenCanvasIndex;
337 if (V8OffscreenCanvas::hasInstance(value, isolate()) && m_transferredOffscre enCanvas.tryGet(jsObject, &offscreenCanvasIndex)) {
338 return writeTransferredOffscreenCanvas(value, offscreenCanvasIndex, next );
339 }
309 return ScriptValueSerializer::doSerializeValue(value, next); 340 return ScriptValueSerializer::doSerializeValue(value, next);
310 } 341 }
311 342
343 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeTransfer redOffscreenCanvas(v8::Local<v8::Value> value, uint32_t index, ScriptValueSerial izer::StateBase* next)
344 {
345 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl(value.As<v8::Ob ject>());
346 if (!offscreenCanvas)
347 return nullptr;
348 if (offscreenCanvas->isNeutered())
349 return handleError(DataCloneError, "An OffscreenCanvas is neutered and c ould not be cloned.", next);
350 if (offscreenCanvas->renderingContext())
351 return handleError(DataCloneError, "An OffscreenCanvas with a context co uld not be cloned.", next);
352 m_writer.writeTransferredOffscreenCanvas(index, offscreenCanvas->width(), of fscreenCanvas->height(), offscreenCanvas->getAssociatedCanvasId());
353 return nullptr;
354 }
355
312 bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, Sc riptValueCompositeCreator& creator) 356 bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, Sc riptValueCompositeCreator& creator)
313 { 357 {
314 SerializationTag tag; 358 SerializationTag tag;
315 if (!readTag(&tag)) 359 if (!readTag(&tag))
316 return false; 360 return false;
317 switch (tag) { 361 switch (tag) {
318 case DOMFileSystemTag: 362 case DOMFileSystemTag:
319 if (!readDOMFileSystem(value)) 363 if (!readDOMFileSystem(value))
320 return false; 364 return false;
321 creator.pushObjectReference(*value); 365 creator.pushObjectReference(*value);
322 break; 366 break;
323 case CryptoKeyTag: 367 case CryptoKeyTag:
324 if (!readCryptoKey(value)) 368 if (!readCryptoKey(value))
325 return false; 369 return false;
326 creator.pushObjectReference(*value); 370 creator.pushObjectReference(*value);
327 break; 371 break;
372 case OffscreenCanvasTransferTag:
373 uint32_t index, width, height, id;
374 if (!doReadUint32(&index))
375 return false;
376 if (!doReadUint32(&width))
377 return false;
378 if (!doReadUint32(&height))
379 return false;
380 if (!doReadUint32(&id))
381 return false;
382 if (!creator.tryGetTransferredOffscreenCanvas(index, width, height, id, value))
383 return false;
384 break;
328 default: 385 default:
329 return SerializedScriptValueReader::readWithTag(tag, value, creator); 386 return SerializedScriptValueReader::readWithTag(tag, value, creator);
330 } 387 }
331 return !value->IsEmpty(); 388 return !value->IsEmpty();
332 } 389 }
333 390
334 bool SerializedScriptValueReaderForModules::readDOMFileSystem(v8::Local<v8::Valu e>* value) 391 bool SerializedScriptValueReaderForModules::readDOMFileSystem(v8::Local<v8::Valu e>* value)
335 { 392 {
336 uint32_t type; 393 uint32_t type;
337 String name; 394 String name;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (rawUsages & UnwrapKeyUsage) 675 if (rawUsages & UnwrapKeyUsage)
619 usages |= WebCryptoKeyUsageUnwrapKey; 676 usages |= WebCryptoKeyUsageUnwrapKey;
620 if (rawUsages & DeriveBitsUsage) 677 if (rawUsages & DeriveBitsUsage)
621 usages |= WebCryptoKeyUsageDeriveBits; 678 usages |= WebCryptoKeyUsageDeriveBits;
622 679
623 return true; 680 return true;
624 } 681 }
625 682
626 ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedS criptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferC ontentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents ) 683 ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedS criptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferC ontentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents )
627 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBi tmapContents) 684 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBi tmapContents)
685 , m_reader(reader)
628 { 686 {
629 } 687 }
630 688
689 bool ScriptValueDeserializerForModules::tryGetTransferredOffscreenCanvas(uint32_ t index, uint32_t width, uint32_t height, uint32_t id, v8::Local<v8::Value>* obj ect)
690 {
691 OffscreenCanvas* offscreenCanvas = OffscreenCanvas::create(width, height);
692 offscreenCanvas->setAssociatedCanvasId(id);
693 *object = toV8(offscreenCanvas, m_reader.getScriptState());
694 if ((*object).IsEmpty())
695 return false;
696 return true;
697 }
698
631 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) 699 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value)
632 { 700 {
633 return toSerializedScriptValueReaderForModules(reader()).read(value, *this); 701 return toSerializedScriptValueReaderForModules(reader()).read(value, *this);
634 } 702 }
635 703
636 } // namespace blink 704 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698