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

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

Issue 11192017: ********** WebCore blob hacking (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/Source/
Patch Set: Created 8 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 /* 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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 doWriteWebCoreString(type); 385 doWriteWebCoreString(type);
386 } 386 }
387 387
388 void writeFileList(const FileList& fileList) 388 void writeFileList(const FileList& fileList)
389 { 389 {
390 append(FileListTag); 390 append(FileListTag);
391 uint32_t length = fileList.length(); 391 uint32_t length = fileList.length();
392 doWriteUint32(length); 392 doWriteUint32(length);
393 for (unsigned i = 0; i < length; ++i) { 393 for (unsigned i = 0; i < length; ++i) {
394 doWriteWebCoreString(fileList.item(i)->path()); 394 doWriteWebCoreString(fileList.item(i)->path());
395 doWriteWebCoreString(fileList.item(i)->url().string()); 395 doWriteWebCoreString(fileList.item(i)->uuid());
396 doWriteWebCoreString(fileList.item(i)->type()); 396 doWriteWebCoreString(fileList.item(i)->type());
397 } 397 }
398 } 398 }
399 399
400 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) 400 void writeArrayBuffer(const ArrayBuffer& arrayBuffer)
401 { 401 {
402 append(ArrayBufferTag); 402 append(ArrayBufferTag);
403 doWriteArrayBuffer(arrayBuffer); 403 doWriteArrayBuffer(arrayBuffer);
404 } 404 }
405 405
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 public: 619 public:
620 enum Status { 620 enum Status {
621 Success, 621 Success,
622 InputError, 622 InputError,
623 DataCloneError, 623 DataCloneError,
624 InvalidStateError, 624 InvalidStateError,
625 JSException, 625 JSException,
626 JSFailure 626 JSFailure
627 }; 627 };
628 628
629 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vector<String>& blobURLs, v8::TryCatch& tryCatch) 629 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, BlobDataHandleArray& blobDataHandles, v8::TryCatch& tryCatch)
630 : m_writer(writer) 630 : m_writer(writer)
631 , m_tryCatch(tryCatch) 631 , m_tryCatch(tryCatch)
632 , m_depth(0) 632 , m_depth(0)
633 , m_execDepth(0) 633 , m_execDepth(0)
634 , m_status(Success) 634 , m_status(Success)
635 , m_nextObjectReference(0) 635 , m_nextObjectReference(0)
636 , m_blobURLs(blobURLs) 636 , m_blobDataHandles(blobDataHandles)
637 { 637 {
638 ASSERT(!tryCatch.HasCaught()); 638 ASSERT(!tryCatch.HasCaught());
639 if (messagePorts) { 639 if (messagePorts) {
640 for (size_t i = 0; i < messagePorts->size(); i++) 640 for (size_t i = 0; i < messagePorts->size(); i++)
641 m_transferredMessagePorts.set(V8MessagePort::wrap(messagePorts-> at(i).get(), v8::Handle<v8::Object>(), m_writer.getIsolate()), i); 641 m_transferredMessagePorts.set(V8MessagePort::wrap(messagePorts-> at(i).get(), v8::Handle<v8::Object>(), m_writer.getIsolate()), i);
642 } 642 }
643 if (arrayBuffers) { 643 if (arrayBuffers) {
644 for (size_t i = 0; i < arrayBuffers->size(); i++) { 644 for (size_t i = 0; i < arrayBuffers->size(); i++) {
645 v8::Handle<v8::Object> v8ArrayBuffer = V8ArrayBuffer::wrap(array Buffers->at(i).get(), v8::Handle<v8::Object>(), m_writer.getIsolate()); 645 v8::Handle<v8::Object> v8ArrayBuffer = V8ArrayBuffer::wrap(array Buffers->at(i).get(), v8::Handle<v8::Object>(), m_writer.getIsolate());
646 // Coalesce multiple occurences of the same buffer to the first index. 646 // Coalesce multiple occurences of the same buffer to the first index.
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 { 990 {
991 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject >(); 991 v8::Handle<v8::BooleanObject> booleanObject = value.As<v8::BooleanObject >();
992 m_writer.writeBooleanObject(booleanObject->BooleanValue()); 992 m_writer.writeBooleanObject(booleanObject->BooleanValue());
993 } 993 }
994 994
995 void writeBlob(v8::Handle<v8::Value> value) 995 void writeBlob(v8::Handle<v8::Value> value)
996 { 996 {
997 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); 997 Blob* blob = V8Blob::toNative(value.As<v8::Object>());
998 if (!blob) 998 if (!blob)
999 return; 999 return;
1000 m_writer.writeBlob(blob->url().string(), blob->type(), blob->size()); 1000 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size());
1001 m_blobURLs.append(blob->url().string()); 1001 m_blobDataHandles.append(blob->blobDataHandle());
1002 } 1002 }
1003 1003
1004 #if ENABLE(FILE_SYSTEM) 1004 #if ENABLE(FILE_SYSTEM)
1005 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) 1005 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next)
1006 { 1006 {
1007 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); 1007 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>());
1008 if (!fs) 1008 if (!fs)
1009 return 0; 1009 return 0;
1010 if (!fs->clonable()) 1010 if (!fs->clonable())
1011 return handleError(DataCloneError, next); 1011 return handleError(DataCloneError, next);
1012 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); 1012 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ());
1013 return 0; 1013 return 0;
1014 } 1014 }
1015 #endif 1015 #endif
1016 1016
1017 void writeFile(v8::Handle<v8::Value> value) 1017 void writeFile(v8::Handle<v8::Value> value)
1018 { 1018 {
1019 File* file = V8File::toNative(value.As<v8::Object>()); 1019 File* file = V8File::toNative(value.As<v8::Object>());
1020 if (!file) 1020 if (!file)
1021 return; 1021 return;
1022 m_writer.writeFile(file->path(), file->url().string(), file->type()); 1022 m_writer.writeFile(file->path(), file->uuid(), file->type());
1023 m_blobURLs.append(file->url().string()); 1023 m_blobDataHandles.append(file->blobDataHandle());
1024 } 1024 }
1025 1025
1026 void writeFileList(v8::Handle<v8::Value> value) 1026 void writeFileList(v8::Handle<v8::Value> value)
1027 { 1027 {
1028 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); 1028 FileList* fileList = V8FileList::toNative(value.As<v8::Object>());
1029 if (!fileList) 1029 if (!fileList)
1030 return; 1030 return;
1031 m_writer.writeFileList(*fileList); 1031 m_writer.writeFileList(*fileList);
1032 unsigned length = fileList->length(); 1032 unsigned length = fileList->length();
1033 for (unsigned i = 0; i < length; ++i) 1033 for (unsigned i = 0; i < length; ++i)
1034 m_blobURLs.append(fileList->item(i)->url().string()); 1034 m_blobDataHandles.append(fileList->item(i)->blobDataHandle());
1035 } 1035 }
1036 1036
1037 void writeImageData(v8::Handle<v8::Value> value) 1037 void writeImageData(v8::Handle<v8::Value> value)
1038 { 1038 {
1039 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); 1039 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>());
1040 if (!imageData) 1040 if (!imageData)
1041 return; 1041 return;
1042 Uint8ClampedArray* pixelArray = imageData->data(); 1042 Uint8ClampedArray* pixelArray = imageData->data();
1043 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length()); 1043 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length());
1044 } 1044 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 Writer& m_writer; 1143 Writer& m_writer;
1144 v8::TryCatch& m_tryCatch; 1144 v8::TryCatch& m_tryCatch;
1145 int m_depth; 1145 int m_depth;
1146 int m_execDepth; 1146 int m_execDepth;
1147 Status m_status; 1147 Status m_status;
1148 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; 1148 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool;
1149 ObjectPool m_objectPool; 1149 ObjectPool m_objectPool;
1150 ObjectPool m_transferredMessagePorts; 1150 ObjectPool m_transferredMessagePorts;
1151 ObjectPool m_transferredArrayBuffers; 1151 ObjectPool m_transferredArrayBuffers;
1152 uint32_t m_nextObjectReference; 1152 uint32_t m_nextObjectReference;
1153 Vector<String>& m_blobURLs; 1153 BlobDataHandleArray& m_blobDataHandles;
1154 }; 1154 };
1155 1155
1156 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat eBase* next) 1156 Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, Stat eBase* next)
1157 { 1157 {
1158 if (m_execDepth + (next ? next->execDepth() : 0) > 1) { 1158 if (m_execDepth + (next ? next->execDepth() : 0) > 1) {
1159 m_writer.writeNull(); 1159 m_writer.writeNull();
1160 return 0; 1160 return 0;
1161 } 1161 }
1162 m_writer.writeReferenceCount(m_nextObjectReference); 1162 m_writer.writeReferenceCount(m_nextObjectReference);
1163 uint32_t objectReference; 1163 uint32_t objectReference;
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 return false; 1751 return false;
1752 uint32_t flags; 1752 uint32_t flags;
1753 if (!doReadUint32(&flags)) 1753 if (!doReadUint32(&flags))
1754 return false; 1754 return false;
1755 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags)); 1755 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags));
1756 return true; 1756 return true;
1757 } 1757 }
1758 1758
1759 bool readBlob(v8::Handle<v8::Value>* value) 1759 bool readBlob(v8::Handle<v8::Value>* value)
1760 { 1760 {
1761 String url; 1761 String uuid;
1762 String type; 1762 String type;
1763 uint64_t size; 1763 uint64_t size;
1764 if (!readWebCoreString(&url)) 1764 if (!readWebCoreString(&uuid))
1765 return false; 1765 return false;
1766 if (!readWebCoreString(&type)) 1766 if (!readWebCoreString(&type))
1767 return false; 1767 return false;
1768 if (!doReadUint64(&size)) 1768 if (!doReadUint64(&size))
1769 return false; 1769 return false;
1770 PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, s ize); 1770 PassRefPtr<Blob> blob = Blob::create(BlobDataHandle::create(uuid, type, size));
1771 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); 1771 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate);
1772 return true; 1772 return true;
1773 } 1773 }
1774 1774
1775 #if ENABLE(FILE_SYSTEM) 1775 #if ENABLE(FILE_SYSTEM)
1776 bool readDOMFileSystem(v8::Handle<v8::Value>* value) 1776 bool readDOMFileSystem(v8::Handle<v8::Value>* value)
1777 { 1777 {
1778 uint32_t type; 1778 uint32_t type;
1779 String name; 1779 String name;
1780 String url; 1780 String url;
1781 if (!doReadUint32(&type)) 1781 if (!doReadUint32(&type))
1782 return false; 1782 return false;
1783 if (!readWebCoreString(&name)) 1783 if (!readWebCoreString(&name))
1784 return false; 1784 return false;
1785 if (!readWebCoreString(&url)) 1785 if (!readWebCoreString(&url))
1786 return false; 1786 return false;
1787 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur l), AsyncFileSystem::create()); 1787 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur l), AsyncFileSystem::create());
1788 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); 1788 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate);
1789 return true; 1789 return true;
1790 } 1790 }
1791 #endif 1791 #endif
1792 1792
1793 bool readFile(v8::Handle<v8::Value>* value) 1793 bool readFile(v8::Handle<v8::Value>* value)
1794 { 1794 {
1795 String path; 1795 String path;
1796 String url; 1796 String uuid;
1797 String type; 1797 String type;
1798 if (!readWebCoreString(&path)) 1798 if (!readWebCoreString(&path))
1799 return false; 1799 return false;
1800 if (!readWebCoreString(&url)) 1800 if (!readWebCoreString(&uuid))
1801 return false; 1801 return false;
1802 if (!readWebCoreString(&type)) 1802 if (!readWebCoreString(&type))
1803 return false; 1803 return false;
1804 PassRefPtr<File> file = File::create(path, KURL(ParsedURLString, url), t ype); 1804 PassRefPtr<File> file = File::create(path, uuid, type);
1805 *value = toV8(file, v8::Handle<v8::Object>(), m_isolate); 1805 *value = toV8(file, v8::Handle<v8::Object>(), m_isolate);
1806 return true; 1806 return true;
1807 } 1807 }
1808 1808
1809 bool readFileList(v8::Handle<v8::Value>* value) 1809 bool readFileList(v8::Handle<v8::Value>* value)
1810 { 1810 {
1811 uint32_t length; 1811 uint32_t length;
1812 if (!doReadUint32(&length)) 1812 if (!doReadUint32(&length))
1813 return false; 1813 return false;
1814 PassRefPtr<FileList> fileList = FileList::create(); 1814 PassRefPtr<FileList> fileList = FileList::create();
1815 for (unsigned i = 0; i < length; ++i) { 1815 for (unsigned i = 0; i < length; ++i) {
1816 String path; 1816 String path;
1817 String urlString; 1817 String uuid;
1818 String type; 1818 String type;
1819 if (!readWebCoreString(&path)) 1819 if (!readWebCoreString(&path))
1820 return false; 1820 return false;
1821 if (!readWebCoreString(&urlString)) 1821 if (!readWebCoreString(&uuid))
1822 return false; 1822 return false;
1823 if (!readWebCoreString(&type)) 1823 if (!readWebCoreString(&type))
1824 return false; 1824 return false;
1825 fileList->append(File::create(path, KURL(ParsedURLString, urlString) , type)); 1825 fileList->append(File::create(path, uuid, type));
1826 } 1826 }
1827 *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate); 1827 *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate);
1828 return true; 1828 return true;
1829 } 1829 }
1830 1830
1831 template<class T> 1831 template<class T>
1832 bool doReadUintHelper(T* value) 1832 bool doReadUintHelper(T* value)
1833 { 1833 {
1834 *value = 0; 1834 *value = 0;
1835 uint8_t currentByte; 1835 uint8_t currentByte;
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 MessagePortArray* messagePorts, Arr ayBufferArray* arrayBuffers, 2254 MessagePortArray* messagePorts, Arr ayBufferArray* arrayBuffers,
2255 bool& didThrow, 2255 bool& didThrow,
2256 v8::Isolate* isolate) 2256 v8::Isolate* isolate)
2257 : m_externallyAllocatedMemory(0) 2257 : m_externallyAllocatedMemory(0)
2258 { 2258 {
2259 didThrow = false; 2259 didThrow = false;
2260 Writer writer(isolate); 2260 Writer writer(isolate);
2261 Serializer::Status status; 2261 Serializer::Status status;
2262 { 2262 {
2263 v8::TryCatch tryCatch; 2263 v8::TryCatch tryCatch;
2264 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tr yCatch); 2264 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobDataHand les, tryCatch);
2265 status = serializer.serialize(value); 2265 status = serializer.serialize(value);
2266 if (status == Serializer::JSException) { 2266 if (status == Serializer::JSException) {
2267 // If there was a JS exception thrown, re-throw it. 2267 // If there was a JS exception thrown, re-throw it.
2268 didThrow = true; 2268 didThrow = true;
2269 tryCatch.ReThrow(); 2269 tryCatch.ReThrow();
2270 return; 2270 return;
2271 } 2271 }
2272 } 2272 }
2273 switch (status) { 2273 switch (status) {
2274 case Serializer::InputError: 2274 case Serializer::InputError:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 // If the allocated memory was not registered before, then this class is lik ely 2339 // If the allocated memory was not registered before, then this class is lik ely
2340 // used in a context other then Worker's onmessage environment and the prese nce of 2340 // used in a context other then Worker's onmessage environment and the prese nce of
2341 // current v8 context is not guaranteed. Avoid calling v8 then. 2341 // current v8 context is not guaranteed. Avoid calling v8 then.
2342 if (m_externallyAllocatedMemory) { 2342 if (m_externallyAllocatedMemory) {
2343 ASSERT(v8::Isolate::GetCurrent()); 2343 ASSERT(v8::Isolate::GetCurrent());
2344 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry); 2344 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo ry);
2345 } 2345 }
2346 } 2346 }
2347 2347
2348 } // namespace WebCore 2348 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698