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

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

Issue 718383003: bindings: fixed incorrect dependency of SerializedScriptValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 "public/platform/WebCrypto.h"
12 #include "public/platform/WebCryptoKey.h"
13 #include "public/platform/WebCryptoKeyAlgorithm.h"
14 #include "wtf/ArrayBufferContents.h" 11 #include "wtf/ArrayBufferContents.h"
15 #include "wtf/HashMap.h" 12 #include "wtf/HashMap.h"
16 #include "wtf/Noncopyable.h" 13 #include "wtf/Noncopyable.h"
17 #include "wtf/Vector.h" 14 #include "wtf/Vector.h"
18 #include "wtf/text/WTFString.h" 15 #include "wtf/text/WTFString.h"
19 #include <v8.h> 16 #include <v8.h>
20 17
21 namespace WTF { 18 namespace WTF {
22 19
23 class ArrayBuffer; 20 class ArrayBuffer;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void writeStringObject(const char* data, int length); 121 void writeStringObject(const char* data, int length);
125 void writeWebCoreString(const String&); 122 void writeWebCoreString(const String&);
126 void writeVersion(); 123 void writeVersion();
127 void writeInt32(int32_t value); 124 void writeInt32(int32_t value);
128 void writeUint32(uint32_t value); 125 void writeUint32(uint32_t value);
129 void writeDate(double numberValue); 126 void writeDate(double numberValue);
130 void writeNumber(double number); 127 void writeNumber(double number);
131 void writeNumberObject(double number); 128 void writeNumberObject(double number);
132 void writeBlob(const String& uuid, const String& type, unsigned long long si ze); 129 void writeBlob(const String& uuid, const String& type, unsigned long long si ze);
133 void writeBlobIndex(int blobIndex); 130 void writeBlobIndex(int blobIndex);
134 void writeDOMFileSystem(int type, const String& name, const String& url);
135 void writeFile(const File&); 131 void writeFile(const File&);
136 void writeFileIndex(int blobIndex); 132 void writeFileIndex(int blobIndex);
137 void writeFileList(const FileList&); 133 void writeFileList(const FileList&);
138 void writeFileListIndex(const Vector<int>& blobIndices); 134 void writeFileListIndex(const Vector<int>& blobIndices);
139 bool writeCryptoKey(const WebCryptoKey&);
140 void writeArrayBuffer(const ArrayBuffer&); 135 void writeArrayBuffer(const ArrayBuffer&);
141 void writeArrayBufferView(const ArrayBufferView&); 136 void writeArrayBufferView(const ArrayBufferView&);
142 void writeImageData(uint32_t width, uint32_t height, const uint8_t* pixelDat a, uint32_t pixelDataLength); 137 void writeImageData(uint32_t width, uint32_t height, const uint8_t* pixelDat a, uint32_t pixelDataLength);
143 void writeRegExp(v8::Local<v8::String> pattern, v8::RegExp::Flags); 138 void writeRegExp(v8::Local<v8::String> pattern, v8::RegExp::Flags);
144 void writeTransferredMessagePort(uint32_t index); 139 void writeTransferredMessagePort(uint32_t index);
145 void writeTransferredArrayBuffer(uint32_t index); 140 void writeTransferredArrayBuffer(uint32_t index);
146 void writeObjectReference(uint32_t reference); 141 void writeObjectReference(uint32_t reference);
147 void writeObject(uint32_t numProperties); 142 void writeObject(uint32_t numProperties);
148 void writeSparseArray(uint32_t numProperties, uint32_t length); 143 void writeSparseArray(uint32_t numProperties, uint32_t length);
149 void writeDenseArray(uint32_t numProperties, uint32_t length); 144 void writeDenseArray(uint32_t numProperties, uint32_t length);
150 String takeWireString(); 145 String takeWireString();
151 void writeReferenceCount(uint32_t numberOfReferences); 146 void writeReferenceCount(uint32_t numberOfReferences);
152 void writeGenerateFreshObject(); 147 void writeGenerateFreshObject();
153 void writeGenerateFreshSparseArray(uint32_t length); 148 void writeGenerateFreshSparseArray(uint32_t length);
154 void writeGenerateFreshDenseArray(uint32_t length); 149 void writeGenerateFreshDenseArray(uint32_t length);
155 150
156 protected: 151 protected:
157 void doWriteFile(const File&); 152 void doWriteFile(const File&);
158 void doWriteArrayBuffer(const ArrayBuffer&); 153 void doWriteArrayBuffer(const ArrayBuffer&);
159 void doWriteString(const char* data, int length); 154 void doWriteString(const char* data, int length);
160 void doWriteWebCoreString(const String&); 155 void doWriteWebCoreString(const String&);
161 void doWriteHmacKey(const WebCryptoKey&);
162 void doWriteAesKey(const WebCryptoKey&);
163 void doWriteRsaHashedKey(const WebCryptoKey&);
164 void doWriteEcKey(const WebCryptoKey&);
165 void doWriteAlgorithmId(WebCryptoAlgorithmId);
166 void doWriteAsymmetricKeyType(WebCryptoKeyType);
167 void doWriteNamedCurve(WebCryptoNamedCurve);
168 void doWriteKeyUsages(const WebCryptoKeyUsageMask usages, bool extractable);
169 int bytesNeededToWireEncode(uint32_t value); 156 int bytesNeededToWireEncode(uint32_t value);
170 157
171 template<class T> 158 template<class T>
172 void doWriteUintHelper(T value) 159 void doWriteUintHelper(T value)
173 { 160 {
174 while (true) { 161 while (true) {
175 uint8_t b = (value & SerializedScriptValue::varIntMask); 162 uint8_t b = (value & SerializedScriptValue::varIntMask);
176 value >>= SerializedScriptValue::varIntShift; 163 value >>= SerializedScriptValue::varIntShift;
177 if (!value) { 164 if (!value) {
178 append(b); 165 append(b);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 JSException 198 JSException
212 }; 199 };
213 200
214 Serializer(Writer&, MessagePortArray* messagePorts, ArrayBufferArray* arrayB uffers, WebBlobInfoArray*, BlobDataHandleMap& blobDataHandles, v8::TryCatch&, Sc riptState*); 201 Serializer(Writer&, MessagePortArray* messagePorts, ArrayBufferArray* arrayB uffers, WebBlobInfoArray*, BlobDataHandleMap& blobDataHandles, v8::TryCatch&, Sc riptState*);
215 v8::Isolate* isolate() { return m_scriptState->isolate(); } 202 v8::Isolate* isolate() { return m_scriptState->isolate(); }
216 203
217 Status serialize(v8::Handle<v8::Value>); 204 Status serialize(v8::Handle<v8::Value>);
218 String errorMessage() { return m_errorMessage; } 205 String errorMessage() { return m_errorMessage; }
219 206
220 // Functions used by serialization states. 207 // Functions used by serialization states.
221 Serializer::StateBase* doSerialize(v8::Handle<v8::Value>, Serializer::StateB ase* next); 208 virtual Serializer::StateBase* doSerialize(v8::Handle<v8::Value>, Serializer ::StateBase* next);
222 209
223 StateBase* doSerializeArrayBuffer(v8::Handle<v8::Value> arrayBuffer, StateBa se* next); 210 StateBase* doSerializeArrayBuffer(v8::Handle<v8::Value> arrayBuffer, StateBa se* next);
224 StateBase* checkException(StateBase*); 211 StateBase* checkException(StateBase*);
225 StateBase* writeObject(uint32_t numProperties, StateBase*); 212 StateBase* writeObject(uint32_t numProperties, StateBase*);
226 StateBase* writeSparseArray(uint32_t numProperties, uint32_t length, StateBa se*); 213 StateBase* writeSparseArray(uint32_t numProperties, uint32_t length, StateBa se*);
227 StateBase* writeDenseArray(uint32_t numProperties, uint32_t length, StateBas e*); 214 StateBase* writeDenseArray(uint32_t numProperties, uint32_t length, StateBas e*);
228 215
229 protected: 216 protected:
230 class StateBase { 217 class StateBase {
231 WTF_MAKE_NONCOPYABLE(StateBase); 218 WTF_MAKE_NONCOPYABLE(StateBase);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 delete state; 355 delete state;
369 return next; 356 return next;
370 } 357 }
371 358
372 bool checkComposite(StateBase* top); 359 bool checkComposite(StateBase* top);
373 void writeString(v8::Handle<v8::Value>); 360 void writeString(v8::Handle<v8::Value>);
374 void writeStringObject(v8::Handle<v8::Value>); 361 void writeStringObject(v8::Handle<v8::Value>);
375 void writeNumberObject(v8::Handle<v8::Value>); 362 void writeNumberObject(v8::Handle<v8::Value>);
376 void writeBooleanObject(v8::Handle<v8::Value>); 363 void writeBooleanObject(v8::Handle<v8::Value>);
377 StateBase* writeBlob(v8::Handle<v8::Value>, StateBase* next); 364 StateBase* writeBlob(v8::Handle<v8::Value>, StateBase* next);
378 StateBase* writeDOMFileSystem(v8::Handle<v8::Value>, StateBase* next);
379 StateBase* writeFile(v8::Handle<v8::Value>, StateBase* next); 365 StateBase* writeFile(v8::Handle<v8::Value>, StateBase* next);
380 StateBase* writeFileList(v8::Handle<v8::Value>, StateBase* next); 366 StateBase* writeFileList(v8::Handle<v8::Value>, StateBase* next);
381 bool writeCryptoKey(v8::Handle<v8::Value>);
382 void writeImageData(v8::Handle<v8::Value>); 367 void writeImageData(v8::Handle<v8::Value>);
383 void writeRegExp(v8::Handle<v8::Value>); 368 void writeRegExp(v8::Handle<v8::Value>);
384 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object>, StateBase* ne xt); 369 StateBase* writeAndGreyArrayBufferView(v8::Handle<v8::Object>, StateBase* ne xt);
385 StateBase* writeArrayBuffer(v8::Handle<v8::Value>, StateBase* next); 370 StateBase* writeArrayBuffer(v8::Handle<v8::Value>, StateBase* next);
386 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value>, uint32_t index , StateBase* next); 371 StateBase* writeTransferredArrayBuffer(v8::Handle<v8::Value>, uint32_t index , StateBase* next);
387 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount); 372 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount);
388 373
389 StateBase* startArrayState(v8::Handle<v8::Array>, StateBase* next); 374 StateBase* startArrayState(v8::Handle<v8::Array>, StateBase* next);
390 StateBase* startObjectState(v8::Handle<v8::Object>, StateBase* next); 375 StateBase* startObjectState(v8::Handle<v8::Object>, StateBase* next);
391 376
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 unsigned position() const { return m_position; } 453 unsigned position() const { return m_position; }
469 454
470 const uint8_t* allocate(uint32_t size) 455 const uint8_t* allocate(uint32_t size)
471 { 456 {
472 const uint8_t* allocated = m_buffer + m_position; 457 const uint8_t* allocated = m_buffer + m_position;
473 m_position += size; 458 m_position += size;
474 return allocated; 459 return allocated;
475 } 460 }
476 461
477 public: 462 public:
478 bool read(v8::Handle<v8::Value>*, CompositeCreator&); 463 virtual bool read(v8::Handle<v8::Value>*, CompositeCreator&);
479 bool readVersion(uint32_t& version); 464 bool readVersion(uint32_t& version);
480 void setVersion(uint32_t); 465 void setVersion(uint32_t);
481 466
482 private: 467 protected:
468 bool readWithTag(SerializationTag, v8::Handle<v8::Value>*, CompositeCreator& );
469
483 bool readTag(SerializationTag*); 470 bool readTag(SerializationTag*);
484 bool readWebCoreString(String*); 471 bool readWebCoreString(String*);
485 bool readUint32(v8::Handle<v8::Value>*); 472 bool readUint32(v8::Handle<v8::Value>*);
473
474 bool doReadUint32(uint32_t* value);
475
476 private:
486 void undoReadTag(); 477 void undoReadTag();
487 bool readArrayBufferViewSubTag(ArrayBufferViewSubTag*); 478 bool readArrayBufferViewSubTag(ArrayBufferViewSubTag*);
488 bool readString(v8::Handle<v8::Value>*); 479 bool readString(v8::Handle<v8::Value>*);
489 bool readUCharString(v8::Handle<v8::Value>*); 480 bool readUCharString(v8::Handle<v8::Value>*);
490 bool readStringObject(v8::Handle<v8::Value>*); 481 bool readStringObject(v8::Handle<v8::Value>*);
491 bool readInt32(v8::Handle<v8::Value>*); 482 bool readInt32(v8::Handle<v8::Value>*);
492 bool readDate(v8::Handle<v8::Value>*); 483 bool readDate(v8::Handle<v8::Value>*);
493 bool readNumber(v8::Handle<v8::Value>*); 484 bool readNumber(v8::Handle<v8::Value>*);
494 bool readNumberObject(v8::Handle<v8::Value>*); 485 bool readNumberObject(v8::Handle<v8::Value>*);
495 bool readImageData(v8::Handle<v8::Value>*); 486 bool readImageData(v8::Handle<v8::Value>*);
496 PassRefPtr<ArrayBuffer> doReadArrayBuffer(); 487 PassRefPtr<ArrayBuffer> doReadArrayBuffer();
497 bool readArrayBuffer(v8::Handle<v8::Value>*); 488 bool readArrayBuffer(v8::Handle<v8::Value>*);
498 bool readArrayBufferView(v8::Handle<v8::Value>*, CompositeCreator&); 489 bool readArrayBufferView(v8::Handle<v8::Value>*, CompositeCreator&);
499 bool readRegExp(v8::Handle<v8::Value>*); 490 bool readRegExp(v8::Handle<v8::Value>*);
500 bool readBlob(v8::Handle<v8::Value>*, bool isIndexed); 491 bool readBlob(v8::Handle<v8::Value>*, bool isIndexed);
501 bool readDOMFileSystem(v8::Handle<v8::Value>*);
502 bool readFile(v8::Handle<v8::Value>*, bool isIndexed); 492 bool readFile(v8::Handle<v8::Value>*, bool isIndexed);
503 bool readFileList(v8::Handle<v8::Value>*, bool isIndexed); 493 bool readFileList(v8::Handle<v8::Value>*, bool isIndexed);
504 bool readCryptoKey(v8::Handle<v8::Value>*);
505 File* readFileHelper(); 494 File* readFileHelper();
506 File* readFileIndexHelper(); 495 File* readFileIndexHelper();
507 496
508 template<class T> 497 template<class T>
509 bool doReadUintHelper(T* value) 498 bool doReadUintHelper(T* value)
510 { 499 {
511 *value = 0; 500 *value = 0;
512 uint8_t currentByte; 501 uint8_t currentByte;
513 int shift = 0; 502 int shift = 0;
514 do { 503 do {
515 if (m_position >= m_length) 504 if (m_position >= m_length)
516 return false; 505 return false;
517 currentByte = m_buffer[m_position++]; 506 currentByte = m_buffer[m_position++];
518 *value |= ((currentByte & SerializedScriptValue::varIntMask) << shif t); 507 *value |= ((currentByte & SerializedScriptValue::varIntMask) << shif t);
519 shift += SerializedScriptValue::varIntShift; 508 shift += SerializedScriptValue::varIntShift;
520 } while (currentByte & (1 << SerializedScriptValue::varIntShift)); 509 } while (currentByte & (1 << SerializedScriptValue::varIntShift));
521 return true; 510 return true;
522 } 511 }
523 512
524 bool doReadUint32(uint32_t* value);
525 bool doReadUint64(uint64_t* value); 513 bool doReadUint64(uint64_t* value);
526 bool doReadNumber(double* number); 514 bool doReadNumber(double* number);
527 PassRefPtr<BlobDataHandle> getOrCreateBlobDataHandle(const String& uuid, con st String& type, long long size = -1); 515 PassRefPtr<BlobDataHandle> getOrCreateBlobDataHandle(const String& uuid, con st String& type, long long size = -1);
528 bool doReadHmacKey(WebCryptoKeyAlgorithm&, WebCryptoKeyType&);
529 bool doReadAesKey(WebCryptoKeyAlgorithm&, WebCryptoKeyType&);
530 bool doReadRsaHashedKey(WebCryptoKeyAlgorithm&, WebCryptoKeyType&);
531 bool doReadEcKey(WebCryptoKeyAlgorithm&, WebCryptoKeyType&);
532 bool doReadAlgorithmId(WebCryptoAlgorithmId&);
533 bool doReadAsymmetricKeyType(WebCryptoKeyType&);
534 bool doReadNamedCurve(WebCryptoNamedCurve&);
535 bool doReadKeyUsages(WebCryptoKeyUsageMask& usages, bool& extractable);
536 516
537 private: 517 private:
538 RefPtr<ScriptState> m_scriptState; 518 RefPtr<ScriptState> m_scriptState;
539 const uint8_t* m_buffer; 519 const uint8_t* m_buffer;
540 const unsigned m_length; 520 const unsigned m_length;
541 unsigned m_position; 521 unsigned m_position;
542 uint32_t m_version; 522 uint32_t m_version;
543 const WebBlobInfoArray* m_blobInfo; 523 const WebBlobInfoArray* m_blobInfo;
544 const BlobDataHandleMap& m_blobDataHandles; 524 const BlobDataHandleMap& m_blobDataHandles;
545 }; 525 };
(...skipping 20 matching lines...) Expand all
566 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) override; 546 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) override;
567 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) override; 547 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) override;
568 virtual void pushObjectReference(const v8::Handle<v8::Value>&) override; 548 virtual void pushObjectReference(const v8::Handle<v8::Value>&) override;
569 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Handle<v8::Val ue>*) override; 549 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Handle<v8::Val ue>*) override;
570 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Val ue>*) override; 550 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Handle<v8::Val ue>*) override;
571 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Handle< v8::Value>*) override; 551 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Handle< v8::Value>*) override;
572 virtual uint32_t objectReferenceCount() override; 552 virtual uint32_t objectReferenceCount() override;
573 553
574 protected: 554 protected:
575 Reader& reader() { return m_reader; } 555 Reader& reader() { return m_reader; }
576 bool read(v8::Local<v8::Value>*); 556 virtual bool read(v8::Local<v8::Value>*);
577 557
578 private: 558 private:
579 bool initializeObject(v8::Handle<v8::Object>, uint32_t numProperties, v8::Ha ndle<v8::Value>*); 559 bool initializeObject(v8::Handle<v8::Object>, uint32_t numProperties, v8::Ha ndle<v8::Value>*);
580 bool doDeserialize(); 560 bool doDeserialize();
581 void push(v8::Local<v8::Value> value) { m_stack.append(value); }; 561 void push(v8::Local<v8::Value> value) { m_stack.append(value); };
582 void pop(unsigned length) 562 void pop(unsigned length)
583 { 563 {
584 ASSERT(length <= m_stack.size()); 564 ASSERT(length <= m_stack.size());
585 m_stack.shrink(m_stack.size() - length); 565 m_stack.shrink(m_stack.size() - length);
586 } 566 }
(...skipping 11 matching lines...) Expand all
598 ArrayBufferContentsArray* m_arrayBufferContents; 578 ArrayBufferContentsArray* m_arrayBufferContents;
599 Vector<v8::Handle<v8::Object> > m_arrayBuffers; 579 Vector<v8::Handle<v8::Object> > m_arrayBuffers;
600 uint32_t m_version; 580 uint32_t m_version;
601 }; 581 };
602 582
603 } // namespace SerializedScriptValueInternal 583 } // namespace SerializedScriptValueInternal
604 584
605 } // namespace blink 585 } // namespace blink
606 586
607 #endif // ScriptValueSerializer_h 587 #endif // ScriptValueSerializer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698