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

Side by Side Diff: Source/bindings/v8/SerializedScriptValue.cpp

Issue 23992003: blob hacking webcore style (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 months 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
« no previous file with comments | « Source/bindings/v8/SerializedScriptValue.h ('k') | Source/core/fileapi/Blob.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 append(NumberTag); 387 append(NumberTag);
388 doWriteNumber(number); 388 doWriteNumber(number);
389 } 389 }
390 390
391 void writeNumberObject(double number) 391 void writeNumberObject(double number)
392 { 392 {
393 append(NumberObjectTag); 393 append(NumberObjectTag);
394 doWriteNumber(number); 394 doWriteNumber(number);
395 } 395 }
396 396
397 void writeBlob(const String& url, const String& type, unsigned long long siz e) 397 void writeBlob(const String& uuid, const String& type, unsigned long long si ze)
398 { 398 {
399 append(BlobTag); 399 append(BlobTag);
400 doWriteWebCoreString(url); 400 doWriteWebCoreString(uuid);
401 doWriteWebCoreString(type); 401 doWriteWebCoreString(type);
402 doWriteUint64(size); 402 doWriteUint64(size);
403 } 403 }
404 404
405 void writeDOMFileSystem(int type, const String& name, const String& url) 405 void writeDOMFileSystem(int type, const String& name, const String& url)
406 { 406 {
407 append(DOMFileSystemTag); 407 append(DOMFileSystemTag);
408 doWriteUint32(type); 408 doWriteUint32(type);
409 doWriteWebCoreString(name); 409 doWriteWebCoreString(name);
410 doWriteWebCoreString(url); 410 doWriteWebCoreString(url);
411 } 411 }
412 412
413 void writeFile(const String& path, const String& url, const String& type) 413 void writeFile(const File& file)
414 { 414 {
415 append(FileTag); 415 append(FileTag);
416 doWriteWebCoreString(path); 416 doWriteFile(file);
417 doWriteWebCoreString(url);
418 doWriteWebCoreString(type);
419 } 417 }
420 418
421 void writeFileList(const FileList& fileList) 419 void writeFileList(const FileList& fileList)
422 { 420 {
423 append(FileListTag); 421 append(FileListTag);
424 uint32_t length = fileList.length(); 422 uint32_t length = fileList.length();
425 doWriteUint32(length); 423 doWriteUint32(length);
426 for (unsigned i = 0; i < length; ++i) { 424 for (unsigned i = 0; i < length; ++i)
427 doWriteWebCoreString(fileList.item(i)->path()); 425 doWriteFile(*fileList.item(i));
428 doWriteWebCoreString(fileList.item(i)->url().string());
429 doWriteWebCoreString(fileList.item(i)->type());
430 }
431 } 426 }
432 427
433 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) 428 void writeArrayBuffer(const ArrayBuffer& arrayBuffer)
434 { 429 {
435 append(ArrayBufferTag); 430 append(ArrayBufferTag);
436 doWriteArrayBuffer(arrayBuffer); 431 doWriteArrayBuffer(arrayBuffer);
437 } 432 }
438 433
439 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) 434 void writeArrayBufferView(const ArrayBufferView& arrayBufferView)
440 { 435 {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 550
556 void writeGenerateFreshDenseArray(uint32_t length) 551 void writeGenerateFreshDenseArray(uint32_t length)
557 { 552 {
558 append(GenerateFreshDenseArrayTag); 553 append(GenerateFreshDenseArrayTag);
559 doWriteUint32(length); 554 doWriteUint32(length);
560 } 555 }
561 556
562 v8::Isolate* getIsolate() { return m_isolate; } 557 v8::Isolate* getIsolate() { return m_isolate; }
563 558
564 private: 559 private:
560 void doWriteFile(const File& file)
561 {
562 doWriteWebCoreString(file.path());
563 doWriteWebCoreString(file.uuid());
564 doWriteWebCoreString(file.type());
565 }
566
565 void doWriteArrayBuffer(const ArrayBuffer& arrayBuffer) 567 void doWriteArrayBuffer(const ArrayBuffer& arrayBuffer)
566 { 568 {
567 uint32_t byteLength = arrayBuffer.byteLength(); 569 uint32_t byteLength = arrayBuffer.byteLength();
568 doWriteUint32(byteLength); 570 doWriteUint32(byteLength);
569 append(static_cast<const uint8_t*>(arrayBuffer.data()), byteLength); 571 append(static_cast<const uint8_t*>(arrayBuffer.data()), byteLength);
570 } 572 }
571 573
572 void doWriteString(const char* data, int length) 574 void doWriteString(const char* data, int length)
573 { 575 {
574 doWriteUint32(static_cast<uint32_t>(length)); 576 doWriteUint32(static_cast<uint32_t>(length));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 public: 696 public:
695 enum Status { 697 enum Status {
696 Success, 698 Success,
697 InputError, 699 InputError,
698 DataCloneError, 700 DataCloneError,
699 InvalidStateError, 701 InvalidStateError,
700 JSException, 702 JSException,
701 JSFailure 703 JSFailure
702 }; 704 };
703 705
704 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vector<String>& blobURLs, v8::TryCatch& tryCatch, v8::Isolate* is olate) 706 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, v8::I solate* isolate)
705 : m_writer(writer) 707 : m_writer(writer)
706 , m_tryCatch(tryCatch) 708 , m_tryCatch(tryCatch)
707 , m_depth(0) 709 , m_depth(0)
708 , m_execDepth(0) 710 , m_execDepth(0)
709 , m_status(Success) 711 , m_status(Success)
710 , m_nextObjectReference(0) 712 , m_nextObjectReference(0)
711 , m_blobURLs(blobURLs) 713 , m_blobDataHandles(blobDataHandles)
712 , m_isolate(isolate) 714 , m_isolate(isolate)
713 { 715 {
714 ASSERT(!tryCatch.HasCaught()); 716 ASSERT(!tryCatch.HasCaught());
715 if (messagePorts) { 717 if (messagePorts) {
716 for (size_t i = 0; i < messagePorts->size(); i++) 718 for (size_t i = 0; i < messagePorts->size(); i++)
717 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), m_writer.getIsolate()), i); 719 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), m_writer.getIsolate()), i);
718 } 720 }
719 if (arrayBuffers) { 721 if (arrayBuffers) {
720 for (size_t i = 0; i < arrayBuffers->size(); i++) { 722 for (size_t i = 0; i < arrayBuffers->size(); i++) {
721 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers-> at(i).get(), m_writer.getIsolate()); 723 v8::Handle<v8::Object> v8ArrayBuffer = toV8Object(arrayBuffers-> at(i).get(), m_writer.getIsolate());
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 { 1071 {
1070 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject >(); 1072 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject >();
1071 m_writer.writeBooleanObject(booleanObject->BooleanValue()); 1073 m_writer.writeBooleanObject(booleanObject->BooleanValue());
1072 } 1074 }
1073 1075
1074 void writeBlob(v8::Handle<v8::Value> value) 1076 void writeBlob(v8::Handle<v8::Value> value)
1075 { 1077 {
1076 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); 1078 Blob* blob = V8Blob::toNative(value.As<v8::Object>());
1077 if (!blob) 1079 if (!blob)
1078 return; 1080 return;
1079 m_writer.writeBlob(blob->url().string(), blob->type(), blob->size()); 1081 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size());
1080 m_blobURLs.append(blob->url().string()); 1082 m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle());
1081 } 1083 }
1082 1084
1083 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) 1085 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next)
1084 { 1086 {
1085 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); 1087 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>());
1086 if (!fs) 1088 if (!fs)
1087 return 0; 1089 return 0;
1088 if (!fs->clonable()) 1090 if (!fs->clonable())
1089 return handleError(DataCloneError, next); 1091 return handleError(DataCloneError, next);
1090 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); 1092 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ());
1091 return 0; 1093 return 0;
1092 } 1094 }
1093 1095
1094 void writeFile(v8::Handle<v8::Value> value) 1096 void writeFile(v8::Handle<v8::Value> value)
1095 { 1097 {
1096 File* file = V8File::toNative(value.As<v8::Object>()); 1098 File* file = V8File::toNative(value.As<v8::Object>());
1097 if (!file) 1099 if (!file)
1098 return; 1100 return;
1099 m_writer.writeFile(file->path(), file->url().string(), file->type()); 1101 m_writer.writeFile(*file);
1100 m_blobURLs.append(file->url().string()); 1102 m_blobDataHandles.add(file->uuid(), file->blobDataHandle());
1101 } 1103 }
1102 1104
1103 void writeFileList(v8::Handle<v8::Value> value) 1105 void writeFileList(v8::Handle<v8::Value> value)
1104 { 1106 {
1105 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); 1107 FileList* fileList = V8FileList::toNative(value.As<v8::Object>());
1106 if (!fileList) 1108 if (!fileList)
1107 return; 1109 return;
1108 m_writer.writeFileList(*fileList); 1110 m_writer.writeFileList(*fileList);
1109 unsigned length = fileList->length(); 1111 unsigned length = fileList->length();
1110 for (unsigned i = 0; i < length; ++i) 1112 for (unsigned i = 0; i < length; ++i)
1111 m_blobURLs.append(fileList->item(i)->url().string()); 1113 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)-> blobDataHandle());
1112 } 1114 }
1113 1115
1114 void writeImageData(v8::Handle<v8::Value> value) 1116 void writeImageData(v8::Handle<v8::Value> value)
1115 { 1117 {
1116 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); 1118 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>());
1117 if (!imageData) 1119 if (!imageData)
1118 return; 1120 return;
1119 Uint8ClampedArray* pixelArray = imageData->data(); 1121 Uint8ClampedArray* pixelArray = imageData->data();
1120 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length()); 1122 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length());
1121 } 1123 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 Writer& m_writer; 1222 Writer& m_writer;
1221 v8::TryCatch& m_tryCatch; 1223 v8::TryCatch& m_tryCatch;
1222 int m_depth; 1224 int m_depth;
1223 int m_execDepth; 1225 int m_execDepth;
1224 Status m_status; 1226 Status m_status;
1225 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; 1227 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool;
1226 ObjectPool m_objectPool; 1228 ObjectPool m_objectPool;
1227 ObjectPool m_transferredMessagePorts; 1229 ObjectPool m_transferredMessagePorts;
1228 ObjectPool m_transferredArrayBuffers; 1230 ObjectPool m_transferredArrayBuffers;
1229 uint32_t m_nextObjectReference; 1231 uint32_t m_nextObjectReference;
1230 Vector<String>& m_blobURLs; 1232 BlobDataHandleMap& m_blobDataHandles;
1231 v8::Isolate* m_isolate; 1233 v8::Isolate* m_isolate;
1232 }; 1234 };
1233 1235
1234 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat eBase* next) 1236 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat eBase* next)
1235 { 1237 {
1236 if (m_execDepth + (next ? next->execDepth() : 0) > 1) { 1238 if (m_execDepth + (next ? next->execDepth() : 0) > 1) {
1237 m_writer.writeNull(); 1239 m_writer.writeNull();
1238 return 0; 1240 return 0;
1239 } 1241 }
1240 m_writer.writeReferenceCount(m_nextObjectReference); 1242 m_writer.writeReferenceCount(m_nextObjectReference);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 virtual bool newObject() = 0; 1332 virtual bool newObject() = 0;
1331 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) = 0; 1333 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) = 0;
1332 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) = 0; 1334 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) = 0;
1333 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) = 0; 1335 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) = 0;
1334 }; 1336 };
1335 1337
1336 // Reader is responsible for deserializing primitive types and 1338 // Reader is responsible for deserializing primitive types and
1337 // restoring information about saved objects of composite types. 1339 // restoring information about saved objects of composite types.
1338 class Reader { 1340 class Reader {
1339 public: 1341 public:
1340 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate) 1342 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const BlobD ataHandleMap& blobDataHandles)
1341 : m_buffer(buffer) 1343 : m_buffer(buffer)
1342 , m_length(length) 1344 , m_length(length)
1343 , m_position(0) 1345 , m_position(0)
1344 , m_version(0) 1346 , m_version(0)
1345 , m_isolate(isolate) 1347 , m_isolate(isolate)
1348 , m_blobDataHandles(blobDataHandles)
1346 { 1349 {
1347 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); 1350 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1));
1348 ASSERT(length >= 0); 1351 ASSERT(length >= 0);
1349 } 1352 }
1350 1353
1351 bool isEof() const { return m_position >= m_length; } 1354 bool isEof() const { return m_position >= m_length; }
1352 1355
1353 bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator) 1356 bool read(v8::Handle<v8::Value>* value, CompositeCreator& creator)
1354 { 1357 {
1355 SerializationTag tag; 1358 SerializationTag tag;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 return false; 1848 return false;
1846 uint32_t flags; 1849 uint32_t flags;
1847 if (!doReadUint32(&flags)) 1850 if (!doReadUint32(&flags))
1848 return false; 1851 return false;
1849 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags)); 1852 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags));
1850 return true; 1853 return true;
1851 } 1854 }
1852 1855
1853 bool readBlob(v8::Handle<v8::Value>* value) 1856 bool readBlob(v8::Handle<v8::Value>* value)
1854 { 1857 {
1855 String url; 1858 if (m_version < 3)
1859 return false;
1860 String uuid;
1856 String type; 1861 String type;
1857 uint64_t size; 1862 uint64_t size;
1858 if (!readWebCoreString(&url)) 1863 if (!readWebCoreString(&uuid))
1859 return false; 1864 return false;
1860 if (!readWebCoreString(&type)) 1865 if (!readWebCoreString(&type))
1861 return false; 1866 return false;
1862 if (!doReadUint64(&size)) 1867 if (!doReadUint64(&size))
1863 return false; 1868 return false;
1864 PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, s ize); 1869 RefPtr<Blob> blob = Blob::create(getOrCreateBlobDataHandle(uuid, type, s ize));
1865 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); 1870 *value = toV8(blob.release(), v8::Handle<v8::Object>(), m_isolate);
1866 return true; 1871 return true;
1867 } 1872 }
1868 1873
1869 bool readDOMFileSystem(v8::Handle<v8::Value>* value) 1874 bool readDOMFileSystem(v8::Handle<v8::Value>* value)
1870 { 1875 {
1871 uint32_t type; 1876 uint32_t type;
1872 String name; 1877 String name;
1873 String url; 1878 String url;
1874 if (!doReadUint32(&type)) 1879 if (!doReadUint32(&type))
1875 return false; 1880 return false;
1876 if (!readWebCoreString(&name)) 1881 if (!readWebCoreString(&name))
1877 return false; 1882 return false;
1878 if (!readWebCoreString(&url)) 1883 if (!readWebCoreString(&url))
1879 return false; 1884 return false;
1880 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getExecutionContext(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, url)); 1885 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getExecutionContext(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, url));
1881 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); 1886 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate);
1882 return true; 1887 return true;
1883 } 1888 }
1884 1889
1885 bool readFile(v8::Handle<v8::Value>* value) 1890 bool readFile(v8::Handle<v8::Value>* value)
1886 { 1891 {
1887 String path; 1892 RefPtr<File> file = doReadFileHelper();
1888 String url; 1893 if (!file)
1889 String type;
1890 if (!readWebCoreString(&path))
1891 return false; 1894 return false;
1892 if (!readWebCoreString(&url)) 1895 *value = toV8(file.release(), v8::Handle<v8::Object>(), m_isolate);
1893 return false;
1894 if (!readWebCoreString(&type))
1895 return false;
1896 PassRefPtr<File> file = File::create(path, KURL(ParsedURLString, url), t ype);
1897 *value = toV8(file, v8::Handle<v8::Object>(), m_isolate);
1898 return true; 1896 return true;
1899 } 1897 }
1900 1898
1901 bool readFileList(v8::Handle<v8::Value>* value) 1899 bool readFileList(v8::Handle<v8::Value>* value)
1902 { 1900 {
1901 if (m_version < 3)
1902 return false;
1903 uint32_t length; 1903 uint32_t length;
1904 if (!doReadUint32(&length)) 1904 if (!doReadUint32(&length))
1905 return false; 1905 return false;
1906 PassRefPtr<FileList> fileList = FileList::create(); 1906 RefPtr<FileList> fileList = FileList::create();
1907 for (unsigned i = 0; i < length; ++i) { 1907 for (unsigned i = 0; i < length; ++i) {
1908 String path; 1908 RefPtr<File> file = doReadFileHelper();
1909 String urlString; 1909 if (!file)
1910 String type;
1911 if (!readWebCoreString(&path))
1912 return false; 1910 return false;
1913 if (!readWebCoreString(&urlString)) 1911 fileList->append(file.release());
1914 return false;
1915 if (!readWebCoreString(&type))
1916 return false;
1917 fileList->append(File::create(path, KURL(ParsedURLString, urlString) , type));
1918 } 1912 }
1919 *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate); 1913 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate);
1920 return true; 1914 return true;
1921 } 1915 }
1922 1916
1917 PassRefPtr<File> doReadFileHelper()
1918 {
1919 if (m_version < 3)
1920 return 0;
1921 String path;
1922 String uuid;
1923 String type;
1924 if (!readWebCoreString(&path))
1925 return 0;
1926 if (!readWebCoreString(&uuid))
1927 return 0;
1928 if (!readWebCoreString(&type))
1929 return 0;
1930 return File::create(path, getOrCreateBlobDataHandle(uuid, type));
1931 }
1932
1923 template<class T> 1933 template<class T>
1924 bool doReadUintHelper(T* value) 1934 bool doReadUintHelper(T* value)
1925 { 1935 {
1926 *value = 0; 1936 *value = 0;
1927 uint8_t currentByte; 1937 uint8_t currentByte;
1928 int shift = 0; 1938 int shift = 0;
1929 do { 1939 do {
1930 if (m_position >= m_length) 1940 if (m_position >= m_length)
1931 return false; 1941 return false;
1932 currentByte = m_buffer[m_position++]; 1942 currentByte = m_buffer[m_position++];
(...skipping 16 matching lines...) Expand all
1949 bool doReadNumber(double* number) 1959 bool doReadNumber(double* number)
1950 { 1960 {
1951 if (m_position + sizeof(double) > m_length) 1961 if (m_position + sizeof(double) > m_length)
1952 return false; 1962 return false;
1953 uint8_t* numberAsByteArray = reinterpret_cast<uint8_t*>(number); 1963 uint8_t* numberAsByteArray = reinterpret_cast<uint8_t*>(number);
1954 for (unsigned i = 0; i < sizeof(double); ++i) 1964 for (unsigned i = 0; i < sizeof(double); ++i)
1955 numberAsByteArray[i] = m_buffer[m_position++]; 1965 numberAsByteArray[i] = m_buffer[m_position++];
1956 return true; 1966 return true;
1957 } 1967 }
1958 1968
1969 PassRefPtr<BlobDataHandle> getOrCreateBlobDataHandle(const String& uuid, con st String& type, long long size = -1)
1970 {
1971 // The containing ssv may have a BDH for this uuid if this ssv is just b eing
1972 // passed from main to worker thread (for example). We use those values when creating
1973 // the new blob instead of cons'ing up a new BDH.
1974 //
1975 // FIXME: Maybe we should require that it work that way where the ssv mu st have a BDH for any
1976 // blobs it comes across during deserialization. Would require callers t o explicitly populate
1977 // the collection of BDH's for blobs to work, which would encourage life times to be considered
1978 // when passing ssv's around cross process. At present, we get 'lucky' i n some cases because
1979 // the blob in the src process happens to still exist at the time the de st process is deserializing.
1980 // For example in sharedWorker.postMesssage(...).
1981 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid);
1982 if (it != m_blobDataHandles.end()) {
1983 // make assertions about type and size?
1984 return it->value;
1985 }
1986 return BlobDataHandle::create(uuid, type, size);
1987 }
1988
1959 const uint8_t* m_buffer; 1989 const uint8_t* m_buffer;
1960 const unsigned m_length; 1990 const unsigned m_length;
1961 unsigned m_position; 1991 unsigned m_position;
1962 uint32_t m_version; 1992 uint32_t m_version;
1963 v8::Isolate* m_isolate; 1993 v8::Isolate* m_isolate;
1994 const BlobDataHandleMap& m_blobDataHandles;
1964 }; 1995 };
1965 1996
1966 1997
1967 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; 1998 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray;
1968 1999
1969 class Deserializer : public CompositeCreator { 2000 class Deserializer : public CompositeCreator {
1970 public: 2001 public:
1971 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents) 2002 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents)
1972 : m_reader(reader) 2003 : m_reader(reader)
1973 , m_transferredMessagePorts(messagePorts) 2004 , m_transferredMessagePorts(messagePorts)
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 } 2453 }
2423 2454
2424 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Is olate* isolate, ExceptionPolicy policy) 2455 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, bool& didThrow, v8::Is olate* isolate, ExceptionPolicy policy)
2425 : m_externallyAllocatedMemory(0) 2456 : m_externallyAllocatedMemory(0)
2426 { 2457 {
2427 didThrow = false; 2458 didThrow = false;
2428 Writer writer(isolate); 2459 Writer writer(isolate);
2429 Serializer::Status status; 2460 Serializer::Status status;
2430 { 2461 {
2431 v8::TryCatch tryCatch; 2462 v8::TryCatch tryCatch;
2432 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tr yCatch, isolate); 2463 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobDataHand les, tryCatch, isolate);
2433 status = serializer.serialize(value); 2464 status = serializer.serialize(value);
2434 if (status == Serializer::JSException) { 2465 if (status == Serializer::JSException) {
2435 didThrow = true; 2466 didThrow = true;
2436 // If there was a JS exception thrown, re-throw it. 2467 // If there was a JS exception thrown, re-throw it.
2437 if (policy == ThrowExceptions) 2468 if (policy == ThrowExceptions)
2438 tryCatch.ReThrow(); 2469 tryCatch.ReThrow();
2439 return; 2470 return;
2440 } 2471 }
2441 } 2472 }
2442 switch (status) { 2473 switch (status) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts) 2517 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts)
2487 { 2518 {
2488 if (!m_data.impl()) 2519 if (!m_data.impl())
2489 return v8NullWithCheck(isolate); 2520 return v8NullWithCheck(isolate);
2490 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); 2521 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes);
2491 m_data.ensure16Bit(); 2522 m_data.ensure16Bit();
2492 // FIXME: SerializedScriptValue shouldn't use String for its underlying 2523 // FIXME: SerializedScriptValue shouldn't use String for its underlying
2493 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The 2524 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
2494 // information stored in m_data isn't even encoded in UTF-16. Instead, 2525 // information stored in m_data isn't even encoded in UTF-16. Instead,
2495 // unicode characters are encoded as UTF-8 with two code units per UChar. 2526 // unicode characters are encoded as UTF-8 with two code units per UChar.
2496 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16() ), 2 * m_data.length(), isolate); 2527 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16() ), 2 * m_data.length(), isolate, m_blobDataHandles);
2497 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g et()); 2528 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g et());
2498 2529
2499 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. 2530 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed.
2500 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. 2531 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation.
2501 RefPtr<SerializedScriptValue> protect(this); 2532 RefPtr<SerializedScriptValue> protect(this);
2502 return deserializer.deserialize(); 2533 return deserializer.deserialize();
2503 } 2534 }
2504 2535
2505 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt ate) 2536 ScriptValue SerializedScriptValue::deserializeForInspector(ScriptState* scriptSt ate)
2506 { 2537 {
(...skipping 17 matching lines...) Expand all
2524 // If the allocated memory was not registered before, then this class is lik ely 2555 // If the allocated memory was not registered before, then this class is lik ely
2525 // used in a context other then Worker's onmessage environment and the prese nce of 2556 // used in a context other then Worker's onmessage environment and the prese nce of
2526 // current v8 context is not guaranteed. Avoid calling v8 then. 2557 // current v8 context is not guaranteed. Avoid calling v8 then.
2527 if (m_externallyAllocatedMemory) { 2558 if (m_externallyAllocatedMemory) {
2528 ASSERT(v8::Isolate::GetCurrent()); 2559 ASSERT(v8::Isolate::GetCurrent());
2529 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry); 2560 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry);
2530 } 2561 }
2531 } 2562 }
2532 2563
2533 } // namespace WebCore 2564 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/SerializedScriptValue.h ('k') | Source/core/fileapi/Blob.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698