| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() | 98 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() |
| 99 { | 99 { |
| 100 // Prevent onScriptLoaderFinished from deleting 'this'. | 100 // Prevent onScriptLoaderFinished from deleting 'this'. |
| 101 m_askedToTerminate = true; | 101 m_askedToTerminate = true; |
| 102 | 102 |
| 103 if (m_workerThread) | 103 if (m_workerThread) |
| 104 m_workerThread->terminateAndWait(); | 104 m_workerThread->terminateAndWait(); |
| 105 | 105 |
| 106 ASSERT(runningWorkerInstances().contains(this)); | 106 DCHECK(runningWorkerInstances().contains(this)); |
| 107 runningWorkerInstances().remove(this); | 107 runningWorkerInstances().remove(this); |
| 108 ASSERT(m_webView); | 108 DCHECK(m_webView); |
| 109 | 109 |
| 110 // Detach the client before closing the view to avoid getting called back. | 110 // Detach the client before closing the view to avoid getting called back. |
| 111 m_mainFrame->setClient(0); | 111 m_mainFrame->setClient(0); |
| 112 | 112 |
| 113 if (m_workerGlobalScopeProxy) { | 113 if (m_workerGlobalScopeProxy) { |
| 114 m_workerGlobalScopeProxy->detach(); | 114 m_workerGlobalScopeProxy->detach(); |
| 115 m_workerGlobalScopeProxy.clear(); | 115 m_workerGlobalScopeProxy.clear(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 m_webView->close(); | 118 m_webView->close(); |
| 119 m_mainFrame->close(); | 119 m_mainFrame->close(); |
| 120 if (m_loaderProxy) | 120 if (m_loaderProxy) |
| 121 m_loaderProxy->detachProvider(this); | 121 m_loaderProxy->detachProvider(this); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void WebEmbeddedWorkerImpl::startWorkerContext( | 124 void WebEmbeddedWorkerImpl::startWorkerContext( |
| 125 const WebEmbeddedWorkerStartData& data) | 125 const WebEmbeddedWorkerStartData& data) |
| 126 { | 126 { |
| 127 ASSERT(!m_askedToTerminate); | 127 DCHECK(!m_askedToTerminate); |
| 128 ASSERT(!m_mainScriptLoader); | 128 DCHECK(!m_mainScriptLoader); |
| 129 ASSERT(m_pauseAfterDownloadState == DontPauseAfterDownload); | 129 DCHECK_EQ(m_pauseAfterDownloadState, DontPauseAfterDownload); |
| 130 m_workerStartData = data; | 130 m_workerStartData = data; |
| 131 if (data.pauseAfterDownloadMode == WebEmbeddedWorkerStartData::PauseAfterDow
nload) | 131 if (data.pauseAfterDownloadMode == WebEmbeddedWorkerStartData::PauseAfterDow
nload) |
| 132 m_pauseAfterDownloadState = DoPauseAfterDownload; | 132 m_pauseAfterDownloadState = DoPauseAfterDownload; |
| 133 prepareShadowPageForLoader(); | 133 prepareShadowPageForLoader(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void WebEmbeddedWorkerImpl::terminateWorkerContext() | 136 void WebEmbeddedWorkerImpl::terminateWorkerContext() |
| 137 { | 137 { |
| 138 if (m_askedToTerminate) | 138 if (m_askedToTerminate) |
| 139 return; | 139 return; |
| 140 m_askedToTerminate = true; | 140 m_askedToTerminate = true; |
| 141 if (m_loadingShadowPage) { | 141 if (m_loadingShadowPage) { |
| 142 // This deletes 'this'. | 142 // This deletes 'this'. |
| 143 m_workerContextClient->workerContextFailedToStart(); | 143 m_workerContextClient->workerContextFailedToStart(); |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 if (m_mainScriptLoader) { | 146 if (m_mainScriptLoader) { |
| 147 m_mainScriptLoader->cancel(); | 147 m_mainScriptLoader->cancel(); |
| 148 m_mainScriptLoader.clear(); | 148 m_mainScriptLoader.clear(); |
| 149 // This deletes 'this'. | 149 // This deletes 'this'. |
| 150 m_workerContextClient->workerContextFailedToStart(); | 150 m_workerContextClient->workerContextFailedToStart(); |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 if (!m_workerThread) { | 153 if (!m_workerThread) { |
| 154 // The worker thread has not been created yet if the worker is asked to | 154 // The worker thread has not been created yet if the worker is asked to |
| 155 // terminate during waiting for debugger or paused after download. | 155 // terminate during waiting for debugger or paused after download. |
| 156 ASSERT(m_workerStartData.waitForDebuggerMode == WebEmbeddedWorkerStartDa
ta::WaitForDebugger || m_pauseAfterDownloadState == IsPausedAfterDownload); | 156 DCHECK(m_workerStartData.waitForDebuggerMode == WebEmbeddedWorkerStartDa
ta::WaitForDebugger || m_pauseAfterDownloadState == IsPausedAfterDownload); |
| 157 // This deletes 'this'. | 157 // This deletes 'this'. |
| 158 m_workerContextClient->workerContextFailedToStart(); | 158 m_workerContextClient->workerContextFailedToStart(); |
| 159 return; | 159 return; |
| 160 } | 160 } |
| 161 m_workerThread->terminate(); | 161 m_workerThread->terminate(); |
| 162 m_workerInspectorProxy->workerThreadTerminated(); | 162 m_workerInspectorProxy->workerThreadTerminated(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void WebEmbeddedWorkerImpl::resumeAfterDownload() | 165 void WebEmbeddedWorkerImpl::resumeAfterDownload() |
| 166 { | 166 { |
| 167 ASSERT(!m_askedToTerminate); | 167 DCHECK(!m_askedToTerminate); |
| 168 ASSERT(m_pauseAfterDownloadState == IsPausedAfterDownload); | 168 DCHECK_EQ(m_pauseAfterDownloadState, IsPausedAfterDownload); |
| 169 | 169 |
| 170 m_pauseAfterDownloadState = DontPauseAfterDownload; | 170 m_pauseAfterDownloadState = DontPauseAfterDownload; |
| 171 startWorkerThread(); | 171 startWorkerThread(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void WebEmbeddedWorkerImpl::attachDevTools(const WebString& hostId, int sessionI
d) | 174 void WebEmbeddedWorkerImpl::attachDevTools(const WebString& hostId, int sessionI
d) |
| 175 { | 175 { |
| 176 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); | 176 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); |
| 177 if (devtoolsAgent) | 177 if (devtoolsAgent) |
| 178 devtoolsAgent->attach(hostId, sessionId); | 178 devtoolsAgent->attach(hostId, sessionId); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 222 } |
| 223 | 223 |
| 224 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() | 224 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() |
| 225 { | 225 { |
| 226 // Create 'shadow page', which is never displayed and is used mainly to | 226 // Create 'shadow page', which is never displayed and is used mainly to |
| 227 // provide a context for loading on the main thread. | 227 // provide a context for loading on the main thread. |
| 228 // | 228 // |
| 229 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. | 229 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. |
| 230 // This code, and probably most of the code in this class should be shared | 230 // This code, and probably most of the code in this class should be shared |
| 231 // with SharedWorker. | 231 // with SharedWorker. |
| 232 ASSERT(!m_webView); | 232 DCHECK(!m_webView); |
| 233 m_webView = WebView::create(0); | 233 m_webView = WebView::create(0); |
| 234 WebSettings* settings = m_webView->settings(); | 234 WebSettings* settings = m_webView->settings(); |
| 235 // FIXME: http://crbug.com/363843. This needs to find a better way to | 235 // FIXME: http://crbug.com/363843. This needs to find a better way to |
| 236 // not create graphics layers. | 236 // not create graphics layers. |
| 237 settings->setAcceleratedCompositingEnabled(false); | 237 settings->setAcceleratedCompositingEnabled(false); |
| 238 // Currently we block all mixed-content requests from a ServiceWorker. | 238 // Currently we block all mixed-content requests from a ServiceWorker. |
| 239 // FIXME: When we support FetchEvent.default(), we should relax this | 239 // FIXME: When we support FetchEvent.default(), we should relax this |
| 240 // restriction. | 240 // restriction. |
| 241 settings->setStrictMixedContentChecking(true); | 241 settings->setStrictMixedContentChecking(true); |
| 242 settings->setAllowDisplayOfInsecureContent(false); | 242 settings->setAllowDisplayOfInsecureContent(false); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 269 void WebEmbeddedWorkerImpl::willSendRequest( | 269 void WebEmbeddedWorkerImpl::willSendRequest( |
| 270 WebLocalFrame* frame, unsigned, WebURLRequest& request, | 270 WebLocalFrame* frame, unsigned, WebURLRequest& request, |
| 271 const WebURLResponse& redirectResponse) | 271 const WebURLResponse& redirectResponse) |
| 272 { | 272 { |
| 273 if (m_networkProvider) | 273 if (m_networkProvider) |
| 274 m_networkProvider->willSendRequest(frame->dataSource(), request); | 274 m_networkProvider->willSendRequest(frame->dataSource(), request); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) | 277 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) |
| 278 { | 278 { |
| 279 ASSERT(!m_mainScriptLoader); | 279 DCHECK(!m_mainScriptLoader); |
| 280 ASSERT(!m_networkProvider); | 280 DCHECK(!m_networkProvider); |
| 281 ASSERT(m_mainFrame); | 281 DCHECK(m_mainFrame); |
| 282 ASSERT(m_workerContextClient); | 282 DCHECK(m_workerContextClient); |
| 283 ASSERT(m_loadingShadowPage); | 283 DCHECK(m_loadingShadowPage); |
| 284 ASSERT(!m_askedToTerminate); | 284 DCHECK(!m_askedToTerminate); |
| 285 m_loadingShadowPage = false; | 285 m_loadingShadowPage = false; |
| 286 m_networkProvider = adoptPtr(m_workerContextClient->createServiceWorkerNetwo
rkProvider(frame->dataSource())); | 286 m_networkProvider = adoptPtr(m_workerContextClient->createServiceWorkerNetwo
rkProvider(frame->dataSource())); |
| 287 m_mainScriptLoader = WorkerScriptLoader::create(); | 287 m_mainScriptLoader = WorkerScriptLoader::create(); |
| 288 m_mainScriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo
rker); | 288 m_mainScriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo
rker); |
| 289 m_mainScriptLoader->loadAsynchronously( | 289 m_mainScriptLoader->loadAsynchronously( |
| 290 *m_mainFrame->frame()->document(), | 290 *m_mainFrame->frame()->document(), |
| 291 m_workerStartData.scriptURL, | 291 m_workerStartData.scriptURL, |
| 292 DenyCrossOriginRequests, | 292 DenyCrossOriginRequests, |
| 293 m_mainFrame->frame()->document()->addressSpace(), | 293 m_mainFrame->frame()->document()->addressSpace(), |
| 294 nullptr, | 294 nullptr, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 305 void WebEmbeddedWorkerImpl::resumeStartup() | 305 void WebEmbeddedWorkerImpl::resumeStartup() |
| 306 { | 306 { |
| 307 bool wasWaiting = (m_waitingForDebuggerState == WaitingForDebugger); | 307 bool wasWaiting = (m_waitingForDebuggerState == WaitingForDebugger); |
| 308 m_waitingForDebuggerState = NotWaitingForDebugger; | 308 m_waitingForDebuggerState = NotWaitingForDebugger; |
| 309 if (wasWaiting) | 309 if (wasWaiting) |
| 310 loadShadowPage(); | 310 loadShadowPage(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() | 313 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() |
| 314 { | 314 { |
| 315 ASSERT(m_mainScriptLoader); | 315 DCHECK(m_mainScriptLoader); |
| 316 if (m_askedToTerminate) | 316 if (m_askedToTerminate) |
| 317 return; | 317 return; |
| 318 | 318 |
| 319 if (m_mainScriptLoader->failed()) { | 319 if (m_mainScriptLoader->failed()) { |
| 320 m_mainScriptLoader.clear(); | 320 m_mainScriptLoader.clear(); |
| 321 // This deletes 'this'. | 321 // This deletes 'this'. |
| 322 m_workerContextClient->workerContextFailedToStart(); | 322 m_workerContextClient->workerContextFailedToStart(); |
| 323 return; | 323 return; |
| 324 } | 324 } |
| 325 m_workerContextClient->workerScriptLoaded(); | 325 m_workerContextClient->workerScriptLoaded(); |
| 326 | 326 |
| 327 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptSizeHistogram, ("ServiceWork
er.ScriptSize", 1000, 5000000, 50)); | 327 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptSizeHistogram, ("ServiceWork
er.ScriptSize", 1000, 5000000, 50)); |
| 328 scriptSizeHistogram.count(m_mainScriptLoader->script().length()); | 328 scriptSizeHistogram.count(m_mainScriptLoader->script().length()); |
| 329 if (m_mainScriptLoader->cachedMetadata()) { | 329 if (m_mainScriptLoader->cachedMetadata()) { |
| 330 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptCachedMetadataSizeHistog
ram, ("ServiceWorker.ScriptCachedMetadataSize", 1000, 50000000, 50)); | 330 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptCachedMetadataSizeHistog
ram, ("ServiceWorker.ScriptCachedMetadataSize", 1000, 50000000, 50)); |
| 331 scriptCachedMetadataSizeHistogram.count(m_mainScriptLoader->cachedMetada
ta()->size()); | 331 scriptCachedMetadataSizeHistogram.count(m_mainScriptLoader->cachedMetada
ta()->size()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 if (m_pauseAfterDownloadState == DoPauseAfterDownload) { | 334 if (m_pauseAfterDownloadState == DoPauseAfterDownload) { |
| 335 m_pauseAfterDownloadState = IsPausedAfterDownload; | 335 m_pauseAfterDownloadState = IsPausedAfterDownload; |
| 336 return; | 336 return; |
| 337 } | 337 } |
| 338 startWorkerThread(); | 338 startWorkerThread(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void WebEmbeddedWorkerImpl::startWorkerThread() | 341 void WebEmbeddedWorkerImpl::startWorkerThread() |
| 342 { | 342 { |
| 343 ASSERT(m_pauseAfterDownloadState == DontPauseAfterDownload); | 343 DCHECK_EQ(m_pauseAfterDownloadState, DontPauseAfterDownload); |
| 344 ASSERT(!m_askedToTerminate); | 344 DCHECK(!m_askedToTerminate); |
| 345 | 345 |
| 346 Document* document = m_mainFrame->frame()->document(); | 346 Document* document = m_mainFrame->frame()->document(); |
| 347 | 347 |
| 348 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) | 348 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) |
| 349 SecurityOrigin* starterOrigin = document->getSecurityOrigin(); | 349 SecurityOrigin* starterOrigin = document->getSecurityOrigin(); |
| 350 | 350 |
| 351 RawPtr<WorkerClients> workerClients = WorkerClients::create(); | 351 RawPtr<WorkerClients> workerClients = WorkerClients::create(); |
| 352 provideContentSettingsClientToWorker(workerClients.get(), m_contentSettingsC
lient.release()); | 352 provideContentSettingsClientToWorker(workerClients.get(), m_contentSettingsC
lient.release()); |
| 353 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo
rkerGlobalScopeClientImpl::create(*m_workerContextClient)); | 353 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo
rkerGlobalScopeClientImpl::create(*m_workerContextClient)); |
| 354 provideServiceWorkerContainerClientToWorker(workerClients.get(), adoptPtr(m_
workerContextClient->createServiceWorkerProvider())); | 354 provideServiceWorkerContainerClientToWorker(workerClients.get(), adoptPtr(m_
workerContextClient->createServiceWorkerProvider())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 373 m_mainScriptLoader.clear(); | 373 m_mainScriptLoader.clear(); |
| 374 | 374 |
| 375 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); | 375 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); |
| 376 m_loaderProxy = WorkerLoaderProxy::create(this); | 376 m_loaderProxy = WorkerLoaderProxy::create(this); |
| 377 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); | 377 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); |
| 378 m_workerThread->start(startupData.release()); | 378 m_workerThread->start(startupData.release()); |
| 379 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); | 379 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); |
| 380 } | 380 } |
| 381 | 381 |
| 382 } // namespace blink | 382 } // namespace blink |
| OLD | NEW |