Commit 65db7edc authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

ServiceWorker: Simplify CSP handling in WebEmbeddedWorkerImpl

For simplifying CSP handling in WebEmbeddedWorkerImpl, this CL...

- parses ContentSecurityPolicyResponseHeaders in ServiceWorkerGlobalScopeProxy
  instead of WorkerShadowPage,
- excludes signal handling from WebEmbeddedWorkerImpl to
  ServiceWorkerGlobalScopeProxy, and
- unifies CSP handling between regular script loading (network) and installed
  script loading (script streaming) as
  WebEmbeddedWorkerImpl::SetContentSecurityPolicyAndReferrerPolicy().

Bug: 683037
Change-Id: Id530b30fc0bc8ead0ff29f631dd4f2a52a8ecf72
Reviewed-on: https://chromium-review.googlesource.com/597033Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491328}
parent 6163e501
...@@ -57,17 +57,13 @@ void WorkerShadowPage::Initialize(const KURL& script_url) { ...@@ -57,17 +57,13 @@ void WorkerShadowPage::Initialize(const KURL& script_url) {
} }
void WorkerShadowPage::SetContentSecurityPolicyAndReferrerPolicy( void WorkerShadowPage::SetContentSecurityPolicyAndReferrerPolicy(
ContentSecurityPolicyResponseHeaders csp_headers, ContentSecurityPolicy* content_security_policy,
String referrer_policy) { String referrer_policy) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
Document* document = main_frame_->GetFrame()->GetDocument(); content_security_policy->SetOverrideURLForSelf(GetDocument()->Url());
ContentSecurityPolicy* content_security_policy = GetDocument()->InitContentSecurityPolicy(content_security_policy);
ContentSecurityPolicy::Create();
content_security_policy->SetOverrideURLForSelf(document->Url());
content_security_policy->DidReceiveHeaders(csp_headers);
document->InitContentSecurityPolicy(content_security_policy);
if (!referrer_policy.IsNull()) if (!referrer_policy.IsNull())
document->ParseAndSetReferrerPolicy(referrer_policy); GetDocument()->ParseAndSetReferrerPolicy(referrer_policy);
} }
void WorkerShadowPage::DidFinishDocumentLoad() { void WorkerShadowPage::DidFinishDocumentLoad() {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define WorkerShadowPage_h #define WorkerShadowPage_h
#include "core/frame/WebLocalFrameImpl.h" #include "core/frame/WebLocalFrameImpl.h"
#include "platform/network/ContentSecurityPolicyResponseHeaders.h"
#include "public/web/WebDevToolsAgentClient.h" #include "public/web/WebDevToolsAgentClient.h"
#include "public/web/WebDocumentLoader.h" #include "public/web/WebDocumentLoader.h"
#include "public/web/WebFrameClient.h" #include "public/web/WebFrameClient.h"
...@@ -15,6 +14,7 @@ ...@@ -15,6 +14,7 @@
namespace blink { namespace blink {
class ContentSecurityPolicy;
class WebApplicationCacheHost; class WebApplicationCacheHost;
class WebApplicationCacheHostClient; class WebApplicationCacheHostClient;
class WebSettings; class WebSettings;
...@@ -53,9 +53,8 @@ class CORE_EXPORT WorkerShadowPage : public WebFrameClient { ...@@ -53,9 +53,8 @@ class CORE_EXPORT WorkerShadowPage : public WebFrameClient {
// Calls Client::OnShadowPageInitialized() when complete. // Calls Client::OnShadowPageInitialized() when complete.
void Initialize(const KURL& script_url); void Initialize(const KURL& script_url);
void SetContentSecurityPolicyAndReferrerPolicy( void SetContentSecurityPolicyAndReferrerPolicy(ContentSecurityPolicy*,
ContentSecurityPolicyResponseHeaders csp_headers, String referrer_policy);
String referrer_policy);
// WebFrameClient overrides. // WebFrameClient overrides.
std::unique_ptr<WebApplicationCacheHost> CreateApplicationCacheHost( std::unique_ptr<WebApplicationCacheHost> CreateApplicationCacheHost(
......
...@@ -56,12 +56,9 @@ ...@@ -56,12 +56,9 @@
#include "platform/Histogram.h" #include "platform/Histogram.h"
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
#include "platform/SharedBuffer.h" #include "platform/SharedBuffer.h"
#include "platform/WaitableEvent.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "platform/instrumentation/tracing/TraceEvent.h" #include "platform/instrumentation/tracing/TraceEvent.h"
#include "platform/loader/fetch/SubstituteData.h" #include "platform/loader/fetch/SubstituteData.h"
#include "platform/network/ContentSecurityPolicyParsers.h"
#include "platform/network/ContentSecurityPolicyResponseHeaders.h"
#include "platform/network/NetworkUtils.h" #include "platform/network/NetworkUtils.h"
#include "platform/weborigin/SecurityOrigin.h" #include "platform/weborigin/SecurityOrigin.h"
#include "platform/wtf/Functional.h" #include "platform/wtf/Functional.h"
...@@ -267,12 +264,11 @@ void WebEmbeddedWorkerImpl::PostMessageToPageInspector(int session_id, ...@@ -267,12 +264,11 @@ void WebEmbeddedWorkerImpl::PostMessageToPageInspector(int session_id,
} }
void WebEmbeddedWorkerImpl::SetContentSecurityPolicyAndReferrerPolicy( void WebEmbeddedWorkerImpl::SetContentSecurityPolicyAndReferrerPolicy(
ContentSecurityPolicyResponseHeaders csp_headers, ContentSecurityPolicy* content_security_policy,
String referrer_policy, String referrer_policy) {
WaitableEvent* event) { DCHECK(IsMainThread());
shadow_page_->SetContentSecurityPolicyAndReferrerPolicy( shadow_page_->SetContentSecurityPolicyAndReferrerPolicy(
std::move(csp_headers), std::move(referrer_policy)); content_security_policy, std::move(referrer_policy));
event->Signal();
} }
std::unique_ptr<WebApplicationCacheHost> std::unique_ptr<WebApplicationCacheHost>
...@@ -413,12 +409,9 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() { ...@@ -413,12 +409,9 @@ void WebEmbeddedWorkerImpl::StartWorkerThread() {
if (main_script_loader_) { if (main_script_loader_) {
// We need to set the CSP to both the shadow page's document and the // We need to set the CSP to both the shadow page's document and the
// ServiceWorkerGlobalScope. // ServiceWorkerGlobalScope.
document->InitContentSecurityPolicy( SetContentSecurityPolicyAndReferrerPolicy(
main_script_loader_->ReleaseContentSecurityPolicy()); main_script_loader_->ReleaseContentSecurityPolicy(),
if (!main_script_loader_->GetReferrerPolicy().IsNull()) { main_script_loader_->GetReferrerPolicy());
document->ParseAndSetReferrerPolicy(
main_script_loader_->GetReferrerPolicy());
}
global_scope_creation_params = WTF::MakeUnique<GlobalScopeCreationParams>( global_scope_creation_params = WTF::MakeUnique<GlobalScopeCreationParams>(
worker_start_data_.script_url, worker_start_data_.user_agent, worker_start_data_.script_url, worker_start_data_.user_agent,
main_script_loader_->SourceText(), main_script_loader_->SourceText(),
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "modules/ModulesExport.h" #include "modules/ModulesExport.h"
#include "platform/WebTaskRunner.h" #include "platform/WebTaskRunner.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/WebContentSecurityPolicy.h"
#include "public/web/WebDevToolsAgentClient.h" #include "public/web/WebDevToolsAgentClient.h"
#include "public/web/WebEmbeddedWorker.h" #include "public/web/WebEmbeddedWorker.h"
#include "public/web/WebEmbeddedWorkerStartData.h" #include "public/web/WebEmbeddedWorkerStartData.h"
...@@ -46,9 +45,9 @@ ...@@ -46,9 +45,9 @@
namespace blink { namespace blink {
class ContentSecurityPolicy;
class ServiceWorkerGlobalScopeProxy; class ServiceWorkerGlobalScopeProxy;
class ServiceWorkerInstalledScriptsManager; class ServiceWorkerInstalledScriptsManager;
class WaitableEvent;
class WorkerInspectorProxy; class WorkerInspectorProxy;
class WorkerScriptLoader; class WorkerScriptLoader;
class WorkerThread; class WorkerThread;
...@@ -84,13 +83,10 @@ class MODULES_EXPORT WebEmbeddedWorkerImpl final ...@@ -84,13 +83,10 @@ class MODULES_EXPORT WebEmbeddedWorkerImpl final
// Applies the specified CSP and referrer policy to the worker, so that // Applies the specified CSP and referrer policy to the worker, so that
// fetches initiated by the worker (other than for the main worker script // fetches initiated by the worker (other than for the main worker script
// itself) are affected by these policies. The WaitableEvent is signaled when // itself) are affected by these policies. This must be called before starting
// the policies are set. This enables the caller to ensure that policies are // script execution on the worker thread.
// set before starting script execution on the worker thread. void SetContentSecurityPolicyAndReferrerPolicy(ContentSecurityPolicy*,
void SetContentSecurityPolicyAndReferrerPolicy( String referrer_policy);
ContentSecurityPolicyResponseHeaders,
WTF::String referrer_policy,
WaitableEvent*);
// WorkerShadowPage::Client overrides. // WorkerShadowPage::Client overrides.
std::unique_ptr<WebApplicationCacheHost> CreateApplicationCacheHost( std::unique_ptr<WebApplicationCacheHost> CreateApplicationCacheHost(
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
#include "platform/WaitableEvent.h" #include "platform/WaitableEvent.h"
#include "platform/loader/fetch/ResourceResponse.h" #include "platform/loader/fetch/ResourceResponse.h"
#include "platform/network/ContentSecurityPolicyResponseHeaders.h"
#include "platform/wtf/Assertions.h" #include "platform/wtf/Assertions.h"
#include "platform/wtf/Functional.h" #include "platform/wtf/Functional.h"
#include "platform/wtf/PtrUtil.h" #include "platform/wtf/PtrUtil.h"
...@@ -90,6 +91,24 @@ ...@@ -90,6 +91,24 @@
namespace blink { namespace blink {
namespace {
void SetContentSecurityPolicyAndReferrerPolicyOnMainThread(
WebEmbeddedWorkerImpl* embedded_worker,
ContentSecurityPolicyResponseHeaders csp_headers,
String referrer_policy,
WaitableEvent* waitable_event) {
DCHECK(IsMainThread());
ContentSecurityPolicy* content_security_policy =
ContentSecurityPolicy::Create();
content_security_policy->DidReceiveHeaders(csp_headers);
embedded_worker->SetContentSecurityPolicyAndReferrerPolicy(
content_security_policy, std::move(referrer_policy));
waitable_event->Signal();
}
} // namespace
ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::Create( ServiceWorkerGlobalScopeProxy* ServiceWorkerGlobalScopeProxy::Create(
WebEmbeddedWorkerImpl& embedded_worker, WebEmbeddedWorkerImpl& embedded_worker,
WebServiceWorkerContextClient& client) { WebServiceWorkerContextClient& client) {
...@@ -576,7 +595,7 @@ void ServiceWorkerGlobalScopeProxy::DidLoadInstalledScript( ...@@ -576,7 +595,7 @@ void ServiceWorkerGlobalScopeProxy::DidLoadInstalledScript(
->PostTask( ->PostTask(
BLINK_FROM_HERE, BLINK_FROM_HERE,
CrossThreadBind( CrossThreadBind(
&WebEmbeddedWorkerImpl::SetContentSecurityPolicyAndReferrerPolicy, &SetContentSecurityPolicyAndReferrerPolicyOnMainThread,
CrossThreadUnretained(embedded_worker_), CrossThreadUnretained(embedded_worker_),
csp_headers_on_worker_thread, referrer_policy_on_worker_thread, csp_headers_on_worker_thread, referrer_policy_on_worker_thread,
CrossThreadUnretained(&waitable_event))); CrossThreadUnretained(&waitable_event)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment