OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/core/v8/serialization/V8ScriptValueSerializer.h" | 5 #include "bindings/core/v8/serialization/V8ScriptValueSerializer.h" |
6 | 6 |
7 #include "bindings/core/v8/ToV8.h" | 7 #include "bindings/core/v8/ToV8.h" |
| 8 #include "bindings/core/v8/V8Blob.h" |
8 #include "bindings/core/v8/V8ImageBitmap.h" | 9 #include "bindings/core/v8/V8ImageBitmap.h" |
9 #include "bindings/core/v8/V8ImageData.h" | 10 #include "bindings/core/v8/V8ImageData.h" |
10 #include "bindings/core/v8/V8MessagePort.h" | 11 #include "bindings/core/v8/V8MessagePort.h" |
11 #include "bindings/core/v8/V8OffscreenCanvas.h" | 12 #include "bindings/core/v8/V8OffscreenCanvas.h" |
12 #include "core/dom/DOMArrayBufferBase.h" | 13 #include "core/dom/DOMArrayBufferBase.h" |
13 #include "core/html/ImageData.h" | 14 #include "core/html/ImageData.h" |
14 #include "platform/RuntimeEnabledFeatures.h" | 15 #include "platform/RuntimeEnabledFeatures.h" |
| 16 #include "public/platform/WebBlobInfo.h" |
15 #include "wtf/AutoReset.h" | 17 #include "wtf/AutoReset.h" |
16 #include "wtf/text/StringUTF8Adaptor.h" | 18 #include "wtf/text/StringUTF8Adaptor.h" |
17 | 19 |
18 namespace blink { | 20 namespace blink { |
19 | 21 |
20 V8ScriptValueSerializer::V8ScriptValueSerializer(RefPtr<ScriptState> scriptState
) | 22 V8ScriptValueSerializer::V8ScriptValueSerializer(RefPtr<ScriptState> scriptState
) |
21 : m_scriptState(std::move(scriptState)) | 23 : m_scriptState(std::move(scriptState)) |
22 , m_serializedScriptValue(SerializedScriptValue::create()) | 24 , m_serializedScriptValue(SerializedScriptValue::create()) |
23 , m_serializer(m_scriptState->isolate(), this) | 25 , m_serializer(m_scriptState->isolate(), this) |
24 { | 26 { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // StringUTF8Adaptor trick doesn't yet work with StringView. | 118 // StringUTF8Adaptor trick doesn't yet work with StringView. |
117 StringUTF8Adaptor utf8(string); | 119 StringUTF8Adaptor utf8(string); |
118 DCHECK_LT(utf8.length(), std::numeric_limits<uint32_t>::max()); | 120 DCHECK_LT(utf8.length(), std::numeric_limits<uint32_t>::max()); |
119 writeUint32(utf8.length()); | 121 writeUint32(utf8.length()); |
120 writeRawBytes(utf8.data(), utf8.length()); | 122 writeRawBytes(utf8.data(), utf8.length()); |
121 } | 123 } |
122 | 124 |
123 bool V8ScriptValueSerializer::writeDOMObject(ScriptWrappable* wrappable, Excepti
onState& exceptionState) | 125 bool V8ScriptValueSerializer::writeDOMObject(ScriptWrappable* wrappable, Excepti
onState& exceptionState) |
124 { | 126 { |
125 const WrapperTypeInfo* wrapperTypeInfo = wrappable->wrapperTypeInfo(); | 127 const WrapperTypeInfo* wrapperTypeInfo = wrappable->wrapperTypeInfo(); |
| 128 if (wrapperTypeInfo == &V8Blob::wrapperTypeInfo) { |
| 129 Blob* blob = wrappable->toImpl<Blob>(); |
| 130 if (blob->isClosed()) { |
| 131 exceptionState.throwDOMException(DataCloneError, |
| 132 "A Blob object has been closed, and could therefore not be clone
d."); |
| 133 return false; |
| 134 } |
| 135 m_serializedScriptValue->blobDataHandles().set(blob->uuid(), blob->blobD
ataHandle()); |
| 136 if (m_blobInfoArray) { |
| 137 size_t index = m_blobInfoArray->size(); |
| 138 DCHECK_LE(index, std::numeric_limits<uint32_t>::max()); |
| 139 m_blobInfoArray->emplaceAppend(blob->uuid(), blob->type(), blob->siz
e()); |
| 140 writeTag(BlobIndexTag); |
| 141 writeUint32(static_cast<uint32_t>(index)); |
| 142 } else { |
| 143 writeTag(BlobTag); |
| 144 writeUTF8String(blob->uuid()); |
| 145 writeUTF8String(blob->type()); |
| 146 writeUint64(blob->size()); |
| 147 } |
| 148 return true; |
| 149 } |
126 if (wrapperTypeInfo == &V8ImageBitmap::wrapperTypeInfo) { | 150 if (wrapperTypeInfo == &V8ImageBitmap::wrapperTypeInfo) { |
127 ImageBitmap* imageBitmap = wrappable->toImpl<ImageBitmap>(); | 151 ImageBitmap* imageBitmap = wrappable->toImpl<ImageBitmap>(); |
128 if (imageBitmap->isNeutered()) { | 152 if (imageBitmap->isNeutered()) { |
129 exceptionState.throwDOMException(DataCloneError, | 153 exceptionState.throwDOMException(DataCloneError, |
130 "An ImageBitmap is detached and could not be cloned."); | 154 "An ImageBitmap is detached and could not be cloned."); |
131 return false; | 155 return false; |
132 } | 156 } |
133 | 157 |
134 // If this ImageBitmap was transferred, it can be serialized by index. | 158 // If this ImageBitmap was transferred, it can be serialized by index. |
135 size_t index = kNotFound; | 159 size_t index = kNotFound; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return v8::Just(true); | 263 return v8::Just(true); |
240 } | 264 } |
241 if (!exceptionState.hadException()) { | 265 if (!exceptionState.hadException()) { |
242 String interface = wrappable->wrapperTypeInfo()->interfaceName; | 266 String interface = wrappable->wrapperTypeInfo()->interfaceName; |
243 exceptionState.throwDOMException(DataCloneError, interface + " object co
uld not be cloned."); | 267 exceptionState.throwDOMException(DataCloneError, interface + " object co
uld not be cloned."); |
244 } | 268 } |
245 return v8::Nothing<bool>(); | 269 return v8::Nothing<bool>(); |
246 } | 270 } |
247 | 271 |
248 } // namespace blink | 272 } // namespace blink |
OLD | NEW |