Commit 9f3efe05 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Create WebWorkerFetchContext in DedicatedWorker::CreateGlobalScopeCreationParams()

This CL moves WebWorkerFetchContext creation from
ThreadedMessagingProxy::StartGlobalScope() to
Dedicatedworker::CreateGlobalScopeCreationParams() in order to put params
construction in one place for code cleanup.

Bug: 906991
Change-Id: I7a365bbc0706f271b61e9f56648f9b7a47506dd8
Reviewed-on: https://chromium-review.googlesource.com/c/1351199Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611553}
parent 8f9ee588
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/use_counter.h" #include "third_party/blink/renderer/core/frame/use_counter.h"
#include "third_party/blink/renderer/core/inspector/main_thread_debugger.h" #include "third_party/blink/renderer/core/inspector/main_thread_debugger.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
#include "third_party/blink/renderer/core/messaging/post_message_options.h" #include "third_party/blink/renderer/core/messaging/post_message_options.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/weborigin/security_policy.h" #include "third_party/blink/renderer/platform/weborigin/security_policy.h"
namespace blink { namespace blink {
...@@ -172,8 +174,9 @@ void DedicatedWorker::Start() { ...@@ -172,8 +174,9 @@ void DedicatedWorker::Start() {
auto* outside_settings_object = auto* outside_settings_object =
GetExecutionContext()->CreateFetchClientSettingsObjectSnapshot(); GetExecutionContext()->CreateFetchClientSettingsObjectSnapshot();
context_proxy_->StartWorkerGlobalScope( context_proxy_->StartWorkerGlobalScope(
CreateGlobalScopeCreationParams(script_request_url_), options_, CreateGlobalScopeCreationParams(script_request_url_,
script_request_url_, outside_settings_object, stack_id, kReferrerPolicyDefault),
options_, script_request_url_, outside_settings_object, stack_id,
String() /* source_code */); String() /* source_code */);
return; return;
} }
...@@ -181,15 +184,12 @@ void DedicatedWorker::Start() { ...@@ -181,15 +184,12 @@ void DedicatedWorker::Start() {
// Legacy code path (to be deprecated, see https://crbug.com/835717): // Legacy code path (to be deprecated, see https://crbug.com/835717):
// A worker thread will start after scripts are fetched on the current // A worker thread will start after scripts are fetched on the current
// thread. // thread.
network::mojom::FetchRequestMode fetch_request_mode =
network::mojom::FetchRequestMode::kSameOrigin;
network::mojom::FetchCredentialsMode fetch_credentials_mode =
network::mojom::FetchCredentialsMode::kSameOrigin;
classic_script_loader_ = MakeGarbageCollected<WorkerClassicScriptLoader>(); classic_script_loader_ = MakeGarbageCollected<WorkerClassicScriptLoader>();
classic_script_loader_->LoadTopLevelScriptAsynchronously( classic_script_loader_->LoadTopLevelScriptAsynchronously(
*GetExecutionContext(), script_request_url_, *GetExecutionContext(), script_request_url_,
mojom::RequestContextType::WORKER, fetch_request_mode, mojom::RequestContextType::WORKER,
fetch_credentials_mode, network::mojom::FetchRequestMode::kSameOrigin,
network::mojom::FetchCredentialsMode::kSameOrigin,
GetExecutionContext()->GetSecurityContext().AddressSpace(), GetExecutionContext()->GetSecurityContext().AddressSpace(),
GetExecutionContext()->IsWorkerGlobalScope(), GetExecutionContext()->IsWorkerGlobalScope(),
WTF::Bind(&DedicatedWorker::OnResponse, WrapPersistent(this)), WTF::Bind(&DedicatedWorker::OnResponse, WrapPersistent(this)),
...@@ -292,14 +292,11 @@ void DedicatedWorker::OnFinished(const v8_inspector::V8StackTraceId& stack_id) { ...@@ -292,14 +292,11 @@ void DedicatedWorker::OnFinished(const v8_inspector::V8StackTraceId& stack_id) {
DCHECK(script_request_url_ == script_response_url || DCHECK(script_request_url_ == script_response_url ||
SecurityOrigin::AreSameSchemeHostPort(script_request_url_, SecurityOrigin::AreSameSchemeHostPort(script_request_url_,
script_response_url)); script_response_url));
std::unique_ptr<GlobalScopeCreationParams> creation_params =
CreateGlobalScopeCreationParams(script_response_url);
creation_params->referrer_policy = referrer_policy;
auto* outside_settings_object = auto* outside_settings_object =
GetExecutionContext()->CreateFetchClientSettingsObjectSnapshot(); GetExecutionContext()->CreateFetchClientSettingsObjectSnapshot();
context_proxy_->StartWorkerGlobalScope( context_proxy_->StartWorkerGlobalScope(
std::move(creation_params), options_, script_response_url, CreateGlobalScopeCreationParams(script_response_url, referrer_policy),
outside_settings_object, stack_id, options_, script_response_url, outside_settings_object, stack_id,
classic_script_loader_->SourceText()); classic_script_loader_->SourceText());
probe::scriptImported(GetExecutionContext(), probe::scriptImported(GetExecutionContext(),
classic_script_loader_->Identifier(), classic_script_loader_->Identifier(),
...@@ -309,7 +306,9 @@ void DedicatedWorker::OnFinished(const v8_inspector::V8StackTraceId& stack_id) { ...@@ -309,7 +306,9 @@ void DedicatedWorker::OnFinished(const v8_inspector::V8StackTraceId& stack_id) {
} }
std::unique_ptr<GlobalScopeCreationParams> std::unique_ptr<GlobalScopeCreationParams>
DedicatedWorker::CreateGlobalScopeCreationParams(const KURL& script_url) { DedicatedWorker::CreateGlobalScopeCreationParams(
const KURL& script_url,
ReferrerPolicy referrer_policy) {
base::UnguessableToken parent_devtools_token; base::UnguessableToken parent_devtools_token;
std::unique_ptr<WorkerSettings> settings; std::unique_ptr<WorkerSettings> settings;
if (auto* document = DynamicTo<Document>(GetExecutionContext())) { if (auto* document = DynamicTo<Document>(GetExecutionContext())) {
...@@ -328,13 +327,26 @@ DedicatedWorker::CreateGlobalScopeCreationParams(const KURL& script_url) { ...@@ -328,13 +327,26 @@ DedicatedWorker::CreateGlobalScopeCreationParams(const KURL& script_url) {
? mojom::ScriptType::kClassic ? mojom::ScriptType::kClassic
: mojom::ScriptType::kModule; : mojom::ScriptType::kModule;
// WebWorkerFetchContext is provided later in scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context;
// ThreadedMessagingProxyBase::InitializeWorkerThread(). if (auto* document = DynamicTo<Document>(GetExecutionContext())) {
LocalFrame* frame = document->GetFrame();
web_worker_fetch_context = frame->Client()->CreateWorkerFetchContext();
web_worker_fetch_context->SetApplicationCacheHostID(
GetExecutionContext()->Fetcher()->Context().ApplicationCacheHostID());
web_worker_fetch_context->SetIsOnSubframe(!frame->IsMainFrame());
} else if (auto* scope =
DynamicTo<WorkerGlobalScope>(GetExecutionContext())) {
web_worker_fetch_context =
static_cast<WorkerFetchContext&>(scope->Fetcher()->Context())
.GetWebWorkerFetchContext()
->CloneForNestedWorker();
}
return std::make_unique<GlobalScopeCreationParams>( return std::make_unique<GlobalScopeCreationParams>(
script_url, script_type, GetExecutionContext()->UserAgent(), script_url, script_type, GetExecutionContext()->UserAgent(),
nullptr /* web_worker_fetch_context */, std::move(web_worker_fetch_context),
GetExecutionContext()->GetContentSecurityPolicy()->Headers(), GetExecutionContext()->GetContentSecurityPolicy()->Headers(),
kReferrerPolicyDefault, GetExecutionContext()->GetSecurityOrigin(), referrer_policy, GetExecutionContext()->GetSecurityOrigin(),
GetExecutionContext()->IsSecureContext(), GetExecutionContext()->IsSecureContext(),
GetExecutionContext()->GetHttpsState(), CreateWorkerClients(), GetExecutionContext()->GetHttpsState(), CreateWorkerClients(),
GetExecutionContext()->GetSecurityContext().AddressSpace(), GetExecutionContext()->GetSecurityContext().AddressSpace(),
......
...@@ -88,7 +88,8 @@ class CORE_EXPORT DedicatedWorker final ...@@ -88,7 +88,8 @@ class CORE_EXPORT DedicatedWorker final
void Start(); void Start();
std::unique_ptr<GlobalScopeCreationParams> CreateGlobalScopeCreationParams( std::unique_ptr<GlobalScopeCreationParams> CreateGlobalScopeCreationParams(
const KURL& script_url); const KURL& script_url,
ReferrerPolicy);
WorkerClients* CreateWorkerClients(); WorkerClients* CreateWorkerClients();
......
...@@ -10,13 +10,10 @@ ...@@ -10,13 +10,10 @@
#include "third_party/blink/renderer/bindings/core/v8/source_location.h" #include "third_party/blink/renderer/bindings/core/v8/source_location.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/deprecation.h" #include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/devtools_agent.h" #include "third_party/blink/renderer/core/inspector/devtools_agent.h"
#include "third_party/blink/renderer/core/inspector/worker_devtools_params.h" #include "third_party/blink/renderer/core/inspector/worker_devtools_params.h"
#include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
...@@ -63,33 +60,9 @@ void ThreadedMessagingProxyBase::InitializeWorkerThread( ...@@ -63,33 +60,9 @@ void ThreadedMessagingProxyBase::InitializeWorkerThread(
KURL script_url = global_scope_creation_params->script_url.Copy(); KURL script_url = global_scope_creation_params->script_url.Copy();
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context; if (global_scope_creation_params->web_worker_fetch_context) {
if (auto* document = DynamicTo<Document>(execution_context_.Get())) { global_scope_creation_params->web_worker_fetch_context
LocalFrame* frame = document->GetFrame(); ->SetTerminateSyncLoadEvent(&terminate_sync_load_event_);
web_worker_fetch_context = frame->Client()->CreateWorkerFetchContext();
// |web_worker_fetch_context| is null in some unit tests.
if (web_worker_fetch_context) {
web_worker_fetch_context->SetApplicationCacheHostID(
GetExecutionContext()->Fetcher()->Context().ApplicationCacheHostID());
web_worker_fetch_context->SetIsOnSubframe(!frame->IsMainFrame());
}
} else if (auto* scope = DynamicTo<WorkerGlobalScope>(*execution_context_)) {
web_worker_fetch_context =
static_cast<WorkerFetchContext&>(scope->Fetcher()->Context())
.GetWebWorkerFetchContext()
->CloneForNestedWorker();
}
if (web_worker_fetch_context) {
web_worker_fetch_context->SetTerminateSyncLoadEvent(
&terminate_sync_load_event_);
// In some cases |web_worker_fetch_context| has already been provided and is
// overwritten here, and in other cases |web_worker_fetch_context| has been
// nullptr and is set here.
// TODO(hiroshige): Clean up this.
global_scope_creation_params->web_worker_fetch_context =
std::move(web_worker_fetch_context);
} }
worker_thread_ = CreateWorkerThread(); worker_thread_ = CreateWorkerThread();
......
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