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 10 matching lines...) Expand all Loading... |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 * | 25 * |
26 */ | 26 */ |
27 | 27 |
28 | 28 |
29 #include "core/workers/InProcessWorkerMessagingProxy.h" | 29 #include "core/workers/InProcessWorkerMessagingProxy.h" |
30 | 30 |
31 #include "bindings/core/v8/V8GCController.h" | |
32 #include "core/dom/CrossThreadTask.h" | 31 #include "core/dom/CrossThreadTask.h" |
33 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
34 #include "core/dom/SecurityContext.h" | 33 #include "core/dom/SecurityContext.h" |
35 #include "core/events/ErrorEvent.h" | 34 #include "core/events/ErrorEvent.h" |
36 #include "core/events/MessageEvent.h" | 35 #include "core/events/MessageEvent.h" |
37 #include "core/frame/FrameConsole.h" | 36 #include "core/frame/FrameConsole.h" |
38 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
39 #include "core/frame/csp/ContentSecurityPolicy.h" | 38 #include "core/frame/csp/ContentSecurityPolicy.h" |
40 #include "core/inspector/ConsoleMessage.h" | 39 #include "core/inspector/ConsoleMessage.h" |
41 #include "core/loader/DocumentLoadTiming.h" | 40 #include "core/loader/DocumentLoadTiming.h" |
(...skipping 16 matching lines...) Expand all Loading... |
58 { | 57 { |
59 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); | 58 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); |
60 globalScope->exceptionUnhandled(exceptionId); | 59 globalScope->exceptionUnhandled(exceptionId); |
61 } | 60 } |
62 | 61 |
63 void processMessageOnWorkerGlobalScope(PassRefPtr<SerializedScriptValue> message
, std::unique_ptr<MessagePortChannelArray> channels, InProcessWorkerObjectProxy*
workerObjectProxy, ExecutionContext* scriptContext) | 62 void processMessageOnWorkerGlobalScope(PassRefPtr<SerializedScriptValue> message
, std::unique_ptr<MessagePortChannelArray> channels, InProcessWorkerObjectProxy*
workerObjectProxy, ExecutionContext* scriptContext) |
64 { | 63 { |
65 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); | 64 WorkerGlobalScope* globalScope = toWorkerGlobalScope(scriptContext); |
66 MessagePortArray* ports = MessagePort::entanglePorts(*scriptContext, std::mo
ve(channels)); | 65 MessagePortArray* ports = MessagePort::entanglePorts(*scriptContext, std::mo
ve(channels)); |
67 globalScope->dispatchEvent(MessageEvent::create(ports, message)); | 66 globalScope->dispatchEvent(MessageEvent::create(ports, message)); |
68 workerObjectProxy->confirmMessageFromWorkerObject(V8GCController::hasPending
Activity(globalScope->thread()->isolate(), scriptContext)); | 67 workerObjectProxy->reportPendingActivity(globalScope); |
| 68 workerObjectProxy->confirmMessageFromWorkerObject(); |
69 } | 69 } |
70 | 70 |
71 static int s_liveMessagingProxyCount = 0; | 71 static int s_liveMessagingProxyCount = 0; |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 InProcessWorkerMessagingProxy::InProcessWorkerMessagingProxy(InProcessWorkerBase
* workerObject, WorkerClients* workerClients) | 75 InProcessWorkerMessagingProxy::InProcessWorkerMessagingProxy(ExecutionContext* e
xecutionContext, InProcessWorkerBase* workerObject, WorkerClients* workerClients
) |
76 : m_executionContext(workerObject->getExecutionContext()) | 76 : m_executionContext(executionContext) |
77 , m_workerObjectProxy(InProcessWorkerObjectProxy::create(this)) | 77 , m_workerObjectProxy(InProcessWorkerObjectProxy::create(this)) |
78 , m_workerObject(workerObject) | 78 , m_workerObject(workerObject) |
79 , m_mayBeDestroyed(false) | |
80 , m_unconfirmedMessageCount(0) | 79 , m_unconfirmedMessageCount(0) |
81 , m_workerThreadHadPendingActivity(false) | |
82 , m_askedToTerminate(false) | |
83 , m_workerInspectorProxy(WorkerInspectorProxy::create()) | 80 , m_workerInspectorProxy(WorkerInspectorProxy::create()) |
84 , m_workerClients(workerClients) | 81 , m_workerClients(workerClients) |
85 { | 82 { |
86 DCHECK(isParentContextThread()); | 83 DCHECK(isParentContextThread()); |
87 DCHECK(m_workerObject); | |
88 s_liveMessagingProxyCount++; | 84 s_liveMessagingProxyCount++; |
89 } | 85 } |
90 | 86 |
91 InProcessWorkerMessagingProxy::~InProcessWorkerMessagingProxy() | 87 InProcessWorkerMessagingProxy::~InProcessWorkerMessagingProxy() |
92 { | 88 { |
93 DCHECK(isParentContextThread()); | 89 DCHECK(isParentContextThread()); |
94 DCHECK(!m_workerObject); | 90 DCHECK(!m_workerObject); |
95 if (m_loaderProxy) | 91 if (m_loaderProxy) |
96 m_loaderProxy->detachProvider(this); | 92 m_loaderProxy->detachProvider(this); |
97 s_liveMessagingProxyCount--; | 93 s_liveMessagingProxyCount--; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 m_workerInspectorProxy->workerThreadTerminated(); | 259 m_workerInspectorProxy->workerThreadTerminated(); |
264 } | 260 } |
265 | 261 |
266 void InProcessWorkerMessagingProxy::postMessageToPageInspector(const String& mes
sage) | 262 void InProcessWorkerMessagingProxy::postMessageToPageInspector(const String& mes
sage) |
267 { | 263 { |
268 DCHECK(isParentContextThread()); | 264 DCHECK(isParentContextThread()); |
269 if (m_workerInspectorProxy) | 265 if (m_workerInspectorProxy) |
270 m_workerInspectorProxy->dispatchMessageFromWorker(message); | 266 m_workerInspectorProxy->dispatchMessageFromWorker(message); |
271 } | 267 } |
272 | 268 |
273 void InProcessWorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendi
ngActivity) | 269 void InProcessWorkerMessagingProxy::confirmMessageFromWorkerObject() |
274 { | 270 { |
275 DCHECK(isParentContextThread()); | 271 DCHECK(isParentContextThread()); |
276 if (!m_askedToTerminate) { | 272 if (m_askedToTerminate) |
277 DCHECK(m_unconfirmedMessageCount); | 273 return; |
278 --m_unconfirmedMessageCount; | 274 DCHECK(m_unconfirmedMessageCount); |
279 } | 275 --m_unconfirmedMessageCount; |
280 reportPendingActivity(hasPendingActivity); | |
281 } | 276 } |
282 | 277 |
283 void InProcessWorkerMessagingProxy::reportPendingActivity(bool hasPendingActivit
y) | 278 void InProcessWorkerMessagingProxy::reportPendingActivity(bool hasPendingActivit
y) |
284 { | 279 { |
285 DCHECK(isParentContextThread()); | 280 DCHECK(isParentContextThread()); |
286 m_workerThreadHadPendingActivity = hasPendingActivity; | 281 m_workerThreadHadPendingActivity = hasPendingActivity; |
287 } | 282 } |
288 | 283 |
289 bool InProcessWorkerMessagingProxy::hasPendingActivity() const | 284 bool InProcessWorkerMessagingProxy::hasPendingActivity() const |
290 { | 285 { |
291 DCHECK(isParentContextThread()); | 286 DCHECK(isParentContextThread()); |
292 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m
_askedToTerminate; | 287 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m
_askedToTerminate; |
293 } | 288 } |
294 | 289 |
295 bool InProcessWorkerMessagingProxy::isParentContextThread() const | 290 bool InProcessWorkerMessagingProxy::isParentContextThread() const |
296 { | 291 { |
297 // TODO(nhiroki): Nested worker is not supported yet, so the parent context | 292 // TODO(nhiroki): Nested worker is not supported yet, so the parent context |
298 // thread should be equal to the main thread (http://crbug.com/31666). | 293 // thread should be equal to the main thread (http://crbug.com/31666). |
299 DCHECK(getExecutionContext()->isDocument()); | 294 DCHECK(getExecutionContext()->isDocument()); |
300 return isMainThread(); | 295 return isMainThread(); |
301 } | 296 } |
302 | 297 |
303 } // namespace blink | 298 } // namespace blink |
OLD | NEW |