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

Side by Side Diff: Source/core/workers/WorkerMessagingProxy.cpp

Issue 466753002: DevTools: Do not push to frontend messages from worker while it is alive (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix test Created 6 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/workers/WorkerMessagingProxy.h ('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 * Copyright (C) 2009 Google Inc. All Rights Reserved. 3 * Copyright (C) 2009 Google Inc. All Rights Reserved.
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 15 matching lines...) Expand all
26 */ 26 */
27 27
28 #include "config.h" 28 #include "config.h"
29 29
30 #include "core/workers/WorkerMessagingProxy.h" 30 #include "core/workers/WorkerMessagingProxy.h"
31 31
32 #include "core/dom/CrossThreadTask.h" 32 #include "core/dom/CrossThreadTask.h"
33 #include "core/dom/Document.h" 33 #include "core/dom/Document.h"
34 #include "core/events/ErrorEvent.h" 34 #include "core/events/ErrorEvent.h"
35 #include "core/events/MessageEvent.h" 35 #include "core/events/MessageEvent.h"
36 #include "core/frame/Console.h"
37 #include "core/frame/FrameConsole.h"
36 #include "core/frame/LocalDOMWindow.h" 38 #include "core/frame/LocalDOMWindow.h"
39 #include "core/frame/LocalFrame.h"
37 #include "core/frame/csp/ContentSecurityPolicy.h" 40 #include "core/frame/csp/ContentSecurityPolicy.h"
38 #include "core/inspector/InspectorInstrumentation.h" 41 #include "core/inspector/InspectorInstrumentation.h"
39 #include "core/inspector/ScriptCallStack.h" 42 #include "core/inspector/ScriptCallStack.h"
40 #include "core/inspector/WorkerDebuggerAgent.h" 43 #include "core/inspector/WorkerDebuggerAgent.h"
41 #include "core/inspector/WorkerInspectorController.h" 44 #include "core/inspector/WorkerInspectorController.h"
42 #include "core/loader/DocumentLoadTiming.h" 45 #include "core/loader/DocumentLoadTiming.h"
43 #include "core/loader/DocumentLoader.h" 46 #include "core/loader/DocumentLoader.h"
44 #include "core/workers/DedicatedWorkerGlobalScope.h" 47 #include "core/workers/DedicatedWorkerGlobalScope.h"
45 #include "core/workers/DedicatedWorkerThread.h" 48 #include "core/workers/DedicatedWorkerThread.h"
46 #include "core/workers/Worker.h" 49 #include "core/workers/Worker.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 RefPtrWillBeRawPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sour ceURL, lineNumber, columnNumber, 0); 173 RefPtrWillBeRawPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sour ceURL, lineNumber, columnNumber, 0);
171 bool errorHandled = !m_workerObject->dispatchEvent(event); 174 bool errorHandled = !m_workerObject->dispatchEvent(event);
172 if (!errorHandled) 175 if (!errorHandled)
173 m_executionContext->reportException(event, nullptr, NotSharableCrossOrig in); 176 m_executionContext->reportException(event, nullptr, NotSharableCrossOrig in);
174 } 177 }
175 178
176 void WorkerMessagingProxy::reportConsoleMessage(MessageSource source, MessageLev el level, const String& message, int lineNumber, const String& sourceURL) 179 void WorkerMessagingProxy::reportConsoleMessage(MessageSource source, MessageLev el level, const String& message, int lineNumber, const String& sourceURL)
177 { 180 {
178 if (m_askedToTerminate) 181 if (m_askedToTerminate)
179 return; 182 return;
180 m_executionContext->addConsoleMessage(ConsoleMessage::create(source, level, message, sourceURL, lineNumber)); 183 // FIXME: In case of nested workers, this should go directly to the root Doc ument context.
184 ASSERT(m_executionContext->isDocument());
185 Document* document = toDocument(m_executionContext.get());
186 LocalFrame* frame = document->frame();
187 if (!frame)
188 return;
189
190 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(s ource, level, message, sourceURL, lineNumber);
191 consoleMessage->setWorkerId(this);
192 frame->console().addMessage(consoleMessage.release());
181 } 193 }
182 194
183 void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread> workerThread) 195 void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread> workerThread)
184 { 196 {
185 m_workerThread = workerThread; 197 m_workerThread = workerThread;
186 198
187 if (m_askedToTerminate) { 199 if (m_askedToTerminate) {
188 // Worker.terminate() could be called from JS before the thread was crea ted. 200 // Worker.terminate() could be called from JS before the thread was crea ted.
189 m_workerThread->stop(); 201 m_workerThread->stop();
190 } else { 202 } else {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 else 281 else
270 m_queuedEarlyTasks.append(task.release()); 282 m_queuedEarlyTasks.append(task.release());
271 } 283 }
272 284
273 void WorkerMessagingProxy::workerGlobalScopeDestroyed() 285 void WorkerMessagingProxy::workerGlobalScopeDestroyed()
274 { 286 {
275 // This method is always the last to be performed, so the proxy is not neede d for communication 287 // This method is always the last to be performed, so the proxy is not neede d for communication
276 // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too. 288 // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too.
277 m_askedToTerminate = true; 289 m_askedToTerminate = true;
278 m_workerThread = nullptr; 290 m_workerThread = nullptr;
279 291 terminateInternally();
280 InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get (), this);
281
282 if (m_mayBeDestroyed) 292 if (m_mayBeDestroyed)
283 delete this; 293 delete this;
284 } 294 }
285 295
286 void WorkerMessagingProxy::terminateWorkerGlobalScope() 296 void WorkerMessagingProxy::terminateWorkerGlobalScope()
287 { 297 {
288 if (m_askedToTerminate) 298 if (m_askedToTerminate)
289 return; 299 return;
290 m_askedToTerminate = true; 300 m_askedToTerminate = true;
291 301
292 if (m_workerThread) 302 if (m_workerThread)
293 m_workerThread->stop(); 303 m_workerThread->stop();
294 304
295 InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get (), this); 305 terminateInternally();
296 } 306 }
297 307
298 void WorkerMessagingProxy::postMessageToPageInspector(const String& message) 308 void WorkerMessagingProxy::postMessageToPageInspector(const String& message)
299 { 309 {
300 if (m_pageInspector) 310 if (m_pageInspector)
301 m_pageInspector->dispatchMessageFromWorker(message); 311 m_pageInspector->dispatchMessageFromWorker(message);
302 } 312 }
303 313
304 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivit y) 314 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivit y)
305 { 315 {
306 if (!m_askedToTerminate) { 316 if (!m_askedToTerminate) {
307 ASSERT(m_unconfirmedMessageCount); 317 ASSERT(m_unconfirmedMessageCount);
308 --m_unconfirmedMessageCount; 318 --m_unconfirmedMessageCount;
309 } 319 }
310 reportPendingActivity(hasPendingActivity); 320 reportPendingActivity(hasPendingActivity);
311 } 321 }
312 322
313 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity) 323 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity)
314 { 324 {
315 m_workerThreadHadPendingActivity = hasPendingActivity; 325 m_workerThreadHadPendingActivity = hasPendingActivity;
316 } 326 }
317 327
318 bool WorkerMessagingProxy::hasPendingActivity() const 328 bool WorkerMessagingProxy::hasPendingActivity() const
319 { 329 {
320 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m _askedToTerminate; 330 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m _askedToTerminate;
321 } 331 }
322 332
333 void WorkerMessagingProxy::terminateInternally()
334 {
335 InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get (), this);
336
337 // FIXME: This need to be revisited when we support nested worker one day
338 ASSERT(m_executionContext->isDocument());
339 Document* document = toDocument(m_executionContext.get());
340 LocalFrame* frame = document->frame();
341 if (frame)
342 frame->console().adoptWorkerConsoleMessages(this);
343 }
344
323 } // namespace blink 345 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/workers/WorkerMessagingProxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698