Changeset 57382 in webkit
- Timestamp:
- Apr 9, 2010 4:28:00 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r57379 r57382 1 2010-04-09 Vitaly Repeshko <vitalyr@chromium.org> 2 3 Reviewed by Darin Fisher. 4 5 [V8] SerializedScriptValue value doesn't follow the spec for DOM objects and files 6 https://bugs.webkit.org/show_bug.cgi?id=37094 7 8 This patch adds support for file-related types. 9 10 * bindings/v8/SerializedScriptValue.cpp: 11 (WebCore::): 12 (WebCore::Writer::writeString): 13 (WebCore::Writer::writeWebCoreString): 14 (WebCore::Writer::writeBlob): 15 (WebCore::Writer::writeFile): 16 (WebCore::Writer::writeFileList): 17 (WebCore::Writer::doWriteString): 18 (WebCore::Writer::doWriteWebCoreString): 19 (WebCore::Serializer::writeBlob): 20 (WebCore::Serializer::writeFile): 21 (WebCore::Serializer::writeFileList): 22 (WebCore::Serializer::doSerialize): 23 (WebCore::Reader::read): 24 (WebCore::Reader::readWebCoreString): 25 (WebCore::Reader::readBlob): 26 (WebCore::Reader::readFile): 27 (WebCore::Reader::readFileList): 28 (WebCore::SerializedScriptValue::SerializedScriptValue): 29 1 30 2010-04-09 Geoffrey Garen <ggaren@apple.com> 2 31 -
trunk/WebCore/bindings/v8/SerializedScriptValue.cpp
r57276 r57382 32 32 #include "SerializedScriptValue.h" 33 33 34 #include "Blob.h" 34 35 #include "ByteArray.h" 35 36 #include "CanvasPixelArray.h" 37 #include "File.h" 38 #include "FileList.h" 36 39 #include "ImageData.h" 37 40 #include "SharedBuffer.h" 41 #include "V8Blob.h" 42 #include "V8File.h" 43 #include "V8FileList.h" 38 44 #include "V8ImageData.h" 39 45 #include "V8Proxy.h" … … 68 74 DateTag = 'D', 69 75 NumberTag = 'N', 76 BlobTag = 'b', 77 FileTag = 'f', 78 FileListTag = 'l', 70 79 ImageDataTag = '#', 71 80 ArrayTag = '[', … … 138 147 ASSERT(length >= 0); 139 148 append(StringTag); 140 doWriteUint32(static_cast<uint32_t>(length)); 141 append(reinterpret_cast<const uint8_t*>(data), length); 149 doWriteString(data, length); 150 } 151 152 void writeWebCoreString(const String& string) 153 { 154 // Uses UTF8 encoding so we can read it back as either V8 or 155 // WebCore string. 156 append(StringTag); 157 doWriteWebCoreString(string); 142 158 } 143 159 … … 164 180 append(NumberTag); 165 181 doWriteNumber(number); 182 } 183 184 void writeBlob(const String& path) 185 { 186 append(BlobTag); 187 doWriteWebCoreString(path); 188 } 189 190 void writeFile(const String& path) 191 { 192 append(FileTag); 193 doWriteWebCoreString(path); 194 } 195 196 void writeFileList(const FileList& fileList) 197 { 198 append(FileListTag); 199 uint32_t length = fileList.length(); 200 doWriteUint32(length); 201 for (unsigned i = 0; i < length; ++i) 202 doWriteWebCoreString(fileList.item(i)->path()); 166 203 } 167 204 … … 201 238 202 239 private: 240 void doWriteString(const char* data, int length) 241 { 242 doWriteUint32(static_cast<uint32_t>(length)); 243 append(reinterpret_cast<const uint8_t*>(data), length); 244 } 245 246 void doWriteWebCoreString(const String& string) 247 { 248 RefPtr<SharedBuffer> buffer = utf8Buffer(string); 249 doWriteString(buffer->data(), buffer->size()); 250 } 251 203 252 void doWriteUint32(uint32_t value) 204 253 { … … 505 554 } 506 555 556 void writeBlob(v8::Handle<v8::Value> value) 557 { 558 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); 559 if (!blob) 560 return; 561 m_writer.writeBlob(blob->path()); 562 } 563 564 void writeFile(v8::Handle<v8::Value> value) 565 { 566 File* file = V8File::toNative(value.As<v8::Object>()); 567 if (!file) 568 return; 569 m_writer.writeFile(file->path()); 570 } 571 572 void writeFileList(v8::Handle<v8::Value> value) 573 { 574 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); 575 if (!fileList) 576 return; 577 m_writer.writeFileList(*fileList); 578 } 579 507 580 void writeImageData(v8::Handle<v8::Value> value) 508 581 { … … 556 629 else if (value->IsArray()) 557 630 return push(newArrayState(value.As<v8::Array>(), next)); 631 else if (V8File::HasInstance(value)) 632 writeFile(value); 633 else if (V8Blob::HasInstance(value)) 634 writeBlob(value); 635 else if (V8FileList::HasInstance(value)) 636 writeFileList(value); 558 637 else if (V8ImageData::HasInstance(value)) 559 638 writeImageData(value); … … 629 708 return false; 630 709 break; 710 case BlobTag: 711 if (!readBlob(value)) 712 return false; 713 break; 714 case FileTag: 715 if (!readFile(value)) 716 return false; 717 break; 718 case FileListTag: 719 if (!readFileList(value)) 720 return false; 721 break; 631 722 case ImageDataTag: 632 723 if (!readImageData(value)) … … 683 774 return false; 684 775 *value = v8::String::New(reinterpret_cast<const char*>(m_buffer + m_position), length); 776 m_position += length; 777 return true; 778 } 779 780 bool readWebCoreString(String* string) 781 { 782 uint32_t length; 783 if (!doReadUint32(&length)) 784 return false; 785 if (m_position + length > m_length) 786 return false; 787 *string = String::fromUTF8(reinterpret_cast<const char*>(m_buffer + m_position), length); 685 788 m_position += length; 686 789 return true; … … 743 846 m_position += pixelDataLength; 744 847 *value = toV8(imageData); 848 return true; 849 } 850 851 bool readBlob(v8::Handle<v8::Value>* value) 852 { 853 String path; 854 if (!readWebCoreString(&path)) 855 return false; 856 PassRefPtr<Blob> blob = Blob::create(path); 857 *value = toV8(blob); 858 return true; 859 } 860 861 bool readFile(v8::Handle<v8::Value>* value) 862 { 863 String path; 864 if (!readWebCoreString(&path)) 865 return false; 866 PassRefPtr<File> file = File::create(path); 867 *value = toV8(file); 868 return true; 869 } 870 871 bool readFileList(v8::Handle<v8::Value>* value) 872 { 873 uint32_t length; 874 if (!doReadUint32(&length)) 875 return false; 876 PassRefPtr<FileList> fileList = FileList::create(); 877 for (unsigned i = 0; i < length; ++i) { 878 String path; 879 if (!readWebCoreString(&path)) 880 return false; 881 fileList->append(File::create(path)); 882 } 883 *value = toV8(fileList); 745 884 return true; 746 885 } … … 893 1032 else { 894 1033 ASSERT(mode == StringValue); 895 RefPtr<SharedBuffer> buffer = utf8Buffer(data);896 1034 Writer writer; 897 writer.write String(buffer->data(), buffer->size());1035 writer.writeWebCoreString(data); 898 1036 m_data = StringImpl::adopt(writer.data()); 899 1037 }
Note: See TracChangeset
for help on using the changeset viewer.