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 "bindings/modules/v8/SerializedScriptValueForModulesFactory.h" | 5 #include "bindings/modules/v8/SerializedScriptValueForModulesFactory.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/SerializedScriptValue.h" | 8 #include "bindings/core/v8/SerializedScriptValue.h" |
9 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" | 9 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" |
| 10 #include "bindings/modules/v8/TransferableOffscreenCanvas.h" |
10 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
(v8::Isolate* isolate, v8::Local<v8::Value> value, MessagePortArray* messagePort
s, TransferableArray* transferables, WebBlobInfoArray* blobInfo, ExceptionState&
exceptionState) | 15 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
(v8::Isolate* isolate, v8::Local<v8::Value> value, MessagePortArray* messagePort
s, TransferableArray* transferables, WebBlobInfoArray* blobInfo, ExceptionState&
exceptionState) |
15 { | 16 { |
16 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValueFactory
::create(); | 17 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValueFactory
::create(); |
17 SerializedScriptValueWriterForModules writer; | 18 SerializedScriptValueWriterForModules writer; |
18 ScriptValueSerializer::Status status; | 19 ScriptValueSerializer::Status status; |
19 String errorMessage; | 20 String errorMessage; |
(...skipping 23 matching lines...) Expand all Loading... |
43 } | 44 } |
44 | 45 |
45 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
(v8::Isolate* isolate, const String& data) | 46 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create
(v8::Isolate* isolate, const String& data) |
46 { | 47 { |
47 SerializedScriptValueWriterForModules writer; | 48 SerializedScriptValueWriterForModules writer; |
48 writer.writeWebCoreString(data); | 49 writer.writeWebCoreString(data); |
49 String wireData = writer.takeWireString(); | 50 String wireData = writer.takeWireString(); |
50 return createFromWire(wireData); | 51 return createFromWire(wireData); |
51 } | 52 } |
52 | 53 |
| 54 void SerializedScriptValueForModulesFactory::transferData(SerializedScriptValue*
serializedValue, SerializedScriptValueWriter& writer, TransferableArray* transf
erables, ExceptionState& exceptionState, v8::Isolate* isolate) |
| 55 { |
| 56 serializedValue->setData(writer.takeWireString()); |
| 57 ASSERT(serializedValue->data().impl()->hasOneRef()); |
| 58 if (!transferables) |
| 59 return; |
| 60 if (auto* transferableOffscreenCanvases = TransferableOffscreenCanvas::get(*
transferables)) { |
| 61 HeapVector<Member<OffscreenCanvas>, 1> offscreenCanvases = transferableO
ffscreenCanvases->getArray(); |
| 62 if (offscreenCanvases.size()) { |
| 63 for (size_t i = 0; i < offscreenCanvases.size(); i++) { |
| 64 if (offscreenCanvases[i]->isNeutered()) { |
| 65 exceptionState.throwDOMException(DataCloneError, "OffscreenC
anvas at index " + String::number(i) + " is already neutered."); |
| 66 return; |
| 67 } |
| 68 if (offscreenCanvases[i]->renderingContext()) { |
| 69 exceptionState.throwDOMException(DataCloneError, "OffscreenC
anvas at index " + String::number(i) + " has an associated context."); |
| 70 return; |
| 71 } |
| 72 } |
| 73 HeapHashSet<Member<OffscreenCanvas>> visited; |
| 74 for (size_t i = 0; i < offscreenCanvases.size(); i++) { |
| 75 if (visited.contains(offscreenCanvases[i].get())) |
| 76 continue; |
| 77 visited.add(offscreenCanvases[i].get()); |
| 78 offscreenCanvases[i].get()->setNeutered(); |
| 79 } |
| 80 } |
| 81 } |
| 82 SerializedScriptValueFactory::transferData(serializedValue, writer, transfer
ables, exceptionState, isolate); |
| 83 } |
| 84 |
53 ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerializ
e(v8::Local<v8::Value> value, SerializedScriptValueWriter& writer, MessagePortAr
ray* messagePorts, TransferableArray* transferables, WebBlobInfoArray* blobInfo,
BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessag
e, v8::Isolate* isolate) | 85 ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerializ
e(v8::Local<v8::Value> value, SerializedScriptValueWriter& writer, MessagePortAr
ray* messagePorts, TransferableArray* transferables, WebBlobInfoArray* blobInfo,
BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessag
e, v8::Isolate* isolate) |
54 { | 86 { |
55 ScriptValueSerializerForModules serializer(writer, messagePorts, transferabl
es, blobInfo, blobDataHandles, tryCatch, ScriptState::current(isolate)); | 87 ScriptValueSerializerForModules serializer(writer, messagePorts, transferabl
es, blobInfo, blobDataHandles, tryCatch, ScriptState::current(isolate)); |
56 ScriptValueSerializer::Status status = serializer.serialize(value); | 88 ScriptValueSerializer::Status status = serializer.serialize(value); |
57 errorMessage = serializer.errorMessage(); | 89 errorMessage = serializer.errorMessage(); |
58 return status; | 90 return status; |
59 } | 91 } |
60 | 92 |
61 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String&
data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer
ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate*
isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 93 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String&
data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer
ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate*
isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
62 { | 94 { |
63 if (!data.impl()) | 95 if (!data.impl()) |
64 return v8::Null(isolate); | 96 return v8::Null(isolate); |
65 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu
fferValueType should be 2 bytes"); | 97 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu
fferValueType should be 2 bytes"); |
66 data.ensure16Bit(); | 98 data.ensure16Bit(); |
67 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 99 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
68 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 100 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
69 // information stored in m_data isn't even encoded in UTF-16. Instead, | 101 // information stored in m_data isn't even encoded in UTF-16. Instead, |
70 // unicode characters are encoded as UTF-8 with two code units per UChar. | 102 // unicode characters are encoded as UTF-8 with two code units per UChar. |
71 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t*
>(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc
riptState::current(isolate)); | 103 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t*
>(data.impl()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, Sc
riptState::current(isolate)); |
72 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); | 104 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu
fferContentsArray, imageBitmapContentsArray); |
73 return deserializer.deserialize(); | 105 return deserializer.deserialize(); |
74 } | 106 } |
75 | 107 |
76 } // namespace blink | 108 } // namespace blink |
77 | 109 |
OLD | NEW |