OLD | NEW |
---|---|
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 Loading... | |
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 RefPtrWillBeRawPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sour ceURL, lineNumber, columnNumber, 0); | 172 RefPtrWillBeRawPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, sour ceURL, lineNumber, columnNumber, 0); |
170 bool errorHandled = !m_workerObject->dispatchEvent(event); | 173 bool errorHandled = !m_workerObject->dispatchEvent(event); |
171 if (!errorHandled) | 174 if (!errorHandled) |
172 m_executionContext->reportException(event, nullptr, NotSharableCrossOrig in); | 175 m_executionContext->reportException(event, nullptr, NotSharableCrossOrig in); |
173 } | 176 } |
174 | 177 |
175 void WorkerMessagingProxy::reportConsoleMessage(MessageSource source, MessageLev el level, const String& message, int lineNumber, const String& sourceURL) | 178 void WorkerMessagingProxy::reportConsoleMessage(MessageSource source, MessageLev el level, const String& message, int lineNumber, const String& sourceURL) |
176 { | 179 { |
177 if (m_askedToTerminate) | 180 if (m_askedToTerminate) |
178 return; | 181 return; |
179 m_executionContext->addConsoleMessage(ConsoleMessage::create(source, level, message, sourceURL, lineNumber)); | 182 // FIXME: In case of nested workers, this should go directly to the root Doc ument context. |
183 ASSERT(m_executionContext->isDocument()); | |
184 Document* document = toDocument(m_executionContext.get()); | |
185 LocalFrame* frame = document->frame(); | |
186 if (!frame) | |
187 return; | |
188 | |
189 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(s ource, level, message, sourceURL, lineNumber); | |
190 consoleMessage->setWorkerId(this); | |
191 frame->console().addMessage(consoleMessage.release()); | |
180 } | 192 } |
181 | 193 |
182 void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread> workerThread) | 194 void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread> workerThread) |
183 { | 195 { |
184 m_workerThread = workerThread; | 196 m_workerThread = workerThread; |
185 | 197 |
186 if (m_askedToTerminate) { | 198 if (m_askedToTerminate) { |
187 // Worker.terminate() could be called from JS before the thread was crea ted. | 199 // Worker.terminate() could be called from JS before the thread was crea ted. |
188 m_workerThread->stop(); | 200 m_workerThread->stop(); |
189 } else { | 201 } else { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 } | 266 } |
255 | 267 |
256 void WorkerMessagingProxy::workerGlobalScopeDestroyed() | 268 void WorkerMessagingProxy::workerGlobalScopeDestroyed() |
257 { | 269 { |
258 // This method is always the last to be performed, so the proxy is not neede d for communication | 270 // This method is always the last to be performed, so the proxy is not neede d for communication |
259 // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too. | 271 // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too. |
260 m_askedToTerminate = true; | 272 m_askedToTerminate = true; |
261 m_workerThread = nullptr; | 273 m_workerThread = nullptr; |
262 | 274 |
263 InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get (), this); | 275 InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get (), this); |
276 // FIXME: This need to be revisited when we support nested worker one day | |
vsevik
2014/08/12 15:46:07
Let's extract a method here.
sergeyv
2014/08/12 16:00:59
Done.
| |
277 ASSERT(m_executionContext->isDocument()); | |
278 Document* document = toDocument(m_executionContext.get()); | |
279 LocalFrame* frame = document->frame(); | |
280 if (frame) | |
281 frame->console().workerGlobalScopeTerminated(this); | |
vsevik
2014/08/12 15:49:31
adoptWorkerConsoleMsssages
sergeyv
2014/08/12 16:00:59
Done.
| |
264 | 282 |
265 if (m_mayBeDestroyed) | 283 if (m_mayBeDestroyed) |
266 delete this; | 284 delete this; |
267 } | 285 } |
268 | 286 |
269 void WorkerMessagingProxy::terminateWorkerGlobalScope() | 287 void WorkerMessagingProxy::terminateWorkerGlobalScope() |
270 { | 288 { |
271 if (m_askedToTerminate) | 289 if (m_askedToTerminate) |
272 return; | 290 return; |
273 m_askedToTerminate = true; | 291 m_askedToTerminate = true; |
274 | 292 |
275 if (m_workerThread) | 293 if (m_workerThread) |
276 m_workerThread->stop(); | 294 m_workerThread->stop(); |
277 | 295 |
278 InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get (), this); | 296 InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get (), this); |
297 // FIXME: This need to be revisited when we support nested worker one day | |
298 ASSERT(m_executionContext->isDocument()); | |
299 Document* document = toDocument(m_executionContext.get()); | |
300 LocalFrame* frame = document->frame(); | |
301 if (frame) | |
302 frame->console().workerGlobalScopeTerminated(this); | |
279 } | 303 } |
280 | 304 |
281 void WorkerMessagingProxy::postMessageToPageInspector(const String& message) | 305 void WorkerMessagingProxy::postMessageToPageInspector(const String& message) |
282 { | 306 { |
283 if (m_pageInspector) | 307 if (m_pageInspector) |
284 m_pageInspector->dispatchMessageFromWorker(message); | 308 m_pageInspector->dispatchMessageFromWorker(message); |
285 } | 309 } |
286 | 310 |
287 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivit y) | 311 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivit y) |
288 { | 312 { |
289 if (!m_askedToTerminate) { | 313 if (!m_askedToTerminate) { |
290 ASSERT(m_unconfirmedMessageCount); | 314 ASSERT(m_unconfirmedMessageCount); |
291 --m_unconfirmedMessageCount; | 315 --m_unconfirmedMessageCount; |
292 } | 316 } |
293 reportPendingActivity(hasPendingActivity); | 317 reportPendingActivity(hasPendingActivity); |
294 } | 318 } |
295 | 319 |
296 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity) | 320 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity) |
297 { | 321 { |
298 m_workerThreadHadPendingActivity = hasPendingActivity; | 322 m_workerThreadHadPendingActivity = hasPendingActivity; |
299 } | 323 } |
300 | 324 |
301 bool WorkerMessagingProxy::hasPendingActivity() const | 325 bool WorkerMessagingProxy::hasPendingActivity() const |
302 { | 326 { |
303 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m _askedToTerminate; | 327 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m _askedToTerminate; |
304 } | 328 } |
305 | 329 |
306 } // namespace blink | 330 } // namespace blink |
OLD | NEW |