| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "web/WebSharedWorkerImpl.h" | 31 #include "web/WebSharedWorkerImpl.h" |
| 32 | 32 |
| 33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 34 #include "core/events/MessageEvent.h" | 34 #include "core/events/MessageEvent.h" |
| 35 #include "core/html/HTMLFormElement.h" | |
| 36 #include "core/inspector/ConsoleMessage.h" | 35 #include "core/inspector/ConsoleMessage.h" |
| 37 #include "core/inspector/InspectorInstrumentation.h" | 36 #include "core/inspector/InspectorInstrumentation.h" |
| 38 #include "core/loader/FrameLoadRequest.h" | 37 #include "core/loader/FrameLoadRequest.h" |
| 39 #include "core/loader/FrameLoader.h" | 38 #include "core/loader/FrameLoader.h" |
| 40 #include "core/page/Page.h" | |
| 41 #include "core/workers/ParentFrameTaskRunners.h" | 39 #include "core/workers/ParentFrameTaskRunners.h" |
| 42 #include "core/workers/SharedWorkerGlobalScope.h" | 40 #include "core/workers/SharedWorkerGlobalScope.h" |
| 43 #include "core/workers/SharedWorkerThread.h" | 41 #include "core/workers/SharedWorkerThread.h" |
| 44 #include "core/workers/WorkerClients.h" | 42 #include "core/workers/WorkerClients.h" |
| 45 #include "core/workers/WorkerGlobalScope.h" | 43 #include "core/workers/WorkerGlobalScope.h" |
| 46 #include "core/workers/WorkerInspectorProxy.h" | 44 #include "core/workers/WorkerInspectorProxy.h" |
| 47 #include "core/workers/WorkerLoaderProxy.h" | 45 #include "core/workers/WorkerLoaderProxy.h" |
| 48 #include "core/workers/WorkerScriptLoader.h" | 46 #include "core/workers/WorkerScriptLoader.h" |
| 49 #include "core/workers/WorkerThreadStartupData.h" | 47 #include "core/workers/WorkerThreadStartupData.h" |
| 50 #include "platform/CrossThreadFunctional.h" | 48 #include "platform/CrossThreadFunctional.h" |
| 51 #include "platform/RuntimeEnabledFeatures.h" | |
| 52 #include "platform/heap/Handle.h" | 49 #include "platform/heap/Handle.h" |
| 53 #include "platform/heap/Persistent.h" | 50 #include "platform/heap/Persistent.h" |
| 54 #include "platform/network/ContentSecurityPolicyParsers.h" | 51 #include "platform/network/ContentSecurityPolicyParsers.h" |
| 55 #include "platform/network/ResourceResponse.h" | 52 #include "platform/network/ResourceResponse.h" |
| 56 #include "platform/weborigin/KURL.h" | 53 #include "platform/weborigin/KURL.h" |
| 57 #include "platform/weborigin/SecurityOrigin.h" | 54 #include "platform/weborigin/SecurityOrigin.h" |
| 58 #include "public/platform/Platform.h" | 55 #include "public/platform/Platform.h" |
| 59 #include "public/platform/WebFileError.h" | |
| 60 #include "public/platform/WebMessagePortChannel.h" | 56 #include "public/platform/WebMessagePortChannel.h" |
| 61 #include "public/platform/WebString.h" | 57 #include "public/platform/WebString.h" |
| 62 #include "public/platform/WebURL.h" | 58 #include "public/platform/WebURL.h" |
| 63 #include "public/platform/WebURLRequest.h" | 59 #include "public/platform/WebURLRequest.h" |
| 64 #include "public/web/WebDevToolsAgent.h" | 60 #include "public/web/WebDevToolsAgent.h" |
| 65 #include "public/web/WebFrame.h" | 61 #include "public/web/WebFrame.h" |
| 66 #include "public/web/WebSettings.h" | 62 #include "public/web/WebSettings.h" |
| 67 #include "public/web/WebView.h" | 63 #include "public/web/WebView.h" |
| 68 #include "public/web/WebWorkerContentSettingsClientProxy.h" | 64 #include "public/web/WebWorkerContentSettingsClientProxy.h" |
| 69 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" | 65 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 82 // possible. | 78 // possible. |
| 83 | 79 |
| 84 WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client) | 80 WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client) |
| 85 : m_webView(nullptr), | 81 : m_webView(nullptr), |
| 86 m_mainFrame(nullptr), | 82 m_mainFrame(nullptr), |
| 87 m_askedToTerminate(false), | 83 m_askedToTerminate(false), |
| 88 m_workerInspectorProxy(WorkerInspectorProxy::create()), | 84 m_workerInspectorProxy(WorkerInspectorProxy::create()), |
| 89 m_client(client), | 85 m_client(client), |
| 90 m_pauseWorkerContextOnStart(false), | 86 m_pauseWorkerContextOnStart(false), |
| 91 m_isPausedOnStart(false), | 87 m_isPausedOnStart(false), |
| 92 m_creationAddressSpace(WebAddressSpacePublic) {} | 88 m_creationAddressSpace(WebAddressSpacePublic) { |
| 89 DCHECK(isMainThread()); |
| 90 } |
| 93 | 91 |
| 94 WebSharedWorkerImpl::~WebSharedWorkerImpl() { | 92 WebSharedWorkerImpl::~WebSharedWorkerImpl() { |
| 93 DCHECK(isMainThread()); |
| 95 DCHECK(m_webView); | 94 DCHECK(m_webView); |
| 96 // Detach the client before closing the view to avoid getting called back. | 95 // Detach the client before closing the view to avoid getting called back. |
| 97 m_mainFrame->setClient(0); | 96 m_mainFrame->setClient(0); |
| 98 | 97 |
| 99 m_webView->close(); | 98 m_webView->close(); |
| 100 m_mainFrame->close(); | 99 m_mainFrame->close(); |
| 101 if (m_loaderProxy) | 100 if (m_loaderProxy) |
| 102 m_loaderProxy->detachProvider(this); | 101 m_loaderProxy->detachProvider(this); |
| 103 } | 102 } |
| 104 | 103 |
| 105 void WebSharedWorkerImpl::terminateWorkerThread() { | 104 void WebSharedWorkerImpl::terminateWorkerThread() { |
| 105 DCHECK(isMainThread()); |
| 106 if (m_askedToTerminate) | 106 if (m_askedToTerminate) |
| 107 return; | 107 return; |
| 108 m_askedToTerminate = true; | 108 m_askedToTerminate = true; |
| 109 if (m_mainScriptLoader) { | 109 if (m_mainScriptLoader) { |
| 110 m_mainScriptLoader->cancel(); | 110 m_mainScriptLoader->cancel(); |
| 111 m_mainScriptLoader.clear(); | 111 m_mainScriptLoader.clear(); |
| 112 m_client->workerScriptLoadFailed(); | 112 m_client->workerScriptLoadFailed(); |
| 113 delete this; | 113 delete this; |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 if (m_workerThread) | 116 if (m_workerThread) |
| 117 m_workerThread->terminate(); | 117 m_workerThread->terminate(); |
| 118 m_workerInspectorProxy->workerThreadTerminated(); | 118 m_workerInspectorProxy->workerThreadTerminated(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void WebSharedWorkerImpl::initializeLoader() { | 121 void WebSharedWorkerImpl::initializeLoader() { |
| 122 DCHECK(isMainThread()); |
| 123 |
| 122 // Create 'shadow page'. This page is never displayed, it is used to proxy the | 124 // Create 'shadow page'. This page is never displayed, it is used to proxy the |
| 123 // loading requests from the worker context to the rest of WebKit and Chromium | 125 // loading requests from the worker context to the rest of WebKit and Chromium |
| 124 // infrastructure. | 126 // infrastructure. |
| 125 DCHECK(!m_webView); | 127 DCHECK(!m_webView); |
| 126 m_webView = WebView::create(nullptr, WebPageVisibilityStateVisible); | 128 m_webView = WebView::create(nullptr, WebPageVisibilityStateVisible); |
| 127 // FIXME: http://crbug.com/363843. This needs to find a better way to | 129 // FIXME: http://crbug.com/363843. This needs to find a better way to |
| 128 // not create graphics layers. | 130 // not create graphics layers. |
| 129 m_webView->settings()->setAcceleratedCompositingEnabled(false); | 131 m_webView->settings()->setAcceleratedCompositingEnabled(false); |
| 130 // FIXME: Settings information should be passed to the Worker process from | 132 // FIXME: Settings information should be passed to the Worker process from |
| 131 // Browser process when the worker is created (similar to | 133 // Browser process when the worker is created (similar to |
| 132 // RenderThread::OnCreateNewView). | 134 // RenderThread::OnCreateNewView). |
| 133 m_mainFrame = toWebLocalFrameImpl( | 135 m_mainFrame = toWebLocalFrameImpl( |
| 134 WebLocalFrame::create(WebTreeScopeType::Document, this, | 136 WebLocalFrame::create(WebTreeScopeType::Document, this, |
| 135 Platform::current()->interfaceProvider(), nullptr)); | 137 Platform::current()->interfaceProvider(), nullptr)); |
| 136 m_webView->setMainFrame(m_mainFrame.get()); | 138 m_webView->setMainFrame(m_mainFrame.get()); |
| 137 m_mainFrame->setDevToolsAgentClient(this); | 139 m_mainFrame->setDevToolsAgentClient(this); |
| 138 | 140 |
| 139 // If we were asked to pause worker context on start and wait for debugger | 141 // If we were asked to pause worker context on start and wait for debugger |
| 140 // then it is the good time to do that. | 142 // then it is the good time to do that. |
| 141 m_client->workerReadyForInspection(); | 143 m_client->workerReadyForInspection(); |
| 142 if (m_pauseWorkerContextOnStart) { | 144 if (m_pauseWorkerContextOnStart) { |
| 143 m_isPausedOnStart = true; | 145 m_isPausedOnStart = true; |
| 144 return; | 146 return; |
| 145 } | 147 } |
| 146 loadShadowPage(); | 148 loadShadowPage(); |
| 147 } | 149 } |
| 148 | 150 |
| 149 WebApplicationCacheHost* WebSharedWorkerImpl::createApplicationCacheHost( | 151 WebApplicationCacheHost* WebSharedWorkerImpl::createApplicationCacheHost( |
| 150 WebApplicationCacheHostClient* appcacheHostClient) { | 152 WebApplicationCacheHostClient* appcacheHostClient) { |
| 153 DCHECK(isMainThread()); |
| 151 return m_client->createApplicationCacheHost(appcacheHostClient); | 154 return m_client->createApplicationCacheHost(appcacheHostClient); |
| 152 } | 155 } |
| 153 | 156 |
| 154 void WebSharedWorkerImpl::loadShadowPage() { | 157 void WebSharedWorkerImpl::loadShadowPage() { |
| 158 DCHECK(isMainThread()); |
| 159 |
| 155 // Construct substitute data source for the 'shadow page'. We only need it | 160 // Construct substitute data source for the 'shadow page'. We only need it |
| 156 // to have same origin as the worker so the loading checks work correctly. | 161 // to have same origin as the worker so the loading checks work correctly. |
| 157 CString content(""); | 162 CString content(""); |
| 158 RefPtr<SharedBuffer> buffer( | 163 RefPtr<SharedBuffer> buffer( |
| 159 SharedBuffer::create(content.data(), content.length())); | 164 SharedBuffer::create(content.data(), content.length())); |
| 160 m_mainFrame->frame()->loader().load( | 165 m_mainFrame->frame()->loader().load( |
| 161 FrameLoadRequest(0, ResourceRequest(m_url), | 166 FrameLoadRequest(0, ResourceRequest(m_url), |
| 162 SubstituteData(buffer, "text/html", "UTF-8", KURL()))); | 167 SubstituteData(buffer, "text/html", "UTF-8", KURL()))); |
| 163 } | 168 } |
| 164 | 169 |
| 165 void WebSharedWorkerImpl::willSendRequest(WebLocalFrame* frame, | 170 void WebSharedWorkerImpl::willSendRequest(WebLocalFrame* frame, |
| 166 WebURLRequest& request) { | 171 WebURLRequest& request) { |
| 172 DCHECK(isMainThread()); |
| 167 if (m_networkProvider) | 173 if (m_networkProvider) |
| 168 m_networkProvider->willSendRequest(frame->dataSource(), request); | 174 m_networkProvider->willSendRequest(frame->dataSource(), request); |
| 169 } | 175 } |
| 170 | 176 |
| 171 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) { | 177 void WebSharedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) { |
| 178 DCHECK(isMainThread()); |
| 172 DCHECK(!m_loadingDocument); | 179 DCHECK(!m_loadingDocument); |
| 173 DCHECK(!m_mainScriptLoader); | 180 DCHECK(!m_mainScriptLoader); |
| 174 m_networkProvider = WTF::wrapUnique( | 181 m_networkProvider = WTF::wrapUnique( |
| 175 m_client->createServiceWorkerNetworkProvider(frame->dataSource())); | 182 m_client->createServiceWorkerNetworkProvider(frame->dataSource())); |
| 176 m_mainScriptLoader = WorkerScriptLoader::create(); | 183 m_mainScriptLoader = WorkerScriptLoader::create(); |
| 177 m_mainScriptLoader->setRequestContext( | 184 m_mainScriptLoader->setRequestContext( |
| 178 WebURLRequest::RequestContextSharedWorker); | 185 WebURLRequest::RequestContextSharedWorker); |
| 179 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document(); | 186 m_loadingDocument = toWebLocalFrameImpl(frame)->frame()->document(); |
| 180 | 187 |
| 181 CrossOriginRequestPolicy crossOriginRequestPolicy = | 188 CrossOriginRequestPolicy crossOriginRequestPolicy = |
| 182 (static_cast<KURL>(m_url)).protocolIsData() ? AllowCrossOriginRequests | 189 (static_cast<KURL>(m_url)).protocolIsData() ? AllowCrossOriginRequests |
| 183 : DenyCrossOriginRequests; | 190 : DenyCrossOriginRequests; |
| 184 | 191 |
| 185 m_mainScriptLoader->loadAsynchronously( | 192 m_mainScriptLoader->loadAsynchronously( |
| 186 *m_loadingDocument.get(), m_url, crossOriginRequestPolicy, | 193 *m_loadingDocument.get(), m_url, crossOriginRequestPolicy, |
| 187 m_creationAddressSpace, | 194 m_creationAddressSpace, |
| 188 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse, | 195 bind(&WebSharedWorkerImpl::didReceiveScriptLoaderResponse, |
| 189 WTF::unretained(this)), | 196 WTF::unretained(this)), |
| 190 bind(&WebSharedWorkerImpl::onScriptLoaderFinished, | 197 bind(&WebSharedWorkerImpl::onScriptLoaderFinished, |
| 191 WTF::unretained(this))); | 198 WTF::unretained(this))); |
| 192 // Do nothing here since onScriptLoaderFinished() might have been already | 199 // Do nothing here since onScriptLoaderFinished() might have been already |
| 193 // invoked and |this| might have been deleted at this point. | 200 // invoked and |this| might have been deleted at this point. |
| 194 } | 201 } |
| 195 | 202 |
| 196 bool WebSharedWorkerImpl::isControlledByServiceWorker( | 203 bool WebSharedWorkerImpl::isControlledByServiceWorker( |
| 197 WebDataSource& dataSource) { | 204 WebDataSource& dataSource) { |
| 205 DCHECK(isMainThread()); |
| 198 return m_networkProvider && | 206 return m_networkProvider && |
| 199 m_networkProvider->isControlledByServiceWorker(dataSource); | 207 m_networkProvider->isControlledByServiceWorker(dataSource); |
| 200 } | 208 } |
| 201 | 209 |
| 202 int64_t WebSharedWorkerImpl::serviceWorkerID(WebDataSource& dataSource) { | 210 int64_t WebSharedWorkerImpl::serviceWorkerID(WebDataSource& dataSource) { |
| 211 DCHECK(isMainThread()); |
| 203 if (!m_networkProvider) | 212 if (!m_networkProvider) |
| 204 return -1; | 213 return -1; |
| 205 return m_networkProvider->serviceWorkerID(dataSource); | 214 return m_networkProvider->serviceWorkerID(dataSource); |
| 206 } | 215 } |
| 207 | 216 |
| 208 void WebSharedWorkerImpl::sendProtocolMessage(int sessionId, | 217 void WebSharedWorkerImpl::sendProtocolMessage(int sessionId, |
| 209 int callId, | 218 int callId, |
| 210 const WebString& message, | 219 const WebString& message, |
| 211 const WebString& state) { | 220 const WebString& state) { |
| 221 DCHECK(isMainThread()); |
| 212 m_client->sendDevToolsMessage(sessionId, callId, message, state); | 222 m_client->sendDevToolsMessage(sessionId, callId, message, state); |
| 213 } | 223 } |
| 214 | 224 |
| 215 void WebSharedWorkerImpl::resumeStartup() { | 225 void WebSharedWorkerImpl::resumeStartup() { |
| 226 DCHECK(isMainThread()); |
| 216 bool isPausedOnStart = m_isPausedOnStart; | 227 bool isPausedOnStart = m_isPausedOnStart; |
| 217 m_isPausedOnStart = false; | 228 m_isPausedOnStart = false; |
| 218 if (isPausedOnStart) | 229 if (isPausedOnStart) |
| 219 loadShadowPage(); | 230 loadShadowPage(); |
| 220 } | 231 } |
| 221 | 232 |
| 222 WebDevToolsAgentClient::WebKitClientMessageLoop* | 233 WebDevToolsAgentClient::WebKitClientMessageLoop* |
| 223 WebSharedWorkerImpl::createClientMessageLoop() { | 234 WebSharedWorkerImpl::createClientMessageLoop() { |
| 235 DCHECK(isMainThread()); |
| 224 return m_client->createDevToolsMessageLoop(); | 236 return m_client->createDevToolsMessageLoop(); |
| 225 } | 237 } |
| 226 | 238 |
| 227 // WorkerReportingProxy -------------------------------------------------------- | |
| 228 | |
| 229 void WebSharedWorkerImpl::countFeature(UseCounter::Feature feature) { | 239 void WebSharedWorkerImpl::countFeature(UseCounter::Feature feature) { |
| 230 m_parentFrameTaskRunners->get(TaskType::UnspecedTimer) | 240 DCHECK(isMainThread()); |
| 231 ->postTask(BLINK_FROM_HERE, | 241 m_client->countFeature(feature); |
| 232 crossThreadBind(&WebSharedWorkerClient::countFeature, | |
| 233 crossThreadUnretained(m_client), feature)); | |
| 234 } | |
| 235 | |
| 236 void WebSharedWorkerImpl::countDeprecation(UseCounter::Feature feature) { | |
| 237 // Go through the same code path with countFeature() because a deprecation | |
| 238 // message is already shown on the worker console and a remaining work is just | |
| 239 // to record an API use. | |
| 240 countFeature(feature); | |
| 241 } | |
| 242 | |
| 243 void WebSharedWorkerImpl::reportException(const String& errorMessage, | |
| 244 std::unique_ptr<SourceLocation>, | |
| 245 int exceptionId) { | |
| 246 // Not suppported in SharedWorker. | |
| 247 } | |
| 248 | |
| 249 void WebSharedWorkerImpl::reportConsoleMessage(MessageSource, | |
| 250 MessageLevel, | |
| 251 const String& message, | |
| 252 SourceLocation*) { | |
| 253 // Not supported in SharedWorker. | |
| 254 } | 242 } |
| 255 | 243 |
| 256 void WebSharedWorkerImpl::postMessageToPageInspector(const String& message) { | 244 void WebSharedWorkerImpl::postMessageToPageInspector(const String& message) { |
| 257 // The TaskType of Inspector tasks need to be Unthrottled because they need to | 245 DCHECK(isMainThread()); |
| 258 // run even on a suspended page. | |
| 259 m_parentFrameTaskRunners->get(TaskType::Unthrottled) | |
| 260 ->postTask( | |
| 261 BLINK_FROM_HERE, | |
| 262 crossThreadBind( | |
| 263 &WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread, | |
| 264 crossThreadUnretained(this), message)); | |
| 265 } | |
| 266 | |
| 267 void WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread( | |
| 268 const String& message) { | |
| 269 m_workerInspectorProxy->dispatchMessageFromWorker(message); | 246 m_workerInspectorProxy->dispatchMessageFromWorker(message); |
| 270 } | 247 } |
| 271 | 248 |
| 272 void WebSharedWorkerImpl::didCloseWorkerGlobalScope() { | 249 void WebSharedWorkerImpl::didCloseWorkerGlobalScope() { |
| 273 m_parentFrameTaskRunners->get(TaskType::UnspecedTimer) | 250 DCHECK(isMainThread()); |
| 274 ->postTask( | |
| 275 BLINK_FROM_HERE, | |
| 276 crossThreadBind( | |
| 277 &WebSharedWorkerImpl::didCloseWorkerGlobalScopeOnMainThread, | |
| 278 crossThreadUnretained(this))); | |
| 279 } | |
| 280 | |
| 281 void WebSharedWorkerImpl::didCloseWorkerGlobalScopeOnMainThread() { | |
| 282 m_client->workerContextClosed(); | 251 m_client->workerContextClosed(); |
| 283 | |
| 284 terminateWorkerThread(); | 252 terminateWorkerThread(); |
| 285 } | 253 } |
| 286 | 254 |
| 287 void WebSharedWorkerImpl::didTerminateWorkerThread() { | 255 void WebSharedWorkerImpl::didTerminateWorkerThread() { |
| 288 m_parentFrameTaskRunners->get(TaskType::UnspecedTimer) | 256 DCHECK(isMainThread()); |
| 289 ->postTask(BLINK_FROM_HERE, | |
| 290 crossThreadBind( | |
| 291 &WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread, | |
| 292 crossThreadUnretained(this))); | |
| 293 } | |
| 294 | |
| 295 void WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread() { | |
| 296 m_client->workerContextDestroyed(); | 257 m_client->workerContextDestroyed(); |
| 297 // The lifetime of this proxy is controlled by the worker context. | 258 // The lifetime of this proxy is controlled by the worker context. |
| 298 delete this; | 259 delete this; |
| 299 } | 260 } |
| 300 | 261 |
| 301 // WorkerLoaderProxyProvider ------------------------------------------------- | 262 // WorkerLoaderProxyProvider ------------------------------------------------- |
| 302 | 263 |
| 303 void WebSharedWorkerImpl::postTaskToLoader( | 264 void WebSharedWorkerImpl::postTaskToLoader( |
| 304 const WebTraceLocation& location, | 265 const WebTraceLocation& location, |
| 305 std::unique_ptr<WTF::CrossThreadClosure> task) { | 266 std::unique_ptr<WTF::CrossThreadClosure> task) { |
| 267 DCHECK(m_workerThread->isCurrentThread()); |
| 306 m_parentFrameTaskRunners->get(TaskType::Networking) | 268 m_parentFrameTaskRunners->get(TaskType::Networking) |
| 307 ->postTask(FROM_HERE, std::move(task)); | 269 ->postTask(FROM_HERE, std::move(task)); |
| 308 } | 270 } |
| 309 | 271 |
| 310 void WebSharedWorkerImpl::postTaskToWorkerGlobalScope( | 272 void WebSharedWorkerImpl::postTaskToWorkerGlobalScope( |
| 311 const WebTraceLocation& location, | 273 const WebTraceLocation& location, |
| 312 std::unique_ptr<WTF::CrossThreadClosure> task) { | 274 std::unique_ptr<WTF::CrossThreadClosure> task) { |
| 275 DCHECK(isMainThread()); |
| 313 m_workerThread->postTask(location, std::move(task)); | 276 m_workerThread->postTask(location, std::move(task)); |
| 314 } | 277 } |
| 315 | 278 |
| 316 ExecutionContext* WebSharedWorkerImpl::getLoaderExecutionContext() { | 279 ExecutionContext* WebSharedWorkerImpl::getLoaderExecutionContext() { |
| 280 DCHECK(isMainThread()); |
| 317 return m_loadingDocument.get(); | 281 return m_loadingDocument.get(); |
| 318 } | 282 } |
| 319 | 283 |
| 320 void WebSharedWorkerImpl::connect(WebMessagePortChannel* webChannel) { | 284 void WebSharedWorkerImpl::connect(WebMessagePortChannel* webChannel) { |
| 321 DCHECK(isMainThread()); | 285 DCHECK(isMainThread()); |
| 322 workerThread()->postTask( | 286 workerThread()->postTask( |
| 323 BLINK_FROM_HERE, | 287 BLINK_FROM_HERE, |
| 324 crossThreadBind(&WebSharedWorkerImpl::connectTask, | 288 crossThreadBind(&WebSharedWorkerImpl::connectTaskOnWorkerThread, |
| 325 WTF::crossThreadUnretained(this), | 289 WTF::crossThreadUnretained(this), |
| 326 WTF::passed(WebMessagePortChannelUniquePtr(webChannel)))); | 290 WTF::passed(WebMessagePortChannelUniquePtr(webChannel)))); |
| 327 } | 291 } |
| 328 | 292 |
| 329 void WebSharedWorkerImpl::connectTask(WebMessagePortChannelUniquePtr channel) { | 293 void WebSharedWorkerImpl::connectTaskOnWorkerThread( |
| 294 WebMessagePortChannelUniquePtr channel) { |
| 330 // Wrap the passed-in channel in a MessagePort, and send it off via a connect | 295 // Wrap the passed-in channel in a MessagePort, and send it off via a connect |
| 331 // event. | 296 // event. |
| 332 DCHECK(m_workerThread->isCurrentThread()); | 297 DCHECK(m_workerThread->isCurrentThread()); |
| 333 WorkerGlobalScope* workerGlobalScope = | 298 WorkerGlobalScope* workerGlobalScope = |
| 334 toWorkerGlobalScope(m_workerThread->globalScope()); | 299 toWorkerGlobalScope(m_workerThread->globalScope()); |
| 335 MessagePort* port = MessagePort::create(*workerGlobalScope); | 300 MessagePort* port = MessagePort::create(*workerGlobalScope); |
| 336 port->entangle(std::move(channel)); | 301 port->entangle(std::move(channel)); |
| 337 SECURITY_DCHECK(workerGlobalScope->isSharedWorkerGlobalScope()); | 302 SECURITY_DCHECK(workerGlobalScope->isSharedWorkerGlobalScope()); |
| 338 workerGlobalScope->dispatchEvent(createConnectEvent(port)); | 303 workerGlobalScope->dispatchEvent(createConnectEvent(port)); |
| 339 } | 304 } |
| 340 | 305 |
| 341 void WebSharedWorkerImpl::startWorkerContext( | 306 void WebSharedWorkerImpl::startWorkerContext( |
| 342 const WebURL& url, | 307 const WebURL& url, |
| 343 const WebString& name, | 308 const WebString& name, |
| 344 const WebString& contentSecurityPolicy, | 309 const WebString& contentSecurityPolicy, |
| 345 WebContentSecurityPolicyType policyType, | 310 WebContentSecurityPolicyType policyType, |
| 346 WebAddressSpace creationAddressSpace) { | 311 WebAddressSpace creationAddressSpace) { |
| 312 DCHECK(isMainThread()); |
| 347 m_url = url; | 313 m_url = url; |
| 348 m_name = name; | 314 m_name = name; |
| 349 m_creationAddressSpace = creationAddressSpace; | 315 m_creationAddressSpace = creationAddressSpace; |
| 350 initializeLoader(); | 316 initializeLoader(); |
| 351 } | 317 } |
| 352 | 318 |
| 353 void WebSharedWorkerImpl::didReceiveScriptLoaderResponse() { | 319 void WebSharedWorkerImpl::didReceiveScriptLoaderResponse() { |
| 320 DCHECK(isMainThread()); |
| 354 InspectorInstrumentation::didReceiveScriptResponse( | 321 InspectorInstrumentation::didReceiveScriptResponse( |
| 355 m_loadingDocument, m_mainScriptLoader->identifier()); | 322 m_loadingDocument, m_mainScriptLoader->identifier()); |
| 356 m_client->selectAppCacheID(m_mainScriptLoader->appCacheID()); | 323 m_client->selectAppCacheID(m_mainScriptLoader->appCacheID()); |
| 357 } | 324 } |
| 358 | 325 |
| 359 void WebSharedWorkerImpl::onScriptLoaderFinished() { | 326 void WebSharedWorkerImpl::onScriptLoaderFinished() { |
| 327 DCHECK(isMainThread()); |
| 360 DCHECK(m_loadingDocument); | 328 DCHECK(m_loadingDocument); |
| 361 DCHECK(m_mainScriptLoader); | 329 DCHECK(m_mainScriptLoader); |
| 362 if (m_askedToTerminate) | 330 if (m_askedToTerminate) |
| 363 return; | 331 return; |
| 364 if (m_mainScriptLoader->failed()) { | 332 if (m_mainScriptLoader->failed()) { |
| 365 m_mainScriptLoader->cancel(); | 333 m_mainScriptLoader->cancel(); |
| 366 m_client->workerScriptLoadFailed(); | 334 m_client->workerScriptLoadFailed(); |
| 367 | 335 |
| 368 // The SharedWorker was unable to load the initial script, so | 336 // The SharedWorker was unable to load the initial script, so |
| 369 // shut it down right here. | 337 // shut it down right here. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 373 |
| 406 // SharedWorker can sometimes run tasks that are initiated by/associated with | 374 // SharedWorker can sometimes run tasks that are initiated by/associated with |
| 407 // a document's frame but these documents can be from a different process. So | 375 // a document's frame but these documents can be from a different process. So |
| 408 // we intentionally populate the task runners with null document in order to | 376 // we intentionally populate the task runners with null document in order to |
| 409 // use the thread's default task runner. Note that |m_document| should not be | 377 // use the thread's default task runner. Note that |m_document| should not be |
| 410 // used as it's a dummy document for loading that doesn't represent the frame | 378 // used as it's a dummy document for loading that doesn't represent the frame |
| 411 // of any associated document. | 379 // of any associated document. |
| 412 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr); | 380 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr); |
| 413 | 381 |
| 414 m_loaderProxy = WorkerLoaderProxy::create(this); | 382 m_loaderProxy = WorkerLoaderProxy::create(this); |
| 415 m_workerThread = SharedWorkerThread::create(m_name, m_loaderProxy, *this); | 383 m_reportingProxy = new WebSharedWorkerReportingProxyImpl( |
| 384 this, m_parentFrameTaskRunners.get()); |
| 385 m_workerThread = |
| 386 SharedWorkerThread::create(m_name, m_loaderProxy, *m_reportingProxy); |
| 416 InspectorInstrumentation::scriptImported(m_loadingDocument, | 387 InspectorInstrumentation::scriptImported(m_loadingDocument, |
| 417 m_mainScriptLoader->identifier(), | 388 m_mainScriptLoader->identifier(), |
| 418 m_mainScriptLoader->script()); | 389 m_mainScriptLoader->script()); |
| 419 m_mainScriptLoader.clear(); | 390 m_mainScriptLoader.clear(); |
| 420 | 391 |
| 421 workerThread()->start(std::move(startupData), m_parentFrameTaskRunners.get()); | 392 workerThread()->start(std::move(startupData), m_parentFrameTaskRunners.get()); |
| 422 m_workerInspectorProxy->workerThreadCreated(toDocument(m_loadingDocument), | 393 m_workerInspectorProxy->workerThreadCreated(toDocument(m_loadingDocument), |
| 423 workerThread(), m_url); | 394 workerThread(), m_url); |
| 424 m_client->workerScriptLoaded(); | 395 m_client->workerScriptLoaded(); |
| 425 } | 396 } |
| 426 | 397 |
| 427 void WebSharedWorkerImpl::terminateWorkerContext() { | 398 void WebSharedWorkerImpl::terminateWorkerContext() { |
| 399 DCHECK(isMainThread()); |
| 428 terminateWorkerThread(); | 400 terminateWorkerThread(); |
| 429 } | 401 } |
| 430 | 402 |
| 431 void WebSharedWorkerImpl::pauseWorkerContextOnStart() { | 403 void WebSharedWorkerImpl::pauseWorkerContextOnStart() { |
| 432 m_pauseWorkerContextOnStart = true; | 404 m_pauseWorkerContextOnStart = true; |
| 433 } | 405 } |
| 434 | 406 |
| 435 void WebSharedWorkerImpl::attachDevTools(const WebString& hostId, | 407 void WebSharedWorkerImpl::attachDevTools(const WebString& hostId, |
| 436 int sessionId) { | 408 int sessionId) { |
| 437 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); | 409 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 464 if (devtoolsAgent) | 436 if (devtoolsAgent) |
| 465 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, | 437 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, |
| 466 message); | 438 message); |
| 467 } | 439 } |
| 468 | 440 |
| 469 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { | 441 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { |
| 470 return new WebSharedWorkerImpl(client); | 442 return new WebSharedWorkerImpl(client); |
| 471 } | 443 } |
| 472 | 444 |
| 473 } // namespace blink | 445 } // namespace blink |
| OLD | NEW |