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/core/v8/SerializedScriptValueFactory.h" | 5 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptValueSerializer.h" | 8 #include "bindings/core/v8/ScriptValueSerializer.h" |
9 #include "bindings/core/v8/Transferables.h" | 9 #include "bindings/core/v8/Transferables.h" |
10 #include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h" | 10 #include "bindings/core/v8/serialization/V8ScriptValueDeserializer.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 v8::Isolate* isolate, | 41 v8::Isolate* isolate, |
42 MessagePortArray* messagePorts, | 42 MessagePortArray* messagePorts, |
43 const WebBlobInfoArray* blobInfo) { | 43 const WebBlobInfoArray* blobInfo) { |
44 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { | 44 if (RuntimeEnabledFeatures::v8BasedStructuredCloneEnabled()) { |
45 V8ScriptValueDeserializer deserializer(ScriptState::current(isolate), | 45 V8ScriptValueDeserializer deserializer(ScriptState::current(isolate), |
46 value); | 46 value); |
47 deserializer.setTransferredMessagePorts(messagePorts); | 47 deserializer.setTransferredMessagePorts(messagePorts); |
48 deserializer.setBlobInfoArray(blobInfo); | 48 deserializer.setBlobInfoArray(blobInfo); |
49 return deserializer.deserialize(); | 49 return deserializer.deserialize(); |
50 } | 50 } |
51 // deserialize() can run arbitrary script (e.g., setters), which could result
in |this| being destroyed. | 51 // deserialize() can run arbitrary script (e.g., setters), which could result |
52 // Holding a RefPtr ensures we are alive (along with our internal data) throug
hout the operation. | 52 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along |
| 53 // with our internal data) throughout the operation. |
53 RefPtr<SerializedScriptValue> protect(value); | 54 RefPtr<SerializedScriptValue> protect(value); |
54 String& data = value->data(); | 55 String& data = value->data(); |
55 if (!data.impl()) | 56 if (!data.impl()) |
56 return v8::Null(isolate); | 57 return v8::Null(isolate); |
57 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, | 58 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, |
58 "BufferValueType should be 2 bytes"); | 59 "BufferValueType should be 2 bytes"); |
59 data.ensure16Bit(); | 60 data.ensure16Bit(); |
60 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 61 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
61 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 62 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
62 // information stored in m_data isn't even encoded in UTF-16. Instead, | 63 // information stored in m_data isn't even encoded in UTF-16. Instead, |
63 // unicode characters are encoded as UTF-8 with two code units per UChar. | 64 // unicode characters are encoded as UTF-8 with two code units per UChar. |
64 SerializedScriptValueReader reader( | 65 SerializedScriptValueReader reader( |
65 reinterpret_cast<const uint8_t*>(data.impl()->characters16()), | 66 reinterpret_cast<const uint8_t*>(data.impl()->characters16()), |
66 2 * data.length(), blobInfo, value->blobDataHandles(), | 67 2 * data.length(), blobInfo, value->blobDataHandles(), |
67 ScriptState::current(isolate)); | 68 ScriptState::current(isolate)); |
68 ScriptValueDeserializer deserializer(reader, messagePorts, | 69 ScriptValueDeserializer deserializer(reader, messagePorts, |
69 value->getArrayBufferContentsArray(), | 70 value->getArrayBufferContentsArray(), |
70 value->getImageBitmapContentsArray()); | 71 value->getImageBitmapContentsArray()); |
71 | 72 |
72 // deserialize() can run arbitrary script (e.g., setters), which could result
in |this| being destroyed. | 73 // deserialize() can run arbitrary script (e.g., setters), which could result |
73 // Holding a RefPtr ensures we are alive (along with our internal data) throug
hout the operation. | 74 // in |this| being destroyed. Holding a RefPtr ensures we are alive (along |
| 75 // with our internal data) throughout the operation. |
74 return deserializer.deserialize(); | 76 return deserializer.deserialize(); |
75 } | 77 } |
76 | 78 |
77 } // namespace blink | 79 } // namespace blink |
OLD | NEW |