OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/workers/InProcessWorkerBase.h" | 5 #include "core/workers/InProcessWorkerBase.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "core/events/MessageEvent.h" | 8 #include "core/events/MessageEvent.h" |
9 #include "core/fetch/ResourceFetcher.h" | 9 #include "core/fetch/ResourceFetcher.h" |
10 #include "core/frame/LocalDOMWindow.h" | 10 #include "core/frame/LocalDOMWindow.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 return; | 42 return; |
43 m_contextProxy->postMessageToWorkerGlobalScope(std::move(message), | 43 m_contextProxy->postMessageToWorkerGlobalScope(std::move(message), |
44 std::move(channels)); | 44 std::move(channels)); |
45 } | 45 } |
46 | 46 |
47 bool InProcessWorkerBase::initialize(ExecutionContext* context, | 47 bool InProcessWorkerBase::initialize(ExecutionContext* context, |
48 const String& url, | 48 const String& url, |
49 ExceptionState& exceptionState) { | 49 ExceptionState& exceptionState) { |
50 suspendIfNeeded(); | 50 suspendIfNeeded(); |
51 | 51 |
52 // TODO(mkwst): Revisit the context as https://drafts.css-houdini.org/worklets
/ evolves. | 52 // TODO(mkwst): Revisit the context as |
| 53 // https://drafts.css-houdini.org/worklets/ evolves. |
53 KURL scriptURL = | 54 KURL scriptURL = |
54 resolveURL(url, exceptionState, WebURLRequest::RequestContextScript); | 55 resolveURL(url, exceptionState, WebURLRequest::RequestContextScript); |
55 if (scriptURL.isEmpty()) | 56 if (scriptURL.isEmpty()) |
56 return false; | 57 return false; |
57 | 58 |
58 m_scriptLoader = WorkerScriptLoader::create(); | 59 m_scriptLoader = WorkerScriptLoader::create(); |
59 m_scriptLoader->loadAsynchronously( | 60 m_scriptLoader->loadAsynchronously( |
60 *context, scriptURL, DenyCrossOriginRequests, | 61 *context, scriptURL, DenyCrossOriginRequests, |
61 context->securityContext().addressSpace(), | 62 context->securityContext().addressSpace(), |
62 WTF::bind(&InProcessWorkerBase::onResponse, wrapPersistent(this)), | 63 WTF::bind(&InProcessWorkerBase::onResponse, wrapPersistent(this)), |
63 WTF::bind(&InProcessWorkerBase::onFinished, wrapPersistent(this))); | 64 WTF::bind(&InProcessWorkerBase::onFinished, wrapPersistent(this))); |
64 | 65 |
65 m_contextProxy = createInProcessWorkerMessagingProxy(context); | 66 m_contextProxy = createInProcessWorkerMessagingProxy(context); |
66 | 67 |
67 return true; | 68 return true; |
68 } | 69 } |
69 | 70 |
70 void InProcessWorkerBase::terminate() { | 71 void InProcessWorkerBase::terminate() { |
71 if (m_contextProxy) | 72 if (m_contextProxy) |
72 m_contextProxy->terminateGlobalScope(); | 73 m_contextProxy->terminateGlobalScope(); |
73 } | 74 } |
74 | 75 |
75 void InProcessWorkerBase::stop() { | 76 void InProcessWorkerBase::stop() { |
76 terminate(); | 77 terminate(); |
77 } | 78 } |
78 | 79 |
79 bool InProcessWorkerBase::hasPendingActivity() const { | 80 bool InProcessWorkerBase::hasPendingActivity() const { |
80 // The worker context does not exist while loading, so we must ensure that the
worker object is not collected, nor are its event listeners. | 81 // The worker context does not exist while loading, so we must ensure that the |
| 82 // worker object is not collected, nor are its event listeners. |
81 return (m_contextProxy && m_contextProxy->hasPendingActivity()) || | 83 return (m_contextProxy && m_contextProxy->hasPendingActivity()) || |
82 m_scriptLoader; | 84 m_scriptLoader; |
83 } | 85 } |
84 | 86 |
85 ContentSecurityPolicy* InProcessWorkerBase::contentSecurityPolicy() { | 87 ContentSecurityPolicy* InProcessWorkerBase::contentSecurityPolicy() { |
86 if (m_scriptLoader) | 88 if (m_scriptLoader) |
87 return m_scriptLoader->contentSecurityPolicy(); | 89 return m_scriptLoader->contentSecurityPolicy(); |
88 return m_contentSecurityPolicy.get(); | 90 return m_contentSecurityPolicy.get(); |
89 } | 91 } |
90 | 92 |
(...skipping 24 matching lines...) Expand all Loading... |
115 m_referrerPolicy = m_scriptLoader->referrerPolicy(); | 117 m_referrerPolicy = m_scriptLoader->referrerPolicy(); |
116 m_scriptLoader = nullptr; | 118 m_scriptLoader = nullptr; |
117 } | 119 } |
118 | 120 |
119 DEFINE_TRACE(InProcessWorkerBase) { | 121 DEFINE_TRACE(InProcessWorkerBase) { |
120 visitor->trace(m_contentSecurityPolicy); | 122 visitor->trace(m_contentSecurityPolicy); |
121 AbstractWorker::trace(visitor); | 123 AbstractWorker::trace(visitor); |
122 } | 124 } |
123 | 125 |
124 } // namespace blink | 126 } // namespace blink |
OLD | NEW |