| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef SerializedScriptValue_h | 31 #ifndef SerializedScriptValue_h |
| 32 #define SerializedScriptValue_h | 32 #define SerializedScriptValue_h |
| 33 | 33 |
| 34 #include <memory> | 34 #include <memory> |
| 35 | 35 |
| 36 #include "bindings/core/v8/NativeValueTraits.h" | 36 #include "bindings/core/v8/NativeValueTraits.h" |
| 37 #include "bindings/core/v8/ScriptValue.h" | 37 #include "bindings/core/v8/ScriptValue.h" |
| 38 #include "bindings/core/v8/Transferables.h" | 38 #include "bindings/core/v8/Transferables.h" |
| 39 #include "bindings/core/v8/serialization/LongStringCollection.h" |
| 39 #include "core/CoreExport.h" | 40 #include "core/CoreExport.h" |
| 40 #include "v8/include/v8.h" | 41 #include "v8/include/v8.h" |
| 41 #include "wtf/Allocator.h" | 42 #include "wtf/Allocator.h" |
| 42 #include "wtf/HashMap.h" | 43 #include "wtf/HashMap.h" |
| 43 #include "wtf/ThreadSafeRefCounted.h" | 44 #include "wtf/ThreadSafeRefCounted.h" |
| 44 #include "wtf/allocator/Partitions.h" | 45 #include "wtf/allocator/Partitions.h" |
| 45 #include "wtf/typed_arrays/ArrayBufferContents.h" | 46 #include "wtf/typed_arrays/ArrayBufferContents.h" |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 74 static const uint32_t wireFormatVersion = 9; | 75 static const uint32_t wireFormatVersion = 9; |
| 75 | 76 |
| 76 // VarInt encoding constants. | 77 // VarInt encoding constants. |
| 77 static const int varIntShift = 7; | 78 static const int varIntShift = 7; |
| 78 static const int varIntMask = (1 << varIntShift) - 1; | 79 static const int varIntMask = (1 << varIntShift) - 1; |
| 79 | 80 |
| 80 struct SerializeOptions { | 81 struct SerializeOptions { |
| 81 STACK_ALLOCATED(); | 82 STACK_ALLOCATED(); |
| 82 Transferables* transferables = nullptr; | 83 Transferables* transferables = nullptr; |
| 83 WebBlobInfoArray* blobInfo = nullptr; | 84 WebBlobInfoArray* blobInfo = nullptr; |
| 85 LongStringPolicy longStringPolicy; |
| 84 }; | 86 }; |
| 85 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, | 87 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, |
| 86 v8::Local<v8::Value>, | 88 v8::Local<v8::Value>, |
| 87 const SerializeOptions&, | 89 const SerializeOptions&, |
| 88 ExceptionState&); | 90 ExceptionState&); |
| 89 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions( | 91 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions( |
| 90 v8::Isolate*, | 92 v8::Isolate*, |
| 91 v8::Local<v8::Value>); | 93 v8::Local<v8::Value>); |
| 92 | 94 |
| 93 static PassRefPtr<SerializedScriptValue> create(); | 95 static PassRefPtr<SerializedScriptValue> create(); |
| 96 static PassRefPtr<SerializedScriptValue> create(LongStringPolicy); |
| 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; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 const uint8_t* data() const { return m_dataBuffer.get(); } | 160 const uint8_t* data() const { return m_dataBuffer.get(); } |
| 158 size_t dataLengthInBytes() const { return m_dataBufferSize; } | 161 size_t dataLengthInBytes() const { return m_dataBufferSize; } |
| 159 | 162 |
| 160 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } | 163 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } |
| 161 ArrayBufferContentsArray* getArrayBufferContentsArray() { | 164 ArrayBufferContentsArray* getArrayBufferContentsArray() { |
| 162 return m_arrayBufferContentsArray.get(); | 165 return m_arrayBufferContentsArray.get(); |
| 163 } | 166 } |
| 164 ImageBitmapContentsArray* getImageBitmapContentsArray() { | 167 ImageBitmapContentsArray* getImageBitmapContentsArray() { |
| 165 return m_imageBitmapContentsArray.get(); | 168 return m_imageBitmapContentsArray.get(); |
| 166 } | 169 } |
| 170 const LongStringCollection& longStrings() { return m_longStrings; } |
| 167 | 171 |
| 168 private: | 172 private: |
| 169 friend class ScriptValueSerializer; | 173 friend class ScriptValueSerializer; |
| 170 friend class V8ScriptValueSerializer; | 174 friend class V8ScriptValueSerializer; |
| 171 | 175 |
| 172 struct BufferDeleter { | 176 struct BufferDeleter { |
| 173 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); } | 177 void operator()(uint8_t* buffer) { WTF::Partitions::bufferFree(buffer); } |
| 174 }; | 178 }; |
| 175 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>; | 179 using DataBufferPtr = std::unique_ptr<uint8_t[], BufferDeleter>; |
| 176 | 180 |
| 177 SerializedScriptValue(); | 181 SerializedScriptValue(); |
| 182 explicit SerializedScriptValue(LongStringPolicy); |
| 178 explicit SerializedScriptValue(const String& wireData); | 183 explicit SerializedScriptValue(const String& wireData); |
| 179 | 184 |
| 180 void setData(DataBufferPtr data, size_t size) { | 185 void setData(DataBufferPtr data, size_t size) { |
| 181 m_dataBuffer = std::move(data); | 186 m_dataBuffer = std::move(data); |
| 182 m_dataBufferSize = size; | 187 m_dataBufferSize = size; |
| 183 } | 188 } |
| 184 | 189 |
| 185 void transferArrayBuffers(v8::Isolate*, | 190 void transferArrayBuffers(v8::Isolate*, |
| 186 const ArrayBufferArray&, | 191 const ArrayBufferArray&, |
| 187 ExceptionState&); | 192 ExceptionState&); |
| 188 void transferImageBitmaps(v8::Isolate*, | 193 void transferImageBitmaps(v8::Isolate*, |
| 189 const ImageBitmapArray&, | 194 const ImageBitmapArray&, |
| 190 ExceptionState&); | 195 ExceptionState&); |
| 191 void transferOffscreenCanvas(v8::Isolate*, | 196 void transferOffscreenCanvas(v8::Isolate*, |
| 192 const OffscreenCanvasArray&, | 197 const OffscreenCanvasArray&, |
| 193 ExceptionState&); | 198 ExceptionState&); |
| 194 | 199 |
| 195 DataBufferPtr m_dataBuffer; | 200 DataBufferPtr m_dataBuffer; |
| 196 size_t m_dataBufferSize = 0; | 201 size_t m_dataBufferSize = 0; |
| 197 | 202 |
| 198 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 203 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 199 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; | 204 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; |
| 200 BlobDataHandleMap m_blobDataHandles; | 205 BlobDataHandleMap m_blobDataHandles; |
| 206 LongStringCollection m_longStrings; |
| 201 | 207 |
| 202 bool m_hasRegisteredExternalAllocation; | 208 bool m_hasRegisteredExternalAllocation; |
| 203 bool m_transferablesNeedExternalAllocationRegistration; | 209 bool m_transferablesNeedExternalAllocationRegistration; |
| 204 }; | 210 }; |
| 205 | 211 |
| 206 template <> | 212 template <> |
| 207 struct NativeValueTraits<SerializedScriptValue> | 213 struct NativeValueTraits<SerializedScriptValue> |
| 208 : public NativeValueTraitsBase<SerializedScriptValue> { | 214 : public NativeValueTraitsBase<SerializedScriptValue> { |
| 209 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( | 215 CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue( |
| 210 v8::Isolate* isolate, | 216 v8::Isolate* isolate, |
| 211 v8::Local<v8::Value> value, | 217 v8::Local<v8::Value> value, |
| 212 ExceptionState& exceptionState) { | 218 ExceptionState& exceptionState) { |
| 213 return SerializedScriptValue::serialize( | 219 return SerializedScriptValue::serialize( |
| 214 isolate, value, SerializedScriptValue::SerializeOptions(), | 220 isolate, value, SerializedScriptValue::SerializeOptions(), |
| 215 exceptionState); | 221 exceptionState); |
| 216 } | 222 } |
| 217 }; | 223 }; |
| 218 | 224 |
| 219 } // namespace blink | 225 } // namespace blink |
| 220 | 226 |
| 221 #endif // SerializedScriptValue_h | 227 #endif // SerializedScriptValue_h |
| OLD | NEW |