| 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 10 matching lines...) Expand all Loading... |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #ifndef MessageEvent_h | 28 #ifndef MessageEvent_h |
| 29 #define MessageEvent_h | 29 #define MessageEvent_h |
| 30 | 30 |
| 31 #include "bindings/v8/ScriptValue.h" | |
| 32 #include "bindings/v8/SerializedScriptValue.h" | 31 #include "bindings/v8/SerializedScriptValue.h" |
| 33 #include "core/dom/Event.h" | 32 #include "core/dom/Event.h" |
| 34 #include "core/dom/MessagePort.h" | 33 #include "core/dom/MessagePort.h" |
| 35 #include "core/fileapi/Blob.h" | 34 #include "core/fileapi/Blob.h" |
| 36 #include "core/page/DOMWindow.h" | 35 #include "core/page/DOMWindow.h" |
| 37 #include <wtf/ArrayBuffer.h> | 36 #include <wtf/ArrayBuffer.h> |
| 38 | 37 |
| 39 namespace WebCore { | 38 namespace WebCore { |
| 40 | 39 |
| 41 class DOMWindow; | 40 class DOMWindow; |
| 42 | 41 |
| 43 struct MessageEventInit : public EventInit { | 42 struct MessageEventInit : public EventInit { |
| 44 MessageEventInit(); | 43 MessageEventInit(); |
| 45 | 44 |
| 46 ScriptValue data; | |
| 47 String origin; | 45 String origin; |
| 48 String lastEventId; | 46 String lastEventId; |
| 49 RefPtr<DOMWindow> source; | 47 RefPtr<DOMWindow> source; |
| 50 MessagePortArray ports; | 48 MessagePortArray ports; |
| 49 |
| 50 bool dataIsSet; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 class MessageEvent : public Event { | 53 class MessageEvent : public Event { |
| 54 public: | 54 public: |
| 55 static PassRefPtr<MessageEvent> create() | 55 static PassRefPtr<MessageEvent> create() |
| 56 { | 56 { |
| 57 return adoptRef(new MessageEvent); | 57 return adoptRef(new MessageEvent); |
| 58 } | 58 } |
| 59 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c
onst ScriptValue& data = ScriptValue(), const String& origin = "", const String&
lastEventId = "", PassRefPtr<DOMWindow> source = 0) | 59 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c
onst String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow>
source = 0) |
| 60 { | 60 { |
| 61 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); | 61 return adoptRef(new MessageEvent(origin, lastEventId, source, ports)); |
| 62 } | 62 } |
| 63 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P
assRefPtr<SerializedScriptValue> data, const String& origin = "", const String&
lastEventId = "", PassRefPtr<DOMWindow> source = 0) | 63 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P
assRefPtr<SerializedScriptValue> data, const String& origin = "", const String&
lastEventId = "", PassRefPtr<DOMWindow> source = 0) |
| 64 { | 64 { |
| 65 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); | 65 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); |
| 66 } | 66 } |
| 67 static PassRefPtr<MessageEvent> create(const String& data, const String& ori
gin = "") | 67 static PassRefPtr<MessageEvent> create(const String& data, const String& ori
gin = "") |
| 68 { | 68 { |
| 69 return adoptRef(new MessageEvent(data, origin)); | 69 return adoptRef(new MessageEvent(data, origin)); |
| 70 } | 70 } |
| 71 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String&
origin = "") | 71 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String&
origin = "") |
| 72 { | 72 { |
| 73 return adoptRef(new MessageEvent(data, origin)); | 73 return adoptRef(new MessageEvent(data, origin)); |
| 74 } | 74 } |
| 75 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S
tring& origin = "") | 75 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S
tring& origin = "") |
| 76 { | 76 { |
| 77 return adoptRef(new MessageEvent(data, origin)); | 77 return adoptRef(new MessageEvent(data, origin)); |
| 78 } | 78 } |
| 79 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa
geEventInit& initializer) | 79 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa
geEventInit& initializer) |
| 80 { | 80 { |
| 81 return adoptRef(new MessageEvent(type, initializer)); | 81 return adoptRef(new MessageEvent(type, initializer)); |
| 82 } | 82 } |
| 83 virtual ~MessageEvent(); | 83 virtual ~MessageEvent(); |
| 84 | 84 |
| 85 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, const ScriptValue& data, const String& origin, const String& lastEventId, D
OMWindow* source, PassOwnPtr<MessagePortArray>); | 85 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, const String& origin, const String& lastEventId, DOMWindow* source, PassOwn
Ptr<MessagePortArray>); |
| 86 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String&
lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>); | 86 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String&
lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>); |
| 87 | 87 |
| 88 const String& origin() const { return m_origin; } | 88 const String& origin() const { return m_origin; } |
| 89 const String& lastEventId() const { return m_lastEventId; } | 89 const String& lastEventId() const { return m_lastEventId; } |
| 90 DOMWindow* source() const { return m_source.get(); } | 90 DOMWindow* source() const { return m_source.get(); } |
| 91 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra
y(); } | 91 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra
y(); } |
| 92 | 92 |
| 93 virtual const AtomicString& interfaceName() const; | 93 virtual const AtomicString& interfaceName() const; |
| 94 | 94 |
| 95 enum DataType { | 95 enum DataType { |
| 96 DataTypeScriptValue, | 96 DataTypeScriptValue, |
| 97 DataTypeSerializedScriptValue, | 97 DataTypeSerializedScriptValue, |
| 98 DataTypeString, | 98 DataTypeString, |
| 99 DataTypeBlob, | 99 DataTypeBlob, |
| 100 DataTypeArrayBuffer | 100 DataTypeArrayBuffer |
| 101 }; | 101 }; |
| 102 DataType dataType() const { return m_dataType; } | 102 DataType dataType() const { return m_dataType; } |
| 103 const ScriptValue& dataAsScriptValue() const { ASSERT(m_dataType == DataType
ScriptValue); return m_dataAsScriptValue; } | |
| 104 PassRefPtr<SerializedScriptValue> dataAsSerializedScriptValue() const { ASSE
RT(m_dataType == DataTypeSerializedScriptValue); return m_dataAsSerializedScript
Value; } | 103 PassRefPtr<SerializedScriptValue> dataAsSerializedScriptValue() const { ASSE
RT(m_dataType == DataTypeSerializedScriptValue); return m_dataAsSerializedScript
Value; } |
| 105 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } | 104 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } |
| 106 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data
AsBlob.get(); } | 105 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data
AsBlob.get(); } |
| 107 ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayB
uffer); return m_dataAsArrayBuffer.get(); } | 106 ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayB
uffer); return m_dataAsArrayBuffer.get(); } |
| 108 | 107 |
| 108 bool isDataSet() const { return m_dataIsSet; } |
| 109 |
| 109 private: | 110 private: |
| 110 MessageEvent(); | 111 MessageEvent(); |
| 111 MessageEvent(const AtomicString&, const MessageEventInit&); | 112 MessageEvent(const AtomicString&, const MessageEventInit&); |
| 112 MessageEvent(const ScriptValue& data, const String& origin, const String& la
stEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray>); | 113 MessageEvent(const String& origin, const String& lastEventId, PassRefPtr<DOM
Window> source, PassOwnPtr<MessagePortArray>); |
| 113 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortAr
ray>); | 114 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortAr
ray>); |
| 114 | 115 |
| 115 explicit MessageEvent(const String& data, const String& origin); | 116 explicit MessageEvent(const String& data, const String& origin); |
| 116 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); | 117 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); |
| 117 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); | 118 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); |
| 118 | 119 |
| 119 DataType m_dataType; | 120 DataType m_dataType; |
| 120 ScriptValue m_dataAsScriptValue; | |
| 121 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; | 121 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; |
| 122 String m_dataAsString; | 122 String m_dataAsString; |
| 123 RefPtr<Blob> m_dataAsBlob; | 123 RefPtr<Blob> m_dataAsBlob; |
| 124 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; | 124 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; |
| 125 String m_origin; | 125 String m_origin; |
| 126 String m_lastEventId; | 126 String m_lastEventId; |
| 127 RefPtr<DOMWindow> m_source; | 127 RefPtr<DOMWindow> m_source; |
| 128 OwnPtr<MessagePortArray> m_ports; | 128 OwnPtr<MessagePortArray> m_ports; |
| 129 |
| 130 bool m_dataIsSet; |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 } // namespace WebCore | 133 } // namespace WebCore |
| 132 | 134 |
| 133 #endif // MessageEvent_h | 135 #endif // MessageEvent_h |
| OLD | NEW |