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

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

Issue 1904973003: Revert of Make OffscreenCanvas Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
10 #include "bindings/modules/v8/V8CryptoKey.h" 9 #include "bindings/modules/v8/V8CryptoKey.h"
11 #include "bindings/modules/v8/V8DOMFileSystem.h" 10 #include "bindings/modules/v8/V8DOMFileSystem.h"
12 #include "bindings/modules/v8/V8OffscreenCanvas.h"
13 #include "modules/filesystem/DOMFileSystem.h" 11 #include "modules/filesystem/DOMFileSystem.h"
14 #include "public/platform/Platform.h" 12 #include "public/platform/Platform.h"
15 13
16 namespace blink { 14 namespace blink {
17 15
18 enum CryptoKeyAlgorithmTag { 16 enum CryptoKeyAlgorithmTag {
19 AesCbcTag = 1, 17 AesCbcTag = 1,
20 HmacTag = 2, 18 HmacTag = 2,
21 RsaSsaPkcs1v1_5Tag = 3, 19 RsaSsaPkcs1v1_5Tag = 3,
22 // ID 4 was used by RsaEs, while still behind experimental flag. 20 // ID 4 was used by RsaEs, while still behind experimental flag.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 NoParamsKeyTag = 6, 65 NoParamsKeyTag = 6,
68 // Maximum allowed value is 255 66 // Maximum allowed value is 255
69 }; 67 };
70 68
71 enum AssymetricCryptoKeyType { 69 enum AssymetricCryptoKeyType {
72 PublicKeyType = 1, 70 PublicKeyType = 1,
73 PrivateKeyType = 2, 71 PrivateKeyType = 2,
74 // Maximum allowed value is 2^32-1 72 // Maximum allowed value is 2^32-1
75 }; 73 };
76 74
77 ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScrip tValueWriter& writer, Transferables* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptS tate) 75
76 ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScrip tValueWriter& writer, const Transferables* transferables, WebBlobInfoArray* blob Info, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* s criptState)
78 : ScriptValueSerializer(writer, transferables, blobInfo, blobDataHandles, tr yCatch, scriptState) 77 : ScriptValueSerializer(writer, transferables, blobInfo, blobDataHandles, tr yCatch, scriptState)
79 , m_writer(writer)
80 { 78 {
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 }
96 } 79 }
97 80
98 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileS ystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next) 81 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileS ystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next)
99 { 82 {
100 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>()); 83 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>());
101 if (!fs) 84 if (!fs)
102 return 0; 85 return 0;
103 if (!fs->clonable()) 86 if (!fs->clonable())
104 return handleError(DataCloneError, "A FileSystem object could not be clo ned.", next); 87 return handleError(DataCloneError, "A FileSystem object could not be clo ned.", next);
105 88
(...skipping 10 matching lines...) Expand all
116 } 99 }
117 100
118 void SerializedScriptValueWriterForModules::writeDOMFileSystem(int type, const S tring& name, const String& url) 101 void SerializedScriptValueWriterForModules::writeDOMFileSystem(int type, const S tring& name, const String& url)
119 { 102 {
120 append(DOMFileSystemTag); 103 append(DOMFileSystemTag);
121 doWriteUint32(type); 104 doWriteUint32(type);
122 doWriteWebCoreString(name); 105 doWriteWebCoreString(name);
123 doWriteWebCoreString(url); 106 doWriteWebCoreString(url);
124 } 107 }
125 108
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
135 bool SerializedScriptValueWriterForModules::writeCryptoKey(const WebCryptoKey& k ey) 109 bool SerializedScriptValueWriterForModules::writeCryptoKey(const WebCryptoKey& k ey)
136 { 110 {
137 append(static_cast<uint8_t>(CryptoKeyTag)); 111 append(static_cast<uint8_t>(CryptoKeyTag));
138 112
139 switch (key.algorithm().paramsType()) { 113 switch (key.algorithm().paramsType()) {
140 case WebCryptoKeyAlgorithmParamsTypeAes: 114 case WebCryptoKeyAlgorithmParamsTypeAes:
141 doWriteAesKey(key); 115 doWriteAesKey(key);
142 break; 116 break;
143 case WebCryptoKeyAlgorithmParamsTypeHmac: 117 case WebCryptoKeyAlgorithmParamsTypeHmac:
144 doWriteHmacKey(key); 118 doWriteHmacKey(key);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return handleError(DataCloneError, "An object could not be cloned.", next); 299 return handleError(DataCloneError, "An object could not be cloned.", next);
326 greyObject(jsObject); 300 greyObject(jsObject);
327 301
328 if (isDOMFileSystem) 302 if (isDOMFileSystem)
329 return writeDOMFileSystem(value, next); 303 return writeDOMFileSystem(value, next);
330 304
331 if (!writeCryptoKey(value)) 305 if (!writeCryptoKey(value))
332 return handleError(DataCloneError, "Couldn't serialize key data", ne xt); 306 return handleError(DataCloneError, "Couldn't serialize key data", ne xt);
333 return 0; 307 return 0;
334 } 308 }
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 }
340 return ScriptValueSerializer::doSerializeValue(value, next); 309 return ScriptValueSerializer::doSerializeValue(value, next);
341 } 310 }
342 311
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
356 bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, Sc riptValueCompositeCreator& creator) 312 bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, Sc riptValueCompositeCreator& creator)
357 { 313 {
358 SerializationTag tag; 314 SerializationTag tag;
359 if (!readTag(&tag)) 315 if (!readTag(&tag))
360 return false; 316 return false;
361 switch (tag) { 317 switch (tag) {
362 case DOMFileSystemTag: 318 case DOMFileSystemTag:
363 if (!readDOMFileSystem(value)) 319 if (!readDOMFileSystem(value))
364 return false; 320 return false;
365 creator.pushObjectReference(*value); 321 creator.pushObjectReference(*value);
366 break; 322 break;
367 case CryptoKeyTag: 323 case CryptoKeyTag:
368 if (!readCryptoKey(value)) 324 if (!readCryptoKey(value))
369 return false; 325 return false;
370 creator.pushObjectReference(*value); 326 creator.pushObjectReference(*value);
371 break; 327 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;
385 default: 328 default:
386 return SerializedScriptValueReader::readWithTag(tag, value, creator); 329 return SerializedScriptValueReader::readWithTag(tag, value, creator);
387 } 330 }
388 return !value->IsEmpty(); 331 return !value->IsEmpty();
389 } 332 }
390 333
391 bool SerializedScriptValueReaderForModules::readDOMFileSystem(v8::Local<v8::Valu e>* value) 334 bool SerializedScriptValueReaderForModules::readDOMFileSystem(v8::Local<v8::Valu e>* value)
392 { 335 {
393 uint32_t type; 336 uint32_t type;
394 String name; 337 String name;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 if (rawUsages & UnwrapKeyUsage) 618 if (rawUsages & UnwrapKeyUsage)
676 usages |= WebCryptoKeyUsageUnwrapKey; 619 usages |= WebCryptoKeyUsageUnwrapKey;
677 if (rawUsages & DeriveBitsUsage) 620 if (rawUsages & DeriveBitsUsage)
678 usages |= WebCryptoKeyUsageDeriveBits; 621 usages |= WebCryptoKeyUsageDeriveBits;
679 622
680 return true; 623 return true;
681 } 624 }
682 625
683 ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedS criptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferC ontentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents ) 626 ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedS criptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferC ontentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents )
684 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBi tmapContents) 627 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBi tmapContents)
685 , m_reader(reader)
686 { 628 {
687 } 629 }
688 630
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
699 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) 631 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value)
700 { 632 {
701 return toSerializedScriptValueReaderForModules(reader()).read(value, *this); 633 return toSerializedScriptValueReaderForModules(reader()).read(value, *this);
702 } 634 }
703 635
704 } // namespace blink 636 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698