Commit 94907325 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Create WebWorkerFetchContext before starting shared workers

As a part of the Onion Soup project, this CL changes the timing to
create WebWorkerFetchContext for shared workers.

Before this CL, WebWorkerFetchContext was created as follows:

- [in content] EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub()
  - [in blink] WebSharedWorkerImpl::CreateAndStart()
    - [in content] EmbeddedSharedWorkerStub::CreateWorkerFetchContext()
      - Creates WebWorkerFetchContext instance here.

This needed an inter-module function from blink to content, and
WebSharedWorkerClient::CreateWorkerFetchContext() was that.

After this CL, WebWorkerFetchContext is created as follows:

- [in content] EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub()
  - [in content] EmbeddedSharedWorkerStub::CreateWorkerFetchContext()
    - Creates WebWorkerFetchContext instance here.
  - [in blink] WebSharedWorkerImpl::CreateAndStart()
    - Passes the context into WebSharedWorkerImpl here.

This enables to remove the function.

Bug: 911415
Change-Id: Ieec240321f7a5884c5680c8ce6d3f24b4081813e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309314
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790709}
parent bcf531cf
...@@ -56,11 +56,7 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( ...@@ -56,11 +56,7 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
browser_interface_broker, browser_interface_broker,
ukm::SourceId ukm_source_id, ukm::SourceId ukm_source_id,
const std::vector<std::string>& cors_exempt_header_list) const std::vector<std::string>& cors_exempt_header_list)
: receiver_(this, std::move(receiver)), : receiver_(this, std::move(receiver)) {
url_(info->url),
renderer_preferences_(renderer_preferences),
preference_watcher_receiver_(std::move(preference_watcher_receiver)),
cors_exempt_header_list_(cors_exempt_header_list) {
DCHECK(main_script_load_params); DCHECK(main_script_load_params);
DCHECK(pending_subresource_loader_factory_bundle); DCHECK(pending_subresource_loader_factory_bundle);
...@@ -68,6 +64,7 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( ...@@ -68,6 +64,7 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
// the browser process. // the browser process.
std::unique_ptr<blink::WorkerMainScriptLoadParameters> std::unique_ptr<blink::WorkerMainScriptLoadParameters>
worker_main_script_load_params; worker_main_script_load_params;
std::unique_ptr<NavigationResponseOverrideParameters> response_override;
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
blink::features::kLoadMainScriptForPlzDedicatedWorkerByParams)) { blink::features::kLoadMainScriptForPlzDedicatedWorkerByParams)) {
worker_main_script_load_params = worker_main_script_load_params =
...@@ -83,18 +80,17 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( ...@@ -83,18 +80,17 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
worker_main_script_load_params->url_loader_client_endpoints = worker_main_script_load_params->url_loader_client_endpoints =
std::move(main_script_load_params->url_loader_client_endpoints); std::move(main_script_load_params->url_loader_client_endpoints);
} else { } else {
response_override_ = response_override =
std::make_unique<NavigationResponseOverrideParameters>(); std::make_unique<NavigationResponseOverrideParameters>();
response_override_->url_loader_client_endpoints = response_override->url_loader_client_endpoints =
std::move(main_script_load_params->url_loader_client_endpoints); std::move(main_script_load_params->url_loader_client_endpoints);
response_override_->response_head = response_override->response_head =
std::move(main_script_load_params->response_head); std::move(main_script_load_params->response_head);
response_override_->response_body = response_override->response_body =
std::move(main_script_load_params->response_body); std::move(main_script_load_params->response_body);
response_override_->redirect_responses = response_override->redirect_responses =
std::move(main_script_load_params->redirect_response_heads); std::move(main_script_load_params->redirect_response_heads);
response_override_->redirect_infos = response_override->redirect_infos = main_script_load_params->redirect_infos;
main_script_load_params->redirect_infos;
} }
// If the network service crashes, then self-destruct so clients don't get // If the network service crashes, then self-destruct so clients don't get
...@@ -127,8 +123,14 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( ...@@ -127,8 +123,14 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
std::move(controller_info), subresource_loader_factory_bundle_); std::move(controller_info), subresource_loader_factory_bundle_);
} }
scoped_refptr<blink::WebWorkerFetchContext> worker_fetch_context =
CreateWorkerFetchContext(info->url, std::move(renderer_preferences),
std::move(preference_watcher_receiver),
cors_exempt_header_list,
std::move(response_override));
impl_ = blink::WebSharedWorker::CreateAndStart( impl_ = blink::WebSharedWorker::CreateAndStart(
url_, info->options->type, info->options->credentials, info->url, info->options->type, info->options->credentials,
blink::WebString::FromUTF8(info->options->name), blink::WebString::FromUTF8(info->options->name),
blink::WebSecurityOrigin(constructor_origin), blink::WebSecurityOrigin(constructor_origin),
blink::WebString::FromUTF8(user_agent), ua_metadata, blink::WebString::FromUTF8(user_agent), ua_metadata,
...@@ -138,8 +140,8 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( ...@@ -138,8 +140,8 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
info->outside_fetch_client_settings_object), info->outside_fetch_client_settings_object),
appcache_host_id, devtools_worker_token, std::move(content_settings), appcache_host_id, devtools_worker_token, std::move(content_settings),
std::move(browser_interface_broker), pause_on_start, std::move(browser_interface_broker), pause_on_start,
std::move(worker_main_script_load_params), std::move(host), this, std::move(worker_main_script_load_params),
ukm_source_id); std::move(worker_fetch_context), std::move(host), this, ukm_source_id);
// If the host drops its connection, then self-destruct. // If the host drops its connection, then self-destruct.
receiver_.set_disconnect_handler(base::BindOnce( receiver_.set_disconnect_handler(base::BindOnce(
...@@ -156,7 +158,13 @@ void EmbeddedSharedWorkerStub::WorkerContextDestroyed() { ...@@ -156,7 +158,13 @@ void EmbeddedSharedWorkerStub::WorkerContextDestroyed() {
} }
scoped_refptr<blink::WebWorkerFetchContext> scoped_refptr<blink::WebWorkerFetchContext>
EmbeddedSharedWorkerStub::CreateWorkerFetchContext() { EmbeddedSharedWorkerStub::CreateWorkerFetchContext(
const GURL& url,
const blink::mojom::RendererPreferences& renderer_preferences,
mojo::PendingReceiver<blink::mojom::RendererPreferenceWatcher>
preference_watcher_receiver,
const std::vector<std::string>& cors_exempt_header_list,
std::unique_ptr<NavigationResponseOverrideParameters> response_override) {
// Make the factory used for service worker network fallback (that should // Make the factory used for service worker network fallback (that should
// skip AppCache if it is provided). // skip AppCache if it is provided).
std::unique_ptr<network::PendingSharedURLLoaderFactory> fallback_factory = std::unique_ptr<network::PendingSharedURLLoaderFactory> fallback_factory =
...@@ -167,26 +175,25 @@ EmbeddedSharedWorkerStub::CreateWorkerFetchContext() { ...@@ -167,26 +175,25 @@ EmbeddedSharedWorkerStub::CreateWorkerFetchContext() {
scoped_refptr<WebWorkerFetchContextImpl> worker_fetch_context = scoped_refptr<WebWorkerFetchContextImpl> worker_fetch_context =
WebWorkerFetchContextImpl::Create( WebWorkerFetchContextImpl::Create(
service_worker_provider_context_.get(), service_worker_provider_context_.get(),
std::move(renderer_preferences_), std::move(renderer_preferences),
std::move(preference_watcher_receiver_), std::move(preference_watcher_receiver),
subresource_loader_factory_bundle_->Clone(), subresource_loader_factory_bundle_->Clone(),
std::move(fallback_factory), std::move(fallback_factory),
/*pending_subresource_loader_updater=*/mojo::NullReceiver(), /*pending_subresource_loader_updater=*/mojo::NullReceiver(),
cors_exempt_header_list_, cors_exempt_header_list,
/*pending_resource_load_info_notifier=*/mojo::NullRemote()); /*pending_resource_load_info_notifier=*/mojo::NullRemote());
// TODO(horo): To get the correct first_party_to_cookies for the shared // TODO(horo): To get the correct first_party_to_cookies for the shared
// worker, we need to check the all documents bounded by the shared worker. // worker, we need to check the all documents bounded by the shared worker.
// (crbug.com/723553) // (crbug.com/723553)
// https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-07#section-2.1.2 // https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-07#section-2.1.2
worker_fetch_context->set_site_for_cookies( worker_fetch_context->set_site_for_cookies(net::SiteForCookies::FromUrl(url));
net::SiteForCookies::FromUrl(url_));
if (!base::FeatureList::IsEnabled( if (!base::FeatureList::IsEnabled(
blink::features::kLoadMainScriptForPlzDedicatedWorkerByParams)) { blink::features::kLoadMainScriptForPlzDedicatedWorkerByParams)) {
DCHECK(response_override_); DCHECK(response_override);
worker_fetch_context->SetResponseOverrideForMainScript( worker_fetch_context->SetResponseOverrideForMainScript(
std::move(response_override_)); std::move(response_override));
} }
return worker_fetch_context; return worker_fetch_context;
......
...@@ -85,8 +85,6 @@ class EmbeddedSharedWorkerStub : public blink::WebSharedWorkerClient, ...@@ -85,8 +85,6 @@ class EmbeddedSharedWorkerStub : public blink::WebSharedWorkerClient,
// blink::WebSharedWorkerClient implementation. // blink::WebSharedWorkerClient implementation.
void WorkerContextDestroyed() override; void WorkerContextDestroyed() override;
scoped_refptr<blink::WebWorkerFetchContext> CreateWorkerFetchContext()
override;
private: private:
// mojom::SharedWorker methods: // mojom::SharedWorker methods:
...@@ -95,26 +93,22 @@ class EmbeddedSharedWorkerStub : public blink::WebSharedWorkerClient, ...@@ -95,26 +93,22 @@ class EmbeddedSharedWorkerStub : public blink::WebSharedWorkerClient,
blink::MessagePortDescriptor port) override; blink::MessagePortDescriptor port) override;
void Terminate() override; void Terminate() override;
scoped_refptr<blink::WebWorkerFetchContext> CreateWorkerFetchContext(
const GURL& url,
const blink::mojom::RendererPreferences& renderer_preferences,
mojo::PendingReceiver<blink::mojom::RendererPreferenceWatcher>
preference_watcher_receiver,
const std::vector<std::string>& cors_exempt_header_list,
std::unique_ptr<NavigationResponseOverrideParameters> response_override);
mojo::Receiver<blink::mojom::SharedWorker> receiver_; mojo::Receiver<blink::mojom::SharedWorker> receiver_;
GURL url_;
blink::mojom::RendererPreferences renderer_preferences_;
// Set on ctor and passed to the fetch context created when
// CreateWorkerFetchContext() is called.
mojo::PendingReceiver<blink::mojom::RendererPreferenceWatcher>
preference_watcher_receiver_;
std::unique_ptr<blink::WebSharedWorker> impl_; std::unique_ptr<blink::WebSharedWorker> impl_;
std::vector<std::string> cors_exempt_header_list_;
scoped_refptr<ServiceWorkerProviderContext> service_worker_provider_context_; scoped_refptr<ServiceWorkerProviderContext> service_worker_provider_context_;
// The factory bundle used for loading subresources for this shared worker. // The factory bundle used for loading subresources for this shared worker.
scoped_refptr<ChildURLLoaderFactoryBundle> subresource_loader_factory_bundle_; scoped_refptr<ChildURLLoaderFactoryBundle> subresource_loader_factory_bundle_;
// The response override parameters used for taking a resource pre-requested
// by the browser process.
std::unique_ptr<NavigationResponseOverrideParameters> response_override_;
// Out-of-process NetworkService: // Out-of-process NetworkService:
// Detects disconnection from the default factory of the loader factory bundle // Detects disconnection from the default factory of the loader factory bundle
// used by this worker (typically the network service). // used by this worker (typically the network service).
......
...@@ -53,6 +53,7 @@ namespace blink { ...@@ -53,6 +53,7 @@ namespace blink {
class WebString; class WebString;
class WebSharedWorkerClient; class WebSharedWorkerClient;
class WebURL; class WebURL;
class WebWorkerFetchContext;
struct WebFetchClientSettingsObject; struct WebFetchClientSettingsObject;
struct WorkerMainScriptLoadParameters; struct WorkerMainScriptLoadParameters;
...@@ -85,6 +86,7 @@ class BLINK_EXPORT WebSharedWorker { ...@@ -85,6 +86,7 @@ class BLINK_EXPORT WebSharedWorker {
bool pause_worker_context_on_start, bool pause_worker_context_on_start,
std::unique_ptr<blink::WorkerMainScriptLoadParameters> std::unique_ptr<blink::WorkerMainScriptLoadParameters>
worker_main_script_load_params, worker_main_script_load_params,
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context,
CrossVariantMojoRemote<mojom::SharedWorkerHostInterfaceBase>, CrossVariantMojoRemote<mojom::SharedWorkerHostInterfaceBase>,
WebSharedWorkerClient*, WebSharedWorkerClient*,
ukm::SourceId ukm_source_id); ukm::SourceId ukm_source_id);
......
...@@ -48,11 +48,6 @@ namespace blink { ...@@ -48,11 +48,6 @@ namespace blink {
class WebSharedWorkerClient { class WebSharedWorkerClient {
public: public:
virtual void WorkerContextDestroyed() = 0; virtual void WorkerContextDestroyed() = 0;
// Called on the main thread during initialization. Creates a new
// WebWorkerFetchContext for the shared worker. This is passed to the worker
// thread and used loading requests from the shared worker.
virtual scoped_refptr<WebWorkerFetchContext> CreateWorkerFetchContext() = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -214,8 +214,10 @@ void WebSharedWorkerImpl::StartWorkerContext( ...@@ -214,8 +214,10 @@ void WebSharedWorkerImpl::StartWorkerContext(
browser_interface_broker, browser_interface_broker,
bool pause_worker_context_on_start, bool pause_worker_context_on_start,
std::unique_ptr<WorkerMainScriptLoadParameters> std::unique_ptr<WorkerMainScriptLoadParameters>
worker_main_script_load_params) { worker_main_script_load_params,
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
DCHECK(web_worker_fetch_context);
CHECK(constructor_origin.Get()->CanAccessSharedWorkers()); CHECK(constructor_origin.Get()->CanAccessSharedWorkers());
// Creates 'outside settings' used in the "Processing model" algorithm in the // Creates 'outside settings' used in the "Processing model" algorithm in the
...@@ -237,10 +239,6 @@ void WebSharedWorkerImpl::StartWorkerContext( ...@@ -237,10 +239,6 @@ void WebSharedWorkerImpl::StartWorkerContext(
: mojom::blink::InsecureRequestPolicy::kBlockAllMixedContent, : mojom::blink::InsecureRequestPolicy::kBlockAllMixedContent,
FetchClientSettingsObject::InsecureNavigationsSet()); FetchClientSettingsObject::InsecureNavigationsSet());
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context =
client_->CreateWorkerFetchContext();
DCHECK(web_worker_fetch_context);
bool constructor_secure_context = bool constructor_secure_context =
constructor_origin.IsPotentiallyTrustworthy() || constructor_origin.IsPotentiallyTrustworthy() ||
SchemeRegistry::SchemeShouldBypassSecureContextCheck( SchemeRegistry::SchemeShouldBypassSecureContextCheck(
...@@ -353,6 +351,7 @@ std::unique_ptr<WebSharedWorker> WebSharedWorker::CreateAndStart( ...@@ -353,6 +351,7 @@ std::unique_ptr<WebSharedWorker> WebSharedWorker::CreateAndStart(
bool pause_worker_context_on_start, bool pause_worker_context_on_start,
std::unique_ptr<WorkerMainScriptLoadParameters> std::unique_ptr<WorkerMainScriptLoadParameters>
worker_main_script_load_params, worker_main_script_load_params,
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context,
CrossVariantMojoRemote<mojom::SharedWorkerHostInterfaceBase> host, CrossVariantMojoRemote<mojom::SharedWorkerHostInterfaceBase> host,
WebSharedWorkerClient* client, WebSharedWorkerClient* client,
ukm::SourceId ukm_source_id) { ukm::SourceId ukm_source_id) {
...@@ -364,7 +363,8 @@ std::unique_ptr<WebSharedWorker> WebSharedWorker::CreateAndStart( ...@@ -364,7 +363,8 @@ std::unique_ptr<WebSharedWorker> WebSharedWorker::CreateAndStart(
policy_type, creation_address_space, outside_fetch_client_settings_object, policy_type, creation_address_space, outside_fetch_client_settings_object,
devtools_worker_token, std::move(content_settings), devtools_worker_token, std::move(content_settings),
std::move(browser_interface_broker), pause_worker_context_on_start, std::move(browser_interface_broker), pause_worker_context_on_start,
std::move(worker_main_script_load_params)); std::move(worker_main_script_load_params),
std::move(web_worker_fetch_context));
return worker; return worker;
} }
......
...@@ -116,7 +116,8 @@ class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker { ...@@ -116,7 +116,8 @@ class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker {
browser_interface_broker, browser_interface_broker,
bool pause_worker_context_on_start, bool pause_worker_context_on_start,
std::unique_ptr<WorkerMainScriptLoadParameters> std::unique_ptr<WorkerMainScriptLoadParameters>
worker_main_script_load_params); worker_main_script_load_params,
scoped_refptr<WebWorkerFetchContext> web_worker_fetch_context);
void DispatchPendingConnections(); void DispatchPendingConnections();
void ConnectToChannel(int connection_request_id, void ConnectToChannel(int connection_request_id,
......
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