| 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 reserv
ed. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv
ed. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #ifndef MessageEvent_h | 28 #ifndef MessageEvent_h |
| 29 #define MessageEvent_h | 29 #define MessageEvent_h |
| 30 | 30 |
| 31 #include "bindings/core/v8/SerializedScriptValue.h" | 31 #include "bindings/core/v8/SerializedScriptValue.h" |
| 32 #include "core/CoreExport.h" | 32 #include "core/CoreExport.h" |
| 33 #include "core/dom/DOMArrayBuffer.h" | 33 #include "core/dom/DOMArrayBuffer.h" |
| 34 #include "core/dom/MessagePort.h" | 34 #include "core/dom/MessagePort.h" |
| 35 #include "core/events/Event.h" | 35 #include "core/events/Event.h" |
| 36 #include "core/events/EventTarget.h" | 36 #include "core/events/EventTarget.h" |
| 37 #include "core/events/MessageEventInit.h" |
| 37 #include "core/fileapi/Blob.h" | 38 #include "core/fileapi/Blob.h" |
| 38 #include "core/frame/DOMWindow.h" | 39 #include "core/frame/DOMWindow.h" |
| 39 | 40 |
| 40 namespace blink { | 41 namespace blink { |
| 41 | 42 |
| 42 struct MessageEventInit : public EventInit { | |
| 43 MessageEventInit(); | |
| 44 | |
| 45 String origin; | |
| 46 String lastEventId; | |
| 47 RefPtrWillBeMember<EventTarget> source; | |
| 48 MessagePortArray ports; | |
| 49 }; | |
| 50 | |
| 51 class CORE_EXPORT MessageEvent final : public Event { | 43 class CORE_EXPORT MessageEvent final : public Event { |
| 52 DEFINE_WRAPPERTYPEINFO(); | 44 DEFINE_WRAPPERTYPEINFO(); |
| 53 public: | 45 public: |
| 54 static PassRefPtrWillBeRawPtr<MessageEvent> create() | 46 static PassRefPtrWillBeRawPtr<MessageEvent> create() |
| 55 { | 47 { |
| 56 return adoptRefWillBeNoop(new MessageEvent); | 48 return adoptRefWillBeNoop(new MessageEvent); |
| 57 } | 49 } |
| 58 static PassRefPtrWillBeRawPtr<MessageEvent> create(PassOwnPtrWillBeRawPtr<Me
ssagePortArray> ports, const String& origin = String(), const String& lastEventI
d = String(), PassRefPtrWillBeRawPtr<EventTarget> source = nullptr) | 50 static PassRefPtrWillBeRawPtr<MessageEvent> create(PassOwnPtrWillBeRawPtr<Me
ssagePortArray> ports, const String& origin = String(), const String& lastEventI
d = String(), PassRefPtrWillBeRawPtr<EventTarget> source = nullptr) |
| 59 { | 51 { |
| 60 return adoptRefWillBeNoop(new MessageEvent(origin, lastEventId, source,
ports)); | 52 return adoptRefWillBeNoop(new MessageEvent(origin, lastEventId, source,
ports)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 { | 67 { |
| 76 return adoptRefWillBeNoop(new MessageEvent(data, origin)); | 68 return adoptRefWillBeNoop(new MessageEvent(data, origin)); |
| 77 } | 69 } |
| 78 static PassRefPtrWillBeRawPtr<MessageEvent> create(PassRefPtr<DOMArrayBuffer
> data, const String& origin = String()) | 70 static PassRefPtrWillBeRawPtr<MessageEvent> create(PassRefPtr<DOMArrayBuffer
> data, const String& origin = String()) |
| 79 { | 71 { |
| 80 return adoptRefWillBeNoop(new MessageEvent(data, origin)); | 72 return adoptRefWillBeNoop(new MessageEvent(data, origin)); |
| 81 } | 73 } |
| 82 static PassRefPtrWillBeRawPtr<MessageEvent> create(const AtomicString& type,
const MessageEventInit& initializer, ExceptionState&); | 74 static PassRefPtrWillBeRawPtr<MessageEvent> create(const AtomicString& type,
const MessageEventInit& initializer, ExceptionState&); |
| 83 virtual ~MessageEvent(); | 75 virtual ~MessageEvent(); |
| 84 | 76 |
| 85 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, const String& origin, const String& lastEventId, DOMWindow* source, PassOwn
PtrWillBeRawPtr<MessagePortArray>); | 77 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, ScriptValue data, const String& origin, const String& lastEventId, DOMWindo
w* source, PassOwnPtrWillBeRawPtr<MessagePortArray>); |
| 86 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String&
lastEventId, DOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray>); | 78 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String&
lastEventId, DOMWindow* source, PassOwnPtrWillBeRawPtr<MessagePortArray>); |
| 87 | 79 |
| 88 const String& origin() const { return m_origin; } | 80 const String& origin() const { return m_origin; } |
| 89 const String& lastEventId() const { return m_lastEventId; } | 81 const String& lastEventId() const { return m_lastEventId; } |
| 90 EventTarget* source() const { return m_source.get(); } | 82 EventTarget* source() const { return m_source.get(); } |
| 91 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra
y(); } | 83 MessagePortArray ports(bool& isNull) const; |
| 84 MessagePortArray ports() const; |
| 92 MessagePortChannelArray* channels() const { return m_channels ? m_channels.g
et() : 0; } | 85 MessagePortChannelArray* channels() const { return m_channels ? m_channels.g
et() : 0; } |
| 93 | 86 |
| 94 virtual const AtomicString& interfaceName() const override; | 87 virtual const AtomicString& interfaceName() const override; |
| 95 | 88 |
| 96 enum DataType { | 89 enum DataType { |
| 97 DataTypeScriptValue, | 90 DataTypeScriptValue, |
| 98 DataTypeSerializedScriptValue, | 91 DataTypeSerializedScriptValue, |
| 99 DataTypeString, | 92 DataTypeString, |
| 100 DataTypeBlob, | 93 DataTypeBlob, |
| 101 DataTypeArrayBuffer | 94 DataTypeArrayBuffer |
| 102 }; | 95 }; |
| 103 DataType dataType() const { return m_dataType; } | 96 DataType dataType() const { return m_dataType; } |
| 104 SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataTy
pe == DataTypeScriptValue || m_dataType == DataTypeSerializedScriptValue); retur
n m_dataAsSerializedScriptValue.get(); } | 97 ScriptValue dataAsScriptValue() const { ASSERT(m_dataType == DataTypeScriptV
alue); return m_dataAsScriptValue; } |
| 98 SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataTy
pe == DataTypeSerializedScriptValue); return m_dataAsSerializedScriptValue.get()
; } |
| 105 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } | 99 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } |
| 106 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data
AsBlob.get(); } | 100 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data
AsBlob.get(); } |
| 107 DOMArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArr
ayBuffer); return m_dataAsArrayBuffer.get(); } | 101 DOMArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArr
ayBuffer); return m_dataAsArrayBuffer.get(); } |
| 108 | 102 |
| 109 void setSerializedData(PassRefPtr<SerializedScriptValue> data) | 103 void setSerializedData(PassRefPtr<SerializedScriptValue> data) |
| 110 { | 104 { |
| 111 ASSERT(!m_dataAsSerializedScriptValue); | 105 ASSERT(!m_dataAsSerializedScriptValue); |
| 112 m_dataAsSerializedScriptValue = data; | 106 m_dataAsSerializedScriptValue = data; |
| 113 } | 107 } |
| 114 | 108 |
| 115 void entangleMessagePorts(ExecutionContext*); | 109 void entangleMessagePorts(ExecutionContext*); |
| 116 | 110 |
| 117 DECLARE_VIRTUAL_TRACE(); | 111 DECLARE_VIRTUAL_TRACE(); |
| 118 | 112 |
| 119 virtual v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const Wrapp
erTypeInfo*, v8::Local<v8::Object> wrapper) override; | 113 virtual v8::Local<v8::Object> associateWithWrapper(v8::Isolate*, const Wrapp
erTypeInfo*, v8::Local<v8::Object> wrapper) override; |
| 120 | 114 |
| 121 private: | 115 private: |
| 122 MessageEvent(); | 116 MessageEvent(); |
| 123 MessageEvent(const AtomicString&, const MessageEventInit&); | 117 MessageEvent(const AtomicString&, const MessageEventInit&); |
| 124 MessageEvent(const String& origin, const String& lastEventId, PassRefPtrWill
BeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray>); | 118 MessageEvent(const String& origin, const String& lastEventId, PassRefPtrWill
BeRawPtr<EventTarget> source, PassOwnPtrWillBeRawPtr<MessagePortArray>); |
| 125 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtr
WillBeRawPtr<MessagePortArray>); | 119 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtr
WillBeRawPtr<MessagePortArray>); |
| 126 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtr
<MessagePortChannelArray>); | 120 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtrWillBeRawPtr<EventTarget> source, PassOwnPtr
<MessagePortChannelArray>); |
| 127 | 121 |
| 128 MessageEvent(const String& data, const String& origin); | 122 MessageEvent(const String& data, const String& origin); |
| 129 MessageEvent(Blob* data, const String& origin); | 123 MessageEvent(Blob* data, const String& origin); |
| 130 MessageEvent(PassRefPtr<DOMArrayBuffer> data, const String& origin); | 124 MessageEvent(PassRefPtr<DOMArrayBuffer> data, const String& origin); |
| 131 | 125 |
| 132 DataType m_dataType; | 126 DataType m_dataType; |
| 127 ScriptValue m_dataAsScriptValue; |
| 133 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; | 128 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; |
| 134 String m_dataAsString; | 129 String m_dataAsString; |
| 135 PersistentWillBeMember<Blob> m_dataAsBlob; | 130 PersistentWillBeMember<Blob> m_dataAsBlob; |
| 136 RefPtr<DOMArrayBuffer> m_dataAsArrayBuffer; | 131 RefPtr<DOMArrayBuffer> m_dataAsArrayBuffer; |
| 137 String m_origin; | 132 String m_origin; |
| 138 String m_lastEventId; | 133 String m_lastEventId; |
| 139 RefPtrWillBeMember<EventTarget> m_source; | 134 RefPtrWillBeMember<EventTarget> m_source; |
| 140 // m_ports are the MessagePorts in an engtangled state, and m_channels are | 135 // m_ports are the MessagePorts in an engtangled state, and m_channels are |
| 141 // the MessageChannels in a disentangled state. Only one of them can be | 136 // the MessageChannels in a disentangled state. Only one of them can be |
| 142 // non-empty at a time. entangleMessagePorts() moves between the states. | 137 // non-empty at a time. entangleMessagePorts() moves between the states. |
| 143 OwnPtrWillBeMember<MessagePortArray> m_ports; | 138 OwnPtrWillBeMember<MessagePortArray> m_ports; |
| 144 OwnPtr<MessagePortChannelArray> m_channels; | 139 OwnPtr<MessagePortChannelArray> m_channels; |
| 145 }; | 140 }; |
| 146 | 141 |
| 147 } // namespace blink | 142 } // namespace blink |
| 148 | 143 |
| 149 #endif // MessageEvent_h | 144 #endif // MessageEvent_h |
| OLD | NEW |