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" |
78 #include "wtf/Int16Array.h" | 79 #include "wtf/Int16Array.h" |
79 #include "wtf/Int32Array.h" | 80 #include "wtf/Int32Array.h" |
80 #include "wtf/Int8Array.h" | 81 #include "wtf/Int8Array.h" |
81 #include "wtf/RefCounted.h" | 82 #include "wtf/RefCounted.h" |
82 #include "wtf/Uint16Array.h" | 83 #include "wtf/Uint16Array.h" |
83 #include "wtf/Uint32Array.h" | 84 #include "wtf/Uint32Array.h" |
84 #include "wtf/Uint8Array.h" | 85 #include "wtf/Uint8Array.h" |
85 #include "wtf/Uint8ClampedArray.h" | 86 #include "wtf/Uint8ClampedArray.h" |
86 #include "wtf/Vector.h" | 87 #include "wtf/Vector.h" |
87 #include "wtf/text/StringBuffer.h" | 88 #include "wtf/text/StringBuffer.h" |
88 #include "wtf/text/StringUTF8Adaptor.h" | 89 #include "wtf/text/StringUTF8Adaptor.h" |
89 | 90 |
90 // FIXME: consider crashing in debug mode on deserialization errors | 91 // FIXME: consider crashing in debug mode on deserialization errors |
91 // NOTE: be sure to change wireFormatVersion as necessary! | 92 // NOTE: be sure to change wireFormatVersion as necessary! |
jsbell
2014/04/03 18:16:33
So... this is a philosophically interesting change
ericu
2014/04/07 23:14:20
I think that's an excellent idea.
| |
92 | 93 |
93 namespace WebCore { | 94 namespace WebCore { |
94 | 95 |
95 namespace { | 96 namespace { |
96 | 97 |
97 // This code implements the HTML5 Structured Clone algorithm: | 98 // This code implements the HTML5 Structured Clone algorithm: |
98 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa ssing-of-structured-data | 99 // http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-pa ssing-of-structured-data |
99 | 100 |
100 // V8ObjectMap is a map from V8 objects to arbitrary values of type T. | 101 // V8ObjectMap is a map from V8 objects to arbitrary values of type T. |
101 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf: :HashMaps; | 102 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf: :HashMaps; |
(...skipping 90 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) |
203 FileTag = 'f', // file:RawFile -> File (ref) | 204 FileTag = 'f', // file:RawFile -> File (ref) |
204 DOMFileSystemTag = 'd', // type:int32_t, name:WebCoreString, url:WebCoreStri ng -> FileSystem (ref) | 205 DOMFileSystemTag = 'd', // type:int32_t, name:WebCoreString, uuid:WebCoreStr ing -> FileSystem (ref) |
205 FileListTag = 'l', // length:uint32_t, files:RawFile[length] -> FileList (re f) | 206 FileListTag = 'l', // length:uint32_t, files:RawFile[length] -> FileList (re f) |
206 ImageDataTag = '#', // width:uint32_t, height:uint32_t, pixelDataLength:uint 32_t, data:byte[pixelDataLength] -> ImageData (ref) | 207 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; | 208 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 | 209 // 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; | 210 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 | 211 // 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; | 212 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 | 213 // 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) | 214 RegExpTag = 'R', // pattern:RawString, flags:uint32_t -> RegExp (ref) |
214 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array Buffer (ref) | 215 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array Buffer (ref) |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 } | 452 } |
452 | 453 |
453 void writeBlob(const String& uuid, const String& type, unsigned long long si ze) | 454 void writeBlob(const String& uuid, const String& type, unsigned long long si ze) |
454 { | 455 { |
455 append(BlobTag); | 456 append(BlobTag); |
456 doWriteWebCoreString(uuid); | 457 doWriteWebCoreString(uuid); |
457 doWriteWebCoreString(type); | 458 doWriteWebCoreString(type); |
458 doWriteUint64(size); | 459 doWriteUint64(size); |
459 } | 460 } |
460 | 461 |
462 void writeBlob(int blobIndex) | |
463 { | |
464 append(BlobTag); | |
465 doWriteUint32(blobIndex); | |
466 } | |
467 | |
461 void writeDOMFileSystem(int type, const String& name, const String& url) | 468 void writeDOMFileSystem(int type, const String& name, const String& url) |
462 { | 469 { |
463 append(DOMFileSystemTag); | 470 append(DOMFileSystemTag); |
464 doWriteUint32(type); | 471 doWriteUint32(type); |
465 doWriteWebCoreString(name); | 472 doWriteWebCoreString(name); |
466 doWriteWebCoreString(url); | 473 doWriteWebCoreString(url); |
467 } | 474 } |
468 | 475 |
469 void writeFile(const File& file) | 476 void writeFile(const File& file) |
470 { | 477 { |
471 append(FileTag); | 478 append(FileTag); |
472 doWriteFile(file); | 479 doWriteFile(file); |
473 } | 480 } |
474 | 481 |
482 void writeFile(int blobIndex) | |
483 { | |
484 append(FileTag); | |
485 doWriteUint32(blobIndex); | |
486 } | |
487 | |
475 void writeFileList(const FileList& fileList) | 488 void writeFileList(const FileList& fileList) |
476 { | 489 { |
477 append(FileListTag); | 490 append(FileListTag); |
478 uint32_t length = fileList.length(); | 491 uint32_t length = fileList.length(); |
479 doWriteUint32(length); | 492 doWriteUint32(length); |
480 for (unsigned i = 0; i < length; ++i) | 493 for (unsigned i = 0; i < length; ++i) |
481 doWriteFile(*fileList.item(i)); | 494 doWriteFile(*fileList.item(i)); |
482 } | 495 } |
483 | 496 |
497 void writeFileList(const Vector<int>& blobIndices) | |
498 { | |
499 append(FileListTag); | |
500 uint32_t length = blobIndices.size(); | |
501 doWriteUint32(length); | |
502 for (unsigned i = 0; i < length; ++i) { | |
cmumford
2014/04/03 16:32:45
Nit: can ditch the braces in this for loop.
ericu
2014/04/07 23:14:20
Done.
| |
503 doWriteUint32(blobIndices[i]); | |
504 } | |
505 } | |
506 | |
484 bool writeCryptoKey(const blink::WebCryptoKey& key) | 507 bool writeCryptoKey(const blink::WebCryptoKey& key) |
485 { | 508 { |
486 append(static_cast<uint8_t>(CryptoKeyTag)); | 509 append(static_cast<uint8_t>(CryptoKeyTag)); |
487 | 510 |
488 switch (key.algorithm().paramsType()) { | 511 switch (key.algorithm().paramsType()) { |
489 case blink::WebCryptoKeyAlgorithmParamsTypeAes: | 512 case blink::WebCryptoKeyAlgorithmParamsTypeAes: |
490 doWriteAesKey(key); | 513 doWriteAesKey(key); |
491 break; | 514 break; |
492 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: | 515 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: |
493 doWriteHmacKey(key); | 516 doWriteHmacKey(key); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 class Serializer { | 926 class Serializer { |
904 class StateBase; | 927 class StateBase; |
905 public: | 928 public: |
906 enum Status { | 929 enum Status { |
907 Success, | 930 Success, |
908 InputError, | 931 InputError, |
909 DataCloneError, | 932 DataCloneError, |
910 JSException | 933 JSException |
911 }; | 934 }; |
912 | 935 |
913 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, v8::I solate* isolate) | 936 Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vector<blink::WebBlobInfo>* blobInfo, BlobDataHandleMap& blobData Handles, v8::TryCatch& tryCatch, v8::Isolate* isolate) |
914 : m_writer(writer) | 937 : m_writer(writer) |
915 , m_tryCatch(tryCatch) | 938 , m_tryCatch(tryCatch) |
916 , m_depth(0) | 939 , m_depth(0) |
917 , m_status(Success) | 940 , m_status(Success) |
918 , m_nextObjectReference(0) | 941 , m_nextObjectReference(0) |
942 , m_blobInfo(blobInfo) | |
919 , m_blobDataHandles(blobDataHandles) | 943 , m_blobDataHandles(blobDataHandles) |
920 , m_isolate(isolate) | 944 , m_isolate(isolate) |
921 { | 945 { |
922 ASSERT(!tryCatch.HasCaught()); | 946 ASSERT(!tryCatch.HasCaught()); |
923 if (messagePorts) { | 947 if (messagePorts) { |
924 for (size_t i = 0; i < messagePorts->size(); i++) | 948 for (size_t i = 0; i < messagePorts->size(); i++) |
925 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), isolate), i); | 949 m_transferredMessagePorts.set(toV8Object(messagePorts->at(i).get (), isolate), i); |
926 } | 950 } |
927 if (arrayBuffers) { | 951 if (arrayBuffers) { |
928 for (size_t i = 0; i < arrayBuffers->size(); i++) { | 952 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()); | 1276 m_writer.writeBooleanObject(booleanObject->ValueOf()); |
1253 } | 1277 } |
1254 | 1278 |
1255 StateBase* writeBlob(v8::Handle<v8::Value> value, StateBase* next) | 1279 StateBase* writeBlob(v8::Handle<v8::Value> value, StateBase* next) |
1256 { | 1280 { |
1257 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); | 1281 Blob* blob = V8Blob::toNative(value.As<v8::Object>()); |
1258 if (!blob) | 1282 if (!blob) |
1259 return 0; | 1283 return 0; |
1260 if (blob->hasBeenClosed()) | 1284 if (blob->hasBeenClosed()) |
1261 return handleError(DataCloneError, "A Blob object has been closed, a nd could therefore not be cloned.", next); | 1285 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()); | 1286 int blobIndex = -1; |
1263 m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle()); | 1287 m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle()); |
1288 if (appendBlobInfo(blob->uuid(), blob->type(), blob->size(), &blobIndex) ) { | |
1289 ASSERT(blobIndex >= 0); | |
cmumford
2014/04/03 16:32:45
What do you think about moving this ASSERT into wr
ericu
2014/04/07 23:14:20
Done.
| |
1290 m_writer.writeBlob(blobIndex); | |
1291 } else { | |
1292 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); | |
1293 } | |
1264 return 0; | 1294 return 0; |
1265 } | 1295 } |
1266 | 1296 |
1267 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) | 1297 StateBase* writeDOMFileSystem(v8::Handle<v8::Value> value, StateBase* next) |
1268 { | 1298 { |
1269 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); | 1299 DOMFileSystem* fs = V8DOMFileSystem::toNative(value.As<v8::Object>()); |
1270 if (!fs) | 1300 if (!fs) |
1271 return 0; | 1301 return 0; |
1272 if (!fs->clonable()) | 1302 if (!fs->clonable()) |
1273 return handleError(DataCloneError, "A FileSystem object could not be cloned.", next); | 1303 return handleError(DataCloneError, "A FileSystem object could not be cloned.", next); |
1274 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); | 1304 m_writer.writeDOMFileSystem(fs->type(), fs->name(), fs->rootURL().string ()); |
1275 return 0; | 1305 return 0; |
1276 } | 1306 } |
1277 | 1307 |
1278 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next) | 1308 StateBase* writeFile(v8::Handle<v8::Value> value, StateBase* next) |
1279 { | 1309 { |
1280 File* file = V8File::toNative(value.As<v8::Object>()); | 1310 File* file = V8File::toNative(value.As<v8::Object>()); |
1281 if (!file) | 1311 if (!file) |
1282 return 0; | 1312 return 0; |
1283 if (file->hasBeenClosed()) | 1313 if (file->hasBeenClosed()) |
1284 return handleError(DataCloneError, "A File object has been closed, a nd could therefore not be cloned.", next); | 1314 return handleError(DataCloneError, "A File object has been closed, a nd could therefore not be cloned.", next); |
1285 m_writer.writeFile(*file); | 1315 int blobIndex = -1; |
1286 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); | 1316 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); |
1317 if (appendFileInfo(file->uuid(), file->path(), file->name(), file->type( ), &blobIndex)) { | |
1318 ASSERT(blobIndex >= 0); | |
1319 m_writer.writeFile(blobIndex); | |
1320 } else { | |
1321 m_writer.writeFile(*file); | |
1322 } | |
1287 return 0; | 1323 return 0; |
1288 } | 1324 } |
1289 | 1325 |
1290 void writeFileList(v8::Handle<v8::Value> value) | 1326 void writeFileList(v8::Handle<v8::Value> value) |
1291 { | 1327 { |
1292 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1328 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); |
1293 if (!fileList) | 1329 if (!fileList) |
1294 return; | 1330 return; |
1295 m_writer.writeFileList(*fileList); | |
1296 unsigned length = fileList->length(); | 1331 unsigned length = fileList->length(); |
1297 for (unsigned i = 0; i < length; ++i) | 1332 Vector<int> blobIndices; |
1298 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)-> blobDataHandle()); | 1333 bool useBlobIndices = false; |
cmumford
2014/04/03 16:32:45
Do you need useBlobIndices, or can you instead use
ericu
2014/04/07 23:14:20
Switched to blobIndices.isEmpty().
| |
1334 for (unsigned i = 0; i < length; ++i) { | |
1335 int blobIndex = -1; | |
1336 const File* file = fileList->item(i); | |
1337 m_blobDataHandles.add(file->uuid(), file->blobDataHandle()); | |
1338 if (appendFileInfo(file->uuid(), file->path(), file->name(), file->t ype(), &blobIndex)) { | |
cmumford
2014/04/03 16:32:45
In writeFile you call file->hasBeenClosed() and re
ericu
2014/04/07 23:14:20
No, it should be there; that's new stuff from a me
| |
1339 ASSERT(!i || useBlobIndices); | |
1340 ASSERT(blobIndex >= 0); | |
1341 useBlobIndices = true; | |
1342 blobIndices.append(blobIndex); | |
1343 } | |
1344 } | |
1345 if (useBlobIndices) { | |
1346 m_writer.writeFileList(blobIndices); | |
1347 } else { | |
1348 m_writer.writeFileList(*fileList); | |
1349 } | |
1299 } | 1350 } |
1300 | 1351 |
1301 bool writeCryptoKey(v8::Handle<v8::Value> value) | 1352 bool writeCryptoKey(v8::Handle<v8::Value> value) |
1302 { | 1353 { |
1303 Key* key = V8Key::toNative(value.As<v8::Object>()); | 1354 Key* key = V8Key::toNative(value.As<v8::Object>()); |
1304 if (!key) | 1355 if (!key) |
1305 return 0; | 1356 return 0; |
1306 return m_writer.writeCryptoKey(key->key()); | 1357 return m_writer.writeCryptoKey(key->key()); |
1307 } | 1358 } |
1308 | 1359 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 | 1458 |
1408 // Marks object as having been visited by the serializer and assigns it a un ique object reference ID. | 1459 // 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. | 1460 // An object may only be greyed once. |
1410 void greyObject(const v8::Handle<v8::Object>& object) | 1461 void greyObject(const v8::Handle<v8::Object>& object) |
1411 { | 1462 { |
1412 ASSERT(!m_objectPool.contains(object)); | 1463 ASSERT(!m_objectPool.contains(object)); |
1413 uint32_t objectReference = m_nextObjectReference++; | 1464 uint32_t objectReference = m_nextObjectReference++; |
1414 m_objectPool.set(object, objectReference); | 1465 m_objectPool.set(object, objectReference); |
1415 } | 1466 } |
1416 | 1467 |
1468 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo ng size, int* index) | |
1469 { | |
1470 if (!m_blobInfo) | |
1471 return false; | |
1472 *index = m_blobInfo->size(); | |
1473 m_blobInfo->append(blink::WebBlobInfo(uuid, type, size)); | |
1474 return true; | |
1475 } | |
1476 | |
1477 bool appendFileInfo(const String& uuid, const String& filePath, const String & fileName, const String& type, int* index) | |
1478 { | |
1479 if (!m_blobInfo) | |
1480 return false; | |
1481 *index = m_blobInfo->size(); | |
1482 m_blobInfo->append(blink::WebBlobInfo(uuid, filePath, fileName, type)); | |
1483 return true; | |
1484 } | |
1485 | |
1417 Writer& m_writer; | 1486 Writer& m_writer; |
1418 v8::TryCatch& m_tryCatch; | 1487 v8::TryCatch& m_tryCatch; |
1419 int m_depth; | 1488 int m_depth; |
1420 Status m_status; | 1489 Status m_status; |
1421 String m_errorMessage; | 1490 String m_errorMessage; |
1422 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 1491 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; |
1423 ObjectPool m_objectPool; | 1492 ObjectPool m_objectPool; |
1424 ObjectPool m_transferredMessagePorts; | 1493 ObjectPool m_transferredMessagePorts; |
1425 ObjectPool m_transferredArrayBuffers; | 1494 ObjectPool m_transferredArrayBuffers; |
1426 uint32_t m_nextObjectReference; | 1495 uint32_t m_nextObjectReference; |
1496 Vector<blink::WebBlobInfo>* m_blobInfo; | |
1427 BlobDataHandleMap& m_blobDataHandles; | 1497 BlobDataHandleMap& m_blobDataHandles; |
1428 v8::Isolate* m_isolate; | 1498 v8::Isolate* m_isolate; |
1429 }; | 1499 }; |
1430 | 1500 |
1431 // Returns true if the provided object is to be considered a 'host object', as u sed in the | 1501 // Returns true if the provided object is to be considered a 'host object', as u sed in the |
1432 // HTML5 structured clone algorithm. | 1502 // HTML5 structured clone algorithm. |
1433 static bool isHostObject(v8::Handle<v8::Object> object) | 1503 static bool isHostObject(v8::Handle<v8::Object> object) |
1434 { | 1504 { |
1435 // If the object has any internal fields, then we won't be able to serialize or deserialize | 1505 // 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 | 1506 // them; conveniently, this is also a quick way to detect DOM wrapper object s, because |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1536 virtual bool newObject() = 0; | 1606 virtual bool newObject() = 0; |
1537 virtual bool completeObject(uint32_t numProperties, v8::Handle<v8::Value>*) = 0; | 1607 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; | 1608 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; | 1609 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8: :Handle<v8::Value>*) = 0; |
1540 }; | 1610 }; |
1541 | 1611 |
1542 // Reader is responsible for deserializing primitive types and | 1612 // Reader is responsible for deserializing primitive types and |
1543 // restoring information about saved objects of composite types. | 1613 // restoring information about saved objects of composite types. |
1544 class Reader { | 1614 class Reader { |
1545 public: | 1615 public: |
1546 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const BlobD ataHandleMap& blobDataHandles) | 1616 Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const Vector <blink::WebBlobInfo>* blobInfo, BlobDataHandleMap& blobDataHandles) |
1547 : m_buffer(buffer) | 1617 : m_buffer(buffer) |
1548 , m_length(length) | 1618 , m_length(length) |
1549 , m_position(0) | 1619 , m_position(0) |
1550 , m_version(0) | 1620 , m_version(0) |
1551 , m_isolate(isolate) | 1621 , m_isolate(isolate) |
1622 , m_blobInfo(blobInfo) | |
1552 , m_blobDataHandles(blobDataHandles) | 1623 , m_blobDataHandles(blobDataHandles) |
1553 { | 1624 { |
1554 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); | 1625 ASSERT(!(reinterpret_cast<size_t>(buffer) & 1)); |
1555 ASSERT(length >= 0); | 1626 ASSERT(length >= 0); |
1556 } | 1627 } |
1557 | 1628 |
1558 bool isEof() const { return m_position >= m_length; } | 1629 bool isEof() const { return m_position >= m_length; } |
1559 | 1630 |
1560 v8::Isolate* isolate() const { return m_isolate; } | 1631 v8::Isolate* isolate() const { return m_isolate; } |
1561 | 1632 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2064 return true; | 2135 return true; |
2065 } | 2136 } |
2066 | 2137 |
2067 bool readBlob(v8::Handle<v8::Value>* value) | 2138 bool readBlob(v8::Handle<v8::Value>* value) |
2068 { | 2139 { |
2069 if (m_version < 3) | 2140 if (m_version < 3) |
2070 return false; | 2141 return false; |
2071 String uuid; | 2142 String uuid; |
2072 String type; | 2143 String type; |
2073 uint64_t size; | 2144 uint64_t size; |
2074 if (!readWebCoreString(&uuid)) | 2145 if (m_blobInfo) { |
2075 return false; | 2146 uint32_t index; |
2076 if (!readWebCoreString(&type)) | 2147 if (!doReadUint32(&index) || index >= m_blobInfo->size()) |
2077 return false; | 2148 return false; |
2078 if (!doReadUint64(&size)) | 2149 const blink::WebBlobInfo& info = (*m_blobInfo)[index]; |
2079 return false; | 2150 uuid = info.uuid(); |
2151 type = info.type(); | |
2152 size = info.size(); | |
2153 } else { | |
2154 if (!readWebCoreString(&uuid)) | |
2155 return false; | |
2156 if (!readWebCoreString(&type)) | |
2157 return false; | |
2158 if (!doReadUint64(&size)) | |
2159 return false; | |
2160 } | |
2080 RefPtrWillBeRawPtr<Blob> blob = Blob::create(getOrCreateBlobDataHandle(u uid, type, size)); | 2161 RefPtrWillBeRawPtr<Blob> blob = Blob::create(getOrCreateBlobDataHandle(u uid, type, size)); |
2081 *value = toV8(blob.release(), v8::Handle<v8::Object>(), m_isolate); | 2162 *value = toV8(blob.release(), v8::Handle<v8::Object>(), m_isolate); |
2082 return true; | 2163 return true; |
2083 } | 2164 } |
2084 | 2165 |
2085 bool readDOMFileSystem(v8::Handle<v8::Value>* value) | 2166 bool readDOMFileSystem(v8::Handle<v8::Value>* value) |
2086 { | 2167 { |
2087 uint32_t type; | 2168 uint32_t type; |
2088 String name; | 2169 String name; |
2089 String url; | 2170 String url; |
2090 if (!doReadUint32(&type)) | 2171 if (!doReadUint32(&type)) |
2091 return false; | 2172 return false; |
2092 if (!readWebCoreString(&name)) | 2173 if (!readWebCoreString(&name)) |
2093 return false; | 2174 return false; |
2094 if (!readWebCoreString(&url)) | 2175 if (!readWebCoreString(&url)) |
2095 return false; | 2176 return false; |
2096 RefPtrWillBeRawPtr<DOMFileSystem> fs = DOMFileSystem::create(currentExec utionContext(m_isolate), name, static_cast<WebCore::FileSystemType>(type), KURL( ParsedURLString, url)); | 2177 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); | 2178 *value = toV8(fs.release(), v8::Handle<v8::Object>(), m_isolate); |
2098 return true; | 2179 return true; |
2099 } | 2180 } |
2100 | 2181 |
2101 bool readFile(v8::Handle<v8::Value>* value) | 2182 bool readFile(v8::Handle<v8::Value>* value) |
2102 { | 2183 { |
2103 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); | 2184 RefPtrWillBeRawPtr<File> file = readFileHelper(); |
2104 if (!file) | 2185 if (!file) |
2105 return false; | 2186 return false; |
2106 *value = toV8(file.release(), v8::Handle<v8::Object>(), m_isolate); | 2187 *value = toV8(file.release(), v8::Handle<v8::Object>(), m_isolate); |
2107 return true; | 2188 return true; |
2108 } | 2189 } |
2109 | 2190 |
2110 bool readFileList(v8::Handle<v8::Value>* value) | 2191 bool readFileList(v8::Handle<v8::Value>* value) |
2111 { | 2192 { |
2112 if (m_version < 3) | 2193 if (m_version < 3) |
2113 return false; | 2194 return false; |
2114 uint32_t length; | 2195 uint32_t length; |
2115 if (!doReadUint32(&length)) | 2196 if (!doReadUint32(&length)) |
2116 return false; | 2197 return false; |
2117 RefPtrWillBeRawPtr<FileList> fileList = FileList::create(); | 2198 RefPtrWillBeRawPtr<FileList> fileList = FileList::create(); |
2118 for (unsigned i = 0; i < length; ++i) { | 2199 for (unsigned i = 0; i < length; ++i) { |
2119 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); | 2200 RefPtrWillBeRawPtr<File> file = readFileHelper(); |
2120 if (!file) | 2201 if (!file) |
2121 return false; | 2202 return false; |
2122 fileList->append(file.release()); | 2203 fileList->append(file.release()); |
2123 } | 2204 } |
2124 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); | 2205 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); |
2125 return true; | 2206 return true; |
2126 } | 2207 } |
2127 | 2208 |
2128 bool readCryptoKey(v8::Handle<v8::Value>* value) | 2209 bool readCryptoKey(v8::Handle<v8::Value>* value) |
2129 { | 2210 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2174 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( | 2255 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( |
2175 algorithm, type, extractable, usages, keyData, keyDataLength, key)) { | 2256 algorithm, type, extractable, usages, keyData, keyDataLength, key)) { |
2176 return false; | 2257 return false; |
2177 } | 2258 } |
2178 | 2259 |
2179 RefPtrWillBeRawPtr<Key> k = Key::create(key); | 2260 RefPtrWillBeRawPtr<Key> k = Key::create(key); |
2180 *value = toV8(k.release(), v8::Handle<v8::Object>(), m_isolate); | 2261 *value = toV8(k.release(), v8::Handle<v8::Object>(), m_isolate); |
2181 return true; | 2262 return true; |
2182 } | 2263 } |
2183 | 2264 |
2184 PassRefPtrWillBeRawPtr<File> doReadFileHelper() | 2265 PassRefPtr<File> readFileHelper() |
2185 { | 2266 { |
2186 if (m_version < 3) | 2267 if (m_version < 3) |
2187 return nullptr; | 2268 return nullptr; |
2269 if (m_blobInfo) { | |
2270 uint32_t index; | |
2271 if (!doReadUint32(&index) || index >= m_blobInfo->size()) | |
2272 return nullptr; | |
2273 const blink::WebBlobInfo& info = (*m_blobInfo)[index]; | |
2274 return File::create(info.filePath(), info.fileName(), getOrCreateBlo bDataHandle(info.uuid(), info.type(), info.size()), info.lastModified(), info.si ze()); | |
2275 } | |
2188 String path; | 2276 String path; |
2189 String name; | 2277 String name; |
2190 String relativePath; | 2278 String relativePath; |
2191 String uuid; | 2279 String uuid; |
2192 String type; | 2280 String type; |
2193 uint32_t hasSnapshot = 0; | 2281 uint32_t hasSnapshot = 0; |
2194 uint64_t size = 0; | 2282 uint64_t size = 0; |
2195 double lastModified = 0; | 2283 double lastModified = 0; |
2196 if (!readWebCoreString(&path)) | 2284 if (!readWebCoreString(&path)) |
2197 return nullptr; | 2285 return nullptr; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2254 { | 2342 { |
2255 // The containing ssv may have a BDH for this uuid if this ssv is just b eing | 2343 // 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 | 2344 // 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. | 2345 // the new blob instead of cons'ing up a new BDH. |
2258 // | 2346 // |
2259 // FIXME: Maybe we should require that it work that way where the ssv mu st have a BDH for any | 2347 // 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 | 2348 // 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 | 2349 // 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 | 2350 // 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. | 2351 // 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(...). | 2352 // For example in sharedWorker.postMessage(...). |
2265 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); | 2353 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); |
2266 if (it != m_blobDataHandles.end()) { | 2354 if (it != m_blobDataHandles.end()) { |
2267 // make assertions about type and size? | 2355 // make assertions about type and size? |
2268 return it->value; | 2356 return it->value; |
2269 } | 2357 } |
2270 return BlobDataHandle::create(uuid, type, size); | 2358 return BlobDataHandle::create(uuid, type, size); |
2271 } | 2359 } |
2272 | 2360 |
2273 bool doReadHmacKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCrypto KeyType& type) | 2361 bool doReadHmacKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCrypto KeyType& type) |
2274 { | 2362 { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2425 usages |= blink::WebCryptoKeyUsageUnwrapKey; | 2513 usages |= blink::WebCryptoKeyUsageUnwrapKey; |
2426 | 2514 |
2427 return true; | 2515 return true; |
2428 } | 2516 } |
2429 | 2517 |
2430 const uint8_t* m_buffer; | 2518 const uint8_t* m_buffer; |
2431 const unsigned m_length; | 2519 const unsigned m_length; |
2432 unsigned m_position; | 2520 unsigned m_position; |
2433 uint32_t m_version; | 2521 uint32_t m_version; |
2434 v8::Isolate* m_isolate; | 2522 v8::Isolate* m_isolate; |
2523 const Vector<blink::WebBlobInfo>* m_blobInfo; | |
2435 const BlobDataHandleMap& m_blobDataHandles; | 2524 const BlobDataHandleMap& m_blobDataHandles; |
2436 }; | 2525 }; |
2437 | 2526 |
2438 | 2527 |
2439 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 2528 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
2440 | 2529 |
2441 class Deserializer FINAL : public CompositeCreator { | 2530 class Deserializer FINAL : public CompositeCreator { |
2442 public: | 2531 public: |
2443 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents) | 2532 Deserializer(Reader& reader, MessagePortArray* messagePorts, ArrayBufferCont entsArray* arrayBufferContents) |
2444 : m_reader(reader) | 2533 : m_reader(reader) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2667 MessagePortArray* m_transferredMessagePorts; | 2756 MessagePortArray* m_transferredMessagePorts; |
2668 ArrayBufferContentsArray* m_arrayBufferContents; | 2757 ArrayBufferContentsArray* m_arrayBufferContents; |
2669 Vector<v8::Handle<v8::Object> > m_arrayBuffers; | 2758 Vector<v8::Handle<v8::Object> > m_arrayBuffers; |
2670 uint32_t m_version; | 2759 uint32_t m_version; |
2671 }; | 2760 }; |
2672 | 2761 |
2673 } // namespace | 2762 } // namespace |
2674 | 2763 |
2675 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Exc eptionState& exceptionState, v8::Isolate* isolate) | 2764 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Exc eptionState& exceptionState, v8::Isolate* isolate) |
2676 { | 2765 { |
2677 return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, exceptionState, isolate)); | 2766 return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, 0, exceptionState, isolate)); |
2678 } | 2767 } |
2679 | 2768 |
2680 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti ons(v8::Handle<v8::Value> value, v8::Isolate* isolate) | 2769 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti ons(v8::Handle<v8::Value> value, v8::Isolate* isolate) |
2681 { | 2770 { |
2682 TrackExceptionState exceptionState; | 2771 TrackExceptionState exceptionState; |
2683 return adoptRef(new SerializedScriptValue(value, 0, 0, exceptionState, isola te)); | 2772 return adoptRef(new SerializedScriptValue(value, 0, 0, 0, exceptionState, is olate)); |
2684 } | 2773 } |
2685 | 2774 |
2686 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const ScriptValu e& value, ExceptionState& exceptionState, ScriptState* state) | 2775 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const ScriptValu e& value, Vector<blink::WebBlobInfo>* blobInfo, ExceptionState& exceptionState, ScriptState* state) |
2687 { | 2776 { |
2688 ScriptScope scope(state); | 2777 ScriptScope scope(state); |
2689 return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, exceptionSt ate, state->isolate())); | 2778 return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, blobInfo, e xceptionState, state->isolate())); |
2690 } | 2779 } |
2691 | 2780 |
2692 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St ring& data) | 2781 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St ring& data) |
2693 { | 2782 { |
2694 return adoptRef(new SerializedScriptValue(data)); | 2783 return adoptRef(new SerializedScriptValue(data)); |
2695 } | 2784 } |
2696 | 2785 |
2697 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con st Vector<uint8_t>& data) | 2786 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con st Vector<uint8_t>& data) |
2698 { | 2787 { |
2699 // Decode wire data from big endian to host byte order. | 2788 // 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) { | 2892 if (!result) { |
2804 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred."); | 2893 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " could not be transferred."); |
2805 return nullptr; | 2894 return nullptr; |
2806 } | 2895 } |
2807 | 2896 |
2808 neuterArrayBufferInAllWorlds(arrayBuffers[i].get()); | 2897 neuterArrayBufferInAllWorlds(arrayBuffers[i].get()); |
2809 } | 2898 } |
2810 return contents.release(); | 2899 return contents.release(); |
2811 } | 2900 } |
2812 | 2901 |
2813 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, ExceptionState& except ionState, v8::Isolate* isolate) | 2902 SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, Messag ePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vector<blink::WebBlobI nfo>* blobInfo, ExceptionState& exceptionState, v8::Isolate* isolate) |
2814 : m_externallyAllocatedMemory(0) | 2903 : m_externallyAllocatedMemory(0) |
2815 { | 2904 { |
2816 Writer writer; | 2905 Writer writer; |
2817 Serializer::Status status; | 2906 Serializer::Status status; |
2818 String errorMessage; | 2907 String errorMessage; |
2819 { | 2908 { |
2820 v8::TryCatch tryCatch; | 2909 v8::TryCatch tryCatch; |
2821 Serializer serializer(writer, messagePorts, arrayBuffers, m_blobDataHand les, tryCatch, isolate); | 2910 Serializer serializer(writer, messagePorts, arrayBuffers, blobInfo, m_bl obDataHandles, tryCatch, isolate); |
2822 status = serializer.serialize(value); | 2911 status = serializer.serialize(value); |
2823 if (status == Serializer::JSException) { | 2912 if (status == Serializer::JSException) { |
2824 // If there was a JS exception thrown, re-throw it. | 2913 // If there was a JS exception thrown, re-throw it. |
2825 exceptionState.rethrowV8Exception(tryCatch.Exception()); | 2914 exceptionState.rethrowV8Exception(tryCatch.Exception()); |
2826 return; | 2915 return; |
2827 } | 2916 } |
2828 errorMessage = serializer.errorMessage(); | 2917 errorMessage = serializer.errorMessage(); |
2829 } | 2918 } |
2830 switch (status) { | 2919 switch (status) { |
2831 case Serializer::InputError: | 2920 case Serializer::InputError: |
(...skipping 14 matching lines...) Expand all Loading... | |
2846 } | 2935 } |
2847 | 2936 |
2848 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 2937 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
2849 : m_externallyAllocatedMemory(0) | 2938 : m_externallyAllocatedMemory(0) |
2850 { | 2939 { |
2851 m_data = wireData.isolatedCopy(); | 2940 m_data = wireData.isolatedCopy(); |
2852 } | 2941 } |
2853 | 2942 |
2854 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa gePorts) | 2943 v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messa gePorts) |
2855 { | 2944 { |
2856 return deserialize(v8::Isolate::GetCurrent(), messagePorts); | 2945 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); |
2857 } | 2946 } |
2858 | 2947 |
2859 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts) | 2948 v8::Handle<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, M essagePortArray* messagePorts, const Vector<blink::WebBlobInfo>* blobInfo) |
2860 { | 2949 { |
2861 if (!m_data.impl()) | 2950 if (!m_data.impl()) |
2862 return v8::Null(isolate); | 2951 return v8::Null(isolate); |
2863 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); | 2952 COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes); |
2864 m_data.ensure16Bit(); | 2953 m_data.ensure16Bit(); |
2865 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 2954 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
2866 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 2955 // 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, | 2956 // 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. | 2957 // 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); | 2958 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()); | 2959 Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.g et()); |
2871 | 2960 |
2872 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. | 2961 // 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. | 2962 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. |
2874 RefPtr<SerializedScriptValue> protect(this); | 2963 RefPtr<SerializedScriptValue> protect(this); |
2875 return deserializer.deserialize(); | 2964 return deserializer.deserialize(); |
2876 } | 2965 } |
2877 | 2966 |
2878 bool SerializedScriptValue::extractTransferables(v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, Excepti onState& exceptionState, v8::Isolate* isolate) | 2967 bool SerializedScriptValue::extractTransferables(v8::Local<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, Excepti onState& exceptionState, v8::Isolate* isolate) |
2879 { | 2968 { |
(...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 | 3028 // 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 | 3029 // 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. | 3030 // current v8 context is not guaranteed. Avoid calling v8 then. |
2942 if (m_externallyAllocatedMemory) { | 3031 if (m_externallyAllocatedMemory) { |
2943 ASSERT(v8::Isolate::GetCurrent()); | 3032 ASSERT(v8::Isolate::GetCurrent()); |
2944 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); | 3033 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); |
2945 } | 3034 } |
2946 } | 3035 } |
2947 | 3036 |
2948 } // namespace WebCore | 3037 } // namespace WebCore |
OLD | NEW |