| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 protected: | 189 protected: |
| 188 class StateBase; | 190 class StateBase; |
| 189 public: | 191 public: |
| 190 enum Status { | 192 enum Status { |
| 191 Success, | 193 Success, |
| 192 InputError, | 194 InputError, |
| 193 DataCloneError, | 195 DataCloneError, |
| 194 JSException | 196 JSException |
| 195 }; | 197 }; |
| 196 | 198 |
| 197 ScriptValueSerializer(SerializedScriptValueWriter&, MessagePortArray* messag
ePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray*, BlobDataHandleMap& bl
obDataHandles, v8::TryCatch&, ScriptState*); | 199 ScriptValueSerializer(SerializedScriptValueWriter&, MessagePortArray* messag
ePorts, ArrayBufferArray* arrayBuffers, SharedArrayBufferArray* sharedArrayBuffe
rs, WebBlobInfoArray*, BlobDataHandleMap& blobDataHandles, v8::TryCatch&, Script
State*); |
| 198 v8::Isolate* isolate() { return m_scriptState->isolate(); } | 200 v8::Isolate* isolate() { return m_scriptState->isolate(); } |
| 199 v8::Local<v8::Context> context() { return m_scriptState->context(); } | 201 v8::Local<v8::Context> context() { return m_scriptState->context(); } |
| 200 | 202 |
| 201 Status serialize(v8::Local<v8::Value>); | 203 Status serialize(v8::Local<v8::Value>); |
| 202 String errorMessage() { return m_errorMessage; } | 204 String errorMessage() { return m_errorMessage; } |
| 203 | 205 |
| 204 protected: | 206 protected: |
| 205 class StateBase { | 207 class StateBase { |
| 206 WTF_MAKE_NONCOPYABLE(StateBase); | 208 WTF_MAKE_NONCOPYABLE(StateBase); |
| 207 public: | 209 public: |
| (...skipping 153 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. |
| 381 // An object may only be greyed once. | 384 // An object may only be greyed once. |
| 382 void greyObject(const v8::Local<v8::Object>&); | 385 void greyObject(const v8::Local<v8::Object>&); |
| 383 | 386 |
| 384 StateBase* handleError(Status errorStatus, const String& message, StateBase*
); | 387 StateBase* handleError(Status errorStatus, const String& message, StateBase*
); |
| 385 | 388 |
| 386 SerializedScriptValueWriter& writer() { return m_writer; } | 389 SerializedScriptValueWriter& writer() { return m_writer; } |
| 387 uint32_t nextObjectReference() const { return m_nextObjectReference; } | 390 uint32_t nextObjectReference() const { return m_nextObjectReference; } |
| 388 | 391 |
| 389 private: | 392 private: |
| 390 RefPtr<ScriptState> m_scriptState; | 393 RefPtr<ScriptState> m_scriptState; |
| 391 SerializedScriptValueWriter& m_writer; | 394 SerializedScriptValueWriter& m_writer; |
| 392 v8::TryCatch& m_tryCatch; | 395 v8::TryCatch& m_tryCatch; |
| 393 int m_depth; | 396 int m_depth; |
| 394 Status m_status; | 397 Status m_status; |
| 395 String m_errorMessage; | 398 String m_errorMessage; |
| 396 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 399 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; |
| 397 ObjectPool m_objectPool; | 400 ObjectPool m_objectPool; |
| 398 ObjectPool m_transferredMessagePorts; | 401 ObjectPool m_transferredMessagePorts; |
| 399 ObjectPool m_transferredArrayBuffers; | 402 ObjectPool m_transferredArrayBuffers; |
| 403 ObjectPool m_transferredSharedArrayBuffers; |
| 400 uint32_t m_nextObjectReference; | 404 uint32_t m_nextObjectReference; |
| 401 WebBlobInfoArray* m_blobInfo; | 405 WebBlobInfoArray* m_blobInfo; |
| 402 BlobDataHandleMap& m_blobDataHandles; | 406 BlobDataHandleMap& m_blobDataHandles; |
| 403 }; | 407 }; |
| 404 | 408 |
| 405 // Interface used by SerializedScriptValueReader to create objects of composite
types. | 409 // Interface used by SerializedScriptValueReader to create objects of composite
types. |
| 406 class CORE_EXPORT ScriptValueCompositeCreator { | 410 class CORE_EXPORT ScriptValueCompositeCreator { |
| 407 STACK_ALLOCATED(); | 411 STACK_ALLOCATED(); |
| 408 WTF_MAKE_NONCOPYABLE(ScriptValueCompositeCreator); | 412 WTF_MAKE_NONCOPYABLE(ScriptValueCompositeCreator); |
| 409 public: | 413 public: |
| 410 ScriptValueCompositeCreator() { } | 414 ScriptValueCompositeCreator() { } |
| 411 virtual ~ScriptValueCompositeCreator() { } | 415 virtual ~ScriptValueCompositeCreator() { } |
| 412 | 416 |
| 413 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; | 417 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; |
| 414 virtual uint32_t objectReferenceCount() = 0; | 418 virtual uint32_t objectReferenceCount() = 0; |
| 415 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; | 419 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; |
| 416 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) = 0; | 420 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; | 421 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; | 422 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) = 0; |
| 423 virtual bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8
::Value>*) = 0; |
| 419 virtual bool newSparseArray(uint32_t length) = 0; | 424 virtual bool newSparseArray(uint32_t length) = 0; |
| 420 virtual bool newDenseArray(uint32_t length) = 0; | 425 virtual bool newDenseArray(uint32_t length) = 0; |
| 421 virtual bool newObject() = 0; | 426 virtual bool newObject() = 0; |
| 422 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) =
0; | 427 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; | 428 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; | 429 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) = 0; |
| 425 }; | 430 }; |
| 426 | 431 |
| 427 // SerializedScriptValueReader is responsible for deserializing primitive types
and | 432 // SerializedScriptValueReader is responsible for deserializing primitive types
and |
| 428 // restoring information about saved objects of composite types. | 433 // 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; | 548 virtual bool newSparseArray(uint32_t) override; |
| 544 virtual bool newDenseArray(uint32_t length) override; | 549 virtual bool newDenseArray(uint32_t length) override; |
| 545 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) override; | 550 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) override; |
| 546 virtual bool newObject() override; | 551 virtual bool newObject() override; |
| 547 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) o
verride; | 552 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; | 553 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; | 554 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) override; |
| 550 virtual void pushObjectReference(const v8::Local<v8::Value>&) override; | 555 virtual void pushObjectReference(const v8::Local<v8::Value>&) override; |
| 551 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) override; | 556 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; | 557 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) override; |
| 558 virtual bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8
::Value>*) override; |
| 553 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) override; | 559 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) override; |
| 554 virtual uint32_t objectReferenceCount() override; | 560 virtual uint32_t objectReferenceCount() override; |
| 555 | 561 |
| 556 protected: | 562 protected: |
| 557 SerializedScriptValueReader& reader() { return m_reader; } | 563 SerializedScriptValueReader& reader() { return m_reader; } |
| 558 virtual bool read(v8::Local<v8::Value>*); | 564 virtual bool read(v8::Local<v8::Value>*); |
| 559 | 565 |
| 560 private: | 566 private: |
| 561 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); | 567 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); |
| 562 bool doDeserialize(); | 568 bool doDeserialize(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 578 Vector<uint32_t> m_openCompositeReferenceStack; | 584 Vector<uint32_t> m_openCompositeReferenceStack; |
| 579 MessagePortArray* m_transferredMessagePorts; | 585 MessagePortArray* m_transferredMessagePorts; |
| 580 ArrayBufferContentsArray* m_arrayBufferContents; | 586 ArrayBufferContentsArray* m_arrayBufferContents; |
| 581 Vector<v8::Local<v8::Value>> m_arrayBuffers; | 587 Vector<v8::Local<v8::Value>> m_arrayBuffers; |
| 582 uint32_t m_version; | 588 uint32_t m_version; |
| 583 }; | 589 }; |
| 584 | 590 |
| 585 } // namespace blink | 591 } // namespace blink |
| 586 | 592 |
| 587 #endif // ScriptValueSerializer_h | 593 #endif // ScriptValueSerializer_h |
| OLD | NEW |