| 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" |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 ObjectPool m_objectPool; | 441 ObjectPool m_objectPool; |
| 442 ObjectPool m_transferredMessagePorts; | 442 ObjectPool m_transferredMessagePorts; |
| 443 ObjectPool m_transferredArrayBuffers; | 443 ObjectPool m_transferredArrayBuffers; |
| 444 ObjectPool m_transferredImageBitmaps; | 444 ObjectPool m_transferredImageBitmaps; |
| 445 ObjectPool m_transferredOffscreenCanvas; | 445 ObjectPool m_transferredOffscreenCanvas; |
| 446 uint32_t m_nextObjectReference; | 446 uint32_t m_nextObjectReference; |
| 447 WebBlobInfoArray* m_blobInfo; | 447 WebBlobInfoArray* m_blobInfo; |
| 448 BlobDataHandleMap& m_blobDataHandles; | 448 BlobDataHandleMap& m_blobDataHandles; |
| 449 }; | 449 }; |
| 450 | 450 |
| 451 // Interface used by SerializedScriptValueReader to create objects of composite
types. | 451 class ScriptValueDeserializer; |
| 452 class CORE_EXPORT ScriptValueCompositeCreator { | |
| 453 STACK_ALLOCATED(); | |
| 454 WTF_MAKE_NONCOPYABLE(ScriptValueCompositeCreator); | |
| 455 public: | |
| 456 ScriptValueCompositeCreator() { } | |
| 457 virtual ~ScriptValueCompositeCreator() { } | |
| 458 | |
| 459 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; | |
| 460 virtual uint32_t objectReferenceCount() = 0; | |
| 461 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; | |
| 462 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) = 0; | |
| 463 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) = 0; | |
| 464 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) = 0; | |
| 465 virtual bool tryGetTransferredImageBitmap(uint32_t index, v8::Local<v8::Valu
e>*) = 0; | |
| 466 virtual bool tryGetTransferredOffscreenCanvas(uint32_t index, uint32_t width
, uint32_t height, uint32_t id, v8::Local<v8::Value>*) = 0; | |
| 467 virtual bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8
::Value>*) = 0; | |
| 468 virtual bool newSparseArray(uint32_t length) = 0; | |
| 469 virtual bool newDenseArray(uint32_t length) = 0; | |
| 470 virtual bool newMap() = 0; | |
| 471 virtual bool newSet() = 0; | |
| 472 virtual bool newObject() = 0; | |
| 473 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) =
0; | |
| 474 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) = 0; | |
| 475 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) = 0; | |
| 476 virtual bool completeMap(uint32_t length, v8::Local<v8::Value>*) = 0; | |
| 477 virtual bool completeSet(uint32_t length, v8::Local<v8::Value>*) = 0; | |
| 478 }; | |
| 479 | 452 |
| 480 // SerializedScriptValueReader is responsible for deserializing primitive types
and | 453 // SerializedScriptValueReader is responsible for deserializing primitive types
and |
| 481 // restoring information about saved objects of composite types. | 454 // restoring information about saved objects of composite types. |
| 482 class CORE_EXPORT SerializedScriptValueReader { | 455 class CORE_EXPORT SerializedScriptValueReader { |
| 483 STACK_ALLOCATED(); | 456 STACK_ALLOCATED(); |
| 484 WTF_MAKE_NONCOPYABLE(SerializedScriptValueReader); | 457 WTF_MAKE_NONCOPYABLE(SerializedScriptValueReader); |
| 485 public: | 458 public: |
| 486 SerializedScriptValueReader(const uint8_t* buffer, int length, const WebBlob
InfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, ScriptState* scriptStat
e) | 459 SerializedScriptValueReader(const uint8_t* buffer, int length, const WebBlob
InfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, ScriptState* scriptStat
e) |
| 487 : m_scriptState(scriptState) | 460 : m_scriptState(scriptState) |
| 488 , m_buffer(buffer) | 461 , m_buffer(buffer) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 507 unsigned position() const { return m_position; } | 480 unsigned position() const { return m_position; } |
| 508 | 481 |
| 509 const uint8_t* allocate(uint32_t size) | 482 const uint8_t* allocate(uint32_t size) |
| 510 { | 483 { |
| 511 const uint8_t* allocated = m_buffer + m_position; | 484 const uint8_t* allocated = m_buffer + m_position; |
| 512 m_position += size; | 485 m_position += size; |
| 513 return allocated; | 486 return allocated; |
| 514 } | 487 } |
| 515 | 488 |
| 516 public: | 489 public: |
| 517 virtual bool read(v8::Local<v8::Value>*, ScriptValueCompositeCreator&); | 490 virtual bool read(v8::Local<v8::Value>*, ScriptValueDeserializer&); |
| 518 bool readVersion(uint32_t& version); | 491 bool readVersion(uint32_t& version); |
| 519 void setVersion(uint32_t); | 492 void setVersion(uint32_t); |
| 520 | 493 |
| 521 protected: | 494 protected: |
| 522 bool readWithTag(SerializationTag, v8::Local<v8::Value>*, ScriptValueComposi
teCreator&); | 495 bool readWithTag(SerializationTag, v8::Local<v8::Value>*, ScriptValueDeseria
lizer&); |
| 523 | 496 |
| 524 bool readTag(SerializationTag*); | 497 bool readTag(SerializationTag*); |
| 525 bool readWebCoreString(String*); | 498 bool readWebCoreString(String*); |
| 526 bool readUint32(v8::Local<v8::Value>*); | 499 bool readUint32(v8::Local<v8::Value>*); |
| 527 | 500 |
| 528 bool doReadUint32(uint32_t* value); | 501 bool doReadUint32(uint32_t* value); |
| 529 | 502 |
| 530 private: | 503 private: |
| 531 void undoReadTag(); | 504 void undoReadTag(); |
| 532 bool readArrayBufferViewSubTag(ArrayBufferViewSubTag*); | 505 bool readArrayBufferViewSubTag(ArrayBufferViewSubTag*); |
| 533 bool readString(v8::Local<v8::Value>*); | 506 bool readString(v8::Local<v8::Value>*); |
| 534 bool readUCharString(v8::Local<v8::Value>*); | 507 bool readUCharString(v8::Local<v8::Value>*); |
| 535 bool readStringObject(v8::Local<v8::Value>*); | 508 bool readStringObject(v8::Local<v8::Value>*); |
| 536 bool readInt32(v8::Local<v8::Value>*); | 509 bool readInt32(v8::Local<v8::Value>*); |
| 537 bool readDate(v8::Local<v8::Value>*); | 510 bool readDate(v8::Local<v8::Value>*); |
| 538 bool readNumber(v8::Local<v8::Value>*); | 511 bool readNumber(v8::Local<v8::Value>*); |
| 539 bool readNumberObject(v8::Local<v8::Value>*); | 512 bool readNumberObject(v8::Local<v8::Value>*); |
| 540 ImageData* doReadImageData(); | 513 ImageData* doReadImageData(); |
| 541 bool readImageData(v8::Local<v8::Value>*); | 514 bool readImageData(v8::Local<v8::Value>*); |
| 542 bool readImageBitmap(v8::Local<v8::Value>*); | 515 bool readImageBitmap(v8::Local<v8::Value>*); |
| 543 bool readCompositorProxy(v8::Local<v8::Value>*); | 516 bool readCompositorProxy(v8::Local<v8::Value>*); |
| 544 DOMArrayBuffer* doReadArrayBuffer(); | 517 DOMArrayBuffer* doReadArrayBuffer(); |
| 545 bool readArrayBuffer(v8::Local<v8::Value>*); | 518 bool readArrayBuffer(v8::Local<v8::Value>*); |
| 546 bool readArrayBufferView(v8::Local<v8::Value>*, ScriptValueCompositeCreator&
); | 519 bool readArrayBufferView(v8::Local<v8::Value>*, ScriptValueDeserializer&); |
| 547 bool readRegExp(v8::Local<v8::Value>*); | 520 bool readRegExp(v8::Local<v8::Value>*); |
| 548 bool readBlob(v8::Local<v8::Value>*, bool isIndexed); | 521 bool readBlob(v8::Local<v8::Value>*, bool isIndexed); |
| 549 bool readFile(v8::Local<v8::Value>*, bool isIndexed); | 522 bool readFile(v8::Local<v8::Value>*, bool isIndexed); |
| 550 bool readFileList(v8::Local<v8::Value>*, bool isIndexed); | 523 bool readFileList(v8::Local<v8::Value>*, bool isIndexed); |
| 551 File* readFileHelper(); | 524 File* readFileHelper(); |
| 552 File* readFileIndexHelper(); | 525 File* readFileIndexHelper(); |
| 553 | 526 |
| 554 template<class T> | 527 template<class T> |
| 555 bool doReadUintHelper(T* value) | 528 bool doReadUintHelper(T* value) |
| 556 { | 529 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 574 private: | 547 private: |
| 575 RefPtr<ScriptState> m_scriptState; | 548 RefPtr<ScriptState> m_scriptState; |
| 576 const uint8_t* m_buffer; | 549 const uint8_t* m_buffer; |
| 577 const unsigned m_length; | 550 const unsigned m_length; |
| 578 unsigned m_position; | 551 unsigned m_position; |
| 579 uint32_t m_version; | 552 uint32_t m_version; |
| 580 const WebBlobInfoArray* m_blobInfo; | 553 const WebBlobInfoArray* m_blobInfo; |
| 581 const BlobDataHandleMap& m_blobDataHandles; | 554 const BlobDataHandleMap& m_blobDataHandles; |
| 582 }; | 555 }; |
| 583 | 556 |
| 584 class CORE_EXPORT ScriptValueDeserializer : public ScriptValueCompositeCreator { | 557 class CORE_EXPORT ScriptValueDeserializer { |
| 585 STACK_ALLOCATED(); | 558 STACK_ALLOCATED(); |
| 586 WTF_MAKE_NONCOPYABLE(ScriptValueDeserializer); | 559 WTF_MAKE_NONCOPYABLE(ScriptValueDeserializer); |
| 587 public: | 560 public: |
| 588 ScriptValueDeserializer(SerializedScriptValueReader& reader, MessagePortArra
y* messagePorts, ArrayBufferContentsArray* arrayBufferContents, ImageBitmapConte
ntsArray* imageBitmapContents) | 561 ScriptValueDeserializer(SerializedScriptValueReader& reader, MessagePortArra
y* messagePorts, ArrayBufferContentsArray* arrayBufferContents, ImageBitmapConte
ntsArray* imageBitmapContents) |
| 589 : m_reader(reader) | 562 : m_reader(reader) |
| 590 , m_transferredMessagePorts(messagePorts) | 563 , m_transferredMessagePorts(messagePorts) |
| 591 , m_arrayBufferContents(arrayBufferContents) | 564 , m_arrayBufferContents(arrayBufferContents) |
| 592 , m_imageBitmapContents(imageBitmapContents) | 565 , m_imageBitmapContents(imageBitmapContents) |
| 593 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) | 566 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) |
| 594 , m_imageBitmaps(imageBitmapContents ? imageBitmapContents->size() : 0) | 567 , m_imageBitmaps(imageBitmapContents ? imageBitmapContents->size() : 0) |
| 595 , m_version(0) | 568 , m_version(0) |
| 596 { | 569 { |
| 597 } | 570 } |
| 598 | 571 |
| 599 v8::Local<v8::Value> deserialize(); | 572 v8::Local<v8::Value> deserialize(); |
| 600 bool newSparseArray(uint32_t) override; | 573 bool newSparseArray(uint32_t); |
| 601 bool newDenseArray(uint32_t length) override; | 574 bool newDenseArray(uint32_t length); |
| 602 bool newMap() override; | 575 bool newMap(); |
| 603 bool newSet() override; | 576 bool newSet(); |
| 604 bool consumeTopOfStack(v8::Local<v8::Value>*) override; | 577 bool consumeTopOfStack(v8::Local<v8::Value>*); |
| 605 bool newObject() override; | 578 bool newObject(); |
| 606 bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) override; | 579 bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*); |
| 607 bool completeSparseArray(uint32_t numProperties, uint32_t length, v8::Local<
v8::Value>*) override; | 580 bool completeSparseArray(uint32_t numProperties, uint32_t length, v8::Local<
v8::Value>*); |
| 608 bool completeDenseArray(uint32_t numProperties, uint32_t length, v8::Local<v
8::Value>*) override; | 581 bool completeDenseArray(uint32_t numProperties, uint32_t length, v8::Local<v
8::Value>*); |
| 609 bool completeMap(uint32_t length, v8::Local<v8::Value>*) override; | 582 bool completeMap(uint32_t length, v8::Local<v8::Value>*); |
| 610 bool completeSet(uint32_t length, v8::Local<v8::Value>*) override; | 583 bool completeSet(uint32_t length, v8::Local<v8::Value>*); |
| 611 void pushObjectReference(const v8::Local<v8::Value>&) override; | 584 void pushObjectReference(const v8::Local<v8::Value>&); |
| 612 bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Value>*) ove
rride; | 585 bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Value>*); |
| 613 bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Value>*) ove
rride; | 586 bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Value>*); |
| 614 bool tryGetTransferredImageBitmap(uint32_t index, v8::Local<v8::Value>*) ove
rride; | 587 bool tryGetTransferredImageBitmap(uint32_t index, v8::Local<v8::Value>*); |
| 615 bool tryGetTransferredOffscreenCanvas(uint32_t index, uint32_t width, uint32
_t height, uint32_t id, v8::Local<v8::Value>*) override; | 588 bool tryGetTransferredOffscreenCanvas(uint32_t index, uint32_t width, uint32
_t height, uint32_t id, v8::Local<v8::Value>*); |
| 616 bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8::Value>
*) override; | 589 bool tryGetTransferredSharedArrayBuffer(uint32_t index, v8::Local<v8::Value>
*); |
| 617 bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v8::Value
>*) override; | 590 bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v8::Value
>*); |
| 618 uint32_t objectReferenceCount() override; | 591 uint32_t objectReferenceCount(); |
| 619 | 592 |
| 620 protected: | 593 protected: |
| 621 SerializedScriptValueReader& reader() { return m_reader; } | 594 SerializedScriptValueReader& reader() { return m_reader; } |
| 622 virtual bool read(v8::Local<v8::Value>*); | 595 virtual bool read(v8::Local<v8::Value>*); |
| 623 | 596 |
| 624 private: | 597 private: |
| 625 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); | 598 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); |
| 626 bool doDeserialize(); | 599 bool doDeserialize(); |
| 627 void push(v8::Local<v8::Value> value) { m_stack.append(value); }; | 600 void push(v8::Local<v8::Value> value) { m_stack.append(value); }; |
| 628 void pop(unsigned length) | 601 void pop(unsigned length) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 644 ArrayBufferContentsArray* m_arrayBufferContents; | 617 ArrayBufferContentsArray* m_arrayBufferContents; |
| 645 ImageBitmapContentsArray* m_imageBitmapContents; | 618 ImageBitmapContentsArray* m_imageBitmapContents; |
| 646 Vector<v8::Local<v8::Value>> m_arrayBuffers; | 619 Vector<v8::Local<v8::Value>> m_arrayBuffers; |
| 647 Vector<v8::Local<v8::Value>> m_imageBitmaps; | 620 Vector<v8::Local<v8::Value>> m_imageBitmaps; |
| 648 uint32_t m_version; | 621 uint32_t m_version; |
| 649 }; | 622 }; |
| 650 | 623 |
| 651 } // namespace blink | 624 } // namespace blink |
| 652 | 625 |
| 653 #endif // ScriptValueSerializer_h | 626 #endif // ScriptValueSerializer_h |
| OLD | NEW |