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; |
51 }; | 49 }; |
52 | 50 |
53 class MessageEvent : public Event { | 51 class MessageEvent : public Event { |
54 public: | 52 public: |
55 static PassRefPtr<MessageEvent> create() | 53 static PassRefPtr<MessageEvent> create() |
56 { | 54 { |
57 return adoptRef(new MessageEvent); | 55 return adoptRef(new MessageEvent); |
58 } | 56 } |
59 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c
onst ScriptValue& data = ScriptValue(), const String& origin = "", const String&
lastEventId = "", PassRefPtr<DOMWindow> source = 0) | 57 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c
onst String& origin = "", const String& lastEventId = "", PassRefPtr<DOMWindow>
source = 0) |
60 { | 58 { |
61 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); | 59 return adoptRef(new MessageEvent(origin, lastEventId, source, ports)); |
62 } | 60 } |
63 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P
assRefPtr<SerializedScriptValue> data, const String& origin = "", const String&
lastEventId = "", PassRefPtr<DOMWindow> source = 0) | 61 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P
assRefPtr<SerializedScriptValue> data, const String& origin = "", const String&
lastEventId = "", PassRefPtr<DOMWindow> source = 0) |
64 { | 62 { |
65 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); | 63 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); |
66 } | 64 } |
67 static PassRefPtr<MessageEvent> create(const String& data, const String& ori
gin = "") | 65 static PassRefPtr<MessageEvent> create(const String& data, const String& ori
gin = "") |
68 { | 66 { |
69 return adoptRef(new MessageEvent(data, origin)); | 67 return adoptRef(new MessageEvent(data, origin)); |
70 } | 68 } |
71 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String&
origin = "") | 69 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String&
origin = "") |
72 { | 70 { |
73 return adoptRef(new MessageEvent(data, origin)); | 71 return adoptRef(new MessageEvent(data, origin)); |
74 } | 72 } |
75 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S
tring& origin = "") | 73 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S
tring& origin = "") |
76 { | 74 { |
77 return adoptRef(new MessageEvent(data, origin)); | 75 return adoptRef(new MessageEvent(data, origin)); |
78 } | 76 } |
79 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa
geEventInit& initializer) | 77 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa
geEventInit& initializer) |
80 { | 78 { |
81 return adoptRef(new MessageEvent(type, initializer)); | 79 return adoptRef(new MessageEvent(type, initializer)); |
82 } | 80 } |
83 virtual ~MessageEvent(); | 81 virtual ~MessageEvent(); |
84 | 82 |
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>); | 83 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>); | 84 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String&
lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>); |
87 | 85 |
88 const String& origin() const { return m_origin; } | 86 const String& origin() const { return m_origin; } |
89 const String& lastEventId() const { return m_lastEventId; } | 87 const String& lastEventId() const { return m_lastEventId; } |
90 DOMWindow* source() const { return m_source.get(); } | 88 DOMWindow* source() const { return m_source.get(); } |
91 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra
y(); } | 89 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra
y(); } |
92 | 90 |
93 virtual const AtomicString& interfaceName() const; | 91 virtual const AtomicString& interfaceName() const; |
94 | 92 |
95 enum DataType { | 93 enum DataType { |
96 DataTypeScriptValue, | 94 DataTypeScriptValue, |
97 DataTypeSerializedScriptValue, | 95 DataTypeSerializedScriptValue, |
98 DataTypeString, | 96 DataTypeString, |
99 DataTypeBlob, | 97 DataTypeBlob, |
100 DataTypeArrayBuffer | 98 DataTypeArrayBuffer |
101 }; | 99 }; |
102 DataType dataType() const { return m_dataType; } | 100 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; } | 101 PassRefPtr<SerializedScriptValue> dataAsSerializedScriptValue() const { ASSE
RT(m_dataType == DataTypeSerializedScriptValue); return m_dataAsSerializedScript
Value; } |
105 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } | 102 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } |
106 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data
AsBlob.get(); } | 103 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(); } | 104 ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayB
uffer); return m_dataAsArrayBuffer.get(); } |
108 | 105 |
109 private: | 106 private: |
110 MessageEvent(); | 107 MessageEvent(); |
111 MessageEvent(const AtomicString&, const MessageEventInit&); | 108 MessageEvent(const AtomicString&, const MessageEventInit&); |
112 MessageEvent(const ScriptValue& data, const String& origin, const String& la
stEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortArray>); | 109 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>); | 110 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortAr
ray>); |
114 | 111 |
115 explicit MessageEvent(const String& data, const String& origin); | 112 explicit MessageEvent(const String& data, const String& origin); |
116 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); | 113 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); |
117 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); | 114 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); |
118 | 115 |
119 DataType m_dataType; | 116 DataType m_dataType; |
120 ScriptValue m_dataAsScriptValue; | |
121 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; | 117 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; |
122 String m_dataAsString; | 118 String m_dataAsString; |
123 RefPtr<Blob> m_dataAsBlob; | 119 RefPtr<Blob> m_dataAsBlob; |
124 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; | 120 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; |
125 String m_origin; | 121 String m_origin; |
126 String m_lastEventId; | 122 String m_lastEventId; |
127 RefPtr<DOMWindow> m_source; | 123 RefPtr<DOMWindow> m_source; |
128 OwnPtr<MessagePortArray> m_ports; | 124 OwnPtr<MessagePortArray> m_ports; |
129 }; | 125 }; |
130 | 126 |
131 } // namespace WebCore | 127 } // namespace WebCore |
132 | 128 |
133 #endif // MessageEvent_h | 129 #endif // MessageEvent_h |
OLD | NEW |