Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Henry Mason (hmason@mac.com) | 2 * Copyright (C) 2007 Henry Mason (hmason@mac.com) |
| 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights |
| 4 * reserved. | 4 * reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 * | 26 * |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #ifndef MessageEvent_h | 29 #ifndef MessageEvent_h |
| 30 #define MessageEvent_h | 30 #define MessageEvent_h |
| 31 | 31 |
| 32 #include <memory> | 32 #include <memory> |
| 33 #include "bindings/core/v8/SerializedScriptValue.h" | 33 #include "bindings/core/v8/SerializedScriptValue.h" |
| 34 #include "bindings/core/v8/TraceWrapperV8Reference.h" | |
| 34 #include "core/CoreExport.h" | 35 #include "core/CoreExport.h" |
| 35 #include "core/dom/DOMArrayBuffer.h" | 36 #include "core/dom/DOMArrayBuffer.h" |
| 36 #include "core/dom/MessagePort.h" | 37 #include "core/dom/MessagePort.h" |
| 37 #include "core/events/Event.h" | 38 #include "core/events/Event.h" |
| 38 #include "core/events/EventTarget.h" | 39 #include "core/events/EventTarget.h" |
| 39 #include "core/events/MessageEventInit.h" | 40 #include "core/events/MessageEventInit.h" |
| 40 #include "core/fileapi/Blob.h" | 41 #include "core/fileapi/Blob.h" |
| 41 #include "platform/wtf/Compiler.h" | 42 #include "platform/wtf/Compiler.h" |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 const String& lastEventId() const { return last_event_id_; } | 123 const String& lastEventId() const { return last_event_id_; } |
| 123 EventTarget* source() const { return source_.Get(); } | 124 EventTarget* source() const { return source_.Get(); } |
| 124 MessagePortArray ports(bool& is_null) const; | 125 MessagePortArray ports(bool& is_null) const; |
| 125 MessagePortArray ports() const; | 126 MessagePortArray ports() const; |
| 126 | 127 |
| 127 MessagePortChannelArray ReleaseChannels() { return std::move(channels_); } | 128 MessagePortChannelArray ReleaseChannels() { return std::move(channels_); } |
| 128 | 129 |
| 129 const AtomicString& InterfaceName() const override; | 130 const AtomicString& InterfaceName() const override; |
| 130 | 131 |
| 131 enum DataType { | 132 enum DataType { |
| 132 kDataTypeScriptValue, | 133 kDataTypeV8Reference, |
| 133 kDataTypeSerializedScriptValue, | 134 kDataTypeSerializedScriptValue, |
| 134 kDataTypeString, | 135 kDataTypeString, |
| 135 kDataTypeBlob, | 136 kDataTypeBlob, |
| 136 kDataTypeArrayBuffer | 137 kDataTypeArrayBuffer |
| 137 }; | 138 }; |
| 138 DataType GetDataType() const { return data_type_; } | 139 DataType GetDataType() const { return data_type_; } |
| 139 ScriptValue DataAsScriptValue() const { | 140 ScriptValue DataAsScriptValue(ScriptState*) const; |
| 140 DCHECK_EQ(data_type_, kDataTypeScriptValue); | |
| 141 return data_as_script_value_; | |
| 142 } | |
| 143 SerializedScriptValue* DataAsSerializedScriptValue() const { | 141 SerializedScriptValue* DataAsSerializedScriptValue() const { |
| 144 DCHECK_EQ(data_type_, kDataTypeSerializedScriptValue); | 142 DCHECK_EQ(data_type_, kDataTypeSerializedScriptValue); |
| 145 return data_as_serialized_script_value_.Get(); | 143 return data_as_serialized_script_value_.Get(); |
| 146 } | 144 } |
| 147 String DataAsString() const { | 145 String DataAsString() const { |
| 148 DCHECK_EQ(data_type_, kDataTypeString); | 146 DCHECK_EQ(data_type_, kDataTypeString); |
| 149 return data_as_string_; | 147 return data_as_string_; |
| 150 } | 148 } |
| 151 Blob* DataAsBlob() const { | 149 Blob* DataAsBlob() const { |
| 152 DCHECK_EQ(data_type_, kDataTypeBlob); | 150 DCHECK_EQ(data_type_, kDataTypeBlob); |
| 153 return data_as_blob_.Get(); | 151 return data_as_blob_.Get(); |
| 154 } | 152 } |
| 155 DOMArrayBuffer* DataAsArrayBuffer() const { | 153 DOMArrayBuffer* DataAsArrayBuffer() const { |
| 156 DCHECK_EQ(data_type_, kDataTypeArrayBuffer); | 154 DCHECK_EQ(data_type_, kDataTypeArrayBuffer); |
| 157 return data_as_array_buffer_.Get(); | 155 return data_as_array_buffer_.Get(); |
| 158 } | 156 } |
| 159 | 157 |
| 160 void SetSerializedData(PassRefPtr<SerializedScriptValue> data) { | 158 void SetSerializedData(PassRefPtr<SerializedScriptValue> data) { |
| 161 DCHECK(!data_as_serialized_script_value_); | 159 DCHECK(!data_as_serialized_script_value_); |
| 162 data_as_serialized_script_value_ = std::move(data); | 160 data_as_serialized_script_value_ = std::move(data); |
| 163 } | 161 } |
| 164 | 162 |
| 165 void EntangleMessagePorts(ExecutionContext*); | 163 void EntangleMessagePorts(ExecutionContext*); |
| 166 | 164 |
| 167 DECLARE_VIRTUAL_TRACE(); | 165 DECLARE_VIRTUAL_TRACE(); |
| 168 | 166 |
| 167 DECLARE_VIRTUAL_TRACE_WRAPPERS(); | |
| 168 | |
| 169 WARN_UNUSED_RESULT v8::Local<v8::Object> AssociateWithWrapper( | 169 WARN_UNUSED_RESULT v8::Local<v8::Object> AssociateWithWrapper( |
| 170 v8::Isolate*, | 170 v8::Isolate*, |
| 171 const WrapperTypeInfo*, | 171 const WrapperTypeInfo*, |
| 172 v8::Local<v8::Object> wrapper) override; | 172 v8::Local<v8::Object> wrapper) override; |
| 173 | 173 |
| 174 private: | 174 private: |
| 175 MessageEvent(); | 175 MessageEvent(); |
| 176 MessageEvent(const AtomicString&, const MessageEventInit&); | 176 MessageEvent(const AtomicString&, const MessageEventInit&); |
| 177 MessageEvent(const String& origin, | 177 MessageEvent(const String& origin, |
| 178 const String& last_event_id, | 178 const String& last_event_id, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 194 | 194 |
| 195 MessageEvent(const String& data, | 195 MessageEvent(const String& data, |
| 196 const String& origin, | 196 const String& origin, |
| 197 const String& suborigin); | 197 const String& suborigin); |
| 198 MessageEvent(Blob* data, const String& origin, const String& suborigin); | 198 MessageEvent(Blob* data, const String& origin, const String& suborigin); |
| 199 MessageEvent(DOMArrayBuffer* data, | 199 MessageEvent(DOMArrayBuffer* data, |
| 200 const String& origin, | 200 const String& origin, |
| 201 const String& suborigin); | 201 const String& suborigin); |
| 202 | 202 |
| 203 DataType data_type_; | 203 DataType data_type_; |
| 204 ScriptValue data_as_script_value_; | 204 TraceWrapperV8Reference<v8::Value> data_as_v8_value_reference_; |
|
haraken
2017/05/02 08:10:14
In a follow-up CL, I'd prefer introducing:
Worl
bashi
2017/05/02 08:46:22
Agreed that we should have such class or mechanism
| |
| 205 RefPtr<SerializedScriptValue> data_as_serialized_script_value_; | 205 RefPtr<SerializedScriptValue> data_as_serialized_script_value_; |
| 206 String data_as_string_; | 206 String data_as_string_; |
| 207 Member<Blob> data_as_blob_; | 207 Member<Blob> data_as_blob_; |
| 208 Member<DOMArrayBuffer> data_as_array_buffer_; | 208 Member<DOMArrayBuffer> data_as_array_buffer_; |
| 209 String origin_; | 209 String origin_; |
| 210 String last_event_id_; | 210 String last_event_id_; |
| 211 Member<EventTarget> source_; | 211 Member<EventTarget> source_; |
| 212 // m_ports are the MessagePorts in an entangled state, and m_channels are | 212 // m_ports are the MessagePorts in an entangled state, and m_channels are |
| 213 // the MessageChannels in a disentangled state. Only one of them can be | 213 // the MessageChannels in a disentangled state. Only one of them can be |
| 214 // non-empty at a time. entangleMessagePorts() moves between the states. | 214 // non-empty at a time. entangleMessagePorts() moves between the states. |
| 215 Member<MessagePortArray> ports_; | 215 Member<MessagePortArray> ports_; |
| 216 MessagePortChannelArray channels_; | 216 MessagePortChannelArray channels_; |
| 217 String suborigin_; | 217 String suborigin_; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 } // namespace blink | 220 } // namespace blink |
| 221 | 221 |
| 222 #endif // MessageEvent_h | 222 #endif // MessageEvent_h |
| OLD | NEW |