OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 m_entangledChannel->postMessage(messageString, webChannels.leakPtr()); | 91 m_entangledChannel->postMessage(messageString, webChannels.leakPtr()); |
92 } | 92 } |
93 | 93 |
94 // static | 94 // static |
95 PassOwnPtr<WebMessagePortChannelArray> MessagePort::toWebMessagePortChannelArray
(PassOwnPtr<MessagePortChannelArray> channels) | 95 PassOwnPtr<WebMessagePortChannelArray> MessagePort::toWebMessagePortChannelArray
(PassOwnPtr<MessagePortChannelArray> channels) |
96 { | 96 { |
97 OwnPtr<WebMessagePortChannelArray> webChannels; | 97 OwnPtr<WebMessagePortChannelArray> webChannels; |
98 if (channels && channels->size()) { | 98 if (channels && channels->size()) { |
99 webChannels = adoptPtr(new WebMessagePortChannelArray(channels->size()))
; | 99 webChannels = adoptPtr(new WebMessagePortChannelArray(channels->size()))
; |
100 for (size_t i = 0; i < channels->size(); ++i) | 100 for (size_t i = 0; i < channels->size(); ++i) |
101 (*webChannels)[i] = (*channels)[i].leakPtr(); | 101 (*webChannels)[i] = (*channels)[i].release(); |
102 } | 102 } |
103 return webChannels; | 103 return webChannels; |
104 } | 104 } |
105 | 105 |
106 // static | 106 // static |
107 MessagePortArray* MessagePort::toMessagePortArray(ExecutionContext* context, con
st WebMessagePortChannelArray& webChannels) | 107 MessagePortArray* MessagePort::toMessagePortArray(ExecutionContext* context, con
st WebMessagePortChannelArray& webChannels) |
108 { | 108 { |
109 OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelAr
ray(webChannels.size())); | 109 OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelAr
ray(webChannels.size())); |
110 for (size_t i = 0; i < webChannels.size(); ++i) | 110 for (size_t i = 0; i < webChannels.size(); ++i) |
111 (*channels)[i] = adoptPtr(webChannels[i]); | 111 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); |
112 return MessagePort::entanglePorts(*context, std::move(channels)); | 112 return MessagePort::entanglePorts(*context, std::move(channels)); |
113 } | 113 } |
114 | 114 |
115 PassOwnPtr<WebMessagePortChannel> MessagePort::disentangle() | 115 WebMessagePortChannelUniquePtr MessagePort::disentangle() |
116 { | 116 { |
117 DCHECK(m_entangledChannel); | 117 DCHECK(m_entangledChannel); |
118 m_entangledChannel->setClient(0); | 118 m_entangledChannel->setClient(0); |
119 return std::move(m_entangledChannel); | 119 return std::move(m_entangledChannel); |
120 } | 120 } |
121 | 121 |
122 // Invoked to notify us that there are messages available for this port. | 122 // Invoked to notify us that there are messages available for this port. |
123 // This code may be called from another thread, and so should not call any non-t
hreadsafe APIs (i.e. should not call into the entangled channel or access mutabl
e variables). | 123 // This code may be called from another thread, and so should not call any non-t
hreadsafe APIs (i.e. should not call into the entangled channel or access mutabl
e variables). |
124 void MessagePort::messageAvailable() | 124 void MessagePort::messageAvailable() |
125 { | 125 { |
(...skipping 15 matching lines...) Expand all Loading... |
141 messageAvailable(); | 141 messageAvailable(); |
142 } | 142 } |
143 | 143 |
144 void MessagePort::close() | 144 void MessagePort::close() |
145 { | 145 { |
146 if (isEntangled()) | 146 if (isEntangled()) |
147 m_entangledChannel->setClient(0); | 147 m_entangledChannel->setClient(0); |
148 m_closed = true; | 148 m_closed = true; |
149 } | 149 } |
150 | 150 |
151 void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote) | 151 void MessagePort::entangle(WebMessagePortChannelUniquePtr remote) |
152 { | 152 { |
153 // Only invoked to set our initial entanglement. | 153 // Only invoked to set our initial entanglement. |
154 DCHECK(!m_entangledChannel); | 154 DCHECK(!m_entangledChannel); |
155 DCHECK(getExecutionContext()); | 155 DCHECK(getExecutionContext()); |
156 | 156 |
157 m_entangledChannel = std::move(remote); | 157 m_entangledChannel = std::move(remote); |
158 m_entangledChannel->setClient(this); | 158 m_entangledChannel->setClient(this); |
159 } | 159 } |
160 | 160 |
161 const AtomicString& MessagePort::interfaceName() const | 161 const AtomicString& MessagePort::interfaceName() const |
162 { | 162 { |
163 return EventTargetNames::MessagePort; | 163 return EventTargetNames::MessagePort; |
164 } | 164 } |
165 | 165 |
166 static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<Serializ
edScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels) | 166 static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<Serializ
edScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels) |
167 { | 167 { |
168 WebString messageString; | 168 WebString messageString; |
169 WebMessagePortChannelArray webChannels; | 169 WebMessagePortChannelArray webChannels; |
170 if (!webChannel.tryGetMessage(&messageString, webChannels)) | 170 if (!webChannel.tryGetMessage(&messageString, webChannels)) |
171 return false; | 171 return false; |
172 | 172 |
173 if (webChannels.size()) { | 173 if (webChannels.size()) { |
174 channels = adoptPtr(new MessagePortChannelArray(webChannels.size())); | 174 channels = adoptPtr(new MessagePortChannelArray(webChannels.size())); |
175 for (size_t i = 0; i < webChannels.size(); ++i) | 175 for (size_t i = 0; i < webChannels.size(); ++i) |
176 (*channels)[i] = adoptPtr(webChannels[i]); | 176 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); |
177 } | 177 } |
178 message = SerializedScriptValue::create(messageString); | 178 message = SerializedScriptValue::create(messageString); |
179 return true; | 179 return true; |
180 } | 180 } |
181 | 181 |
182 bool MessagePort::tryGetMessage(RefPtr<SerializedScriptValue>& message, OwnPtr<M
essagePortChannelArray>& channels) | 182 bool MessagePort::tryGetMessage(RefPtr<SerializedScriptValue>& message, OwnPtr<M
essagePortChannelArray>& channels) |
183 { | 183 { |
184 if (!m_entangledChannel) | 184 if (!m_entangledChannel) |
185 return false; | 185 return false; |
186 return tryGetMessageFrom(*m_entangledChannel, message, channels); | 186 return tryGetMessageFrom(*m_entangledChannel, message, channels); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return portArray; | 267 return portArray; |
268 } | 268 } |
269 | 269 |
270 DEFINE_TRACE(MessagePort) | 270 DEFINE_TRACE(MessagePort) |
271 { | 271 { |
272 ActiveDOMObject::trace(visitor); | 272 ActiveDOMObject::trace(visitor); |
273 EventTargetWithInlineData::trace(visitor); | 273 EventTargetWithInlineData::trace(visitor); |
274 } | 274 } |
275 | 275 |
276 } // namespace blink | 276 } // namespace blink |
OLD | NEW |