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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptValueSerializer.h

Issue 1409243005: Make ImageBitmap Transferable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better transfer function Created 5 years, 2 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 #ifndef ScriptValueSerializer_h 5 #ifndef ScriptValueSerializer_h
6 #define ScriptValueSerializer_h 6 #define ScriptValueSerializer_h
7 7
8 #include "bindings/core/v8/SerializationTag.h" 8 #include "bindings/core/v8/SerializationTag.h"
9 #include "bindings/core/v8/SerializedScriptValue.h" 9 #include "bindings/core/v8/SerializedScriptValue.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
11 #include "core/CoreExport.h" 11 #include "core/CoreExport.h"
12 #include "core/frame/ImageBitmap.h"
12 #include "wtf/ArrayBufferContents.h" 13 #include "wtf/ArrayBufferContents.h"
13 #include "wtf/HashMap.h" 14 #include "wtf/HashMap.h"
14 #include "wtf/Noncopyable.h" 15 #include "wtf/Noncopyable.h"
15 #include "wtf/Vector.h" 16 #include "wtf/Vector.h"
16 #include "wtf/text/WTFString.h" 17 #include "wtf/text/WTFString.h"
17 #include <v8.h> 18 #include <v8.h>
18 19
19 namespace blink { 20 namespace blink {
20 21
21 class CompositorProxy; 22 class CompositorProxy;
22 class DOMArrayBuffer; 23 class DOMArrayBuffer;
23 class DOMArrayBufferView; 24 class DOMArrayBufferView;
24 class DOMSharedArrayBuffer; 25 class DOMSharedArrayBuffer;
25 class File; 26 class File;
26 class FileList; 27 class FileList;
28 class ImageBitmap;
27 29
28 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; 30 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
29 31
30 // V8ObjectMap is a map from V8 objects to arbitrary values of type T. 32 // V8ObjectMap is a map from V8 objects to arbitrary values of type T.
31 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf: :HashMaps; 33 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf: :HashMaps;
32 // this class should be used instead. GCObject must be a subtype of v8::Object. 34 // this class should be used instead. GCObject must be a subtype of v8::Object.
33 // Suggested usage: 35 // Suggested usage:
34 // V8ObjectMap<v8::Object, int> map; 36 // V8ObjectMap<v8::Object, int> map;
35 // v8::Local<v8::Object> obj = ...; 37 // v8::Local<v8::Object> obj = ...;
36 // map.set(obj, 42); 38 // map.set(obj, 42);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void writeFile(const File&); 132 void writeFile(const File&);
131 void writeFileIndex(int blobIndex); 133 void writeFileIndex(int blobIndex);
132 void writeFileList(const FileList&); 134 void writeFileList(const FileList&);
133 void writeFileListIndex(const Vector<int>& blobIndices); 135 void writeFileListIndex(const Vector<int>& blobIndices);
134 void writeArrayBuffer(const DOMArrayBuffer&); 136 void writeArrayBuffer(const DOMArrayBuffer&);
135 void writeArrayBufferView(const DOMArrayBufferView&); 137 void writeArrayBufferView(const DOMArrayBufferView&);
136 void writeImageData(uint32_t width, uint32_t height, const uint8_t* pixelDat a, uint32_t pixelDataLength); 138 void writeImageData(uint32_t width, uint32_t height, const uint8_t* pixelDat a, uint32_t pixelDataLength);
137 void writeRegExp(v8::Local<v8::String> pattern, v8::RegExp::Flags); 139 void writeRegExp(v8::Local<v8::String> pattern, v8::RegExp::Flags);
138 void writeTransferredMessagePort(uint32_t index); 140 void writeTransferredMessagePort(uint32_t index);
139 void writeTransferredArrayBuffer(uint32_t index); 141 void writeTransferredArrayBuffer(uint32_t index);
142 void writeTransferredImageBitmap(uint32_t index);
140 void writeTransferredSharedArrayBuffer(uint32_t index); 143 void writeTransferredSharedArrayBuffer(uint32_t index);
141 void writeObjectReference(uint32_t reference); 144 void writeObjectReference(uint32_t reference);
142 void writeObject(uint32_t numProperties); 145 void writeObject(uint32_t numProperties);
143 void writeSparseArray(uint32_t numProperties, uint32_t length); 146 void writeSparseArray(uint32_t numProperties, uint32_t length);
144 void writeDenseArray(uint32_t numProperties, uint32_t length); 147 void writeDenseArray(uint32_t numProperties, uint32_t length);
145 String takeWireString(); 148 String takeWireString();
146 void writeReferenceCount(uint32_t numberOfReferences); 149 void writeReferenceCount(uint32_t numberOfReferences);
147 void writeGenerateFreshObject(); 150 void writeGenerateFreshObject();
148 void writeGenerateFreshSparseArray(uint32_t length); 151 void writeGenerateFreshSparseArray(uint32_t length);
149 void writeGenerateFreshDenseArray(uint32_t length); 152 void writeGenerateFreshDenseArray(uint32_t length);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 protected: 198 protected:
196 class StateBase; 199 class StateBase;
197 public: 200 public:
198 enum Status { 201 enum Status {
199 Success, 202 Success,
200 InputError, 203 InputError,
201 DataCloneError, 204 DataCloneError,
202 JSException 205 JSException
203 }; 206 };
204 207
205 ScriptValueSerializer(SerializedScriptValueWriter&, MessagePortArray* messag ePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray*, BlobDataHandleMap& bl obDataHandles, v8::TryCatch&, ScriptState*); 208 ScriptValueSerializer(SerializedScriptValueWriter&, MessagePortArray* messag ePorts, ArrayBufferArray* arrayBuffers, ImageBitmapArray* imageBitmaps, WebBlobI nfoArray*, BlobDataHandleMap& blobDataHandles, v8::TryCatch&, ScriptState*);
206 v8::Isolate* isolate() { return m_scriptState->isolate(); } 209 v8::Isolate* isolate() { return m_scriptState->isolate(); }
207 v8::Local<v8::Context> context() { return m_scriptState->context(); } 210 v8::Local<v8::Context> context() { return m_scriptState->context(); }
208 211
209 Status serialize(v8::Local<v8::Value>); 212 Status serialize(v8::Local<v8::Value>);
210 String errorMessage() { return m_errorMessage; } 213 String errorMessage() { return m_errorMessage; }
211 214
212 protected: 215 protected:
213 class StateBase { 216 class StateBase {
214 WTF_MAKE_FAST_ALLOCATED(StateBase); 217 WTF_MAKE_FAST_ALLOCATED(StateBase);
215 WTF_MAKE_NONCOPYABLE(StateBase); 218 WTF_MAKE_NONCOPYABLE(StateBase);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 void writeBooleanObject(v8::Local<v8::Value>); 397 void writeBooleanObject(v8::Local<v8::Value>);
395 StateBase* writeBlob(v8::Local<v8::Value>, StateBase* next); 398 StateBase* writeBlob(v8::Local<v8::Value>, StateBase* next);
396 StateBase* writeCompositorProxy(v8::Local<v8::Value>, StateBase* next); 399 StateBase* writeCompositorProxy(v8::Local<v8::Value>, StateBase* next);
397 StateBase* writeFile(v8::Local<v8::Value>, StateBase* next); 400 StateBase* writeFile(v8::Local<v8::Value>, StateBase* next);
398 StateBase* writeFileList(v8::Local<v8::Value>, StateBase* next); 401 StateBase* writeFileList(v8::Local<v8::Value>, StateBase* next);
399 void writeImageData(v8::Local<v8::Value>); 402 void writeImageData(v8::Local<v8::Value>);
400 void writeRegExp(v8::Local<v8::Value>); 403 void writeRegExp(v8::Local<v8::Value>);
401 StateBase* writeAndGreyArrayBufferView(v8::Local<v8::Object>, StateBase* nex t); 404 StateBase* writeAndGreyArrayBufferView(v8::Local<v8::Object>, StateBase* nex t);
402 StateBase* writeArrayBuffer(v8::Local<v8::Value>, StateBase* next); 405 StateBase* writeArrayBuffer(v8::Local<v8::Value>, StateBase* next);
403 StateBase* writeTransferredArrayBuffer(v8::Local<v8::Value>, uint32_t index, StateBase* next); 406 StateBase* writeTransferredArrayBuffer(v8::Local<v8::Value>, uint32_t index, StateBase* next);
407 StateBase* writeTransferredImageBitmap(v8::Local<v8::Value>, uint32_t index, StateBase* next);
404 StateBase* writeTransferredSharedArrayBuffer(v8::Local<v8::Value>, uint32_t index, StateBase* next); 408 StateBase* writeTransferredSharedArrayBuffer(v8::Local<v8::Value>, uint32_t index, StateBase* next);
405 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount); 409 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount);
406 410
407 StateBase* startArrayState(v8::Local<v8::Array>, StateBase* next); 411 StateBase* startArrayState(v8::Local<v8::Array>, StateBase* next);
408 StateBase* startObjectState(v8::Local<v8::Object>, StateBase* next); 412 StateBase* startObjectState(v8::Local<v8::Object>, StateBase* next);
409 StateBase* startMapState(v8::Local<v8::Map>, StateBase* next); 413 StateBase* startMapState(v8::Local<v8::Map>, StateBase* next);
410 StateBase* startSetState(v8::Local<v8::Set>, StateBase* next); 414 StateBase* startSetState(v8::Local<v8::Set>, StateBase* next);
411 415
412 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo ng size, int* index); 416 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo ng size, int* index);
413 bool appendFileInfo(const File*, int* index); 417 bool appendFileInfo(const File*, int* index);
(...skipping 12 matching lines...) Expand all
426 RefPtr<ScriptState> m_scriptState; 430 RefPtr<ScriptState> m_scriptState;
427 SerializedScriptValueWriter& m_writer; 431 SerializedScriptValueWriter& m_writer;
428 v8::TryCatch& m_tryCatch; 432 v8::TryCatch& m_tryCatch;
429 int m_depth; 433 int m_depth;
430 Status m_status; 434 Status m_status;
431 String m_errorMessage; 435 String m_errorMessage;
432 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; 436 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool;
433 ObjectPool m_objectPool; 437 ObjectPool m_objectPool;
434 ObjectPool m_transferredMessagePorts; 438 ObjectPool m_transferredMessagePorts;
435 ObjectPool m_transferredArrayBuffers; 439 ObjectPool m_transferredArrayBuffers;
440 ObjectPool m_transferredImageBitmaps;
436 uint32_t m_nextObjectReference; 441 uint32_t m_nextObjectReference;
437 WebBlobInfoArray* m_blobInfo; 442 WebBlobInfoArray* m_blobInfo;
438 BlobDataHandleMap& m_blobDataHandles; 443 BlobDataHandleMap& m_blobDataHandles;
439 }; 444 };
440 445
441 // Interface used by SerializedScriptValueReader to create objects of composite types. 446 // Interface used by SerializedScriptValueReader to create objects of composite types.
442 class CORE_EXPORT ScriptValueCompositeCreator { 447 class CORE_EXPORT ScriptValueCompositeCreator {
443 STACK_ALLOCATED(); 448 STACK_ALLOCATED();
444 WTF_MAKE_NONCOPYABLE(ScriptValueCompositeCreator); 449 WTF_MAKE_NONCOPYABLE(ScriptValueCompositeCreator);
445 public: 450 public:
446 ScriptValueCompositeCreator() { } 451 ScriptValueCompositeCreator() { }
447 virtual ~ScriptValueCompositeCreator() { } 452 virtual ~ScriptValueCompositeCreator() { }
448 453
449 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; 454 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0;
450 virtual uint32_t objectReferenceCount() = 0; 455 virtual uint32_t objectReferenceCount() = 0;
451 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; 456 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0;
452 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v 8::Value>*) = 0; 457 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v 8::Value>*) = 0;
453 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu e>*) = 0; 458 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu e>*) = 0;
454 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu e>*) = 0; 459 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu e>*) = 0;
460 virtual bool tryGetTransferredImageBitmap(uint32_t index, v8::Local<v8::Valu e>*) = 0;
455 virtual bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8 ::Value>*) = 0; 461 virtual bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8 ::Value>*) = 0;
456 virtual bool newSparseArray(uint32_t length) = 0; 462 virtual bool newSparseArray(uint32_t length) = 0;
457 virtual bool newDenseArray(uint32_t length) = 0; 463 virtual bool newDenseArray(uint32_t length) = 0;
458 virtual bool newMap() = 0; 464 virtual bool newMap() = 0;
459 virtual bool newSet() = 0; 465 virtual bool newSet() = 0;
460 virtual bool newObject() = 0; 466 virtual bool newObject() = 0;
461 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) = 0; 467 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) = 0;
462 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Local<v8::Value>*) = 0; 468 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Local<v8::Value>*) = 0;
463 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Local<v8::Value>*) = 0; 469 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Local<v8::Value>*) = 0;
464 virtual bool completeMap(uint32_t length, v8::Local<v8::Value>*) = 0; 470 virtual bool completeMap(uint32_t length, v8::Local<v8::Value>*) = 0;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 unsigned m_position; 570 unsigned m_position;
565 uint32_t m_version; 571 uint32_t m_version;
566 const WebBlobInfoArray* m_blobInfo; 572 const WebBlobInfoArray* m_blobInfo;
567 const BlobDataHandleMap& m_blobDataHandles; 573 const BlobDataHandleMap& m_blobDataHandles;
568 }; 574 };
569 575
570 class CORE_EXPORT ScriptValueDeserializer : public ScriptValueCompositeCreator { 576 class CORE_EXPORT ScriptValueDeserializer : public ScriptValueCompositeCreator {
571 STACK_ALLOCATED(); 577 STACK_ALLOCATED();
572 WTF_MAKE_NONCOPYABLE(ScriptValueDeserializer); 578 WTF_MAKE_NONCOPYABLE(ScriptValueDeserializer);
573 public: 579 public:
574 ScriptValueDeserializer(SerializedScriptValueReader& reader, MessagePortArra y* messagePorts, ArrayBufferContentsArray* arrayBufferContents) 580 ScriptValueDeserializer(SerializedScriptValueReader& reader, MessagePortArra y* messagePorts, ArrayBufferContentsArray* arrayBufferContents, ImageBitmapArray * imageBitmaps)
575 : m_reader(reader) 581 : m_reader(reader)
576 , m_transferredMessagePorts(messagePorts) 582 , m_transferredMessagePorts(messagePorts)
577 , m_arrayBufferContents(arrayBufferContents) 583 , m_arrayBufferContents(arrayBufferContents)
584 , m_imageBitmaps(imageBitmaps)
578 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) 585 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0)
579 , m_version(0) 586 , m_version(0)
580 { 587 {
581 } 588 }
582 589
583 v8::Local<v8::Value> deserialize(); 590 v8::Local<v8::Value> deserialize();
584 bool newSparseArray(uint32_t) override; 591 bool newSparseArray(uint32_t) override;
585 bool newDenseArray(uint32_t length) override; 592 bool newDenseArray(uint32_t length) override;
586 bool newMap() override; 593 bool newMap() override;
587 bool newSet() override; 594 bool newSet() override;
588 bool consumeTopOfStack(v8::Local<v8::Value>*) override; 595 bool consumeTopOfStack(v8::Local<v8::Value>*) override;
589 bool newObject() override; 596 bool newObject() override;
590 bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) override; 597 bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) override;
591 bool completeSparseArray(uint32_t numProperties, uint32_t length, v8::Local< v8::Value>*) override; 598 bool completeSparseArray(uint32_t numProperties, uint32_t length, v8::Local< v8::Value>*) override;
592 bool completeDenseArray(uint32_t numProperties, uint32_t length, v8::Local<v 8::Value>*) override; 599 bool completeDenseArray(uint32_t numProperties, uint32_t length, v8::Local<v 8::Value>*) override;
593 bool completeMap(uint32_t length, v8::Local<v8::Value>*) override; 600 bool completeMap(uint32_t length, v8::Local<v8::Value>*) override;
594 bool completeSet(uint32_t length, v8::Local<v8::Value>*) override; 601 bool completeSet(uint32_t length, v8::Local<v8::Value>*) override;
595 void pushObjectReference(const v8::Local<v8::Value>&) override; 602 void pushObjectReference(const v8::Local<v8::Value>&) override;
596 bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Value>*) ove rride; 603 bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Value>*) ove rride;
597 bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Value>*) ove rride; 604 bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Value>*) ove rride;
605 bool tryGetTransferredImageBitmap(uint32_t index, v8::Local<v8::Value>*) ove rride;
598 bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8::Value> *) override; 606 bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8::Value> *) override;
599 bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v8::Value >*) override; 607 bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v8::Value >*) override;
600 uint32_t objectReferenceCount() override; 608 uint32_t objectReferenceCount() override;
601 609
602 protected: 610 protected:
603 SerializedScriptValueReader& reader() { return m_reader; } 611 SerializedScriptValueReader& reader() { return m_reader; }
604 virtual bool read(v8::Local<v8::Value>*); 612 virtual bool read(v8::Local<v8::Value>*);
605 613
606 private: 614 private:
607 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc al<v8::Value>*); 615 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc al<v8::Value>*);
608 bool doDeserialize(); 616 bool doDeserialize();
609 void push(v8::Local<v8::Value> value) { m_stack.append(value); }; 617 void push(v8::Local<v8::Value> value) { m_stack.append(value); };
610 void pop(unsigned length) 618 void pop(unsigned length)
611 { 619 {
612 ASSERT(length <= m_stack.size()); 620 ASSERT(length <= m_stack.size());
613 m_stack.shrink(m_stack.size() - length); 621 m_stack.shrink(m_stack.size() - length);
614 } 622 }
615 unsigned stackDepth() const { return m_stack.size(); } 623 unsigned stackDepth() const { return m_stack.size(); }
616 624
617 v8::Local<v8::Value> element(unsigned index); 625 v8::Local<v8::Value> element(unsigned index);
618 void openComposite(const v8::Local<v8::Value>&); 626 void openComposite(const v8::Local<v8::Value>&);
619 bool closeComposite(v8::Local<v8::Value>*); 627 bool closeComposite(v8::Local<v8::Value>*);
620 628
621 SerializedScriptValueReader& m_reader; 629 SerializedScriptValueReader& m_reader;
622 Vector<v8::Local<v8::Value>> m_stack; 630 Vector<v8::Local<v8::Value>> m_stack;
623 Vector<v8::Local<v8::Value>> m_objectPool; 631 Vector<v8::Local<v8::Value>> m_objectPool;
624 Vector<uint32_t> m_openCompositeReferenceStack; 632 Vector<uint32_t> m_openCompositeReferenceStack;
625 MessagePortArray* m_transferredMessagePorts; 633 MessagePortArray* m_transferredMessagePorts;
626 ArrayBufferContentsArray* m_arrayBufferContents; 634 ArrayBufferContentsArray* m_arrayBufferContents;
635 ImageBitmapArray* m_imageBitmaps;
sof 2015/10/26 16:31:35 This works out overall, but it is not quite compat
haraken 2015/10/26 16:35:39 yutak@: It would be better if the GC plugin can de
xidachen 2015/10/27 12:23:24 Done.
627 Vector<v8::Local<v8::Value>> m_arrayBuffers; 636 Vector<v8::Local<v8::Value>> m_arrayBuffers;
628 uint32_t m_version; 637 uint32_t m_version;
629 }; 638 };
630 639
631 } // namespace blink 640 } // namespace blink
632 641
633 #endif // ScriptValueSerializer_h 642 #endif // ScriptValueSerializer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698