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