| OLD | NEW |
| 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 27 matching lines...) Expand all Loading... |
| 38 #include "File.h" | 38 #include "File.h" |
| 39 #include "FileList.h" | 39 #include "FileList.h" |
| 40 #include "ImageData.h" | 40 #include "ImageData.h" |
| 41 #include "MessagePort.h" | 41 #include "MessagePort.h" |
| 42 #include "SharedBuffer.h" | 42 #include "SharedBuffer.h" |
| 43 #include "V8ArrayBuffer.h" | 43 #include "V8ArrayBuffer.h" |
| 44 #include "V8ArrayBufferCustom.h" | 44 #include "V8ArrayBufferCustom.h" |
| 45 #include "V8ArrayBufferView.h" | 45 #include "V8ArrayBufferView.h" |
| 46 #include "V8Binding.h" | 46 #include "V8Binding.h" |
| 47 #include "V8Blob.h" | 47 #include "V8Blob.h" |
| 48 #include "V8DOMFileSystem.h" |
| 48 #include "V8DataView.h" | 49 #include "V8DataView.h" |
| 49 #include "V8File.h" | 50 #include "V8File.h" |
| 50 #include "V8FileList.h" | 51 #include "V8FileList.h" |
| 51 #include "V8Float32Array.h" | 52 #include "V8Float32Array.h" |
| 52 #include "V8Float64Array.h" | 53 #include "V8Float64Array.h" |
| 53 #include "V8ImageData.h" | 54 #include "V8ImageData.h" |
| 54 #include "V8Int16Array.h" | 55 #include "V8Int16Array.h" |
| 55 #include "V8Int32Array.h" | 56 #include "V8Int32Array.h" |
| 56 #include "V8Int8Array.h" | 57 #include "V8Int8Array.h" |
| 57 #include "V8MessagePort.h" | 58 #include "V8MessagePort.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 #include <wtf/Int16Array.h> | 71 #include <wtf/Int16Array.h> |
| 71 #include <wtf/Int32Array.h> | 72 #include <wtf/Int32Array.h> |
| 72 #include <wtf/Int8Array.h> | 73 #include <wtf/Int8Array.h> |
| 73 #include <wtf/RefCounted.h> | 74 #include <wtf/RefCounted.h> |
| 74 #include <wtf/Uint16Array.h> | 75 #include <wtf/Uint16Array.h> |
| 75 #include <wtf/Uint32Array.h> | 76 #include <wtf/Uint32Array.h> |
| 76 #include <wtf/Uint8Array.h> | 77 #include <wtf/Uint8Array.h> |
| 77 #include <wtf/Uint8ClampedArray.h> | 78 #include <wtf/Uint8ClampedArray.h> |
| 78 #include <wtf/Vector.h> | 79 #include <wtf/Vector.h> |
| 79 | 80 |
| 80 #if ENABLE(FILE_SYSTEM) | |
| 81 #include "V8DOMFileSystem.h" | |
| 82 #endif | |
| 83 | |
| 84 // FIXME: consider crashing in debug mode on deserialization errors | 81 // FIXME: consider crashing in debug mode on deserialization errors |
| 85 // NOTE: be sure to change wireFormatVersion as necessary! | 82 // NOTE: be sure to change wireFormatVersion as necessary! |
| 86 | 83 |
| 87 namespace WebCore { | 84 namespace WebCore { |
| 88 | 85 |
| 89 namespace { | 86 namespace { |
| 90 | 87 |
| 91 // This code implements the HTML5 Structured Clone algorithm: | 88 // This code implements the HTML5 Structured Clone algorithm: |
| 92 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa
ssing-of-structured-data | 89 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa
ssing-of-structured-data |
| 93 | 90 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 FalseTag = 'F', // -> <false> | 185 FalseTag = 'F', // -> <false> |
| 189 StringTag = 'S', // string:RawString -> string | 186 StringTag = 'S', // string:RawString -> string |
| 190 StringUCharTag = 'c', // string:RawUCharString -> string | 187 StringUCharTag = 'c', // string:RawUCharString -> string |
| 191 Int32Tag = 'I', // value:ZigZag-encoded int32 -> Integer | 188 Int32Tag = 'I', // value:ZigZag-encoded int32 -> Integer |
| 192 Uint32Tag = 'U', // value:uint32_t -> Integer | 189 Uint32Tag = 'U', // value:uint32_t -> Integer |
| 193 DateTag = 'D', // value:double -> Date (ref) | 190 DateTag = 'D', // value:double -> Date (ref) |
| 194 MessagePortTag = 'M', // index:int -> MessagePort. Fills the result with tra
nsferred MessagePort. | 191 MessagePortTag = 'M', // index:int -> MessagePort. Fills the result with tra
nsferred MessagePort. |
| 195 NumberTag = 'N', // value:double -> Number | 192 NumberTag = 'N', // value:double -> Number |
| 196 BlobTag = 'b', // url:WebCoreString, type:WebCoreString, size:uint64_t -> Bl
ob (ref) | 193 BlobTag = 'b', // url:WebCoreString, type:WebCoreString, size:uint64_t -> Bl
ob (ref) |
| 197 FileTag = 'f', // file:RawFile -> File (ref) | 194 FileTag = 'f', // file:RawFile -> File (ref) |
| 198 #if ENABLE(FILE_SYSTEM) | |
| 199 DOMFileSystemTag = 'd', // type:int32_t, name:WebCoreString, url:WebCoreStri
ng -> FileSystem (ref) | 195 DOMFileSystemTag = 'd', // type:int32_t, name:WebCoreString, url:WebCoreStri
ng -> FileSystem (ref) |
| 200 #endif | |
| 201 FileListTag = 'l', // length:uint32_t, files:RawFile[length] -> FileList (re
f) | 196 FileListTag = 'l', // length:uint32_t, files:RawFile[length] -> FileList (re
f) |
| 202 ImageDataTag = '#', // width:uint32_t, height:uint32_t, pixelDataLength:uint
32_t, data:byte[pixelDataLength] -> ImageData (ref) | 197 ImageDataTag = '#', // width:uint32_t, height:uint32_t, pixelDataLength:uint
32_t, data:byte[pixelDataLength] -> ImageData (ref) |
| 203 ObjectTag = '{', // numProperties:uint32_t -> pops the last object from the
open stack; | 198 ObjectTag = '{', // numProperties:uint32_t -> pops the last object from the
open stack; |
| 204 // fills it with the last numProp
erties name,value pairs pushed onto the deserialization stack | 199 // fills it with the last numProp
erties name,value pairs pushed onto the deserialization stack |
| 205 SparseArrayTag = '@', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; | 200 SparseArrayTag = '@', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; |
| 206 // fills it
with the last numProperties name,value pairs pushed onto the deserialization st
ack | 201 // fills it
with the last numProperties name,value pairs pushed onto the deserialization st
ack |
| 207 DenseArrayTag = '$', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; | 202 DenseArrayTag = '$', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; |
| 208 // fills it
with the last length elements and numProperties name,value pairs pushed onto des
erialization stack | 203 // fills it
with the last length elements and numProperties name,value pairs pushed onto des
erialization stack |
| 209 RegExpTag = 'R', // pattern:RawString, flags:uint32_t -> RegExp (ref) | 204 RegExpTag = 'R', // pattern:RawString, flags:uint32_t -> RegExp (ref) |
| 210 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array
Buffer (ref) | 205 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array
Buffer (ref) |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 400 } |
| 406 | 401 |
| 407 void writeBlob(const String& url, const String& type, unsigned long long siz
e) | 402 void writeBlob(const String& url, const String& type, unsigned long long siz
e) |
| 408 { | 403 { |
| 409 append(BlobTag); | 404 append(BlobTag); |
| 410 doWriteWebCoreString(url); | 405 doWriteWebCoreString(url); |
| 411 doWriteWebCoreString(type); | 406 doWriteWebCoreString(type); |
| 412 doWriteUint64(size); | 407 doWriteUint64(size); |
| 413 } | 408 } |
| 414 | 409 |
| 415 #if ENABLE(FILE_SYSTEM) | |
| 416 void writeDOMFileSystem(int type, const String& name, const String& url) | 410 void writeDOMFileSystem(int type, const String& name, const String& url) |
| 417 { | 411 { |
| 418 append(DOMFileSystemTag); | 412 append(DOMFileSystemTag); |
| 419 doWriteUint32(type); | 413 doWriteUint32(type); |
| 420 doWriteWebCoreString(name); | 414 doWriteWebCoreString(name); |
| 421 doWriteWebCoreString(url); | 415 doWriteWebCoreString(url); |
| 422 } | 416 } |
| 423 #endif | |
| 424 | 417 |
| 425 void writeFile(const String& path, const String& url, const String& type) | 418 void writeFile(const String& path, const String& url, const String& type) |
| 426 { | 419 { |
| 427 append(FileTag); | 420 append(FileTag); |
| 428 doWriteWebCoreString(path); | 421 doWriteWebCoreString(path); |
| 429 doWriteWebCoreString(url); | 422 doWriteWebCoreString(url); |
| 430 doWriteWebCoreString(type); | 423 doWriteWebCoreString(type); |
| 431 } | 424 } |
| 432 | 425 |
| 433 void writeFileList(const FileList& fileList) | 426 void writeFileList(const FileList& fileList) |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 | 1075 |
| 1083 void writeBlob(v8::Handle<v8::Value> value) | 1076 void writeBlob(v8::Handle<v8::Value> value) |
| 1084 { | 1077 { |
| 1085 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 1078 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); |
| 1086 if (!blob) | 1079 if (!blob) |
| 1087 return; | 1080 return; |
| 1088 m_writer.writeBlob(blob->url().string(), blob->type(), blob->size()); | 1081 m_writer.writeBlob(blob->url().string(), blob->type(), blob->size()); |
| 1089 m_blobURLs.append(blob->url().string()); | 1082 m_blobURLs.append(blob->url().string()); |
| 1090 } | 1083 } |
| 1091 | 1084 |
| 1092 #if ENABLE(FILE_SYSTEM) | |
| 1093 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 1085 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) |
| 1094 { | 1086 { |
| 1095 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 1087 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); |
| 1096 if (!fs) | 1088 if (!fs) |
| 1097 return 0; | 1089 return 0; |
| 1098 if (!fs->clonable()) | 1090 if (!fs->clonable()) |
| 1099 return handleError(DataCloneError, next); | 1091 return handleError(DataCloneError, next); |
| 1100 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
()); | 1092 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string
()); |
| 1101 return 0; | 1093 return 0; |
| 1102 } | 1094 } |
| 1103 #endif | |
| 1104 | 1095 |
| 1105 void writeFile(v8::Handle<v8::Value> value) | 1096 void writeFile(v8::Handle<v8::Value> value) |
| 1106 { | 1097 { |
| 1107 File* file = V8File::toNative(value.As<v8::Object>()); | 1098 File* file = V8File::toNative(value.As<v8::Object>()); |
| 1108 if (!file) | 1099 if (!file) |
| 1109 return; | 1100 return; |
| 1110 m_writer.writeFile(file->path(), file->url().string(), file->type()); | 1101 m_writer.writeFile(file->path(), file->url().string(), file->type()); |
| 1111 m_blobURLs.append(file->url().string()); | 1102 m_blobURLs.append(file->url().string()); |
| 1112 } | 1103 } |
| 1113 | 1104 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 else if (value->IsNumberObject()) | 1289 else if (value->IsNumberObject()) |
| 1299 writeNumberObject(value); | 1290 writeNumberObject(value); |
| 1300 else if (value->IsBooleanObject()) | 1291 else if (value->IsBooleanObject()) |
| 1301 writeBooleanObject(value); | 1292 writeBooleanObject(value); |
| 1302 else if (value->IsArray()) { | 1293 else if (value->IsArray()) { |
| 1303 return startArrayState(value.As<v8::Array>(), next); | 1294 return startArrayState(value.As<v8::Array>(), next); |
| 1304 } else if (V8File::HasInstance(value, m_isolate, currentWorldType)) | 1295 } else if (V8File::HasInstance(value, m_isolate, currentWorldType)) |
| 1305 writeFile(value); | 1296 writeFile(value); |
| 1306 else if (V8Blob::HasInstance(value, m_isolate, currentWorldType)) | 1297 else if (V8Blob::HasInstance(value, m_isolate, currentWorldType)) |
| 1307 writeBlob(value); | 1298 writeBlob(value); |
| 1308 #if ENABLE(FILE_SYSTEM) | |
| 1309 else if (V8DOMFileSystem::HasInstance(value, m_isolate, currentWorldType
)) | 1299 else if (V8DOMFileSystem::HasInstance(value, m_isolate, currentWorldType
)) |
| 1310 return writeDOMFileSystem(value, next); | 1300 return writeDOMFileSystem(value, next); |
| 1311 #endif | |
| 1312 else if (V8FileList::HasInstance(value, m_isolate, currentWorldType)) | 1301 else if (V8FileList::HasInstance(value, m_isolate, currentWorldType)) |
| 1313 writeFileList(value); | 1302 writeFileList(value); |
| 1314 else if (V8ImageData::HasInstance(value, m_isolate, currentWorldType)) | 1303 else if (V8ImageData::HasInstance(value, m_isolate, currentWorldType)) |
| 1315 writeImageData(value); | 1304 writeImageData(value); |
| 1316 else if (value->IsRegExp()) | 1305 else if (value->IsRegExp()) |
| 1317 writeRegExp(value); | 1306 writeRegExp(value); |
| 1318 else if (V8ArrayBuffer::HasInstance(value, m_isolate, currentWorldType)) | 1307 else if (V8ArrayBuffer::HasInstance(value, m_isolate, currentWorldType)) |
| 1319 return writeArrayBuffer(value, next); | 1308 return writeArrayBuffer(value, next); |
| 1320 else if (value->IsObject()) { | 1309 else if (value->IsObject()) { |
| 1321 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) | 1310 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 case BlobTag: | 1433 case BlobTag: |
| 1445 if (!readBlob(value)) | 1434 if (!readBlob(value)) |
| 1446 return false; | 1435 return false; |
| 1447 creator.pushObjectReference(*value); | 1436 creator.pushObjectReference(*value); |
| 1448 break; | 1437 break; |
| 1449 case FileTag: | 1438 case FileTag: |
| 1450 if (!readFile(value)) | 1439 if (!readFile(value)) |
| 1451 return false; | 1440 return false; |
| 1452 creator.pushObjectReference(*value); | 1441 creator.pushObjectReference(*value); |
| 1453 break; | 1442 break; |
| 1454 #if ENABLE(FILE_SYSTEM) | |
| 1455 case DOMFileSystemTag: | 1443 case DOMFileSystemTag: |
| 1456 if (!readDOMFileSystem(value)) | 1444 if (!readDOMFileSystem(value)) |
| 1457 return false; | 1445 return false; |
| 1458 creator.pushObjectReference(*value); | 1446 creator.pushObjectReference(*value); |
| 1459 break; | 1447 break; |
| 1460 #endif | |
| 1461 case FileListTag: | 1448 case FileListTag: |
| 1462 if (!readFileList(value)) | 1449 if (!readFileList(value)) |
| 1463 return false; | 1450 return false; |
| 1464 creator.pushObjectReference(*value); | 1451 creator.pushObjectReference(*value); |
| 1465 break; | 1452 break; |
| 1466 case ImageDataTag: | 1453 case ImageDataTag: |
| 1467 if (!readImageData(value)) | 1454 if (!readImageData(value)) |
| 1468 return false; | 1455 return false; |
| 1469 creator.pushObjectReference(*value); | 1456 creator.pushObjectReference(*value); |
| 1470 break; | 1457 break; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 return false; | 1862 return false; |
| 1876 if (!readWebCoreString(&type)) | 1863 if (!readWebCoreString(&type)) |
| 1877 return false; | 1864 return false; |
| 1878 if (!doReadUint64(&size)) | 1865 if (!doReadUint64(&size)) |
| 1879 return false; | 1866 return false; |
| 1880 PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, s
ize); | 1867 PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, s
ize); |
| 1881 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); | 1868 *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate); |
| 1882 return true; | 1869 return true; |
| 1883 } | 1870 } |
| 1884 | 1871 |
| 1885 #if ENABLE(FILE_SYSTEM) | |
| 1886 bool readDOMFileSystem(v8::Handle<v8::Value>* value) | 1872 bool readDOMFileSystem(v8::Handle<v8::Value>* value) |
| 1887 { | 1873 { |
| 1888 uint32_t type; | 1874 uint32_t type; |
| 1889 String name; | 1875 String name; |
| 1890 String url; | 1876 String url; |
| 1891 if (!doReadUint32(&type)) | 1877 if (!doReadUint32(&type)) |
| 1892 return false; | 1878 return false; |
| 1893 if (!readWebCoreString(&name)) | 1879 if (!readWebCoreString(&name)) |
| 1894 return false; | 1880 return false; |
| 1895 if (!readWebCoreString(&url)) | 1881 if (!readWebCoreString(&url)) |
| 1896 return false; | 1882 return false; |
| 1897 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte
xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur
l), AsyncFileSystem::create()); | 1883 RefPtr<DOMFileSystem> fs = DOMFileSystem::create(getScriptExecutionConte
xt(), name, static_cast<WebCore::FileSystemType>(type), KURL(ParsedURLString, ur
l), AsyncFileSystem::create()); |
| 1898 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); | 1884 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); |
| 1899 return true; | 1885 return true; |
| 1900 } | 1886 } |
| 1901 #endif | |
| 1902 | 1887 |
| 1903 bool readFile(v8::Handle<v8::Value>* value) | 1888 bool readFile(v8::Handle<v8::Value>* value) |
| 1904 { | 1889 { |
| 1905 String path; | 1890 String path; |
| 1906 String url; | 1891 String url; |
| 1907 String type; | 1892 String type; |
| 1908 if (!readWebCoreString(&path)) | 1893 if (!readWebCoreString(&path)) |
| 1909 return false; | 1894 return false; |
| 1910 if (!readWebCoreString(&url)) | 1895 if (!readWebCoreString(&url)) |
| 1911 return false; | 1896 return false; |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2517 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); | 2502 v8::V8::AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemo
ry); |
| 2518 } | 2503 } |
| 2519 } | 2504 } |
| 2520 | 2505 |
| 2521 uint32_t SerializedScriptValue::wireFormatVersion() | 2506 uint32_t SerializedScriptValue::wireFormatVersion() |
| 2522 { | 2507 { |
| 2523 return WebCore::wireFormatVersion; | 2508 return WebCore::wireFormatVersion; |
| 2524 } | 2509 } |
| 2525 | 2510 |
| 2526 } // namespace WebCore | 2511 } // namespace WebCore |
| OLD | NEW |