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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 { | 60 { |
61 close(); | 61 close(); |
62 if (m_scriptStateForConversion) | 62 if (m_scriptStateForConversion) |
63 m_scriptStateForConversion->disposePerContextData(); | 63 m_scriptStateForConversion->disposePerContextData(); |
64 } | 64 } |
65 | 65 |
66 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc
riptValue> message, const MessagePortArray* ports, ExceptionState& exceptionStat
e) | 66 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc
riptValue> message, const MessagePortArray* ports, ExceptionState& exceptionStat
e) |
67 { | 67 { |
68 if (!isEntangled()) | 68 if (!isEntangled()) |
69 return; | 69 return; |
70 ASSERT(executionContext()); | 70 ASSERT(getExecutionContext()); |
71 ASSERT(m_entangledChannel); | 71 ASSERT(m_entangledChannel); |
72 | 72 |
73 OwnPtr<MessagePortChannelArray> channels; | 73 OwnPtr<MessagePortChannelArray> channels; |
74 // Make sure we aren't connected to any of the passed-in ports. | 74 // Make sure we aren't connected to any of the passed-in ports. |
75 if (ports) { | 75 if (ports) { |
76 for (unsigned i = 0; i < ports->size(); ++i) { | 76 for (unsigned i = 0; i < ports->size(); ++i) { |
77 MessagePort* dataPort = (*ports)[i]; | 77 MessagePort* dataPort = (*ports)[i]; |
78 if (dataPort == this) { | 78 if (dataPort == this) { |
79 exceptionState.throwDOMException(DataCloneError, "Port at index
" + String::number(i) + " contains the source port."); | 79 exceptionState.throwDOMException(DataCloneError, "Port at index
" + String::number(i) + " contains the source port."); |
80 return; | 80 return; |
81 } | 81 } |
82 } | 82 } |
83 channels = MessagePort::disentanglePorts(context, ports, exceptionState)
; | 83 channels = MessagePort::disentanglePorts(context, ports, exceptionState)
; |
84 if (exceptionState.hadException()) | 84 if (exceptionState.hadException()) |
85 return; | 85 return; |
86 } | 86 } |
87 | 87 |
88 if (message->containsTransferableArrayBuffer()) | 88 if (message->containsTransferableArrayBuffer()) |
89 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSo
urce, WarningMessageLevel, "MessagePort cannot send an ArrayBuffer as a transfer
able object yet. See http://crbug.com/334408")); | 89 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessag
eSource, WarningMessageLevel, "MessagePort cannot send an ArrayBuffer as a trans
ferable object yet. See http://crbug.com/334408")); |
90 | 90 |
91 WebString messageString = message->toWireString(); | 91 WebString messageString = message->toWireString(); |
92 OwnPtr<WebMessagePortChannelArray> webChannels = toWebMessagePortChannelArra
y(channels.release()); | 92 OwnPtr<WebMessagePortChannelArray> webChannels = toWebMessagePortChannelArra
y(channels.release()); |
93 m_entangledChannel->postMessage(messageString, webChannels.leakPtr()); | 93 m_entangledChannel->postMessage(messageString, webChannels.leakPtr()); |
94 } | 94 } |
95 | 95 |
96 // static | 96 // static |
97 PassOwnPtr<WebMessagePortChannelArray> MessagePort::toWebMessagePortChannelArray
(PassOwnPtr<MessagePortChannelArray> channels) | 97 PassOwnPtr<WebMessagePortChannelArray> MessagePort::toWebMessagePortChannelArray
(PassOwnPtr<MessagePortChannelArray> channels) |
98 { | 98 { |
99 OwnPtr<WebMessagePortChannelArray> webChannels; | 99 OwnPtr<WebMessagePortChannelArray> webChannels; |
(...skipping 22 matching lines...) Expand all Loading... |
122 { | 122 { |
123 ASSERT(m_entangledChannel); | 123 ASSERT(m_entangledChannel); |
124 m_entangledChannel->setClient(0); | 124 m_entangledChannel->setClient(0); |
125 return m_entangledChannel.release(); | 125 return m_entangledChannel.release(); |
126 } | 126 } |
127 | 127 |
128 // Invoked to notify us that there are messages available for this port. | 128 // Invoked to notify us that there are messages available for this port. |
129 // 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). | 129 // 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). |
130 void MessagePort::messageAvailable() | 130 void MessagePort::messageAvailable() |
131 { | 131 { |
132 ASSERT(executionContext()); | 132 ASSERT(getExecutionContext()); |
133 executionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Message
Port::dispatchMessages, m_weakFactory.createWeakPtr())); | 133 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess
agePort::dispatchMessages, m_weakFactory.createWeakPtr())); |
134 } | 134 } |
135 | 135 |
136 void MessagePort::start() | 136 void MessagePort::start() |
137 { | 137 { |
138 // Do nothing if we've been cloned or closed. | 138 // Do nothing if we've been cloned or closed. |
139 if (!isEntangled()) | 139 if (!isEntangled()) |
140 return; | 140 return; |
141 | 141 |
142 ASSERT(executionContext()); | 142 ASSERT(getExecutionContext()); |
143 if (m_started) | 143 if (m_started) |
144 return; | 144 return; |
145 | 145 |
146 m_started = true; | 146 m_started = true; |
147 messageAvailable(); | 147 messageAvailable(); |
148 } | 148 } |
149 | 149 |
150 void MessagePort::close() | 150 void MessagePort::close() |
151 { | 151 { |
152 if (isEntangled()) | 152 if (isEntangled()) |
153 m_entangledChannel->setClient(0); | 153 m_entangledChannel->setClient(0); |
154 m_closed = true; | 154 m_closed = true; |
155 } | 155 } |
156 | 156 |
157 void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote) | 157 void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote) |
158 { | 158 { |
159 // Only invoked to set our initial entanglement. | 159 // Only invoked to set our initial entanglement. |
160 ASSERT(!m_entangledChannel); | 160 ASSERT(!m_entangledChannel); |
161 ASSERT(executionContext()); | 161 ASSERT(getExecutionContext()); |
162 | 162 |
163 m_entangledChannel = remote; | 163 m_entangledChannel = remote; |
164 m_entangledChannel->setClient(this); | 164 m_entangledChannel->setClient(this); |
165 } | 165 } |
166 | 166 |
167 const AtomicString& MessagePort::interfaceName() const | 167 const AtomicString& MessagePort::interfaceName() const |
168 { | 168 { |
169 return EventTargetNames::MessagePort; | 169 return EventTargetNames::MessagePort; |
170 } | 170 } |
171 | 171 |
(...skipping 28 matching lines...) Expand all Loading... |
200 | 200 |
201 // Messages for contexts that are not fully active get dispatched too, but J
SAbstractEventListener::handleEvent() doesn't call handlers for these. | 201 // Messages for contexts that are not fully active get dispatched too, but J
SAbstractEventListener::handleEvent() doesn't call handlers for these. |
202 // The HTML5 spec specifies that any messages sent to a document that is not
fully active should be dropped, so this behavior is OK. | 202 // The HTML5 spec specifies that any messages sent to a document that is not
fully active should be dropped, so this behavior is OK. |
203 if (!started()) | 203 if (!started()) |
204 return; | 204 return; |
205 | 205 |
206 RefPtr<SerializedScriptValue> message; | 206 RefPtr<SerializedScriptValue> message; |
207 OwnPtr<MessagePortChannelArray> channels; | 207 OwnPtr<MessagePortChannelArray> channels; |
208 while (tryGetMessage(message, channels)) { | 208 while (tryGetMessage(message, channels)) { |
209 // close() in Worker onmessage handler should prevent next message from
dispatching. | 209 // close() in Worker onmessage handler should prevent next message from
dispatching. |
210 if (executionContext()->isWorkerGlobalScope() && toWorkerGlobalScope(exe
cutionContext())->isClosing()) | 210 if (getExecutionContext()->isWorkerGlobalScope() && toWorkerGlobalScope(
getExecutionContext())->isClosing()) |
211 return; | 211 return; |
212 | 212 |
213 MessagePortArray* ports = MessagePort::entanglePorts(*executionContext()
, channels.release()); | 213 MessagePortArray* ports = MessagePort::entanglePorts(*getExecutionContex
t(), channels.release()); |
214 RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports, message.rele
ase()); | 214 RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports, message.rele
ase()); |
215 | 215 |
216 dispatchEvent(evt.release()); | 216 dispatchEvent(evt.release()); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 bool MessagePort::hasPendingActivity() const | 220 bool MessagePort::hasPendingActivity() const |
221 { | 221 { |
222 // The spec says that entangled message ports should always be treated as if
they have a strong reference. | 222 // The spec says that entangled message ports should always be treated as if
they have a strong reference. |
223 // We'll also stipulate that the queue needs to be open (if the app drops it
s reference to the port before start()-ing it, then it's not really entangled as
it's unreachable). | 223 // We'll also stipulate that the queue needs to be open (if the app drops it
s reference to the port before start()-ing it, then it's not really entangled as
it's unreachable). |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 275 } |
276 | 276 |
277 DEFINE_TRACE(MessagePort) | 277 DEFINE_TRACE(MessagePort) |
278 { | 278 { |
279 ContextLifecycleObserver::trace(visitor); | 279 ContextLifecycleObserver::trace(visitor); |
280 RefCountedGarbageCollectedEventTargetWithInlineData<MessagePort>::trace(visi
tor); | 280 RefCountedGarbageCollectedEventTargetWithInlineData<MessagePort>::trace(visi
tor); |
281 } | 281 } |
282 | 282 |
283 v8::Isolate* MessagePort::scriptIsolate() | 283 v8::Isolate* MessagePort::scriptIsolate() |
284 { | 284 { |
285 ASSERT(executionContext()); | 285 ASSERT(getExecutionContext()); |
286 return toIsolate(executionContext()); | 286 return toIsolate(getExecutionContext()); |
287 } | 287 } |
288 | 288 |
289 v8::Local<v8::Context> MessagePort::scriptContextForMessageConversion() | 289 v8::Local<v8::Context> MessagePort::scriptContextForMessageConversion() |
290 { | 290 { |
291 ASSERT(executionContext()); | 291 ASSERT(getExecutionContext()); |
292 if (!m_scriptStateForConversion) { | 292 if (!m_scriptStateForConversion) { |
293 v8::Isolate* isolate = scriptIsolate(); | 293 v8::Isolate* isolate = scriptIsolate(); |
294 m_scriptStateForConversion = ScriptState::create(v8::Context::New(isolat
e), DOMWrapperWorld::create(isolate)); | 294 m_scriptStateForConversion = ScriptState::create(v8::Context::New(isolat
e), DOMWrapperWorld::create(isolate)); |
295 } | 295 } |
296 return m_scriptStateForConversion->context(); | 296 return m_scriptStateForConversion->context(); |
297 } | 297 } |
298 | 298 |
299 } // namespace blink | 299 } // namespace blink |
OLD | NEW |