Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: third_party/WebKit/Source/core/dom/MessagePort.cpp

Issue 2546313003: M56: Messaging: Fix crash when MessagePort is closed while messages are queued (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/workers/resources/close-context-messageport-crash-iframe.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 bool MessagePort::tryGetMessage( 184 bool MessagePort::tryGetMessage(
185 RefPtr<SerializedScriptValue>& message, 185 RefPtr<SerializedScriptValue>& message,
186 std::unique_ptr<MessagePortChannelArray>& channels) { 186 std::unique_ptr<MessagePortChannelArray>& channels) {
187 if (!m_entangledChannel) 187 if (!m_entangledChannel)
188 return false; 188 return false;
189 return tryGetMessageFrom(*m_entangledChannel, message, channels); 189 return tryGetMessageFrom(*m_entangledChannel, message, channels);
190 } 190 }
191 191
192 void MessagePort::dispatchMessages() { 192 void MessagePort::dispatchMessages() {
193 // Because close() doesn't cancel any in flight calls to dispatchMessages() we
194 // need to check if the port is still open before dispatch.
195 if (m_closed)
196 return;
197
198 // Messages for contexts that are not fully active get dispatched too, but 193 // Messages for contexts that are not fully active get dispatched too, but
199 // JSAbstractEventListener::handleEvent() doesn't call handlers for these. 194 // JSAbstractEventListener::handleEvent() doesn't call handlers for these.
200 // The HTML5 spec specifies that any messages sent to a document that is not 195 // The HTML5 spec specifies that any messages sent to a document that is not
201 // fully active should be dropped, so this behavior is OK. 196 // fully active should be dropped, so this behavior is OK.
202 if (!started()) 197 if (!started())
203 return; 198 return;
204 199
205 RefPtr<SerializedScriptValue> message; 200 while (true) {
206 std::unique_ptr<MessagePortChannelArray> channels; 201 // Because close() doesn't cancel any in flight calls to dispatchMessages(),
207 while (tryGetMessage(message, channels)) { 202 // and can be triggered by the onmessage event handler, we need to check if
208 // close() in Worker onmessage handler should prevent next message from 203 // the port is still open before each dispatch.
209 // dispatching. 204 if (m_closed)
205 break;
206
207 // WorkerGlobalScope::close() in Worker onmessage handler should prevent
208 // the next message from dispatching.
210 if (getExecutionContext()->isWorkerGlobalScope() && 209 if (getExecutionContext()->isWorkerGlobalScope() &&
211 toWorkerGlobalScope(getExecutionContext())->isClosing()) 210 toWorkerGlobalScope(getExecutionContext())->isClosing()) {
212 return; 211 break;
212 }
213
214 RefPtr<SerializedScriptValue> message;
215 std::unique_ptr<MessagePortChannelArray> channels;
216 if (!tryGetMessage(message, channels))
217 break;
213 218
214 MessagePortArray* ports = 219 MessagePortArray* ports =
215 MessagePort::entanglePorts(*getExecutionContext(), std::move(channels)); 220 MessagePort::entanglePorts(*getExecutionContext(), std::move(channels));
216 Event* evt = MessageEvent::create(ports, message.release()); 221 Event* evt = MessageEvent::create(ports, message.release());
217 222
218 dispatchEvent(evt); 223 dispatchEvent(evt);
219 } 224 }
220 } 225 }
221 226
222 bool MessagePort::hasPendingActivity() const { 227 bool MessagePort::hasPendingActivity() const {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 288 }
284 return portArray; 289 return portArray;
285 } 290 }
286 291
287 DEFINE_TRACE(MessagePort) { 292 DEFINE_TRACE(MessagePort) {
288 ActiveDOMObject::trace(visitor); 293 ActiveDOMObject::trace(visitor);
289 EventTargetWithInlineData::trace(visitor); 294 EventTargetWithInlineData::trace(visitor);
290 } 295 }
291 296
292 } // namespace blink 297 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/workers/resources/close-context-messageport-crash-iframe.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698