| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 class WebBlobInfo; | 53 class WebBlobInfo; |
| 54 | 54 |
| 55 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap; | 55 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap; |
| 56 typedef Vector<WebBlobInfo> WebBlobInfoArray; | 56 typedef Vector<WebBlobInfo> WebBlobInfoArray; |
| 57 | 57 |
| 58 class CORE_EXPORT SerializedScriptValue | 58 class CORE_EXPORT SerializedScriptValue |
| 59 : public ThreadSafeRefCounted<SerializedScriptValue> { | 59 : public ThreadSafeRefCounted<SerializedScriptValue> { |
| 60 public: | 60 public: |
| 61 using ArrayBufferContentsArray = Vector<WTF::ArrayBufferContents, 1>; | 61 using ArrayBufferContentsArray = Vector<WTF::ArrayBufferContents, 1>; |
| 62 using ImageBitmapContentsArray = Vector<RefPtr<StaticBitmapImage>, 1>; | 62 using ImageBitmapContentsArray = Vector<RefPtr<StaticBitmapImage>, 1>; |
| 63 using TransferredWasmModulesArray = |
| 64 WTF::Vector<v8::WasmCompiledModule::TransferrableModule>; |
| 63 | 65 |
| 64 // Increment this for each incompatible change to the wire format. | 66 // Increment this for each incompatible change to the wire format. |
| 65 // Version 2: Added StringUCharTag for UChar v8 strings. | 67 // Version 2: Added StringUCharTag for UChar v8 strings. |
| 66 // Version 3: Switched to using uuids as blob data identifiers. | 68 // Version 3: Switched to using uuids as blob data identifiers. |
| 67 // Version 4: Extended File serialization to be complete. | 69 // Version 4: Extended File serialization to be complete. |
| 68 // Version 5: Added CryptoKeyTag for Key objects. | 70 // Version 5: Added CryptoKeyTag for Key objects. |
| 69 // Version 6: Added indexed serialization for File, Blob, and FileList. | 71 // Version 6: Added indexed serialization for File, Blob, and FileList. |
| 70 // Version 7: Extended File serialization with user visibility. | 72 // Version 7: Extended File serialization with user visibility. |
| 71 // Version 8: File.lastModified in milliseconds (seconds-based in earlier | 73 // Version 8: File.lastModified in milliseconds (seconds-based in earlier |
| 72 // versions.) | 74 // versions.) |
| 73 // Version 9: Added Map and Set support. | 75 // Version 9: Added Map and Set support. |
| 74 // [versions skipped] | 76 // [versions skipped] |
| 75 // Version 16: Separate versioning between V8 and Blink. | 77 // Version 16: Separate versioning between V8 and Blink. |
| 76 static const uint32_t wireFormatVersion = 16; | 78 static const uint32_t wireFormatVersion = 16; |
| 77 | 79 |
| 78 struct SerializeOptions { | 80 struct SerializeOptions { |
| 79 STACK_ALLOCATED(); | 81 STACK_ALLOCATED(); |
| 80 Transferables* transferables = nullptr; | 82 Transferables* transferables = nullptr; |
| 81 WebBlobInfoArray* blobInfo = nullptr; | 83 WebBlobInfoArray* blobInfo = nullptr; |
| 84 bool writeWasmToStream = false; |
| 82 }; | 85 }; |
| 83 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, | 86 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, |
| 84 v8::Local<v8::Value>, | 87 v8::Local<v8::Value>, |
| 85 const SerializeOptions&, | 88 const SerializeOptions&, |
| 86 ExceptionState&); | 89 ExceptionState&); |
| 87 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions( | 90 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions( |
| 88 v8::Isolate*, | 91 v8::Isolate*, |
| 89 v8::Local<v8::Value>); | 92 v8::Local<v8::Value>); |
| 90 | 93 |
| 91 static PassRefPtr<SerializedScriptValue> create(); | 94 static PassRefPtr<SerializedScriptValue> create(); |
| 92 static PassRefPtr<SerializedScriptValue> create(const String&); | 95 static PassRefPtr<SerializedScriptValue> create(const String&); |
| 93 static PassRefPtr<SerializedScriptValue> create(const char* data, | 96 static PassRefPtr<SerializedScriptValue> create(const char* data, |
| 94 size_t length); | 97 size_t length); |
| 95 | 98 |
| 96 ~SerializedScriptValue(); | 99 ~SerializedScriptValue(); |
| 97 | 100 |
| 98 static PassRefPtr<SerializedScriptValue> nullValue(); | 101 static PassRefPtr<SerializedScriptValue> nullValue(); |
| 99 | 102 |
| 100 String toWireString() const; | 103 String toWireString() const; |
| 101 void toWireBytes(Vector<char>&) const; | 104 void toWireBytes(Vector<char>&) const; |
| 102 | 105 |
| 103 // Deserializes the value (in the current context). Returns a null value in | 106 // Deserializes the value (in the current context). Returns a null value in |
| 104 // case of failure. | 107 // case of failure. |
| 105 struct DeserializeOptions { | 108 struct DeserializeOptions { |
| 106 STACK_ALLOCATED(); | 109 STACK_ALLOCATED(); |
| 107 MessagePortArray* messagePorts = nullptr; | 110 MessagePortArray* messagePorts = nullptr; |
| 108 const WebBlobInfoArray* blobInfo = nullptr; | 111 const WebBlobInfoArray* blobInfo = nullptr; |
| 112 bool readWasmFromStream = false; |
| 109 }; | 113 }; |
| 110 v8::Local<v8::Value> deserialize(v8::Isolate* isolate) { | 114 v8::Local<v8::Value> deserialize(v8::Isolate* isolate) { |
| 111 return deserialize(isolate, DeserializeOptions()); | 115 return deserialize(isolate, DeserializeOptions()); |
| 112 } | 116 } |
| 113 v8::Local<v8::Value> deserialize(v8::Isolate*, const DeserializeOptions&); | 117 v8::Local<v8::Value> deserialize(v8::Isolate*, const DeserializeOptions&); |
| 114 | 118 |
| 115 // Helper function which pulls the values out of a JS sequence and into a | 119 // Helper function which pulls the values out of a JS sequence and into a |
| 116 // MessagePortArray. Also validates the elements per sections 4.1.13 and | 120 // MessagePortArray. Also validates the elements per sections 4.1.13 and |
| 117 // 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec and generates | 121 // 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec and generates |
| 118 // exceptions as appropriate. | 122 // exceptions as appropriate. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 size_t dataLengthInBytes() const { return m_dataBufferSize; } | 160 size_t dataLengthInBytes() const { return m_dataBufferSize; } |
| 157 | 161 |
| 158 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } | 162 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } |
| 159 ArrayBufferContentsArray* getArrayBufferContentsArray() { | 163 ArrayBufferContentsArray* getArrayBufferContentsArray() { |
| 160 return m_arrayBufferContentsArray.get(); | 164 return m_arrayBufferContentsArray.get(); |
| 161 } | 165 } |
| 162 ImageBitmapContentsArray* getImageBitmapContentsArray() { | 166 ImageBitmapContentsArray* getImageBitmapContentsArray() { |
| 163 return m_imageBitmapContentsArray.get(); | 167 return m_imageBitmapContentsArray.get(); |
| 164 } | 168 } |
| 165 | 169 |
| 170 TransferredWasmModulesArray& wasmModules() { return m_wasmModules; } |
| 171 |
| 166 private: | 172 private: |
| 167 friend class ScriptValueSerializer; | 173 friend class ScriptValueSerializer; |
| 168 friend class V8ScriptValueSerializer; | 174 friend class V8ScriptValueSerializer; |
| 169 | 175 |
| 170 struct BufferDeleter { | 176 struct BufferDeleter { |
| 171 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); } | 177 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); } |
| 172 }; | 178 }; |
| 173 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>; | 179 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>; |
| 174 | 180 |
| 175 SerializedScriptValue(); | 181 SerializedScriptValue(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 188 ExceptionState&); | 194 ExceptionState&); |
| 189 void transferOffscreenCanvas(v8::Isolate*, | 195 void transferOffscreenCanvas(v8::Isolate*, |
| 190 const OffscreenCanvasArray&, | 196 const OffscreenCanvasArray&, |
| 191 ExceptionState&); | 197 ExceptionState&); |
| 192 | 198 |
| 193 DataBufferPtr m_dataBuffer; | 199 DataBufferPtr m_dataBuffer; |
| 194 size_t m_dataBufferSize = 0; | 200 size_t m_dataBufferSize = 0; |
| 195 | 201 |
| 196 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 202 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 197 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; | 203 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; |
| 204 TransferredWasmModulesArray m_wasmModules; |
| 205 |
| 198 BlobDataHandleMap m_blobDataHandles; | 206 BlobDataHandleMap m_blobDataHandles; |
| 199 | 207 |
| 200 bool m_hasRegisteredExternalAllocation; | 208 bool m_hasRegisteredExternalAllocation; |
| 201 bool m_transferablesNeedExternalAllocationRegistration; | 209 bool m_transferablesNeedExternalAllocationRegistration; |
| 202 }; | 210 }; |
| 203 | 211 |
| 204 template <> | 212 template <> |
| 205 struct NativeValueTraits<SerializedScriptValue> | 213 struct NativeValueTraits<SerializedScriptValue> |
| 206 : public NativeValueTraitsBase<SerializedScriptValue> { | 214 : public NativeValueTraitsBase<SerializedScriptValue> { |
| 207 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( | 215 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( |
| 208 v8::Isolate* isolate, | 216 v8::Isolate* isolate, |
| 209 v8::Local<v8::Value> value, | 217 v8::Local<v8::Value> value, |
| 210 ExceptionState& exceptionState) { | 218 ExceptionState& exceptionState) { |
| 211 return SerializedScriptValue::serialize( | 219 return SerializedScriptValue::serialize( |
| 212 isolate, value, SerializedScriptValue::SerializeOptions(), | 220 isolate, value, SerializedScriptValue::SerializeOptions(), |
| 213 exceptionState); | 221 exceptionState); |
| 214 } | 222 } |
| 215 }; | 223 }; |
| 216 | 224 |
| 217 } // namespace blink | 225 } // namespace blink |
| 218 | 226 |
| 219 #endif // SerializedScriptValue_h | 227 #endif // SerializedScriptValue_h |
| OLD | NEW |