| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include "public/web/WebWorkerContentSettingsClientProxy.h" | 64 #include "public/web/WebWorkerContentSettingsClientProxy.h" |
| 65 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" | 65 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" |
| 66 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" | 66 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" |
| 67 #include "web/IndexedDBClientImpl.h" | 67 #include "web/IndexedDBClientImpl.h" |
| 68 #include "web/ServiceWorkerGlobalScopeClientImpl.h" | 68 #include "web/ServiceWorkerGlobalScopeClientImpl.h" |
| 69 #include "web/ServiceWorkerGlobalScopeProxy.h" | 69 #include "web/ServiceWorkerGlobalScopeProxy.h" |
| 70 #include "web/WebDataSourceImpl.h" | 70 #include "web/WebDataSourceImpl.h" |
| 71 #include "web/WebLocalFrameImpl.h" | 71 #include "web/WebLocalFrameImpl.h" |
| 72 #include "web/WorkerContentSettingsClient.h" | 72 #include "web/WorkerContentSettingsClient.h" |
| 73 #include "wtf/Functional.h" | 73 #include "wtf/Functional.h" |
| 74 #include "wtf/PtrUtil.h" | |
| 75 #include <memory> | |
| 76 | 74 |
| 77 namespace blink { | 75 namespace blink { |
| 78 | 76 |
| 79 WebEmbeddedWorker* WebEmbeddedWorker::create(WebServiceWorkerContextClient* clie
nt, WebWorkerContentSettingsClientProxy* contentSettingsClient) | 77 WebEmbeddedWorker* WebEmbeddedWorker::create(WebServiceWorkerContextClient* clie
nt, WebWorkerContentSettingsClientProxy* contentSettingsClient) |
| 80 { | 78 { |
| 81 return new WebEmbeddedWorkerImpl(wrapUnique(client), wrapUnique(contentSetti
ngsClient)); | 79 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(contentSettingsC
lient)); |
| 82 } | 80 } |
| 83 | 81 |
| 84 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() | 82 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() |
| 85 { | 83 { |
| 86 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); | 84 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); |
| 87 return set; | 85 return set; |
| 88 } | 86 } |
| 89 | 87 |
| 90 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl(std::unique_ptr<WebServiceWorkerCon
textClient> client, std::unique_ptr<WebWorkerContentSettingsClientProxy> content
SettingsClient) | 88 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl(PassOwnPtr<WebServiceWorkerContextC
lient> client, PassOwnPtr<WebWorkerContentSettingsClientProxy> contentSettingsCl
ient) |
| 91 : m_workerContextClient(std::move(client)) | 89 : m_workerContextClient(std::move(client)) |
| 92 , m_contentSettingsClient(std::move(contentSettingsClient)) | 90 , m_contentSettingsClient(std::move(contentSettingsClient)) |
| 93 , m_workerInspectorProxy(WorkerInspectorProxy::create()) | 91 , m_workerInspectorProxy(WorkerInspectorProxy::create()) |
| 94 , m_webView(nullptr) | 92 , m_webView(nullptr) |
| 95 , m_mainFrame(nullptr) | 93 , m_mainFrame(nullptr) |
| 96 , m_loadingShadowPage(false) | 94 , m_loadingShadowPage(false) |
| 97 , m_askedToTerminate(false) | 95 , m_askedToTerminate(false) |
| 98 , m_pauseAfterDownloadState(DontPauseAfterDownload) | 96 , m_pauseAfterDownloadState(DontPauseAfterDownload) |
| 99 , m_waitingForDebuggerState(NotWaitingForDebugger) | 97 , m_waitingForDebuggerState(NotWaitingForDebugger) |
| 100 { | 98 { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 320 |
| 323 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) | 321 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) |
| 324 { | 322 { |
| 325 DCHECK(!m_mainScriptLoader); | 323 DCHECK(!m_mainScriptLoader); |
| 326 DCHECK(!m_networkProvider); | 324 DCHECK(!m_networkProvider); |
| 327 DCHECK(m_mainFrame); | 325 DCHECK(m_mainFrame); |
| 328 DCHECK(m_workerContextClient); | 326 DCHECK(m_workerContextClient); |
| 329 DCHECK(m_loadingShadowPage); | 327 DCHECK(m_loadingShadowPage); |
| 330 DCHECK(!m_askedToTerminate); | 328 DCHECK(!m_askedToTerminate); |
| 331 m_loadingShadowPage = false; | 329 m_loadingShadowPage = false; |
| 332 m_networkProvider = wrapUnique(m_workerContextClient->createServiceWorkerNet
workProvider(frame->dataSource())); | 330 m_networkProvider = adoptPtr(m_workerContextClient->createServiceWorkerNetwo
rkProvider(frame->dataSource())); |
| 333 m_mainScriptLoader = WorkerScriptLoader::create(); | 331 m_mainScriptLoader = WorkerScriptLoader::create(); |
| 334 m_mainScriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo
rker); | 332 m_mainScriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo
rker); |
| 335 m_mainScriptLoader->loadAsynchronously( | 333 m_mainScriptLoader->loadAsynchronously( |
| 336 *m_mainFrame->frame()->document(), | 334 *m_mainFrame->frame()->document(), |
| 337 m_workerStartData.scriptURL, | 335 m_workerStartData.scriptURL, |
| 338 DenyCrossOriginRequests, | 336 DenyCrossOriginRequests, |
| 339 m_workerStartData.addressSpace, | 337 m_workerStartData.addressSpace, |
| 340 nullptr, | 338 nullptr, |
| 341 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished, this)); | 339 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished, this)); |
| 342 // Do nothing here since onScriptLoaderFinished() might have been already | 340 // Do nothing here since onScriptLoaderFinished() might have been already |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 399 |
| 402 Document* document = m_mainFrame->frame()->document(); | 400 Document* document = m_mainFrame->frame()->document(); |
| 403 | 401 |
| 404 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) | 402 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) |
| 405 SecurityOrigin* starterOrigin = document->getSecurityOrigin(); | 403 SecurityOrigin* starterOrigin = document->getSecurityOrigin(); |
| 406 | 404 |
| 407 WorkerClients* workerClients = WorkerClients::create(); | 405 WorkerClients* workerClients = WorkerClients::create(); |
| 408 provideContentSettingsClientToWorker(workerClients, std::move(m_contentSetti
ngsClient)); | 406 provideContentSettingsClientToWorker(workerClients, std::move(m_contentSetti
ngsClient)); |
| 409 provideIndexedDBClientToWorker(workerClients, IndexedDBClientImpl::create())
; | 407 provideIndexedDBClientToWorker(workerClients, IndexedDBClientImpl::create())
; |
| 410 provideServiceWorkerGlobalScopeClientToWorker(workerClients, ServiceWorkerGl
obalScopeClientImpl::create(*m_workerContextClient)); | 408 provideServiceWorkerGlobalScopeClientToWorker(workerClients, ServiceWorkerGl
obalScopeClientImpl::create(*m_workerContextClient)); |
| 411 provideServiceWorkerContainerClientToWorker(workerClients, wrapUnique(m_work
erContextClient->createServiceWorkerProvider())); | 409 provideServiceWorkerContainerClientToWorker(workerClients, adoptPtr(m_worker
ContextClient->createServiceWorkerProvider())); |
| 412 | 410 |
| 413 // We need to set the CSP to both the shadow page's document and the Service
WorkerGlobalScope. | 411 // We need to set the CSP to both the shadow page's document and the Service
WorkerGlobalScope. |
| 414 document->initContentSecurityPolicy(m_mainScriptLoader->releaseContentSecuri
tyPolicy()); | 412 document->initContentSecurityPolicy(m_mainScriptLoader->releaseContentSecuri
tyPolicy()); |
| 415 | 413 |
| 416 KURL scriptURL = m_mainScriptLoader->url(); | 414 KURL scriptURL = m_mainScriptLoader->url(); |
| 417 WorkerThreadStartMode startMode = m_workerInspectorProxy->workerStartMode(do
cument); | 415 WorkerThreadStartMode startMode = m_workerInspectorProxy->workerStartMode(do
cument); |
| 418 | 416 |
| 419 std::unique_ptr<WorkerThreadStartupData> startupData = WorkerThreadStartupDa
ta::create( | 417 OwnPtr<WorkerThreadStartupData> startupData = WorkerThreadStartupData::creat
e( |
| 420 scriptURL, | 418 scriptURL, |
| 421 m_workerStartData.userAgent, | 419 m_workerStartData.userAgent, |
| 422 m_mainScriptLoader->script(), | 420 m_mainScriptLoader->script(), |
| 423 m_mainScriptLoader->releaseCachedMetadata(), | 421 m_mainScriptLoader->releaseCachedMetadata(), |
| 424 startMode, | 422 startMode, |
| 425 document->contentSecurityPolicy()->headers().get(), | 423 document->contentSecurityPolicy()->headers().get(), |
| 426 starterOrigin, | 424 starterOrigin, |
| 427 workerClients, | 425 workerClients, |
| 428 m_mainScriptLoader->responseAddressSpace(), | 426 m_mainScriptLoader->responseAddressSpace(), |
| 429 m_mainScriptLoader->originTrialTokens(), | 427 m_mainScriptLoader->originTrialTokens(), |
| 430 static_cast<V8CacheOptions>(m_workerStartData.v8CacheOptions)); | 428 static_cast<V8CacheOptions>(m_workerStartData.v8CacheOptions)); |
| 431 | 429 |
| 432 m_mainScriptLoader.clear(); | 430 m_mainScriptLoader.clear(); |
| 433 | 431 |
| 434 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); | 432 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); |
| 435 m_loaderProxy = WorkerLoaderProxy::create(this); | 433 m_loaderProxy = WorkerLoaderProxy::create(this); |
| 436 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); | 434 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); |
| 437 m_workerThread->start(std::move(startupData)); | 435 m_workerThread->start(std::move(startupData)); |
| 438 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); | 436 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); |
| 439 } | 437 } |
| 440 | 438 |
| 441 } // namespace blink | 439 } // namespace blink |
| OLD | NEW |