| OLD | NEW |
| 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 "wtf/ArrayBufferContents.h" | 12 #include "wtf/ArrayBufferContents.h" |
| 13 #include "wtf/HashMap.h" | 13 #include "wtf/HashMap.h" |
| 14 #include "wtf/Noncopyable.h" | 14 #include "wtf/Noncopyable.h" |
| 15 #include "wtf/Vector.h" | 15 #include "wtf/Vector.h" |
| 16 #include "wtf/text/WTFString.h" | 16 #include "wtf/text/WTFString.h" |
| 17 #include <v8.h> | 17 #include <v8.h> |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 class CompositorProxy; | 21 class CompositorProxy; |
| 22 class DOMArrayBuffer; | 22 class DOMArrayBuffer; |
| 23 class DOMArrayBufferView; | 23 class DOMArrayBufferView; |
| 24 class DOMSharedArrayBuffer; |
| 24 class File; | 25 class File; |
| 25 class FileList; | 26 class FileList; |
| 26 | 27 |
| 27 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 28 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
| 28 | 29 |
| 29 // V8ObjectMap is a map from V8 objects to arbitrary values of type T. | 30 // V8ObjectMap is a map from V8 objects to arbitrary values of type T. |
| 30 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf:
:HashMaps; | 31 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf:
:HashMaps; |
| 31 // this class should be used instead. GCObject must be a subtype of v8::Object. | 32 // this class should be used instead. GCObject must be a subtype of v8::Object. |
| 32 // Suggested usage: | 33 // Suggested usage: |
| 33 // V8ObjectMap<v8::Object, int> map; | 34 // V8ObjectMap<v8::Object, int> map; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 void writeFile(const File&); | 128 void writeFile(const File&); |
| 128 void writeFileIndex(int blobIndex); | 129 void writeFileIndex(int blobIndex); |
| 129 void writeFileList(const FileList&); | 130 void writeFileList(const FileList&); |
| 130 void writeFileListIndex(const Vector<int>& blobIndices); | 131 void writeFileListIndex(const Vector<int>& blobIndices); |
| 131 void writeArrayBuffer(const DOMArrayBuffer&); | 132 void writeArrayBuffer(const DOMArrayBuffer&); |
| 132 void writeArrayBufferView(const DOMArrayBufferView&); | 133 void writeArrayBufferView(const DOMArrayBufferView&); |
| 133 void writeImageData(uint32_t width, uint32_t height, const uint8_t* pixelDat
a, uint32_t pixelDataLength); | 134 void writeImageData(uint32_t width, uint32_t height, const uint8_t* pixelDat
a, uint32_t pixelDataLength); |
| 134 void writeRegExp(v8::Local<v8::String> pattern, v8::RegExp::Flags); | 135 void writeRegExp(v8::Local<v8::String> pattern, v8::RegExp::Flags); |
| 135 void writeTransferredMessagePort(uint32_t index); | 136 void writeTransferredMessagePort(uint32_t index); |
| 136 void writeTransferredArrayBuffer(uint32_t index); | 137 void writeTransferredArrayBuffer(uint32_t index); |
| 138 void writeTransferredSharedArrayBuffer(uint32_t index); |
| 137 void writeObjectReference(uint32_t reference); | 139 void writeObjectReference(uint32_t reference); |
| 138 void writeObject(uint32_t numProperties); | 140 void writeObject(uint32_t numProperties); |
| 139 void writeSparseArray(uint32_t numProperties, uint32_t length); | 141 void writeSparseArray(uint32_t numProperties, uint32_t length); |
| 140 void writeDenseArray(uint32_t numProperties, uint32_t length); | 142 void writeDenseArray(uint32_t numProperties, uint32_t length); |
| 141 String takeWireString(); | 143 String takeWireString(); |
| 142 void writeReferenceCount(uint32_t numberOfReferences); | 144 void writeReferenceCount(uint32_t numberOfReferences); |
| 143 void writeGenerateFreshObject(); | 145 void writeGenerateFreshObject(); |
| 144 void writeGenerateFreshSparseArray(uint32_t length); | 146 void writeGenerateFreshSparseArray(uint32_t length); |
| 145 void writeGenerateFreshDenseArray(uint32_t length); | 147 void writeGenerateFreshDenseArray(uint32_t length); |
| 146 | 148 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 void writeBooleanObject(v8::Local<v8::Value>); | 363 void writeBooleanObject(v8::Local<v8::Value>); |
| 362 StateBase* writeBlob(v8::Local<v8::Value>, StateBase* next); | 364 StateBase* writeBlob(v8::Local<v8::Value>, StateBase* next); |
| 363 StateBase* writeCompositorProxy(v8::Local<v8::Value>, StateBase* next); | 365 StateBase* writeCompositorProxy(v8::Local<v8::Value>, StateBase* next); |
| 364 StateBase* writeFile(v8::Local<v8::Value>, StateBase* next); | 366 StateBase* writeFile(v8::Local<v8::Value>, StateBase* next); |
| 365 StateBase* writeFileList(v8::Local<v8::Value>, StateBase* next); | 367 StateBase* writeFileList(v8::Local<v8::Value>, StateBase* next); |
| 366 void writeImageData(v8::Local<v8::Value>); | 368 void writeImageData(v8::Local<v8::Value>); |
| 367 void writeRegExp(v8::Local<v8::Value>); | 369 void writeRegExp(v8::Local<v8::Value>); |
| 368 StateBase* writeAndGreyArrayBufferView(v8::Local<v8::Object>, StateBase* nex
t); | 370 StateBase* writeAndGreyArrayBufferView(v8::Local<v8::Object>, StateBase* nex
t); |
| 369 StateBase* writeArrayBuffer(v8::Local<v8::Value>, StateBase* next); | 371 StateBase* writeArrayBuffer(v8::Local<v8::Value>, StateBase* next); |
| 370 StateBase* writeTransferredArrayBuffer(v8::Local<v8::Value>, uint32_t index,
StateBase* next); | 372 StateBase* writeTransferredArrayBuffer(v8::Local<v8::Value>, uint32_t index,
StateBase* next); |
| 373 StateBase* writeTransferredSharedArrayBuffer(v8::Local<v8::Value>, uint32_t
index, StateBase* next); |
| 371 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount); | 374 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount); |
| 372 | 375 |
| 373 StateBase* startArrayState(v8::Local<v8::Array>, StateBase* next); | 376 StateBase* startArrayState(v8::Local<v8::Array>, StateBase* next); |
| 374 StateBase* startObjectState(v8::Local<v8::Object>, StateBase* next); | 377 StateBase* startObjectState(v8::Local<v8::Object>, StateBase* next); |
| 375 | 378 |
| 376 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo
ng size, int* index); | 379 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo
ng size, int* index); |
| 377 bool appendFileInfo(const File*, int* index); | 380 bool appendFileInfo(const File*, int* index); |
| 378 | 381 |
| 379 protected: | 382 protected: |
| 380 // Marks object as having been visited by the serializer and assigns it a un
ique object reference ID. | 383 // Marks object as having been visited by the serializer and assigns it a un
ique object reference ID. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 409 public: | 412 public: |
| 410 ScriptValueCompositeCreator() { } | 413 ScriptValueCompositeCreator() { } |
| 411 virtual ~ScriptValueCompositeCreator() { } | 414 virtual ~ScriptValueCompositeCreator() { } |
| 412 | 415 |
| 413 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; | 416 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; |
| 414 virtual uint32_t objectReferenceCount() = 0; | 417 virtual uint32_t objectReferenceCount() = 0; |
| 415 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; | 418 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; |
| 416 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) = 0; | 419 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) = 0; |
| 417 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) = 0; | 420 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) = 0; |
| 418 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) = 0; | 421 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) = 0; |
| 422 virtual bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8
::Value>*) = 0; |
| 419 virtual bool newSparseArray(uint32_t length) = 0; | 423 virtual bool newSparseArray(uint32_t length) = 0; |
| 420 virtual bool newDenseArray(uint32_t length) = 0; | 424 virtual bool newDenseArray(uint32_t length) = 0; |
| 421 virtual bool newObject() = 0; | 425 virtual bool newObject() = 0; |
| 422 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) =
0; | 426 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) =
0; |
| 423 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) = 0; | 427 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) = 0; |
| 424 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) = 0; | 428 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) = 0; |
| 425 }; | 429 }; |
| 426 | 430 |
| 427 // SerializedScriptValueReader is responsible for deserializing primitive types
and | 431 // SerializedScriptValueReader is responsible for deserializing primitive types
and |
| 428 // restoring information about saved objects of composite types. | 432 // restoring information about saved objects of composite types. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 virtual bool newSparseArray(uint32_t) override; | 547 virtual bool newSparseArray(uint32_t) override; |
| 544 virtual bool newDenseArray(uint32_t length) override; | 548 virtual bool newDenseArray(uint32_t length) override; |
| 545 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) override; | 549 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) override; |
| 546 virtual bool newObject() override; | 550 virtual bool newObject() override; |
| 547 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) o
verride; | 551 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) o
verride; |
| 548 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) override; | 552 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) override; |
| 549 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) override; | 553 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) override; |
| 550 virtual void pushObjectReference(const v8::Local<v8::Value>&) override; | 554 virtual void pushObjectReference(const v8::Local<v8::Value>&) override; |
| 551 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) override; | 555 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) override; |
| 552 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) override; | 556 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) override; |
| 557 virtual bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8
::Value>*) override; |
| 553 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) override; | 558 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) override; |
| 554 virtual uint32_t objectReferenceCount() override; | 559 virtual uint32_t objectReferenceCount() override; |
| 555 | 560 |
| 556 protected: | 561 protected: |
| 557 SerializedScriptValueReader& reader() { return m_reader; } | 562 SerializedScriptValueReader& reader() { return m_reader; } |
| 558 virtual bool read(v8::Local<v8::Value>*); | 563 virtual bool read(v8::Local<v8::Value>*); |
| 559 | 564 |
| 560 private: | 565 private: |
| 561 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); | 566 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); |
| 562 bool doDeserialize(); | 567 bool doDeserialize(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 578 Vector<uint32_t> m_openCompositeReferenceStack; | 583 Vector<uint32_t> m_openCompositeReferenceStack; |
| 579 MessagePortArray* m_transferredMessagePorts; | 584 MessagePortArray* m_transferredMessagePorts; |
| 580 ArrayBufferContentsArray* m_arrayBufferContents; | 585 ArrayBufferContentsArray* m_arrayBufferContents; |
| 581 Vector<v8::Local<v8::Value>> m_arrayBuffers; | 586 Vector<v8::Local<v8::Value>> m_arrayBuffers; |
| 582 uint32_t m_version; | 587 uint32_t m_version; |
| 583 }; | 588 }; |
| 584 | 589 |
| 585 } // namespace blink | 590 } // namespace blink |
| 586 | 591 |
| 587 #endif // ScriptValueSerializer_h | 592 #endif // ScriptValueSerializer_h |
| OLD | NEW |