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 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/v8/SerializedScriptValue.h" | 32 #include "bindings/v8/SerializedScriptValue.h" |
33 | 33 |
34 #include "V8Blob.h" | 34 #include "V8Blob.h" |
35 #include "V8DOMFileSystem.h" | 35 #include "V8DOMFileSystem.h" |
36 #include "V8File.h" | 36 #include "V8File.h" |
37 #include "V8FileList.h" | 37 #include "V8FileList.h" |
38 #include "V8ImageData.h" | 38 #include "V8ImageData.h" |
39 #include "V8Key.h" | 39 #include "V8Key.h" |
40 #include "V8KeyPair.h" | |
40 #include "V8MessagePort.h" | 41 #include "V8MessagePort.h" |
41 #include "bindings/v8/ExceptionState.h" | 42 #include "bindings/v8/ExceptionState.h" |
42 #include "bindings/v8/V8Binding.h" | 43 #include "bindings/v8/V8Binding.h" |
43 #include "bindings/v8/WorkerScriptController.h" | 44 #include "bindings/v8/WorkerScriptController.h" |
44 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 45 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
45 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 46 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
46 #include "bindings/v8/custom/V8DataViewCustom.h" | 47 #include "bindings/v8/custom/V8DataViewCustom.h" |
47 #include "bindings/v8/custom/V8Float32ArrayCustom.h" | 48 #include "bindings/v8/custom/V8Float32ArrayCustom.h" |
48 #include "bindings/v8/custom/V8Float64ArrayCustom.h" | 49 #include "bindings/v8/custom/V8Float64ArrayCustom.h" |
49 #include "bindings/v8/custom/V8Int16ArrayCustom.h" | 50 #include "bindings/v8/custom/V8Int16ArrayCustom.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 ArrayBufferViewTag = 'V', // subtag:byte, byteOffset:uint32_t, byteLength:ui nt32_t -> ArrayBufferView (ref). Consumes an ArrayBuffer from the top of the des erialization stack. | 219 ArrayBufferViewTag = 'V', // subtag:byte, byteOffset:uint32_t, byteLength:ui nt32_t -> ArrayBufferView (ref). Consumes an ArrayBuffer from the top of the des erialization stack. |
219 CryptoKeyTag = 'K', // subtag:byte, props, usages:uint32_t, keyDataLength:ui nt32_t, keyData:byte[keyDataLength] | 220 CryptoKeyTag = 'K', // subtag:byte, props, usages:uint32_t, keyDataLength:ui nt32_t, keyData:byte[keyDataLength] |
220 // If subtag=AesKeyTag: | 221 // If subtag=AesKeyTag: |
221 // props = keyLengthBytes:uint32_t, algorithmId:ui nt32_t | 222 // props = keyLengthBytes:uint32_t, algorithmId:ui nt32_t |
222 // If subtag=HmacKeyTag: | 223 // If subtag=HmacKeyTag: |
223 // props = keyLengthBytes:uint32_t, hashId:uint32_ t | 224 // props = keyLengthBytes:uint32_t, hashId:uint32_ t |
224 // If subtag=RsaKeyTag: | 225 // If subtag=RsaKeyTag: |
225 // props = algorithmId:uint32_t, type:uint32_t, mo dulusLengthBits:uint32_t, publicExponentLength:uint32_t, publicExponent:byte[pub licExponentLength] | 226 // props = algorithmId:uint32_t, type:uint32_t, mo dulusLengthBits:uint32_t, publicExponentLength:uint32_t, publicExponent:byte[pub licExponentLength] |
226 // If subtag=RsaHashedKeyTag: | 227 // If subtag=RsaHashedKeyTag: |
227 // props = <same as for RsaKeyTag>, hashId:uint32_ t | 228 // props = <same as for RsaKeyTag>, hashId:uint32_ t |
229 CryptoKeyPairTag = 'k', // publicKey:CryptoKey, privateKey:CryptoKey | |
228 ObjectReferenceTag = '^', // ref:uint32_t -> reference table[ref] | 230 ObjectReferenceTag = '^', // ref:uint32_t -> reference table[ref] |
229 GenerateFreshObjectTag = 'o', // -> empty object allocated an object ID and pushed onto the open stack (ref) | 231 GenerateFreshObjectTag = 'o', // -> empty object allocated an object ID and pushed onto the open stack (ref) |
230 GenerateFreshSparseArrayTag = 'a', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) | 232 GenerateFreshSparseArrayTag = 'a', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) |
231 GenerateFreshDenseArrayTag = 'A', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) | 233 GenerateFreshDenseArrayTag = 'A', // length:uint32_t -> empty array[length] allocated an object ID and pushed onto the open stack (ref) |
232 ReferenceCountTag = '?', // refTableSize:uint32_t -> If the reference table is not refTableSize big, fails. | 234 ReferenceCountTag = '?', // refTableSize:uint32_t -> If the reference table is not refTableSize big, fails. |
233 StringObjectTag = 's', // string:RawString -> new String(string) (ref) | 235 StringObjectTag = 's', // string:RawString -> new String(string) (ref) |
234 NumberObjectTag = 'n', // value:double -> new Number(value) (ref) | 236 NumberObjectTag = 'n', // value:double -> new Number(value) (ref) |
235 TrueObjectTag = 'y', // new Boolean(true) (ref) | 237 TrueObjectTag = 'y', // new Boolean(true) (ref) |
236 FalseObjectTag = 'x', // new Boolean(false) (ref) | 238 FalseObjectTag = 'x', // new Boolean(false) (ref) |
237 VersionTag = 0xFF // version:uint32_t -> Uses this as the file version. | 239 VersionTag = 0xFF // version:uint32_t -> Uses this as the file version. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 | 501 |
500 void writeFileListIndex(const Vector<int>& blobIndices) | 502 void writeFileListIndex(const Vector<int>& blobIndices) |
501 { | 503 { |
502 append(FileListIndexTag); | 504 append(FileListIndexTag); |
503 uint32_t length = blobIndices.size(); | 505 uint32_t length = blobIndices.size(); |
504 doWriteUint32(length); | 506 doWriteUint32(length); |
505 for (unsigned i = 0; i < length; ++i) | 507 for (unsigned i = 0; i < length; ++i) |
506 doWriteUint32(blobIndices[i]); | 508 doWriteUint32(blobIndices[i]); |
507 } | 509 } |
508 | 510 |
509 bool writeCryptoKey(const blink::WebCryptoKey& key) | 511 bool writeCryptoKey(const blink::WebCryptoKey& key, bool includeTag) |
510 { | 512 { |
511 append(static_cast<uint8_t>(CryptoKeyTag)); | 513 if (includeTag) |
514 append(static_cast<uint8_t>(CryptoKeyTag)); | |
512 | 515 |
513 switch (key.algorithm().paramsType()) { | 516 switch (key.algorithm().paramsType()) { |
514 case blink::WebCryptoKeyAlgorithmParamsTypeAes: | 517 case blink::WebCryptoKeyAlgorithmParamsTypeAes: |
515 doWriteAesKey(key); | 518 doWriteAesKey(key); |
516 break; | 519 break; |
517 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: | 520 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: |
518 doWriteHmacKey(key); | 521 doWriteHmacKey(key); |
519 break; | 522 break; |
520 case blink::WebCryptoKeyAlgorithmParamsTypeRsa: | 523 case blink::WebCryptoKeyAlgorithmParamsTypeRsa: |
521 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: | 524 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: |
522 doWriteRsaKey(key); | 525 doWriteRsaKey(key); |
523 break; | 526 break; |
524 case blink::WebCryptoKeyAlgorithmParamsTypeNone: | 527 case blink::WebCryptoKeyAlgorithmParamsTypeNone: |
525 ASSERT_NOT_REACHED(); | 528 ASSERT_NOT_REACHED(); |
526 return false; | 529 return false; |
527 } | 530 } |
528 | 531 |
529 doWriteKeyUsages(key.usages(), key.extractable()); | 532 doWriteKeyUsages(key.usages(), key.extractable()); |
530 | 533 |
531 blink::WebVector<uint8_t> keyData; | 534 blink::WebVector<uint8_t> keyData; |
532 if (!blink::Platform::current()->crypto()->serializeKeyForClone(key, key Data)) | 535 if (!blink::Platform::current()->crypto()->serializeKeyForClone(key, key Data)) |
533 return false; | 536 return false; |
534 | 537 |
535 doWriteUint32(keyData.size()); | 538 doWriteUint32(keyData.size()); |
536 append(keyData.data(), keyData.size()); | 539 append(keyData.data(), keyData.size()); |
537 return true; | 540 return true; |
538 } | 541 } |
539 | 542 |
543 bool writeCryptoKeyPair(const blink::WebCryptoKey& publicKey, const blink::W ebCryptoKey& privateKey) | |
544 { | |
545 append(static_cast<uint8_t>(CryptoKeyPairTag)); | |
546 return writeCryptoKey(publicKey, false) && writeCryptoKey(privateKey, fa lse); | |
547 } | |
548 | |
540 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 549 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) |
541 { | 550 { |
542 append(ArrayBufferTag); | 551 append(ArrayBufferTag); |
543 doWriteArrayBuffer(arrayBuffer); | 552 doWriteArrayBuffer(arrayBuffer); |
544 } | 553 } |
545 | 554 |
546 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) | 555 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) |
547 { | 556 { |
548 append(ArrayBufferViewTag); | 557 append(ArrayBufferViewTag); |
549 #ifndef NDEBUG | 558 #ifndef NDEBUG |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 m_writer.writeFileListIndex(blobIndices); | 1357 m_writer.writeFileListIndex(blobIndices); |
1349 else | 1358 else |
1350 m_writer.writeFileList(*fileList); | 1359 m_writer.writeFileList(*fileList); |
1351 return 0; | 1360 return 0; |
1352 } | 1361 } |
1353 | 1362 |
1354 bool writeCryptoKey(v8::Handle<v8::Value> value) | 1363 bool writeCryptoKey(v8::Handle<v8::Value> value) |
1355 { | 1364 { |
1356 Key* key = V8Key::toNative(value.As<v8::Object>()); | 1365 Key* key = V8Key::toNative(value.As<v8::Object>()); |
1357 if (!key) | 1366 if (!key) |
1358 return 0; | 1367 return 0; |
jsbell
2014/05/06 20:38:09
(not this cl, but related) nit: return false
eroman
2014/05/06 21:35:17
Done.
| |
1359 return m_writer.writeCryptoKey(key->key()); | 1368 return m_writer.writeCryptoKey(key->key(), true); |
1369 } | |
1370 | |
1371 bool writeCryptoKeyPair(v8::Handle<v8::Value> value) | |
1372 { | |
1373 KeyPair* keyPair = V8KeyPair::toNative(value.As<v8::Object>()); | |
1374 if (!keyPair) | |
1375 return 0; | |
jsbell
2014/05/06 20:38:09
nit: return false
eroman
2014/05/06 21:35:17
Done.
| |
1376 return m_writer.writeCryptoKeyPair(keyPair->publicKey()->key(), keyPair- >privateKey()->key()); | |
1360 } | 1377 } |
1361 | 1378 |
1362 void writeImageData(v8::Handle<v8::Value> value) | 1379 void writeImageData(v8::Handle<v8::Value> value) |
1363 { | 1380 { |
1364 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 1381 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); |
1365 if (!imageData) | 1382 if (!imageData) |
1366 return; | 1383 return; |
1367 Uint8ClampedArray* pixelArray = imageData->data(); | 1384 Uint8ClampedArray* pixelArray = imageData->data(); |
1368 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length()); | 1385 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr ray->data(), pixelArray->length()); |
1369 } | 1386 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1569 return writeFile(value, next); | 1586 return writeFile(value, next); |
1570 else if (V8Blob::hasInstance(value, m_isolate)) | 1587 else if (V8Blob::hasInstance(value, m_isolate)) |
1571 return writeBlob(value, next); | 1588 return writeBlob(value, next); |
1572 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) | 1589 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) |
1573 return writeDOMFileSystem(value, next); | 1590 return writeDOMFileSystem(value, next); |
1574 else if (V8FileList::hasInstance(value, m_isolate)) | 1591 else if (V8FileList::hasInstance(value, m_isolate)) |
1575 return writeFileList(value, next); | 1592 return writeFileList(value, next); |
1576 else if (V8Key::hasInstance(value, m_isolate)) { | 1593 else if (V8Key::hasInstance(value, m_isolate)) { |
1577 if (!writeCryptoKey(value)) | 1594 if (!writeCryptoKey(value)) |
1578 return handleError(DataCloneError, "Couldn't serialize key data" , next); | 1595 return handleError(DataCloneError, "Couldn't serialize key data" , next); |
1596 } else if (V8KeyPair::hasInstance(value, m_isolate)) { | |
1597 if (!writeCryptoKeyPair(value)) | |
1598 return handleError(DataCloneError, "Couldn't serialize key data" , next); | |
1579 } else if (V8ImageData::hasInstance(value, m_isolate)) | 1599 } else if (V8ImageData::hasInstance(value, m_isolate)) |
1580 writeImageData(value); | 1600 writeImageData(value); |
1581 else if (value->IsRegExp()) | 1601 else if (value->IsRegExp()) |
1582 writeRegExp(value); | 1602 writeRegExp(value); |
1583 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) | 1603 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) |
1584 return writeArrayBuffer(value, next); | 1604 return writeArrayBuffer(value, next); |
1585 else if (value->IsObject()) { | 1605 else if (value->IsObject()) { |
1586 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat iveError()) | 1606 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat iveError()) |
1587 return handleError(DataCloneError, "An object could not be clone d.", next); | 1607 return handleError(DataCloneError, "An object could not be clone d.", next); |
1588 return startObjectState(jsObject, next); | 1608 return startObjectState(jsObject, next); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1731 case FileListIndexTag: | 1751 case FileListIndexTag: |
1732 if (!readFileList(value, tag == FileListIndexTag)) | 1752 if (!readFileList(value, tag == FileListIndexTag)) |
1733 return false; | 1753 return false; |
1734 creator.pushObjectReference(*value); | 1754 creator.pushObjectReference(*value); |
1735 break; | 1755 break; |
1736 case CryptoKeyTag: | 1756 case CryptoKeyTag: |
1737 if (!readCryptoKey(value)) | 1757 if (!readCryptoKey(value)) |
1738 return false; | 1758 return false; |
1739 creator.pushObjectReference(*value); | 1759 creator.pushObjectReference(*value); |
1740 break; | 1760 break; |
1761 case CryptoKeyPairTag: | |
1762 if (!readCryptoKeyPair(value)) | |
1763 return false; | |
1764 creator.pushObjectReference(*value); | |
1765 break; | |
1741 case ImageDataTag: | 1766 case ImageDataTag: |
1742 if (!readImageData(value)) | 1767 if (!readImageData(value)) |
1743 return false; | 1768 return false; |
1744 creator.pushObjectReference(*value); | 1769 creator.pushObjectReference(*value); |
1745 break; | 1770 break; |
1746 | 1771 |
1747 case RegExpTag: | 1772 case RegExpTag: |
1748 if (!readRegExp(value)) | 1773 if (!readRegExp(value)) |
1749 return false; | 1774 return false; |
1750 creator.pushObjectReference(*value); | 1775 creator.pushObjectReference(*value); |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2224 if (!file) | 2249 if (!file) |
2225 return false; | 2250 return false; |
2226 fileList->append(file.release()); | 2251 fileList->append(file.release()); |
2227 } | 2252 } |
2228 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); | 2253 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); |
2229 return true; | 2254 return true; |
2230 } | 2255 } |
2231 | 2256 |
2232 bool readCryptoKey(v8::Handle<v8::Value>* value) | 2257 bool readCryptoKey(v8::Handle<v8::Value>* value) |
2233 { | 2258 { |
2259 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | |
2260 if (!readCryptoKey(key)) | |
2261 return false; | |
2262 | |
2263 *value = toV8(Key::create(key), v8::Handle<v8::Object>(), m_isolate); | |
2264 return true; | |
2265 } | |
2266 | |
2267 bool readCryptoKey(blink::WebCryptoKey& key) | |
2268 { | |
2234 uint32_t rawKeyType; | 2269 uint32_t rawKeyType; |
2235 if (!doReadUint32(&rawKeyType)) | 2270 if (!doReadUint32(&rawKeyType)) |
2236 return false; | 2271 return false; |
2237 | 2272 |
2238 blink::WebCryptoKeyAlgorithm algorithm; | 2273 blink::WebCryptoKeyAlgorithm algorithm; |
2239 blink::WebCryptoKeyType type; | 2274 blink::WebCryptoKeyType type; |
2240 | 2275 |
2241 switch (static_cast<CryptoKeySubTag>(rawKeyType)) { | 2276 switch (static_cast<CryptoKeySubTag>(rawKeyType)) { |
2242 case AesKeyTag: | 2277 case AesKeyTag: |
2243 if (!doReadAesKey(algorithm, type)) | 2278 if (!doReadAesKey(algorithm, type)) |
(...skipping 23 matching lines...) Expand all Loading... | |
2267 uint32_t keyDataLength; | 2302 uint32_t keyDataLength; |
2268 if (!doReadUint32(&keyDataLength)) | 2303 if (!doReadUint32(&keyDataLength)) |
2269 return false; | 2304 return false; |
2270 | 2305 |
2271 if (m_position + keyDataLength > m_length) | 2306 if (m_position + keyDataLength > m_length) |
2272 return false; | 2307 return false; |
2273 | 2308 |
2274 const uint8_t* keyData = m_buffer + m_position; | 2309 const uint8_t* keyData = m_buffer + m_position; |
2275 m_position += keyDataLength; | 2310 m_position += keyDataLength; |
2276 | 2311 |
2277 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | |
2278 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( | 2312 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( |
2279 algorithm, type, extractable, usages, keyData, keyDataLength, key)) { | 2313 algorithm, type, extractable, usages, keyData, keyDataLength, key)) { |
2280 return false; | 2314 return false; |
2281 } | 2315 } |
2282 | 2316 |
2283 *value = toV8(Key::create(key), v8::Handle<v8::Object>(), m_isolate); | |
2284 return true; | 2317 return true; |
2285 } | 2318 } |
2286 | 2319 |
2320 bool readCryptoKeyPair(v8::Handle<v8::Value>* value) | |
2321 { | |
2322 blink::WebCryptoKey publicKey = blink::WebCryptoKey::createNull(); | |
2323 blink::WebCryptoKey privateKey = blink::WebCryptoKey::createNull(); | |
2324 | |
2325 if (!readCryptoKey(publicKey) || publicKey.type() != blink::WebCryptoKey TypePublic) | |
2326 return false; | |
2327 if (!readCryptoKey(privateKey) || privateKey.type() != blink::WebCryptoK eyTypePrivate) | |
2328 return false; | |
2329 | |
2330 *value = toV8(KeyPair::create(publicKey, privateKey), v8::Handle<v8::Obj ect>(), m_isolate); | |
2331 return true; | |
2332 } | |
2333 | |
2287 PassRefPtrWillBeRawPtr<File> readFileHelper() | 2334 PassRefPtrWillBeRawPtr<File> readFileHelper() |
2288 { | 2335 { |
2289 if (m_version < 3) | 2336 if (m_version < 3) |
2290 return nullptr; | 2337 return nullptr; |
2291 ASSERT(!m_blobInfo); | 2338 ASSERT(!m_blobInfo); |
2292 String path; | 2339 String path; |
2293 String name; | 2340 String name; |
2294 String relativePath; | 2341 String relativePath; |
2295 String uuid; | 2342 String uuid; |
2296 String type; | 2343 String type; |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3058 // If the allocated memory was not registered before, then this class is lik ely | 3105 // If the allocated memory was not registered before, then this class is lik ely |
3059 // used in a context other then Worker's onmessage environment and the prese nce of | 3106 // used in a context other then Worker's onmessage environment and the prese nce of |
3060 // current v8 context is not guaranteed. Avoid calling v8 then. | 3107 // current v8 context is not guaranteed. Avoid calling v8 then. |
3061 if (m_externallyAllocatedMemory) { | 3108 if (m_externallyAllocatedMemory) { |
3062 ASSERT(v8::Isolate::GetCurrent()); | 3109 ASSERT(v8::Isolate::GetCurrent()); |
3063 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); | 3110 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); |
3064 } | 3111 } |
3065 } | 3112 } |
3066 | 3113 |
3067 } // namespace WebCore | 3114 } // namespace WebCore |
OLD | NEW |