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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 #include "core/dom/ExceptionCode.h" | 58 #include "core/dom/ExceptionCode.h" |
59 #include "core/dom/MessagePort.h" | 59 #include "core/dom/MessagePort.h" |
60 #include "core/fileapi/Blob.h" | 60 #include "core/fileapi/Blob.h" |
61 #include "core/fileapi/File.h" | 61 #include "core/fileapi/File.h" |
62 #include "core/fileapi/FileList.h" | 62 #include "core/fileapi/FileList.h" |
63 #include "core/html/ImageData.h" | 63 #include "core/html/ImageData.h" |
64 #include "core/html/canvas/DataView.h" | 64 #include "core/html/canvas/DataView.h" |
65 #include "heap/Handle.h" | 65 #include "heap/Handle.h" |
66 #include "platform/SharedBuffer.h" | 66 #include "platform/SharedBuffer.h" |
67 #include "public/platform/Platform.h" | 67 #include "public/platform/Platform.h" |
68 #include "public/platform/WebBlobInfo.h" | |
68 #include "public/platform/WebCrypto.h" | 69 #include "public/platform/WebCrypto.h" |
69 #include "public/platform/WebCryptoKey.h" | 70 #include "public/platform/WebCryptoKey.h" |
70 #include "public/platform/WebCryptoKeyAlgorithm.h" | 71 #include "public/platform/WebCryptoKeyAlgorithm.h" |
71 #include "wtf/ArrayBuffer.h" | 72 #include "wtf/ArrayBuffer.h" |
72 #include "wtf/ArrayBufferContents.h" | 73 #include "wtf/ArrayBufferContents.h" |
73 #include "wtf/ArrayBufferView.h" | 74 #include "wtf/ArrayBufferView.h" |
74 #include "wtf/Assertions.h" | 75 #include "wtf/Assertions.h" |
75 #include "wtf/ByteOrder.h" | 76 #include "wtf/ByteOrder.h" |
76 #include "wtf/Float32Array.h" | 77 #include "wtf/Float32Array.h" |
77 #include "wtf/Float64Array.h" | 78 #include "wtf/Float64Array.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 NullTag = '0', // -> <null> | 193 NullTag = '0', // -> <null> |
193 TrueTag = 'T', // -> <true> | 194 TrueTag = 'T', // -> <true> |
194 FalseTag = 'F', // -> <false> | 195 FalseTag = 'F', // -> <false> |
195 StringTag = 'S', // string:RawString -> string | 196 StringTag = 'S', // string:RawString -> string |
196 StringUCharTag = 'c', // string:RawUCharString -> string | 197 StringUCharTag = 'c', // string:RawUCharString -> string |
197 Int32Tag = 'I', // value:ZigZag-encoded int32 -> Integer | 198 Int32Tag = 'I', // value:ZigZag-encoded int32 -> Integer |
198 Uint32Tag = 'U', // value:uint32_t -> Integer | 199 Uint32Tag = 'U', // value:uint32_t -> Integer |
199 DateTag = 'D', // value:double -> Date (ref) | 200 DateTag = 'D', // value:double -> Date (ref) |
200 MessagePortTag = 'M', // index:int -> MessagePort. Fills the result with tra nsferred MessagePort. | 201 MessagePortTag = 'M', // index:int -> MessagePort. Fills the result with tra nsferred MessagePort. |
201 NumberTag = 'N', // value:double -> Number | 202 NumberTag = 'N', // value:double -> Number |
202 BlobTag = 'b', // url:WebCoreString, type:WebCoreString, size:uint64_t -> Bl ob (ref) | 203 BlobTag = 'b', // uuid:WebCoreString, type:WebCoreString, size:uint64_t -> B lob (ref) |
204 BlobIndexTag = 'i', // index:int32_t -> Blob (ref) | |
203 FileTag = 'f', // file:RawFile -> File (ref) | 205 FileTag = 'f', // file:RawFile -> File (ref) |
204 DOMFileSystemTag = 'd', // type:int32_t, name:WebCoreString, url:WebCoreStri ng -> FileSystem (ref) | 206 FileIndexTag = 'e', // index:int32_t -> File (ref) |
207 DOMFileSystemTag = 'd', // type:int32_t, name:WebCoreString, uuid:WebCoreStr ing -> FileSystem (ref) | |
205 FileListTag = 'l', // length:uint32_t, files:RawFile[length] -> FileList (re f) | 208 FileListTag = 'l', // length:uint32_t, files:RawFile[length] -> FileList (re f) |
209 FileListIndexTag = 'L', // length:uint32_t, files:int32_t[length] -> FileLis t (ref) | |
206 ImageDataTag = '#', // width:uint32_t, height:uint32_t, pixelDataLength:uint 32_t, data:byte[pixelDataLength] -> ImageData (ref) | 210 ImageDataTag = '#', // width:uint32_t, height:uint32_t, pixelDataLength:uint 32_t, data:byte[pixelDataLength] -> ImageData (ref) |
207 ObjectTag = '{', // numProperties:uint32_t -> pops the last object from the open stack; | 211 ObjectTag = '{', // numProperties:uint32_t -> pops the last object from the open stack; |
208 // fills it with the last numProp erties name,value pairs pushed onto the deserialization stack | 212 // fills it with the last numProp erties name,value pairs pushed onto the deserialization stack |
209 SparseArrayTag = '@', // numProperties:uint32_t, length:uint32_t -> pops the last object from the open stack; | 213 SparseArrayTag = '@', // numProperties:uint32_t, length:uint32_t -> pops the last object from the open stack; |
210 // fills it with the last numProperties name,value pairs pushed onto the deserialization st ack | 214 // fills it with the last numProperties name,value pairs pushed onto the deserialization st ack |
211 DenseArrayTag = '$', // numProperties:uint32_t, length:uint32_t -> pops the last object from the open stack; | 215 DenseArrayTag = '$', // numProperties:uint32_t, length:uint32_t -> pops the last object from the open stack; |
212 // fills it with the last length elements and numProperties name,value pairs pushed onto des erialization stack | 216 // fills it with the last length elements and numProperties name,value pairs pushed onto des erialization stack |
213 RegExpTag = 'R', // pattern:RawString, flags:uint32_t -> RegExp (ref) | 217 RegExpTag = 'R', // pattern:RawString, flags:uint32_t -> RegExp (ref) |
214 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array Buffer (ref) | 218 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array Buffer (ref) |
215 ArrayBufferTransferTag = 't', // index:uint32_t -> ArrayBuffer. For ArrayBuf fer transfer | 219 ArrayBufferTransferTag = 't', // index:uint32_t -> ArrayBuffer. For ArrayBuf fer transfer |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 } | 455 } |
452 | 456 |
453 void writeBlob(const String& uuid, const String& type, unsigned long long si ze) | 457 void writeBlob(const String& uuid, const String& type, unsigned long long si ze) |
454 { | 458 { |
455 append(BlobTag); | 459 append(BlobTag); |
456 doWriteWebCoreString(uuid); | 460 doWriteWebCoreString(uuid); |
457 doWriteWebCoreString(type); | 461 doWriteWebCoreString(type); |
458 doWriteUint64(size); | 462 doWriteUint64(size); |
459 } | 463 } |
460 | 464 |
465 void writeBlobIndex(int blobIndex) | |
466 { | |
467 ASSERT(blobIndex >= 0); | |
468 append(BlobIndexTag); | |
469 doWriteUint32(blobIndex); | |
470 } | |
471 | |
461 void writeDOMFileSystem(int type, const String& name, const String& url) | 472 void writeDOMFileSystem(int type, const String& name, const String& url) |
462 { | 473 { |
463 append(DOMFileSystemTag); | 474 append(DOMFileSystemTag); |
464 doWriteUint32(type); | 475 doWriteUint32(type); |
465 doWriteWebCoreString(name); | 476 doWriteWebCoreString(name); |
466 doWriteWebCoreString(url); | 477 doWriteWebCoreString(url); |
467 } | 478 } |
468 | 479 |
469 void writeFile(const File& file) | 480 void writeFile(const File& file) |
470 { | 481 { |
471 append(FileTag); | 482 append(FileTag); |
472 doWriteFile(file); | 483 doWriteFile(file); |
473 } | 484 } |
474 | 485 |
486 void writeFileIndex(int blobIndex) | |
487 { | |
488 append(FileIndexTag); | |
489 doWriteUint32(blobIndex); | |
490 } | |
491 | |
475 void writeFileList(const FileList& fileList) | 492 void writeFileList(const FileList& fileList) |
476 { | 493 { |
477 append(FileListTag); | 494 append(FileListTag); |
478 uint32_t length = fileList.length(); | 495 uint32_t length = fileList.length(); |
479 doWriteUint32(length); | 496 doWriteUint32(length); |
480 for (unsigned i = 0; i < length; ++i) | 497 for (unsigned i = 0; i < length; ++i) |
481 doWriteFile(*fileList.item(i)); | 498 doWriteFile(*fileList.item(i)); |
482 } | 499 } |
483 | 500 |
501 void writeFileListIndex(const Vector<int>& blobIndices) | |
502 { | |
503 append(FileListIndexTag); | |
504 uint32_t length = blobIndices.size(); | |
505 doWriteUint32(length); | |
506 for (unsigned i = 0; i < length; ++i) | |
507 doWriteUint32(blobIndices[i]); | |
508 } | |
509 | |
484 bool writeCryptoKey(const blink::WebCryptoKey& key) | 510 bool writeCryptoKey(const blink::WebCryptoKey& key) |
485 { | 511 { |
486 append(static_cast<uint8_t>(CryptoKeyTag)); | 512 append(static_cast<uint8_t>(CryptoKeyTag)); |
487 | 513 |
488 switch (key.algorithm().paramsType()) { | 514 switch (key.algorithm().paramsType()) { |
489 case blink::WebCryptoKeyAlgorithmParamsTypeAes: | 515 case blink::WebCryptoKeyAlgorithmParamsTypeAes: |
490 doWriteAesKey(key); | 516 doWriteAesKey(key); |
491 break; | 517 break; |
492 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: | 518 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: |
493 doWriteHmacKey(key); | 519 doWriteHmacKey(key); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 class Serializer { | 929 class Serializer { |
904 class StateBase; | 930 class StateBase; |
905 public: | 931 public: |
906 enum Status { | 932 enum Status { |
907 Success, | 933 Success, |
908 InputError, | 934 InputError, |
909 DataCloneError, | 935 DataCloneError, |
910 JSException | 936 JSException |
911 }; | 937 }; |
912 | 938 |
913 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, v8::I solate* isolate) | 939 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v 8::TryCatch& tryCatch, v8::Isolate* isolate) |
914 : m_writer(writer) | 940 : m_writer(writer) |
915 , m_tryCatch(tryCatch) | 941 , m_tryCatch(tryCatch) |
916 , m_depth(0) | 942 , m_depth(0) |
917 , m_status(Success) | 943 , m_status(Success) |
918 , m_nextObjectReference(0) | 944 , m_nextObjectReference(0) |
945 , m_blobInfo(blobInfo) | |
919 , m_blobDataHandles(blobDataHandles) | 946 , m_blobDataHandles(blobDataHandles) |
920 , m_isolate(isolate) | 947 , m_isolate(isolate) |
921 { | 948 { |
922 ASSERT(!tryCatch.HasCaught()); | 949 ASSERT(!tryCatch.HasCaught()); |
923 if (messagePorts) { | 950 if (messagePorts) { |
924 for (size_t i = 0; i < messagePorts->size(); i++) | 951 for (size_t i = 0; i < messagePorts->size(); i++) |
925 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), isolate), i); | 952 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), isolate), i); |
926 } | 953 } |
927 if (arrayBuffers) { | 954 if (arrayBuffers) { |
928 for (size_t i = 0; i < arrayBuffers->size(); i++) { | 955 for (size_t i = 0; i < arrayBuffers->size(); i++) { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 m_writer.writeBooleanObject(booleanObject->ValueOf()); | 1279 m_writer.writeBooleanObject(booleanObject->ValueOf()); |
1253 } | 1280 } |
1254 | 1281 |
1255 StateBase* writeBlob(v8::Handle<v8::Value> value, StateBase* next) | 1282 StateBase* writeBlob(v8::Handle<v8::Value> value, StateBase* next) |
1256 { | 1283 { |
1257 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 1284 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); |
1258 if (!blob) | 1285 if (!blob) |
1259 return 0; | 1286 return 0; |
1260 if (blob->hasBeenClosed()) | 1287 if (blob->hasBeenClosed()) |
1261 return handleError(DataCloneError, "A Blob object has been closed, a nd could therefore not be cloned.", next); | 1288 return handleError(DataCloneError, "A Blob object has been closed, a nd could therefore not be cloned.", next); |
1262 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); | 1289 int blobIndex = -1; |
1263 m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle()); | 1290 m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle()); |
1291 if (appendBlobInfo(blob->uuid(), blob->type(), blob->size(), &blobIndex) ) | |
1292 m_writer.writeBlobIndex(blobIndex); | |
1293 else | |
1294 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); | |
1264 return 0; | 1295 return 0; |
1265 } | 1296 } |
1266 | 1297 |
1267 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 1298 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) |
1268 { | 1299 { |
1269 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 1300 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); |
1270 if (!fs) | 1301 if (!fs) |
1271 return 0; | 1302 return 0; |
1272 if (!fs->clonable()) | 1303 if (!fs->clonable()) |
1273 return handleError(DataCloneError, "A FileSystem object could not be cloned.", next); | 1304 return handleError(DataCloneError, "A FileSystem object could not be cloned.", next); |
1274 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); | 1305 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); |
1275 return 0; | 1306 return 0; |
1276 } | 1307 } |
1277 | 1308 |
1278 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next) | 1309 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next) |
1279 { | 1310 { |
1280 File* file = V8File::toNative(value.As<v8::Object>()); | 1311 File* file = V8File::toNative(value.As<v8::Object>()); |
1281 if (!file) | 1312 if (!file) |
1282 return 0; | 1313 return 0; |
1283 if (file->hasBeenClosed()) | 1314 if (file->hasBeenClosed()) |
1284 return handleError(DataCloneError, "A File object has been closed, a nd could therefore not be cloned.", next); | 1315 return handleError(DataCloneError, "A File object has been closed, a nd could therefore not be cloned.", next); |
1285 m_writer.writeFile(*file); | 1316 int blobIndex = -1; |
1286 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); | 1317 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); |
1318 if (appendFileInfo(file->uuid(), file->path(), file->name(), file->type( ), &blobIndex)) { | |
1319 ASSERT(blobIndex >= 0); | |
1320 m_writer.writeFileIndex(blobIndex); | |
1321 } else { | |
1322 m_writer.writeFile(*file); | |
1323 } | |
1287 return 0; | 1324 return 0; |
1288 } | 1325 } |
1289 | 1326 |
1290 void writeFileList(v8::Handle<v8::Value> value) | 1327 StateBase* writeFileList(v8::Handle<v8::Value> value, StateBase* next) |
1291 { | 1328 { |
1292 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1329 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); |
1293 if (!fileList) | 1330 if (!fileList) |
1294 return; | 1331 return 0; |
1295 m_writer.writeFileList(*fileList); | |
1296 unsigned length = fileList->length(); | 1332 unsigned length = fileList->length(); |
1297 for (unsigned i = 0; i < length; ++i) | 1333 Vector<int> blobIndices; |
1298 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)-> blobDataHandle()); | 1334 for (unsigned i = 0; i < length; ++i) { |
1335 int blobIndex = -1; | |
1336 const File* file = fileList->item(i); | |
1337 if (file->hasBeenClosed()) | |
1338 return handleError(DataCloneError, "A File object has been close d, and could therefore not be cloned.", next); | |
1339 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); | |
1340 if (appendFileInfo(file->uuid(), file->path(), file->name(), file->t ype(), &blobIndex)) { | |
1341 ASSERT(!i || blobIndex > 0); | |
1342 ASSERT(blobIndex >= 0); | |
1343 blobIndices.append(blobIndex); | |
1344 } | |
1345 } | |
1346 if (!blobIndices.isEmpty()) | |
1347 m_writer.writeFileListIndex(blobIndices); | |
1348 else | |
1349 m_writer.writeFileList(*fileList); | |
1350 return 0; | |
1299 } | 1351 } |
1300 | 1352 |
1301 bool writeCryptoKey(v8::Handle<v8::Value> value) | 1353 bool writeCryptoKey(v8::Handle<v8::Value> value) |
1302 { | 1354 { |
1303 Key* key = V8Key::toNative(value.As<v8::Object>()); | 1355 Key* key = V8Key::toNative(value.As<v8::Object>()); |
1304 if (!key) | 1356 if (!key) |
1305 return 0; | 1357 return 0; |
1306 return m_writer.writeCryptoKey(key->key()); | 1358 return m_writer.writeCryptoKey(key->key()); |
1307 } | 1359 } |
1308 | 1360 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 | 1459 |
1408 // Marks object as having been visited by the serializer and assigns it a un ique object reference ID. | 1460 // Marks object as having been visited by the serializer and assigns it a un ique object reference ID. |
1409 // An object may only be greyed once. | 1461 // An object may only be greyed once. |
1410 void greyObject(const v8::Handle<v8::Object>& object) | 1462 void greyObject(const v8::Handle<v8::Object>& object) |
1411 { | 1463 { |
1412 ASSERT(!m_objectPool.contains(object)); | 1464 ASSERT(!m_objectPool.contains(object)); |
1413 uint32_t objectReference = m_nextObjectReference++; | 1465 uint32_t objectReference = m_nextObjectReference++; |
1414 m_objectPool.set(object, objectReference); | 1466 m_objectPool.set(object, objectReference); |
1415 } | 1467 } |
1416 | 1468 |
1469 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo ng size, int* index) | |
1470 { | |
1471 if (!m_blobInfo) | |
1472 return false; | |
1473 *index = m_blobInfo->size(); | |
1474 m_blobInfo->append(blink::WebBlobInfo(uuid, type, size)); | |
1475 return true; | |
1476 } | |
1477 | |
1478 bool appendFileInfo(const String& uuid, const String& filePath, const String & fileName, const String& type, int* index) | |
1479 { | |
1480 if (!m_blobInfo) | |
1481 return false; | |
1482 *index = m_blobInfo->size(); | |
1483 m_blobInfo->append(blink::WebBlobInfo(uuid, filePath, fileName, type)); | |
1484 return true; | |
1485 } | |
1486 | |
1417 Writer& m_writer; | 1487 Writer& m_writer; |
1418 v8::TryCatch& m_tryCatch; | 1488 v8::TryCatch& m_tryCatch; |
1419 int m_depth; | 1489 int m_depth; |
1420 Status m_status; | 1490 Status m_status; |
1421 String m_errorMessage; | 1491 String m_errorMessage; |
1422 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 1492 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; |
1423 ObjectPool m_objectPool; | 1493 ObjectPool m_objectPool; |
1424 ObjectPool m_transferredMessagePorts; | 1494 ObjectPool m_transferredMessagePorts; |
1425 ObjectPool m_transferredArrayBuffers; | 1495 ObjectPool m_transferredArrayBuffers; |
1426 uint32_t m_nextObjectReference; | 1496 uint32_t m_nextObjectReference; |
1497 WebBlobInfoArray* m_blobInfo; | |
1427 BlobDataHandleMap& m_blobDataHandles; | 1498 BlobDataHandleMap& m_blobDataHandles; |
1428 v8::Isolate* m_isolate; | 1499 v8::Isolate* m_isolate; |
1429 }; | 1500 }; |
1430 | 1501 |
1431 // Returns true if the provided object is to be considered a 'host object', as u sed in the | 1502 // Returns true if the provided object is to be considered a 'host object', as u sed in the |
1432 // HTML5 structured clone algorithm. | 1503 // HTML5 structured clone algorithm. |
1433 static bool isHostObject(v8::Handle<v8::Object> object) | 1504 static bool isHostObject(v8::Handle<v8::Object> object) |
1434 { | 1505 { |
1435 // If the object has any internal fields, then we won't be able to serialize or deserialize | 1506 // If the object has any internal fields, then we won't be able to serialize or deserialize |
1436 // them; conveniently, this is also a quick way to detect DOM wrapper object s, because | 1507 // them; conveniently, this is also a quick way to detect DOM wrapper object s, because |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1493 writeBooleanObject(value); | 1564 writeBooleanObject(value); |
1494 else if (value->IsArray()) { | 1565 else if (value->IsArray()) { |
1495 return startArrayState(value.As<v8::Array>(), next); | 1566 return startArrayState(value.As<v8::Array>(), next); |
1496 } else if (V8File::hasInstance(value, m_isolate)) | 1567 } else if (V8File::hasInstance(value, m_isolate)) |
1497 return writeFile(value, next); | 1568 return writeFile(value, next); |
1498 else if (V8Blob::hasInstance(value, m_isolate)) | 1569 else if (V8Blob::hasInstance(value, m_isolate)) |
1499 return writeBlob(value, next); | 1570 return writeBlob(value, next); |
1500 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) | 1571 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) |
1501 return writeDOMFileSystem(value, next); | 1572 return writeDOMFileSystem(value, next); |
1502 else if (V8FileList::hasInstance(value, m_isolate)) | 1573 else if (V8FileList::hasInstance(value, m_isolate)) |
1503 writeFileList(value); | 1574 return writeFileList(value, next); |
1504 else if (V8Key::hasInstance(value, m_isolate)) { | 1575 else if (V8Key::hasInstance(value, m_isolate)) { |
1505 if (!writeCryptoKey(value)) | 1576 if (!writeCryptoKey(value)) |
1506 return handleError(DataCloneError, "Couldn't serialize key data" , next); | 1577 return handleError(DataCloneError, "Couldn't serialize key data" , next); |
1507 } else if (V8ImageData::hasInstance(value, m_isolate)) | 1578 } else if (V8ImageData::hasInstance(value, m_isolate)) |
1508 writeImageData(value); | 1579 writeImageData(value); |
1509 else if (value->IsRegExp()) | 1580 else if (value->IsRegExp()) |
1510 writeRegExp(value); | 1581 writeRegExp(value); |
1511 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) | 1582 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) |
1512 return writeArrayBuffer(value, next); | 1583 return writeArrayBuffer(value, next); |
1513 else if (value->IsObject()) { | 1584 else if (value->IsObject()) { |
(...skipping 22 matching lines...) Expand all Loading... | |
1536 virtual bool newObject() = 0; | 1607 virtual bool newObject() = 0; |
1537 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) = 0; | 1608 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) = 0; |
1538 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) = 0; | 1609 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8 ::Handle<v8::Value>*) = 0; |
1539 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) = 0; | 1610 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) = 0; |
1540 }; | 1611 }; |
1541 | 1612 |
1542 // Reader is responsible for deserializing primitive types and | 1613 // Reader is responsible for deserializing primitive types and |
1543 // restoring information about saved objects of composite types. | 1614 // restoring information about saved objects of composite types. |
1544 class Reader { | 1615 class Reader { |
1545 public: | 1616 public: |
1546 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const BlobD ataHandleMap& blobDataHandles) | 1617 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const WebBlo bInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles) |
1547 : m_buffer(buffer) | 1618 : m_buffer(buffer) |
1548 , m_length(length) | 1619 , m_length(length) |
1549 , m_position(0) | 1620 , m_position(0) |
1550 , m_version(0) | 1621 , m_version(0) |
1551 , m_isolate(isolate) | 1622 , m_isolate(isolate) |
1623 , m_blobInfo(blobInfo) | |
1552 , m_blobDataHandles(blobDataHandles) | 1624 , m_blobDataHandles(blobDataHandles) |
1553 { | 1625 { |
1554 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); | 1626 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); |
1555 ASSERT(length >= 0); | 1627 ASSERT(length >= 0); |
1556 } | 1628 } |
1557 | 1629 |
1558 bool isEof() const { return m_position >= m_length; } | 1630 bool isEof() const { return m_position >= m_length; } |
1559 | 1631 |
1560 v8::Isolate* isolate() const { return m_isolate; } | 1632 v8::Isolate* isolate() const { return m_isolate; } |
1561 | 1633 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1631 case NumberTag: | 1703 case NumberTag: |
1632 if (!readNumber(value)) | 1704 if (!readNumber(value)) |
1633 return false; | 1705 return false; |
1634 break; | 1706 break; |
1635 case NumberObjectTag: | 1707 case NumberObjectTag: |
1636 if (!readNumberObject(value)) | 1708 if (!readNumberObject(value)) |
1637 return false; | 1709 return false; |
1638 creator.pushObjectReference(*value); | 1710 creator.pushObjectReference(*value); |
1639 break; | 1711 break; |
1640 case BlobTag: | 1712 case BlobTag: |
1641 if (!readBlob(value)) | 1713 case BlobIndexTag: |
1714 if (!readBlob(value, tag == BlobIndexTag)) | |
1642 return false; | 1715 return false; |
1643 creator.pushObjectReference(*value); | 1716 creator.pushObjectReference(*value); |
1644 break; | 1717 break; |
1645 case FileTag: | 1718 case FileTag: |
1646 if (!readFile(value)) | 1719 case FileIndexTag: |
1720 if (!readFile(value, tag == FileIndexTag)) | |
1647 return false; | 1721 return false; |
1648 creator.pushObjectReference(*value); | 1722 creator.pushObjectReference(*value); |
1649 break; | 1723 break; |
1650 case DOMFileSystemTag: | 1724 case DOMFileSystemTag: |
1651 if (!readDOMFileSystem(value)) | 1725 if (!readDOMFileSystem(value)) |
1652 return false; | 1726 return false; |
1653 creator.pushObjectReference(*value); | 1727 creator.pushObjectReference(*value); |
1654 break; | 1728 break; |
1655 case FileListTag: | 1729 case FileListTag: |
1656 if (!readFileList(value)) | 1730 case FileListIndexTag: |
1731 if (!readFileList(value, tag == FileListIndexTag)) | |
1657 return false; | 1732 return false; |
1658 creator.pushObjectReference(*value); | 1733 creator.pushObjectReference(*value); |
1659 break; | 1734 break; |
1660 case CryptoKeyTag: | 1735 case CryptoKeyTag: |
1661 if (!readCryptoKey(value)) | 1736 if (!readCryptoKey(value)) |
1662 return false; | 1737 return false; |
1663 creator.pushObjectReference(*value); | 1738 creator.pushObjectReference(*value); |
1664 break; | 1739 break; |
1665 case ImageDataTag: | 1740 case ImageDataTag: |
1666 if (!readImageData(value)) | 1741 if (!readImageData(value)) |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2057 v8::Handle<v8::Value> pattern; | 2132 v8::Handle<v8::Value> pattern; |
2058 if (!readString(&pattern)) | 2133 if (!readString(&pattern)) |
2059 return false; | 2134 return false; |
2060 uint32_t flags; | 2135 uint32_t flags; |
2061 if (!doReadUint32(&flags)) | 2136 if (!doReadUint32(&flags)) |
2062 return false; | 2137 return false; |
2063 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags)); | 2138 *value = v8::RegExp::New(pattern.As<v8::String>(), static_cast<v8::RegEx p::Flags>(flags)); |
2064 return true; | 2139 return true; |
2065 } | 2140 } |
2066 | 2141 |
2067 bool readBlob(v8::Handle<v8::Value>* value) | 2142 bool readBlob(v8::Handle<v8::Value>* value, bool isIndexed) |
2068 { | 2143 { |
2069 if (m_version < 3) | 2144 if (m_version < 3) |
2070 return false; | 2145 return false; |
2071 String uuid; | 2146 RefPtrWillBeRawPtr<Blob> blob; |
2072 String type; | 2147 if (isIndexed) { |
2073 uint64_t size; | 2148 if (m_version < 6) |
2074 if (!readWebCoreString(&uuid)) | 2149 return false; |
2075 return false; | 2150 ASSERT(m_blobInfo); |
2076 if (!readWebCoreString(&type)) | 2151 uint32_t index; |
2077 return false; | 2152 if (!doReadUint32(&index) || index >= m_blobInfo->size()) |
2078 if (!doReadUint64(&size)) | 2153 return false; |
2079 return false; | 2154 const blink::WebBlobInfo& info = (*m_blobInfo)[index]; |
2080 RefPtrWillBeRawPtr<Blob> blob = Blob::create(getOrCreateBlobDataHandle(u uid, type, size)); | 2155 blob = Blob::create(getOrCreateBlobDataHandle(info.uuid(), info.type (), info.size())); |
2156 } else { | |
2157 ASSERT(!m_blobInfo); | |
2158 String uuid; | |
2159 String type; | |
2160 uint64_t size; | |
2161 ASSERT(!m_blobInfo); | |
2162 if (!readWebCoreString(&uuid)) | |
2163 return false; | |
2164 if (!readWebCoreString(&type)) | |
2165 return false; | |
2166 if (!doReadUint64(&size)) | |
2167 return false; | |
2168 blob = Blob::create(getOrCreateBlobDataHandle(uuid, type, size)); | |
2169 } | |
2081 *value = toV8(blob.release(), v8::Handle<v8::Object>(), m_isolate); | 2170 *value = toV8(blob.release(), v8::Handle<v8::Object>(), m_isolate); |
2082 return true; | 2171 return true; |
2083 } | 2172 } |
2084 | 2173 |
2085 bool readDOMFileSystem(v8::Handle<v8::Value>* value) | 2174 bool readDOMFileSystem(v8::Handle<v8::Value>* value) |
2086 { | 2175 { |
2087 uint32_t type; | 2176 uint32_t type; |
2088 String name; | 2177 String name; |
2089 String url; | 2178 String url; |
2090 if (!doReadUint32(&type)) | 2179 if (!doReadUint32(&type)) |
2091 return false; | 2180 return false; |
2092 if (!readWebCoreString(&name)) | 2181 if (!readWebCoreString(&name)) |
2093 return false; | 2182 return false; |
2094 if (!readWebCoreString(&url)) | 2183 if (!readWebCoreString(&url)) |
2095 return false; | 2184 return false; |
2096 RefPtrWillBeRawPtr<DOMFileSystem> fs = DOMFileSystem::create(currentExec utionContext(m_isolate), name, static_cast<WebCore::FileSystemType>(type), KURL( ParsedURLString, url)); | 2185 RefPtrWillBeRawPtr<DOMFileSystem> fs = DOMFileSystem::create(currentExec utionContext(m_isolate), name, static_cast<WebCore::FileSystemType>(type), KURL( ParsedURLString, url)); |
2097 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); | 2186 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); |
2098 return true; | 2187 return true; |
2099 } | 2188 } |
2100 | 2189 |
2101 bool readFile(v8::Handle<v8::Value>* value) | 2190 bool readFile(v8::Handle<v8::Value>* value, bool isIndexed) |
2102 { | 2191 { |
2103 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); | 2192 RefPtrWillBeRawPtr<File> file; |
2193 if (isIndexed) { | |
2194 if (m_version < 6) | |
2195 return false; | |
2196 file = readFileIndexHelper(); | |
2197 } else { | |
2198 file = readFileHelper(); | |
2199 } | |
2104 if (!file) | 2200 if (!file) |
2105 return false; | 2201 return false; |
2106 *value = toV8(file.release(), v8::Handle<v8::Object>(), m_isolate); | 2202 *value = toV8(file.release(), v8::Handle<v8::Object>(), m_isolate); |
2107 return true; | 2203 return true; |
2108 } | 2204 } |
2109 | 2205 |
2110 bool readFileList(v8::Handle<v8::Value>* value) | 2206 bool readFileList(v8::Handle<v8::Value>* value, bool isIndexed) |
2111 { | 2207 { |
2112 if (m_version < 3) | 2208 if (m_version < 3) |
2113 return false; | 2209 return false; |
2114 uint32_t length; | 2210 uint32_t length; |
2115 if (!doReadUint32(&length)) | 2211 if (!doReadUint32(&length)) |
2116 return false; | 2212 return false; |
2117 RefPtrWillBeRawPtr<FileList> fileList = FileList::create(); | 2213 RefPtrWillBeRawPtr<FileList> fileList = FileList::create(); |
2118 for (unsigned i = 0; i < length; ++i) { | 2214 for (unsigned i = 0; i < length; ++i) { |
2119 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); | 2215 RefPtrWillBeRawPtr<File> file; |
2216 if (isIndexed) { | |
2217 if (m_version < 6) | |
2218 return false; | |
2219 file = readFileIndexHelper(); | |
2220 } else { | |
2221 file = readFileHelper(); | |
2222 } | |
2120 if (!file) | 2223 if (!file) |
2121 return false; | 2224 return false; |
2122 fileList->append(file.release()); | 2225 fileList->append(file.release()); |
2123 } | 2226 } |
2124 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); | 2227 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); |
2125 return true; | 2228 return true; |
2126 } | 2229 } |
2127 | 2230 |
2128 bool readCryptoKey(v8::Handle<v8::Value>* value) | 2231 bool readCryptoKey(v8::Handle<v8::Value>* value) |
2129 { | 2232 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2174 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( | 2277 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( |
2175 algorithm, type, extractable, usages, keyData, keyDataLength, key)) { | 2278 algorithm, type, extractable, usages, keyData, keyDataLength, key)) { |
2176 return false; | 2279 return false; |
2177 } | 2280 } |
2178 | 2281 |
2179 RefPtrWillBeRawPtr<Key> k = Key::create(key); | 2282 RefPtrWillBeRawPtr<Key> k = Key::create(key); |
2180 *value = toV8(k.release(), v8::Handle<v8::Object>(), m_isolate); | 2283 *value = toV8(k.release(), v8::Handle<v8::Object>(), m_isolate); |
2181 return true; | 2284 return true; |
2182 } | 2285 } |
2183 | 2286 |
2184 PassRefPtrWillBeRawPtr<File> doReadFileHelper() | 2287 PassRefPtr<File> readFileHelper() |
sof
2014/04/08 21:07:55
Change this back to PassRefPtrWillBeRawPtr<File>.
ericu
2014/04/08 21:40:57
Ah, I missed the OilPan stuff when I merged out my
| |
2185 { | 2288 { |
2186 if (m_version < 3) | 2289 if (m_version < 3) |
2187 return nullptr; | 2290 return nullptr; |
2291 ASSERT(!m_blobInfo); | |
2188 String path; | 2292 String path; |
2189 String name; | 2293 String name; |
2190 String relativePath; | 2294 String relativePath; |
2191 String uuid; | 2295 String uuid; |
2192 String type; | 2296 String type; |
2193 uint32_t hasSnapshot = 0; | 2297 uint32_t hasSnapshot = 0; |
2194 uint64_t size = 0; | 2298 uint64_t size = 0; |
2195 double lastModified = 0; | 2299 double lastModified = 0; |
2196 if (!readWebCoreString(&path)) | 2300 if (!readWebCoreString(&path)) |
2197 return nullptr; | 2301 return nullptr; |
2198 if (m_version >= 4 && !readWebCoreString(&name)) | 2302 if (m_version >= 4 && !readWebCoreString(&name)) |
2199 return nullptr; | 2303 return nullptr; |
2200 if (m_version >= 4 && !readWebCoreString(&relativePath)) | 2304 if (m_version >= 4 && !readWebCoreString(&relativePath)) |
2201 return nullptr; | 2305 return nullptr; |
2202 if (!readWebCoreString(&uuid)) | 2306 if (!readWebCoreString(&uuid)) |
2203 return nullptr; | 2307 return nullptr; |
2204 if (!readWebCoreString(&type)) | 2308 if (!readWebCoreString(&type)) |
2205 return nullptr; | 2309 return nullptr; |
2206 if (m_version >= 4 && !doReadUint32(&hasSnapshot)) | 2310 if (m_version >= 4 && !doReadUint32(&hasSnapshot)) |
2207 return nullptr; | 2311 return nullptr; |
2208 if (hasSnapshot) { | 2312 if (hasSnapshot) { |
2209 if (!doReadUint64(&size)) | 2313 if (!doReadUint64(&size)) |
2210 return nullptr; | 2314 return nullptr; |
2211 if (!doReadNumber(&lastModified)) | 2315 if (!doReadNumber(&lastModified)) |
2212 return nullptr; | 2316 return nullptr; |
2213 } | 2317 } |
2214 return File::create(path, name, relativePath, hasSnapshot > 0, size, las tModified, getOrCreateBlobDataHandle(uuid, type)); | 2318 return File::create(path, name, relativePath, hasSnapshot > 0, size, las tModified, getOrCreateBlobDataHandle(uuid, type)); |
2215 } | 2319 } |
2216 | 2320 |
2321 PassRefPtr<File> readFileIndexHelper() | |
sof
2014/04/08 21:07:55
Change to PassRefPtrWillBeRawPtr<>
ericu
2014/04/08 21:40:57
Done.
| |
2322 { | |
2323 if (m_version < 3) | |
2324 return nullptr; | |
2325 ASSERT(m_blobInfo); | |
2326 uint32_t index; | |
2327 if (!doReadUint32(&index) || index >= m_blobInfo->size()) | |
2328 return nullptr; | |
2329 const blink::WebBlobInfo& info = (*m_blobInfo)[index]; | |
2330 return File::create(info.filePath(), info.fileName(), info.size(), info. lastModified(), getOrCreateBlobDataHandle(info.uuid(), info.type(), info.size()) ); | |
2331 } | |
2332 | |
2217 template<class T> | 2333 template<class T> |
2218 bool doReadUintHelper(T* value) | 2334 bool doReadUintHelper(T* value) |
2219 { | 2335 { |
2220 *value = 0; | 2336 *value = 0; |
2221 uint8_t currentByte; | 2337 uint8_t currentByte; |
2222 int shift = 0; | 2338 int shift = 0; |
2223 do { | 2339 do { |
2224 if (m_position >= m_length) | 2340 if (m_position >= m_length) |
2225 return false; | 2341 return false; |
2226 currentByte = m_buffer[m_position++]; | 2342 currentByte = m_buffer[m_position++]; |
(...skipping 27 matching lines...) Expand all Loading... | |
2254 { | 2370 { |
2255 // The containing ssv may have a BDH for this uuid if this ssv is just b eing | 2371 // The containing ssv may have a BDH for this uuid if this ssv is just b eing |
2256 // passed from main to worker thread (for example). We use those values when creating | 2372 // passed from main to worker thread (for example). We use those values when creating |
2257 // the new blob instead of cons'ing up a new BDH. | 2373 // the new blob instead of cons'ing up a new BDH. |
2258 // | 2374 // |
2259 // FIXME: Maybe we should require that it work that way where the ssv mu st have a BDH for any | 2375 // FIXME: Maybe we should require that it work that way where the ssv mu st have a BDH for any |
2260 // blobs it comes across during deserialization. Would require callers t o explicitly populate | 2376 // blobs it comes across during deserialization. Would require callers t o explicitly populate |
2261 // the collection of BDH's for blobs to work, which would encourage life times to be considered | 2377 // the collection of BDH's for blobs to work, which would encourage life times to be considered |
2262 // when passing ssv's around cross process. At present, we get 'lucky' i n some cases because | 2378 // when passing ssv's around cross process. At present, we get 'lucky' i n some cases because |
2263 // the blob in the src process happens to still exist at the time the de st process is deserializing. | 2379 // the blob in the src process happens to still exist at the time the de st process is deserializing. |
2264 // For example in sharedWorker.postMesssage(...). | 2380 // For example in sharedWorker.postMessage(...). |
2265 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); | 2381 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); |
2266 if (it != m_blobDataHandles.end()) { | 2382 if (it != m_blobDataHandles.end()) { |
2267 // make assertions about type and size? | 2383 // make assertions about type and size? |
2268 return it->value; | 2384 return it->value; |
2269 } | 2385 } |
2270 return BlobDataHandle::create(uuid, type, size); | 2386 return BlobDataHandle::create(uuid, type, size); |
2271 } | 2387 } |
2272 | 2388 |
2273 bool doReadHmacKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCrypto KeyType& type) | 2389 bool doReadHmacKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCrypto KeyType& type) |
2274 { | 2390 { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2425 usages |= blink::WebCryptoKeyUsageUnwrapKey; | 2541 usages |= blink::WebCryptoKeyUsageUnwrapKey; |
2426 | 2542 |
2427 return true; | 2543 return true; |
2428 } | 2544 } |
2429 | 2545 |
2430 const uint8_t* m_buffer; | 2546 const uint8_t* m_buffer; |
2431 const unsigned m_length; | 2547 const unsigned m_length; |
2432 unsigned m_position; | 2548 unsigned m_position; |
2433 uint32_t m_version; | 2549 uint32_t m_version; |
2434 v8::Isolate* m_isolate; | 2550 v8::Isolate* m_isolate; |
2551 const WebBlobInfoArray* m_blobInfo; | |
2435 const BlobDataHandleMap& m_blobDataHandles; | 2552 const BlobDataHandleMap& m_blobDataHandles; |
2436 }; | 2553 }; |
2437 | 2554 |
2438 | 2555 |
2439 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 2556 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
2440 | 2557 |
2441 class Deserializer FINAL : public CompositeCreator { | 2558 class Deserializer FINAL : public CompositeCreator { |
2442 public: | 2559 public: |
2443 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents) | 2560 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents) |
2444 : m_reader(reader) | 2561 : m_reader(reader) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2667 MessagePortArray* m_transferredMessagePorts; | 2784 MessagePortArray* m_transferredMessagePorts; |
2668 ArrayBufferContentsArray* m_arrayBufferContents; | 2785 ArrayBufferContentsArray* m_arrayBufferContents; |
2669 Vector<v8::Handle<v8::Object> > m_arrayBuffers; | 2786 Vector<v8::Handle<v8::Object> > m_arrayBuffers; |
2670 uint32_t m_version; | 2787 uint32_t m_version; |
2671 }; | 2788 }; |
2672 | 2789 |
2673 } // namespace | 2790 } // namespace |
2674 | 2791 |
2675 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Exc eptionState& exceptionState, v8::Isolate* isolate) | 2792 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Exc eptionState& exceptionState, v8::Isolate* isolate) |
2676 { | 2793 { |
2677 return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, exceptionState, isolate)); | 2794 return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, 0, exceptionState, isolate)); |
2678 } | 2795 } |
2679 | 2796 |
2680 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti ons(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 2797 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti ons(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
2681 { | 2798 { |
2682 TrackExceptionState exceptionState; | 2799 TrackExceptionState exceptionState; |
2683 return adoptRef(new SerializedScriptValue(value, 0, 0, exceptionState, isola te)); | 2800 return adoptRef(new SerializedScriptValue(value, 0, 0, 0, exceptionState, is olate)); |
2684 } | 2801 } |
2685 | 2802 |
2686 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const ScriptValu e& value, ExceptionState& exceptionState, ScriptState* state) | 2803 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const ScriptValu e& value, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, ScriptStat e* state) |
2687 { | 2804 { |
2688 ScriptScope scope(state); | 2805 ScriptScope scope(state); |
2689 return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, exceptionSt ate, state->isolate())); | 2806 return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, blobInfo, e xceptionState, state->isolate())); |
2690 } | 2807 } |
2691 | 2808 |
2692 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St ring& data) | 2809 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St ring& data) |
2693 { | 2810 { |
2694 return adoptRef(new SerializedScriptValue(data)); | 2811 return adoptRef(new SerializedScriptValue(data)); |
2695 } | 2812 } |
2696 | 2813 |
2697 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con st Vector<uint8_t>& data) | 2814 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con st Vector<uint8_t>& data) |
2698 { | 2815 { |
2699 // Decode wire data from big endian to host byte order. | 2816 // Decode wire data from big endian to host byte order. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2803 if (!result) { | 2920 if (!result) { |
2804 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred."); | 2921 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred."); |
2805 return nullptr; | 2922 return nullptr; |
2806 } | 2923 } |
2807 | 2924 |
2808 neuterArrayBufferInAllWorlds(arrayBuffers[i].get()); | 2925 neuterArrayBufferInAllWorlds(arrayBuffers[i].get()); |
2809 } | 2926 } |
2810 return contents.release(); | 2927 return contents.release(); |
2811 } | 2928 } |
2812 | 2929 |
2813 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, ExceptionState& except ionState, v8::Isolate* isolate) | 2930 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray* blob Info, ExceptionState& exceptionState, v8::Isolate* isolate) |
2814 : m_externallyAllocatedMemory(0) | 2931 : m_externallyAllocatedMemory(0) |
2815 { | 2932 { |
2816 Writer writer; | 2933 Writer writer; |
2817 Serializer::Status status; | 2934 Serializer::Status status; |
2818 String errorMessage; | 2935 String errorMessage; |
2819 { | 2936 { |
2820 v8::TryCatch tryCatch; | 2937 v8::TryCatch tryCatch; |
2821 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobDataHand les, tryCatch, isolate); | 2938 Serializer serializer(writer, messagePorts, arrayBuffers, blobInfo, m_bl obDataHandles, tryCatch, isolate); |
2822 status = serializer.serialize(value); | 2939 status = serializer.serialize(value); |
2823 if (status == Serializer::JSException) { | 2940 if (status == Serializer::JSException) { |
2824 // If there was a JS exception thrown, re-throw it. | 2941 // If there was a JS exception thrown, re-throw it. |
2825 exceptionState.rethrowV8Exception(tryCatch.Exception()); | 2942 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
2826 return; | 2943 return; |
2827 } | 2944 } |
2828 errorMessage = serializer.errorMessage(); | 2945 errorMessage = serializer.errorMessage(); |
2829 } | 2946 } |
2830 switch (status) { | 2947 switch (status) { |
2831 case Serializer::InputError: | 2948 case Serializer::InputError: |
(...skipping 14 matching lines...) Expand all Loading... | |
2846 } | 2963 } |
2847 | 2964 |
2848 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 2965 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
2849 : m_externallyAllocatedMemory(0) | 2966 : m_externallyAllocatedMemory(0) |
2850 { | 2967 { |
2851 m_data = wireData.isolatedCopy(); | 2968 m_data = wireData.isolatedCopy(); |
2852 } | 2969 } |
2853 | 2970 |
2854 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa gePorts) | 2971 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa gePorts) |
2855 { | 2972 { |
2856 return deserialize(v8::Isolate::GetCurrent(), messagePorts); | 2973 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); |
2857 } | 2974 } |
2858 | 2975 |
2859 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts) | 2976 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
2860 { | 2977 { |
2861 if (!m_data.impl()) | 2978 if (!m_data.impl()) |
2862 return v8::Null(isolate); | 2979 return v8::Null(isolate); |
2863 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 2980 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); |
2864 m_data.ensure16Bit(); | 2981 m_data.ensure16Bit(); |
2865 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 2982 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
2866 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 2983 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
2867 // information stored in m_data isn't even encoded in UTF-16. Instead, | 2984 // information stored in m_data isn't even encoded in UTF-16. Instead, |
2868 // unicode characters are encoded as UTF-8 with two code units per UChar. | 2985 // unicode characters are encoded as UTF-8 with two code units per UChar. |
2869 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16() ), 2 * m_data.length(), isolate, m_blobDataHandles); | 2986 Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters16() ), 2 * m_data.length(), isolate, blobInfo, m_blobDataHandles); |
2870 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g et()); | 2987 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g et()); |
2871 | 2988 |
2872 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. | 2989 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. |
2873 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. | 2990 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. |
2874 RefPtr<SerializedScriptValue> protect(this); | 2991 RefPtr<SerializedScriptValue> protect(this); |
2875 return deserializer.deserialize(); | 2992 return deserializer.deserialize(); |
2876 } | 2993 } |
2877 | 2994 |
2878 bool SerializedScriptValue::extractTransferables(v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, Excepti onState& exceptionState, v8::Isolate* isolate) | 2995 bool SerializedScriptValue::extractTransferables(v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, Excepti onState& exceptionState, v8::Isolate* isolate) |
2879 { | 2996 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2939 // If the allocated memory was not registered before, then this class is lik ely | 3056 // If the allocated memory was not registered before, then this class is lik ely |
2940 // used in a context other then Worker's onmessage environment and the prese nce of | 3057 // used in a context other then Worker's onmessage environment and the prese nce of |
2941 // current v8 context is not guaranteed. Avoid calling v8 then. | 3058 // current v8 context is not guaranteed. Avoid calling v8 then. |
2942 if (m_externallyAllocatedMemory) { | 3059 if (m_externallyAllocatedMemory) { |
2943 ASSERT(v8::Isolate::GetCurrent()); | 3060 ASSERT(v8::Isolate::GetCurrent()); |
2944 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); | 3061 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); |
2945 } | 3062 } |
2946 } | 3063 } |
2947 | 3064 |
2948 } // namespace WebCore | 3065 } // namespace WebCore |
OLD | NEW |