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

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

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

Powered by Google App Engine
This is Rietveld 408576698