Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/SerializedScriptValueForModulesFactory.cpp

Issue 2359363005: Support Blob on the V8-based structured clone path. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/serialization/V8ScriptValueDeserializerForModules. h" 10 #include "bindings/modules/v8/serialization/V8ScriptValueDeserializerForModules. h"
11 #include "bindings/modules/v8/serialization/V8ScriptValueSerializerForModules.h" 11 #include "bindings/modules/v8/serialization/V8ScriptValueSerializerForModules.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create (v8::Isolate* isolate, v8::Local<v8::Value> value, Transferables* transferables, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState) 16 PassRefPtr<SerializedScriptValue> SerializedScriptValueForModulesFactory::create (v8::Isolate* isolate, v8::Local<v8::Value> value, Transferables* transferables, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState)
17 { 17 {
18 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { 18 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) {
19 V8ScriptValueSerializerForModules serializer(ScriptState::current(isolat e)); 19 V8ScriptValueSerializerForModules serializer(ScriptState::current(isolat e));
20 serializer.setBlobInfoArray(blobInfo);
20 return serializer.serialize(value, transferables, exceptionState); 21 return serializer.serialize(value, transferables, exceptionState);
21 } 22 }
22 SerializedScriptValueWriterForModules writer; 23 SerializedScriptValueWriterForModules writer;
23 ScriptValueSerializerForModules serializer(writer, blobInfo, ScriptState::cu rrent(isolate)); 24 ScriptValueSerializerForModules serializer(writer, blobInfo, ScriptState::cu rrent(isolate));
24 return serializer.serialize(value, transferables, exceptionState); 25 return serializer.serialize(value, transferables, exceptionState);
25 } 26 }
26 27
27 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(Seriali zedScriptValue* value, v8::Isolate* isolate, MessagePortArray* messagePorts, con st WebBlobInfoArray* blobInfo) 28 v8::Local<v8::Value> SerializedScriptValueForModulesFactory::deserialize(Seriali zedScriptValue* value, v8::Isolate* isolate, MessagePortArray* messagePorts, con st WebBlobInfoArray* blobInfo)
28 { 29 {
29 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { 30 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) {
30 V8ScriptValueDeserializerForModules deserializer(ScriptState::current(is olate), value); 31 V8ScriptValueDeserializerForModules deserializer(ScriptState::current(is olate), value);
31 deserializer.setTransferredMessagePorts(messagePorts); 32 deserializer.setTransferredMessagePorts(messagePorts);
33 deserializer.setBlobInfoArray(blobInfo);
32 return deserializer.deserialize(); 34 return deserializer.deserialize();
33 } 35 }
34 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed. 36 // deserialize() can run arbitrary script (e.g., setters), which could resul t in |this| being destroyed.
35 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation. 37 // Holding a RefPtr ensures we are alive (along with our internal data) thro ughout the operation.
36 RefPtr<SerializedScriptValue> protect(value); 38 RefPtr<SerializedScriptValue> protect(value);
37 String& data = value->data(); 39 String& data = value->data();
38 if (!data.impl()) 40 if (!data.impl())
39 return v8::Null(isolate); 41 return v8::Null(isolate);
40 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes"); 42 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu fferValueType should be 2 bytes");
41 data.ensure16Bit(); 43 data.ensure16Bit();
42 // FIXME: SerializedScriptValue shouldn't use String for its underlying 44 // FIXME: SerializedScriptValue shouldn't use String for its underlying
43 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The 45 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The
44 // information stored in m_data isn't even encoded in UTF-16. Instead, 46 // information stored in m_data isn't even encoded in UTF-16. Instead,
45 // unicode characters are encoded as UTF-8 with two code units per UChar. 47 // unicode characters are encoded as UTF-8 with two code units per UChar.
46 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t* >(data.impl()->characters16()), 2 * data.length(), blobInfo, value->blobDataHand les(), ScriptState::current(isolate)); 48 SerializedScriptValueReaderForModules reader(reinterpret_cast<const uint8_t* >(data.impl()->characters16()), 2 * data.length(), blobInfo, value->blobDataHand les(), ScriptState::current(isolate));
47 ScriptValueDeserializerForModules deserializer(reader, messagePorts, value-> getArrayBufferContentsArray(), value->getImageBitmapContentsArray()); 49 ScriptValueDeserializerForModules deserializer(reader, messagePorts, value-> getArrayBufferContentsArray(), value->getImageBitmapContentsArray());
48 return deserializer.deserialize(); 50 return deserializer.deserialize();
49 } 51 }
50 52
51 } // namespace blink 53 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializerTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698