| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "bindings/core/v8/ScriptValueSerializer.h" | 6 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/V8ArrayBuffer.h" | 8 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 9 #include "bindings/core/v8/V8ArrayBufferView.h" | 9 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 10 #include "bindings/core/v8/V8Blob.h" | 10 #include "bindings/core/v8/V8Blob.h" |
| 11 #include "bindings/core/v8/V8CompositorProxy.h" |
| 11 #include "bindings/core/v8/V8File.h" | 12 #include "bindings/core/v8/V8File.h" |
| 12 #include "bindings/core/v8/V8FileList.h" | 13 #include "bindings/core/v8/V8FileList.h" |
| 13 #include "bindings/core/v8/V8ImageData.h" | 14 #include "bindings/core/v8/V8ImageData.h" |
| 14 #include "bindings/core/v8/V8MessagePort.h" | 15 #include "bindings/core/v8/V8MessagePort.h" |
| 16 #include "core/dom/CompositorProxy.h" |
| 15 #include "core/dom/DOMDataView.h" | 17 #include "core/dom/DOMDataView.h" |
| 16 #include "core/fileapi/Blob.h" | 18 #include "core/fileapi/Blob.h" |
| 17 #include "core/fileapi/File.h" | 19 #include "core/fileapi/File.h" |
| 18 #include "core/fileapi/FileList.h" | 20 #include "core/fileapi/FileList.h" |
| 19 #include "public/platform/Platform.h" | 21 #include "public/platform/Platform.h" |
| 20 #include "public/platform/WebBlobInfo.h" | 22 #include "public/platform/WebBlobInfo.h" |
| 21 #include "wtf/DateMath.h" | 23 #include "wtf/DateMath.h" |
| 22 #include "wtf/text/StringHash.h" | 24 #include "wtf/text/StringHash.h" |
| 23 #include "wtf/text/StringUTF8Adaptor.h" | 25 #include "wtf/text/StringUTF8Adaptor.h" |
| 24 | 26 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 doWriteUint64(size); | 193 doWriteUint64(size); |
| 192 } | 194 } |
| 193 | 195 |
| 194 void SerializedScriptValueWriter::writeBlobIndex(int blobIndex) | 196 void SerializedScriptValueWriter::writeBlobIndex(int blobIndex) |
| 195 { | 197 { |
| 196 ASSERT(blobIndex >= 0); | 198 ASSERT(blobIndex >= 0); |
| 197 append(BlobIndexTag); | 199 append(BlobIndexTag); |
| 198 doWriteUint32(blobIndex); | 200 doWriteUint32(blobIndex); |
| 199 } | 201 } |
| 200 | 202 |
| 203 void SerializedScriptValueWriter::writeCompositorProxy(const CompositorProxy& co
mpositorProxy) |
| 204 { |
| 205 append(CompositorProxyTag); |
| 206 doWriteUint64(compositorProxy.elementId()); |
| 207 doWriteUint32(compositorProxy.bitfieldsSupported()); |
| 208 } |
| 209 |
| 201 void SerializedScriptValueWriter::writeFile(const File& file) | 210 void SerializedScriptValueWriter::writeFile(const File& file) |
| 202 { | 211 { |
| 203 append(FileTag); | 212 append(FileTag); |
| 204 doWriteFile(file); | 213 doWriteFile(file); |
| 205 } | 214 } |
| 206 | 215 |
| 207 void SerializedScriptValueWriter::writeFileIndex(int blobIndex) | 216 void SerializedScriptValueWriter::writeFileIndex(int blobIndex) |
| 208 { | 217 { |
| 209 append(FileIndexTag); | 218 append(FileIndexTag); |
| 210 doWriteUint32(blobIndex); | 219 doWriteUint32(blobIndex); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } else if (V8Blob::hasInstance(value, isolate())) { | 711 } else if (V8Blob::hasInstance(value, isolate())) { |
| 703 return writeBlob(value, next); | 712 return writeBlob(value, next); |
| 704 } else if (V8FileList::hasInstance(value, isolate())) { | 713 } else if (V8FileList::hasInstance(value, isolate())) { |
| 705 return writeFileList(value, next); | 714 return writeFileList(value, next); |
| 706 } else if (V8ImageData::hasInstance(value, isolate())) { | 715 } else if (V8ImageData::hasInstance(value, isolate())) { |
| 707 writeImageData(value); | 716 writeImageData(value); |
| 708 } else if (value->IsRegExp()) { | 717 } else if (value->IsRegExp()) { |
| 709 writeRegExp(value); | 718 writeRegExp(value); |
| 710 } else if (V8ArrayBuffer::hasInstance(value, isolate())) { | 719 } else if (V8ArrayBuffer::hasInstance(value, isolate())) { |
| 711 return writeArrayBuffer(value, next); | 720 return writeArrayBuffer(value, next); |
| 721 } else if (V8CompositorProxy::hasInstance(value, isolate())) { |
| 722 return writeCompositorProxy(value, next); |
| 712 } else if (value->IsObject()) { | 723 } else if (value->IsObject()) { |
| 713 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) | 724 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) |
| 714 return handleError(DataCloneError, "An object could not be clone
d.", next); | 725 return handleError(DataCloneError, "An object could not be clone
d.", next); |
| 715 return startObjectState(jsObject, next); | 726 return startObjectState(jsObject, next); |
| 716 } else { | 727 } else { |
| 717 return handleError(DataCloneError, "A value could not be cloned.", n
ext); | 728 return handleError(DataCloneError, "A value could not be cloned.", n
ext); |
| 718 } | 729 } |
| 719 } | 730 } |
| 720 return 0; | 731 return 0; |
| 721 } | 732 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 return handleError(DataCloneError, "A Blob object has been closed, and c
ould therefore not be cloned.", next); | 824 return handleError(DataCloneError, "A Blob object has been closed, and c
ould therefore not be cloned.", next); |
| 814 int blobIndex = -1; | 825 int blobIndex = -1; |
| 815 m_blobDataHandles.set(blob->uuid(), blob->blobDataHandle()); | 826 m_blobDataHandles.set(blob->uuid(), blob->blobDataHandle()); |
| 816 if (appendBlobInfo(blob->uuid(), blob->type(), blob->size(), &blobIndex)) | 827 if (appendBlobInfo(blob->uuid(), blob->type(), blob->size(), &blobIndex)) |
| 817 m_writer.writeBlobIndex(blobIndex); | 828 m_writer.writeBlobIndex(blobIndex); |
| 818 else | 829 else |
| 819 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); | 830 m_writer.writeBlob(blob->uuid(), blob->type(), blob->size()); |
| 820 return 0; | 831 return 0; |
| 821 } | 832 } |
| 822 | 833 |
| 834 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeCompositorProxy(v8
::Local<v8::Value> value, ScriptValueSerializer::StateBase* next) |
| 835 { |
| 836 CompositorProxy* compositorProxy = V8CompositorProxy::toImpl(value.As<v8::Ob
ject>()); |
| 837 if (!compositorProxy) |
| 838 return nullptr; |
| 839 m_writer.writeCompositorProxy(*compositorProxy); |
| 840 return nullptr; |
| 841 } |
| 842 |
| 823 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeFile(v8::Local<v8:
:Value> value, ScriptValueSerializer::StateBase* next) | 843 ScriptValueSerializer::StateBase* ScriptValueSerializer::writeFile(v8::Local<v8:
:Value> value, ScriptValueSerializer::StateBase* next) |
| 824 { | 844 { |
| 825 File* file = V8File::toImpl(value.As<v8::Object>()); | 845 File* file = V8File::toImpl(value.As<v8::Object>()); |
| 826 if (!file) | 846 if (!file) |
| 827 return 0; | 847 return 0; |
| 828 if (file->hasBeenClosed()) | 848 if (file->hasBeenClosed()) |
| 829 return handleError(DataCloneError, "A File object has been closed, and c
ould therefore not be cloned.", next); | 849 return handleError(DataCloneError, "A File object has been closed, and c
ould therefore not be cloned.", next); |
| 830 int blobIndex = -1; | 850 int blobIndex = -1; |
| 831 m_blobDataHandles.set(file->uuid(), file->blobDataHandle()); | 851 m_blobDataHandles.set(file->uuid(), file->blobDataHandle()); |
| 832 if (appendFileInfo(file, &blobIndex)) { | 852 if (appendFileInfo(file, &blobIndex)) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 if (!readFile(value, tag == FileIndexTag)) | 1110 if (!readFile(value, tag == FileIndexTag)) |
| 1091 return false; | 1111 return false; |
| 1092 creator.pushObjectReference(*value); | 1112 creator.pushObjectReference(*value); |
| 1093 break; | 1113 break; |
| 1094 case FileListTag: | 1114 case FileListTag: |
| 1095 case FileListIndexTag: | 1115 case FileListIndexTag: |
| 1096 if (!readFileList(value, tag == FileListIndexTag)) | 1116 if (!readFileList(value, tag == FileListIndexTag)) |
| 1097 return false; | 1117 return false; |
| 1098 creator.pushObjectReference(*value); | 1118 creator.pushObjectReference(*value); |
| 1099 break; | 1119 break; |
| 1120 case CompositorProxyTag: |
| 1121 if (!readCompositorProxy(value)) |
| 1122 return false; |
| 1123 creator.pushObjectReference(*value); |
| 1124 break; |
| 1125 |
| 1100 case ImageDataTag: | 1126 case ImageDataTag: |
| 1101 if (!readImageData(value)) | 1127 if (!readImageData(value)) |
| 1102 return false; | 1128 return false; |
| 1103 creator.pushObjectReference(*value); | 1129 creator.pushObjectReference(*value); |
| 1104 break; | 1130 break; |
| 1105 | 1131 |
| 1106 case RegExpTag: | 1132 case RegExpTag: |
| 1107 if (!readRegExp(value)) | 1133 if (!readRegExp(value)) |
| 1108 return false; | 1134 return false; |
| 1109 creator.pushObjectReference(*value); | 1135 creator.pushObjectReference(*value); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 RefPtrWillBeRawPtr<ImageData> imageData = ImageData::create(IntSize(width, h
eight)); | 1401 RefPtrWillBeRawPtr<ImageData> imageData = ImageData::create(IntSize(width, h
eight)); |
| 1376 DOMUint8ClampedArray* pixelArray = imageData->data(); | 1402 DOMUint8ClampedArray* pixelArray = imageData->data(); |
| 1377 ASSERT(pixelArray); | 1403 ASSERT(pixelArray); |
| 1378 ASSERT(pixelArray->length() >= pixelDataLength); | 1404 ASSERT(pixelArray->length() >= pixelDataLength); |
| 1379 memcpy(pixelArray->data(), m_buffer + m_position, pixelDataLength); | 1405 memcpy(pixelArray->data(), m_buffer + m_position, pixelDataLength); |
| 1380 m_position += pixelDataLength; | 1406 m_position += pixelDataLength; |
| 1381 *value = toV8(imageData.release(), m_scriptState->context()->Global(), isola
te()); | 1407 *value = toV8(imageData.release(), m_scriptState->context()->Global(), isola
te()); |
| 1382 return true; | 1408 return true; |
| 1383 } | 1409 } |
| 1384 | 1410 |
| 1411 bool SerializedScriptValueReader::readCompositorProxy(v8::Local<v8::Value>* valu
e) |
| 1412 { |
| 1413 uint32_t attributes; |
| 1414 uint64_t element; |
| 1415 if (!doReadUint64(&element)) |
| 1416 return false; |
| 1417 if (!doReadUint32(&attributes)) |
| 1418 return false; |
| 1419 |
| 1420 CompositorProxy* compositorProxy = CompositorProxy::create(element, attribut
es); |
| 1421 *value = toV8(compositorProxy, m_scriptState->context()->Global(), isolate()
); |
| 1422 return true; |
| 1423 } |
| 1424 |
| 1385 PassRefPtr<DOMArrayBuffer> SerializedScriptValueReader::doReadArrayBuffer() | 1425 PassRefPtr<DOMArrayBuffer> SerializedScriptValueReader::doReadArrayBuffer() |
| 1386 { | 1426 { |
| 1387 uint32_t byteLength; | 1427 uint32_t byteLength; |
| 1388 if (!doReadUint32(&byteLength)) | 1428 if (!doReadUint32(&byteLength)) |
| 1389 return nullptr; | 1429 return nullptr; |
| 1390 if (m_position + byteLength > m_length) | 1430 if (m_position + byteLength > m_length) |
| 1391 return nullptr; | 1431 return nullptr; |
| 1392 const void* bufferStart = m_buffer + m_position; | 1432 const void* bufferStart = m_buffer + m_position; |
| 1393 m_position += byteLength; | 1433 m_position += byteLength; |
| 1394 return DOMArrayBuffer::create(bufferStart, byteLength); | 1434 return DOMArrayBuffer::create(bufferStart, byteLength); |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 return false; | 1924 return false; |
| 1885 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; | 1925 uint32_t objectReference = m_openCompositeReferenceStack[m_openCompositeRefe
renceStack.size() - 1]; |
| 1886 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); | 1926 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() -
1); |
| 1887 if (objectReference >= m_objectPool.size()) | 1927 if (objectReference >= m_objectPool.size()) |
| 1888 return false; | 1928 return false; |
| 1889 *object = m_objectPool[objectReference]; | 1929 *object = m_objectPool[objectReference]; |
| 1890 return true; | 1930 return true; |
| 1891 } | 1931 } |
| 1892 | 1932 |
| 1893 } // namespace blink | 1933 } // namespace blink |
| OLD | NEW |