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

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: rebase, compiles but crashes some layout tests 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/TransferableOffscreenCanvas.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
77 static v8::Local<v8::Object> toV8Object(OffscreenCanvas* impl, v8::Local<v8::Obj ect> creationContext, v8::Isolate* isolate)
haraken 2016/04/19 00:48:10 Why do you need this helper method? Can't you simp
xidachen 2016/04/19 15:29:50 Simplified. This helper function is now removed.
78 {
79 if (!impl)
80 return v8::Local<v8::Object>();
81 v8::Local<v8::Value> wrapper = toV8(impl, creationContext, isolate);
82 if (wrapper.IsEmpty())
83 return v8::Local<v8::Object>();
84 return wrapper.As<v8::Object>();
85 }
75 86
76 ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScrip tValueWriter& writer, const Transferables* transferables, WebBlobInfoArray* blob Info, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* s criptState) 87 ScriptValueSerializerForModules::ScriptValueSerializerForModules(SerializedScrip tValueWriter& writer, Transferables* transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, ScriptState* scriptS tate)
77 : ScriptValueSerializer(writer, transferables, blobInfo, blobDataHandles, tr yCatch, scriptState) 88 : ScriptValueSerializer(writer, transferables, blobInfo, blobDataHandles, tr yCatch, scriptState)
89 , m_writer(writer)
78 { 90 {
91 ASSERT(!tryCatch.HasCaught());
92 v8::Local<v8::Object> creationContext = scriptState->context()->Global();
93 auto& offscreenCanvases = static_cast<TransferableOffscreenCanvas*>(transfer ables)->offscreenCanvases;
94 for (size_t i = 0; i < offscreenCanvases.size(); i++) {
95 v8::Local<v8::Object> v8OffscreenCanvas = toV8Object(offscreenCanvases[i ].get(), creationContext, isolate());
96 if (!m_transferredOffscreenCanvas.contains(v8OffscreenCanvas))
97 m_transferredOffscreenCanvas.set(v8OffscreenCanvas, i);
98 }
79 } 99 }
80 100
81 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileS ystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next) 101 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeDOMFileS ystem(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next)
82 { 102 {
83 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>()); 103 DOMFileSystem* fs = V8DOMFileSystem::toImpl(value.As<v8::Object>());
84 if (!fs) 104 if (!fs)
85 return 0; 105 return 0;
86 if (!fs->clonable()) 106 if (!fs->clonable())
87 return handleError(DataCloneError, "A FileSystem object could not be clo ned.", next); 107 return handleError(DataCloneError, "A FileSystem object could not be clo ned.", next);
88 108
(...skipping 10 matching lines...) Expand all
99 } 119 }
100 120
101 void SerializedScriptValueWriterForModules::writeDOMFileSystem(int type, const S tring& name, const String& url) 121 void SerializedScriptValueWriterForModules::writeDOMFileSystem(int type, const S tring& name, const String& url)
102 { 122 {
103 append(DOMFileSystemTag); 123 append(DOMFileSystemTag);
104 doWriteUint32(type); 124 doWriteUint32(type);
105 doWriteWebCoreString(name); 125 doWriteWebCoreString(name);
106 doWriteWebCoreString(url); 126 doWriteWebCoreString(url);
107 } 127 }
108 128
129 void SerializedScriptValueWriterForModules::writeTransferredOffscreenCanvas(uint 32_t index, uint32_t width, uint32_t height, uint32_t id)
130 {
131 append(OffscreenCanvasTransferTag);
132 doWriteUint32(index);
133 doWriteUint32(width);
134 doWriteUint32(height);
135 doWriteUint32(id);
136 }
137
109 bool SerializedScriptValueWriterForModules::writeCryptoKey(const WebCryptoKey& k ey) 138 bool SerializedScriptValueWriterForModules::writeCryptoKey(const WebCryptoKey& k ey)
110 { 139 {
111 append(static_cast<uint8_t>(CryptoKeyTag)); 140 append(static_cast<uint8_t>(CryptoKeyTag));
112 141
113 switch (key.algorithm().paramsType()) { 142 switch (key.algorithm().paramsType()) {
114 case WebCryptoKeyAlgorithmParamsTypeAes: 143 case WebCryptoKeyAlgorithmParamsTypeAes:
115 doWriteAesKey(key); 144 doWriteAesKey(key);
116 break; 145 break;
117 case WebCryptoKeyAlgorithmParamsTypeHmac: 146 case WebCryptoKeyAlgorithmParamsTypeHmac:
118 doWriteHmacKey(key); 147 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); 328 return handleError(DataCloneError, "An object could not be cloned.", next);
300 greyObject(jsObject); 329 greyObject(jsObject);
301 330
302 if (isDOMFileSystem) 331 if (isDOMFileSystem)
303 return writeDOMFileSystem(value, next); 332 return writeDOMFileSystem(value, next);
304 333
305 if (!writeCryptoKey(value)) 334 if (!writeCryptoKey(value))
306 return handleError(DataCloneError, "Couldn't serialize key data", ne xt); 335 return handleError(DataCloneError, "Couldn't serialize key data", ne xt);
307 return 0; 336 return 0;
308 } 337 }
338 v8::Local<v8::Object> jsObject = value.As<v8::Object>();
339 uint32_t offscreenCanvasIndex;
340 if (V8OffscreenCanvas::hasInstance(value, isolate()) && m_transferredOffscre enCanvas.tryGet(jsObject, &offscreenCanvasIndex)) {
341 return writeTransferredOffscreenCanvas(value, offscreenCanvasIndex, next );
342 }
309 return ScriptValueSerializer::doSerializeValue(value, next); 343 return ScriptValueSerializer::doSerializeValue(value, next);
310 } 344 }
311 345
346 ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::writeTransfer redOffscreenCanvas(v8::Local<v8::Value> value, uint32_t index, ScriptValueSerial izer::StateBase* next)
347 {
348 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl(value.As<v8::Ob ject>());
349 if (!offscreenCanvas)
350 return 0;
351 if (offscreenCanvas->isNeutered())
352 return handleError(DataCloneError, "An OffscreenCanvas is neutered and c ould not be cloned.", next);
353 if (offscreenCanvas->renderingContext())
354 return handleError(DataCloneError, "An OffscreenCanvas with a context co uld not be cloned.", next);
355 m_writer.writeTransferredOffscreenCanvas(index, offscreenCanvas->width(), of fscreenCanvas->height(), offscreenCanvas->getAssociatedCanvasId());
356 return 0;
357 }
358
312 bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, Sc riptValueCompositeCreator& creator) 359 bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, Sc riptValueCompositeCreator& creator)
313 { 360 {
314 SerializationTag tag; 361 SerializationTag tag;
315 if (!readTag(&tag)) 362 if (!readTag(&tag))
316 return false; 363 return false;
317 switch (tag) { 364 switch (tag) {
318 case DOMFileSystemTag: 365 case DOMFileSystemTag:
319 if (!readDOMFileSystem(value)) 366 if (!readDOMFileSystem(value))
320 return false; 367 return false;
321 creator.pushObjectReference(*value); 368 creator.pushObjectReference(*value);
322 break; 369 break;
323 case CryptoKeyTag: 370 case CryptoKeyTag:
324 if (!readCryptoKey(value)) 371 if (!readCryptoKey(value))
325 return false; 372 return false;
326 creator.pushObjectReference(*value); 373 creator.pushObjectReference(*value);
327 break; 374 break;
375 case OffscreenCanvasTransferTag:
376 uint32_t index, width, height, id;
377 if (!doReadUint32(&index))
378 return false;
379 if (!doReadUint32(&width))
380 return false;
381 if (!doReadUint32(&height))
382 return false;
383 if (!doReadUint32(&id))
384 return false;
385 if (!creator.tryGetTransferredOffscreenCanvas(index, width, height, id, value))
386 return false;
387 break;
328 default: 388 default:
329 return SerializedScriptValueReader::readWithTag(tag, value, creator); 389 return SerializedScriptValueReader::readWithTag(tag, value, creator);
330 } 390 }
331 return !value->IsEmpty(); 391 return !value->IsEmpty();
332 } 392 }
333 393
334 bool SerializedScriptValueReaderForModules::readDOMFileSystem(v8::Local<v8::Valu e>* value) 394 bool SerializedScriptValueReaderForModules::readDOMFileSystem(v8::Local<v8::Valu e>* value)
335 { 395 {
336 uint32_t type; 396 uint32_t type;
337 String name; 397 String name;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (rawUsages & UnwrapKeyUsage) 678 if (rawUsages & UnwrapKeyUsage)
619 usages |= WebCryptoKeyUsageUnwrapKey; 679 usages |= WebCryptoKeyUsageUnwrapKey;
620 if (rawUsages & DeriveBitsUsage) 680 if (rawUsages & DeriveBitsUsage)
621 usages |= WebCryptoKeyUsageDeriveBits; 681 usages |= WebCryptoKeyUsageDeriveBits;
622 682
623 return true; 683 return true;
624 } 684 }
625 685
626 ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedS criptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferC ontentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents ) 686 ScriptValueDeserializerForModules::ScriptValueDeserializerForModules(SerializedS criptValueReaderForModules& reader, MessagePortArray* messagePorts, ArrayBufferC ontentsArray* arrayBufferContents, ImageBitmapContentsArray* imageBitmapContents )
627 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBi tmapContents) 687 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents, imageBi tmapContents)
688 , m_offscreenCanvases(0)
689 , m_reader(reader)
628 { 690 {
629 } 691 }
630 692
693 bool ScriptValueDeserializerForModules::tryGetTransferredOffscreenCanvas(uint32_ t index, uint32_t width, uint32_t height, uint32_t id, v8::Local<v8::Value>* obj ect)
694 {
695 v8::Local<v8::Value> result;
696 OffscreenCanvas* offscreenCanvas = OffscreenCanvas::create(width, height);
697 offscreenCanvas->setAssociatedCanvasId(id);
698 v8::Isolate* isolate = m_reader.getScriptState()->isolate();
699 v8::Local<v8::Object> creationContext = m_reader.getScriptState()->context() ->Global();
700 result = toV8(offscreenCanvas, creationContext, isolate);
701 if (result.IsEmpty()) {
702 return false;
703 }
704 m_offscreenCanvases.append(result);
haraken 2016/04/19 00:48:10 Where are the appended results used?
xidachen 2016/04/19 15:29:50 Turns out m_offscreenCanvases isn't needed, remove
705 *object = result;
706 return true;
707 }
708
631 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) 709 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value)
632 { 710 {
633 return toSerializedScriptValueReaderForModules(reader()).read(value, *this); 711 return toSerializedScriptValueReaderForModules(reader()).read(value, *this);
634 } 712 }
635 713
636 } // namespace blink 714 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698