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, Transferables* transferables, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState) | 15 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create (v8::Isolate* isolate, v8::Local<v8::Value> value, Transferables* 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, Transferables* transferab les, ExceptionState& exceptionState, v8::Isolate* isolate) | |
55 { | |
56 serializedValue->setData(writer.takeWireString()); | |
57 ASSERT(serializedValue->data().impl()->hasOneRef()); | |
58 const auto& offscreenCanvases = static_cast<TransferableOffscreenCanvas*>(tr ansferables)->offscreenCanvases; | |
59 if (offscreenCanvases.size()) { | |
60 for (size_t i = 0; i < offscreenCanvases.size(); i++) { | |
61 if (offscreenCanvases[i]->isNeutered()) { | |
62 exceptionState.throwDOMException(DataCloneError, "OffscreenCanva s at index " + String::number(i) + " is already neutered."); | |
63 return; | |
64 } | |
65 if (offscreenCanvases[i]->renderingContext()) { | |
66 exceptionState.throwDOMException(DataCloneError, "OffscreenCanva s at index " + String::number(i) + " has an associated context."); | |
67 return; | |
68 } | |
69 } | |
70 HeapHashSet<Member<OffscreenCanvas>> visited; | |
71 for (size_t i = 0; i < offscreenCanvases.size(); i++) { | |
haraken
2016/04/19 00:48:10
Can we avoid iterating over offscreenCanvases twic
xidachen
2016/04/19 15:29:50
Done.
| |
72 if (visited.contains(offscreenCanvases[i].get())) | |
73 continue; | |
74 visited.add(offscreenCanvases[i].get()); | |
75 offscreenCanvases[i].get()->setNeutered(); | |
76 } | |
77 } | |
78 SerializedScriptValueFactory::transferData(serializedValue, writer, transfer ables, exceptionState, isolate); | |
79 } | |
80 | |
53 ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerializ e(v8::Local<v8::Value> value, SerializedScriptValueWriter& writer, Transferables * transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessage, v8::Isolate* isolate) | 81 ScriptValueSerializer::Status SerializedScriptValueForModulesFactory::doSerializ e(v8::Local<v8::Value> value, SerializedScriptValueWriter& writer, Transferables * transferables, WebBlobInfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch, String& errorMessage, v8::Isolate* isolate) |
54 { | 82 { |
55 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo, blobDataHandles, tryCatch, ScriptState::current(isolate)); | 83 ScriptValueSerializerForModules serializer(writer, transferables, blobInfo, blobDataHandles, tryCatch, ScriptState::current(isolate)); |
56 ScriptValueSerializer::Status status = serializer.serialize(value); | 84 ScriptValueSerializer::Status status = serializer.serialize(value); |
57 errorMessage = serializer.errorMessage(); | 85 errorMessage = serializer.errorMessage(); |
58 return status; | 86 return status; |
59 } | 87 } |
60 | 88 |
61 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String& data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 89 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(String& data, BlobDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBuffer ContentsArray, ImageBitmapContentsArray* imageBitmapContentsArray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
62 { | 90 { |
63 if (!data.impl()) | 91 if (!data.impl()) |
64 return v8::Null(isolate); | 92 return v8::Null(isolate); |
65 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes"); | 93 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes"); |
66 data.ensure16Bit(); | 94 data.ensure16Bit(); |
67 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 95 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
68 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 96 // 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, | 97 // 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. | 98 // 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)); | 99 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); | 100 ScriptValueDeserializerForModules deserializer(reader, messagePorts, arrayBu fferContentsArray, imageBitmapContentsArray); |
73 return deserializer.deserialize(); | 101 return deserializer.deserialize(); |
74 } | 102 } |
75 | 103 |
76 } // namespace blink | 104 } // namespace blink |
77 | 105 |
OLD | NEW |