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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return adoptRef(new MessageEvent); | 54 return adoptRef(new MessageEvent); |
55 } | 55 } |
56 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c
onst String& origin = String(), const String& lastEventId = String(), PassRefPtr
<EventTarget> source = 0) | 56 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, c
onst String& origin = String(), const String& lastEventId = String(), PassRefPtr
<EventTarget> source = 0) |
57 { | 57 { |
58 return adoptRef(new MessageEvent(origin, lastEventId, source, ports)); | 58 return adoptRef(new MessageEvent(origin, lastEventId, source, ports)); |
59 } | 59 } |
60 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P
assRefPtr<SerializedScriptValue> data, const String& origin = String(), const St
ring& lastEventId = String(), PassRefPtr<EventTarget> source = 0) | 60 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortArray> ports, P
assRefPtr<SerializedScriptValue> data, const String& origin = String(), const St
ring& lastEventId = String(), PassRefPtr<EventTarget> source = 0) |
61 { | 61 { |
62 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); | 62 return adoptRef(new MessageEvent(data, origin, lastEventId, source, port
s)); |
63 } | 63 } |
| 64 static PassRefPtr<MessageEvent> create(PassOwnPtr<MessagePortChannelArray> c
hannels, PassRefPtr<SerializedScriptValue> data, const String& origin = String()
, const String& lastEventId = String(), PassRefPtr<EventTarget> source = 0) |
| 65 { |
| 66 return adoptRef(new MessageEvent(data, origin, lastEventId, source, chan
nels)); |
| 67 } |
64 static PassRefPtr<MessageEvent> create(const String& data, const String& ori
gin = String()) | 68 static PassRefPtr<MessageEvent> create(const String& data, const String& ori
gin = String()) |
65 { | 69 { |
66 return adoptRef(new MessageEvent(data, origin)); | 70 return adoptRef(new MessageEvent(data, origin)); |
67 } | 71 } |
68 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String&
origin = String()) | 72 static PassRefPtr<MessageEvent> create(PassRefPtr<Blob> data, const String&
origin = String()) |
69 { | 73 { |
70 return adoptRef(new MessageEvent(data, origin)); | 74 return adoptRef(new MessageEvent(data, origin)); |
71 } | 75 } |
72 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S
tring& origin = String()) | 76 static PassRefPtr<MessageEvent> create(PassRefPtr<ArrayBuffer> data, const S
tring& origin = String()) |
73 { | 77 { |
74 return adoptRef(new MessageEvent(data, origin)); | 78 return adoptRef(new MessageEvent(data, origin)); |
75 } | 79 } |
76 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa
geEventInit& initializer) | 80 static PassRefPtr<MessageEvent> create(const AtomicString& type, const Messa
geEventInit& initializer) |
77 { | 81 { |
78 return adoptRef(new MessageEvent(type, initializer)); | 82 return adoptRef(new MessageEvent(type, initializer)); |
79 } | 83 } |
80 virtual ~MessageEvent(); | 84 virtual ~MessageEvent(); |
81 | 85 |
82 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, const String& origin, const String& lastEventId, DOMWindow* source, PassOwn
Ptr<MessagePortArray>); |
83 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String&
lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>); | 87 void initMessageEvent(const AtomicString& type, bool canBubble, bool cancela
ble, PassRefPtr<SerializedScriptValue> data, const String& origin, const String&
lastEventId, DOMWindow* source, PassOwnPtr<MessagePortArray>); |
84 | 88 |
85 const String& origin() const { return m_origin; } | 89 const String& origin() const { return m_origin; } |
86 const String& lastEventId() const { return m_lastEventId; } | 90 const String& lastEventId() const { return m_lastEventId; } |
87 EventTarget* source() const { return m_source.get(); } | 91 EventTarget* source() const { return m_source.get(); } |
88 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra
y(); } | 92 MessagePortArray ports() const { return m_ports ? *m_ports : MessagePortArra
y(); } |
| 93 MessagePortChannelArray channels() const { return m_channels ? *m_channels :
MessagePortChannelArray(); } |
89 | 94 |
90 virtual const AtomicString& interfaceName() const; | 95 virtual const AtomicString& interfaceName() const; |
91 | 96 |
92 enum DataType { | 97 enum DataType { |
93 DataTypeScriptValue, | 98 DataTypeScriptValue, |
94 DataTypeSerializedScriptValue, | 99 DataTypeSerializedScriptValue, |
95 DataTypeString, | 100 DataTypeString, |
96 DataTypeBlob, | 101 DataTypeBlob, |
97 DataTypeArrayBuffer | 102 DataTypeArrayBuffer |
98 }; | 103 }; |
99 DataType dataType() const { return m_dataType; } | 104 DataType dataType() const { return m_dataType; } |
100 SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataTy
pe == DataTypeScriptValue || m_dataType == DataTypeSerializedScriptValue); retur
n m_dataAsSerializedScriptValue.get(); } | 105 SerializedScriptValue* dataAsSerializedScriptValue() const { ASSERT(m_dataTy
pe == DataTypeScriptValue || m_dataType == DataTypeSerializedScriptValue); retur
n m_dataAsSerializedScriptValue.get(); } |
101 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } | 106 String dataAsString() const { ASSERT(m_dataType == DataTypeString); return m
_dataAsString; } |
102 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data
AsBlob.get(); } | 107 Blob* dataAsBlob() const { ASSERT(m_dataType == DataTypeBlob); return m_data
AsBlob.get(); } |
103 ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayB
uffer); return m_dataAsArrayBuffer.get(); } | 108 ArrayBuffer* dataAsArrayBuffer() const { ASSERT(m_dataType == DataTypeArrayB
uffer); return m_dataAsArrayBuffer.get(); } |
104 | 109 |
105 void setSerializedData(PassRefPtr<SerializedScriptValue> data) | 110 void setSerializedData(PassRefPtr<SerializedScriptValue> data) |
106 { | 111 { |
107 ASSERT(!m_dataAsSerializedScriptValue); | 112 ASSERT(!m_dataAsSerializedScriptValue); |
108 m_dataAsSerializedScriptValue = data; | 113 m_dataAsSerializedScriptValue = data; |
109 } | 114 } |
110 | 115 |
| 116 void entangleMessagePorts(ExecutionContext*); |
| 117 |
111 private: | 118 private: |
112 MessageEvent(); | 119 MessageEvent(); |
113 MessageEvent(const AtomicString&, const MessageEventInit&); | 120 MessageEvent(const AtomicString&, const MessageEventInit&); |
114 MessageEvent(const String& origin, const String& lastEventId, PassRefPtr<Eve
ntTarget> source, PassOwnPtr<MessagePortArray>); | 121 MessageEvent(const String& origin, const String& lastEventId, PassRefPtr<Eve
ntTarget> source, PassOwnPtr<MessagePortArray>); |
115 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtr<EventTarget> source, PassOwnPtr<MessagePort
Array>); | 122 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtr<EventTarget> source, PassOwnPtr<MessagePort
Array>); |
| 123 MessageEvent(PassRefPtr<SerializedScriptValue> data, const String& origin, c
onst String& lastEventId, PassRefPtr<EventTarget> source, PassOwnPtr<MessagePort
ChannelArray>); |
116 | 124 |
117 explicit MessageEvent(const String& data, const String& origin); | 125 explicit MessageEvent(const String& data, const String& origin); |
118 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); | 126 explicit MessageEvent(PassRefPtr<Blob> data, const String& origin); |
119 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); | 127 explicit MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); |
120 | 128 |
121 DataType m_dataType; | 129 DataType m_dataType; |
122 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; | 130 RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; |
123 String m_dataAsString; | 131 String m_dataAsString; |
124 RefPtr<Blob> m_dataAsBlob; | 132 RefPtr<Blob> m_dataAsBlob; |
125 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; | 133 RefPtr<ArrayBuffer> m_dataAsArrayBuffer; |
126 String m_origin; | 134 String m_origin; |
127 String m_lastEventId; | 135 String m_lastEventId; |
128 RefPtr<EventTarget> m_source; | 136 RefPtr<EventTarget> m_source; |
| 137 // m_ports are the MessagePorts in an engtangled state, and m_channels are |
| 138 // the MessageChannels in a disentangled state. Only one of them can be |
| 139 // non-empty at a time. entangleMessagePorts() moves between the states. |
129 OwnPtr<MessagePortArray> m_ports; | 140 OwnPtr<MessagePortArray> m_ports; |
| 141 OwnPtr<MessagePortChannelArray> m_channels; |
130 }; | 142 }; |
131 | 143 |
132 } // namespace WebCore | 144 } // namespace WebCore |
133 | 145 |
134 #endif // MessageEvent_h | 146 #endif // MessageEvent_h |
OLD | NEW |