| 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 std::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 static const uint32_t wireFormatVersion = 9; | 76 static const uint32_t wireFormatVersion = 9; |
| 75 | 77 |
| 76 // VarInt encoding constants. | 78 // VarInt encoding constants. |
| 77 static const int varIntShift = 7; | 79 static const int varIntShift = 7; |
| 78 static const int varIntMask = (1 << varIntShift) - 1; | 80 static const int varIntMask = (1 << varIntShift) - 1; |
| 79 | 81 |
| 80 struct SerializeOptions { | 82 struct SerializeOptions { |
| 81 STACK_ALLOCATED(); | 83 STACK_ALLOCATED(); |
| 82 Transferables* transferables = nullptr; | 84 Transferables* transferables = nullptr; |
| 83 WebBlobInfoArray* blobInfo = nullptr; | 85 WebBlobInfoArray* blobInfo = nullptr; |
| 86 bool writeWasmToStream = false; |
| 84 }; | 87 }; |
| 85 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, | 88 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, |
| 86 v8::Local<v8::Value>, | 89 v8::Local<v8::Value>, |
| 87 const SerializeOptions&, | 90 const SerializeOptions&, |
| 88 ExceptionState&); | 91 ExceptionState&); |
| 89 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions( | 92 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions( |
| 90 v8::Isolate*, | 93 v8::Isolate*, |
| 91 v8::Local<v8::Value>); | 94 v8::Local<v8::Value>); |
| 92 | 95 |
| 93 static PassRefPtr<SerializedScriptValue> create(); | 96 static PassRefPtr<SerializedScriptValue> create(); |
| 94 static PassRefPtr<SerializedScriptValue> create(const String&); | 97 static PassRefPtr<SerializedScriptValue> create(const String&); |
| 95 static PassRefPtr<SerializedScriptValue> create(const char* data, | 98 static PassRefPtr<SerializedScriptValue> create(const char* data, |
| 96 size_t length); | 99 size_t length); |
| 97 | 100 |
| 98 ~SerializedScriptValue(); | 101 ~SerializedScriptValue(); |
| 99 | 102 |
| 100 static PassRefPtr<SerializedScriptValue> nullValue(); | 103 static PassRefPtr<SerializedScriptValue> nullValue(); |
| 101 | 104 |
| 102 String toWireString() const; | 105 String toWireString() const; |
| 103 void toWireBytes(Vector<char>&) const; | 106 void toWireBytes(Vector<char>&) const; |
| 104 | 107 |
| 105 // Deserializes the value (in the current context). Returns a null value in | 108 // Deserializes the value (in the current context). Returns a null value in |
| 106 // case of failure. | 109 // case of failure. |
| 107 struct DeserializeOptions { | 110 struct DeserializeOptions { |
| 108 STACK_ALLOCATED(); | 111 STACK_ALLOCATED(); |
| 109 MessagePortArray* messagePorts = nullptr; | 112 MessagePortArray* messagePorts = nullptr; |
| 110 const WebBlobInfoArray* blobInfo = nullptr; | 113 const WebBlobInfoArray* blobInfo = nullptr; |
| 114 bool readWasmFromStream = false; |
| 111 }; | 115 }; |
| 112 v8::Local<v8::Value> deserialize(v8::Isolate* isolate) { | 116 v8::Local<v8::Value> deserialize(v8::Isolate* isolate) { |
| 113 return deserialize(isolate, DeserializeOptions()); | 117 return deserialize(isolate, DeserializeOptions()); |
| 114 } | 118 } |
| 115 v8::Local<v8::Value> deserialize(v8::Isolate*, const DeserializeOptions&); | 119 v8::Local<v8::Value> deserialize(v8::Isolate*, const DeserializeOptions&); |
| 116 | 120 |
| 117 // Helper function which pulls the values out of a JS sequence and into a | 121 // Helper function which pulls the values out of a JS sequence and into a |
| 118 // MessagePortArray. Also validates the elements per sections 4.1.13 and | 122 // MessagePortArray. Also validates the elements per sections 4.1.13 and |
| 119 // 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec and generates | 123 // 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec and generates |
| 120 // exceptions as appropriate. | 124 // exceptions as appropriate. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 size_t dataLengthInBytes() const { return m_dataBufferSize; } | 162 size_t dataLengthInBytes() const { return m_dataBufferSize; } |
| 159 | 163 |
| 160 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } | 164 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } |
| 161 ArrayBufferContentsArray* getArrayBufferContentsArray() { | 165 ArrayBufferContentsArray* getArrayBufferContentsArray() { |
| 162 return m_arrayBufferContentsArray.get(); | 166 return m_arrayBufferContentsArray.get(); |
| 163 } | 167 } |
| 164 ImageBitmapContentsArray* getImageBitmapContentsArray() { | 168 ImageBitmapContentsArray* getImageBitmapContentsArray() { |
| 165 return m_imageBitmapContentsArray.get(); | 169 return m_imageBitmapContentsArray.get(); |
| 166 } | 170 } |
| 167 | 171 |
| 172 TransferredWasmModulesArray& wasmModules() { return m_wasmModules; } |
| 173 |
| 168 private: | 174 private: |
| 169 friend class ScriptValueSerializer; | 175 friend class ScriptValueSerializer; |
| 170 friend class V8ScriptValueSerializer; | 176 friend class V8ScriptValueSerializer; |
| 171 | 177 |
| 172 struct BufferDeleter { | 178 struct BufferDeleter { |
| 173 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); } | 179 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); } |
| 174 }; | 180 }; |
| 175 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>; | 181 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>; |
| 176 | 182 |
| 177 SerializedScriptValue(); | 183 SerializedScriptValue(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 190 ExceptionState&); | 196 ExceptionState&); |
| 191 void transferOffscreenCanvas(v8::Isolate*, | 197 void transferOffscreenCanvas(v8::Isolate*, |
| 192 const OffscreenCanvasArray&, | 198 const OffscreenCanvasArray&, |
| 193 ExceptionState&); | 199 ExceptionState&); |
| 194 | 200 |
| 195 DataBufferPtr m_dataBuffer; | 201 DataBufferPtr m_dataBuffer; |
| 196 size_t m_dataBufferSize = 0; | 202 size_t m_dataBufferSize = 0; |
| 197 | 203 |
| 198 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 204 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 199 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; | 205 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; |
| 206 TransferredWasmModulesArray m_wasmModules; |
| 207 |
| 200 BlobDataHandleMap m_blobDataHandles; | 208 BlobDataHandleMap m_blobDataHandles; |
| 201 | 209 |
| 202 bool m_hasRegisteredExternalAllocation; | 210 bool m_hasRegisteredExternalAllocation; |
| 203 bool m_transferablesNeedExternalAllocationRegistration; | 211 bool m_transferablesNeedExternalAllocationRegistration; |
| 204 }; | 212 }; |
| 205 | 213 |
| 206 template <> | 214 template <> |
| 207 struct NativeValueTraits<SerializedScriptValue> | 215 struct NativeValueTraits<SerializedScriptValue> |
| 208 : public NativeValueTraitsBase<SerializedScriptValue> { | 216 : public NativeValueTraitsBase<SerializedScriptValue> { |
| 209 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( | 217 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( |
| 210 v8::Isolate* isolate, | 218 v8::Isolate* isolate, |
| 211 v8::Local<v8::Value> value, | 219 v8::Local<v8::Value> value, |
| 212 ExceptionState& exceptionState) { | 220 ExceptionState& exceptionState) { |
| 213 return SerializedScriptValue::serialize( | 221 return SerializedScriptValue::serialize( |
| 214 isolate, value, SerializedScriptValue::SerializeOptions(), | 222 isolate, value, SerializedScriptValue::SerializeOptions(), |
| 215 exceptionState); | 223 exceptionState); |
| 216 } | 224 } |
| 217 }; | 225 }; |
| 218 | 226 |
| 219 } // namespace blink | 227 } // namespace blink |
| 220 | 228 |
| 221 #endif // SerializedScriptValue_h | 229 #endif // SerializedScriptValue_h |
| OLD | NEW |