| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 class Transferables; | 46 class Transferables; |
| 47 class ExceptionState; | 47 class ExceptionState; |
| 48 class StaticBitmapImage; | 48 class StaticBitmapImage; |
| 49 class WebBlobInfo; | 49 class WebBlobInfo; |
| 50 | 50 |
| 51 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap; | 51 typedef HashMap<String, RefPtr<BlobDataHandle>> BlobDataHandleMap; |
| 52 typedef Vector<WebBlobInfo> WebBlobInfoArray; | 52 typedef Vector<WebBlobInfo> WebBlobInfoArray; |
| 53 | 53 |
| 54 class CORE_EXPORT SerializedScriptValue : public ThreadSafeRefCounted<Serialized
ScriptValue> { | 54 class CORE_EXPORT SerializedScriptValue : public ThreadSafeRefCounted<Serialized
ScriptValue> { |
| 55 public: | 55 public: |
| 56 using ArrayBufferContentsArray = Vector<WTF::ArrayBufferContents, 1>; |
| 57 using ImageBitmapContentsArray = Vector<RefPtr<StaticBitmapImage>, 1>; |
| 58 |
| 56 // Increment this for each incompatible change to the wire format. | 59 // Increment this for each incompatible change to the wire format. |
| 57 // Version 2: Added StringUCharTag for UChar v8 strings. | 60 // Version 2: Added StringUCharTag for UChar v8 strings. |
| 58 // Version 3: Switched to using uuids as blob data identifiers. | 61 // Version 3: Switched to using uuids as blob data identifiers. |
| 59 // Version 4: Extended File serialization to be complete. | 62 // Version 4: Extended File serialization to be complete. |
| 60 // Version 5: Added CryptoKeyTag for Key objects. | 63 // Version 5: Added CryptoKeyTag for Key objects. |
| 61 // Version 6: Added indexed serialization for File, Blob, and FileList. | 64 // Version 6: Added indexed serialization for File, Blob, and FileList. |
| 62 // Version 7: Extended File serialization with user visibility. | 65 // Version 7: Extended File serialization with user visibility. |
| 63 // Version 8: File.lastModified in milliseconds (seconds-based in earlier ve
rsions.) | 66 // Version 8: File.lastModified in milliseconds (seconds-based in earlier ve
rsions.) |
| 64 // Version 9: Added Map and Set support. | 67 // Version 9: Added Map and Set support. |
| 65 static const uint32_t wireFormatVersion = 9; | 68 static const uint32_t wireFormatVersion = 9; |
| 66 | 69 |
| 67 // VarInt encoding constants. | 70 // VarInt encoding constants. |
| 68 static const int varIntShift = 7; | 71 static const int varIntShift = 7; |
| 69 static const int varIntMask = (1 << varIntShift) - 1; | 72 static const int varIntMask = (1 << varIntShift) - 1; |
| 70 | 73 |
| 71 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, v8::Local<v
8::Value>, Transferables*, WebBlobInfoArray*, ExceptionState&); | 74 static PassRefPtr<SerializedScriptValue> serialize(v8::Isolate*, v8::Local<v
8::Value>, Transferables*, WebBlobInfoArray*, ExceptionState&); |
| 72 static PassRefPtr<SerializedScriptValue> serialize(const String&); | 75 static PassRefPtr<SerializedScriptValue> serialize(const String&); |
| 73 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions(v8::I
solate*, v8::Local<v8::Value>); | 76 static PassRefPtr<SerializedScriptValue> serializeAndSwallowExceptions(v8::I
solate*, v8::Local<v8::Value>); |
| 74 | 77 |
| 75 // TODO(peria): Make these create()s private. | |
| 76 static PassRefPtr<SerializedScriptValue> create(); | 78 static PassRefPtr<SerializedScriptValue> create(); |
| 77 static PassRefPtr<SerializedScriptValue> create(const String&); | 79 static PassRefPtr<SerializedScriptValue> create(const String&); |
| 78 static PassRefPtr<SerializedScriptValue> create(const char* data, size_t len
gth); | 80 static PassRefPtr<SerializedScriptValue> create(const char* data, size_t len
gth); |
| 79 | 81 |
| 80 virtual ~SerializedScriptValue(); | 82 virtual ~SerializedScriptValue(); |
| 81 | 83 |
| 82 static PassRefPtr<SerializedScriptValue> nullValue(); | 84 static PassRefPtr<SerializedScriptValue> nullValue(); |
| 83 | 85 |
| 84 String toWireString() const { return m_data; } | 86 String toWireString() const { return m_data; } |
| 85 void toWireBytes(Vector<char>&) const; | 87 void toWireBytes(Vector<char>&) const; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 97 | 99 |
| 98 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute | 100 // Informs the V8 about external memory allocated and owned by this object.
Large values should contribute |
| 99 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. | 101 // to GC counters to eventually trigger a GC, otherwise flood of postMessage
() can cause OOM. |
| 100 // Ok to invoke multiple times (only adds memory once). | 102 // Ok to invoke multiple times (only adds memory once). |
| 101 // The memory registration is revoked automatically in destructor. | 103 // The memory registration is revoked automatically in destructor. |
| 102 void registerMemoryAllocatedWithCurrentScriptContext(); | 104 void registerMemoryAllocatedWithCurrentScriptContext(); |
| 103 | 105 |
| 104 // Returns true if the value contains a transferable ArrayBuffer. | 106 // Returns true if the value contains a transferable ArrayBuffer. |
| 105 bool containsTransferableArrayBuffer() const; | 107 bool containsTransferableArrayBuffer() const; |
| 106 | 108 |
| 109 String& data() { return m_data; } |
| 110 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } |
| 111 ArrayBufferContentsArray* getArrayBufferContentsArray() { return m_arrayBuff
erContentsArray.get(); } |
| 112 ImageBitmapContentsArray* getImageBitmapContentsArray() { return m_imageBitm
apContentsArray.get(); } |
| 113 |
| 107 private: | 114 private: |
| 108 // The followings are private, but used by SerializedScriptValueFactory. | 115 friend class ScriptValueSerializer; |
| 116 |
| 109 enum StringDataMode { | 117 enum StringDataMode { |
| 110 StringValue, | 118 StringValue, |
| 111 WireData | 119 WireData |
| 112 }; | 120 }; |
| 113 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | |
| 114 typedef Vector<RefPtr<StaticBitmapImage>, 1> ImageBitmapContentsArray; | |
| 115 | 121 |
| 116 SerializedScriptValue(); | 122 SerializedScriptValue(); |
| 117 explicit SerializedScriptValue(const String& wireData); | 123 explicit SerializedScriptValue(const String& wireData); |
| 118 | 124 |
| 119 BlobDataHandleMap& blobDataHandles() { return m_blobDataHandles; } | |
| 120 String& data() { return m_data; } | |
| 121 void setData(const String& data) { m_data = data; } | 125 void setData(const String& data) { m_data = data; } |
| 122 void transferArrayBuffers(v8::Isolate*, const ArrayBufferArray&, ExceptionSt
ate&); | 126 void transferArrayBuffers(v8::Isolate*, const ArrayBufferArray&, ExceptionSt
ate&); |
| 123 void transferImageBitmaps(v8::Isolate*, const ImageBitmapArray&, ExceptionSt
ate&); | 127 void transferImageBitmaps(v8::Isolate*, const ImageBitmapArray&, ExceptionSt
ate&); |
| 124 void transferOffscreenCanvas(v8::Isolate*, const OffscreenCanvasArray&, Exce
ptionState&); | 128 void transferOffscreenCanvas(v8::Isolate*, const OffscreenCanvasArray&, Exce
ptionState&); |
| 125 ArrayBufferContentsArray* getArrayBufferContentsArray() { return m_arrayBuff
erContentsArray.get(); } | |
| 126 ImageBitmapContentsArray* getImageBitmapContentsArray() { return m_imageBitm
apContentsArray.get(); } | |
| 127 | 129 |
| 128 private: | |
| 129 String m_data; | 130 String m_data; |
| 130 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 131 std::unique_ptr<ArrayBufferContentsArray> m_arrayBufferContentsArray; |
| 131 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; | 132 std::unique_ptr<ImageBitmapContentsArray> m_imageBitmapContentsArray; |
| 132 BlobDataHandleMap m_blobDataHandles; | 133 BlobDataHandleMap m_blobDataHandles; |
| 133 intptr_t m_externallyAllocatedMemory; | 134 intptr_t m_externallyAllocatedMemory; |
| 134 | |
| 135 // TODO(peria): remove SerializedScriptValueFactory from friend class | |
| 136 friend class SerializedScriptValueFactory; | |
| 137 friend class ScriptValueSerializer; | |
| 138 }; | 135 }; |
| 139 | 136 |
| 140 } // namespace blink | 137 } // namespace blink |
| 141 | 138 |
| 142 #endif // SerializedScriptValue_h | 139 #endif // SerializedScriptValue_h |
| OLD | NEW |