Commit c0159027 authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

service worker: Pass outside fetch client settings object from browser

This CL is a preparation for passing outside fetch client settings
object. This CL plumbs outside fetch client settings object from
browser process to renderer process but its fields aren't set correctly
yet. Follow-up CLs will fill them correctly.

This CL does not have behavioral changes.

Bug: 967265
Change-Id: I83b9bc6644c2bf33a0516f869166cc639fe61683
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846220Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704495}
parent 263aa9b0
......@@ -865,6 +865,16 @@ void EmbeddedWorkerInstance::SendStartWorker(
process_id(), MakeRequest(&params->provider_info->interface_provider),
params->provider_info->browser_interface_broker
.InitWithNewPipeAndPassReceiver());
// TODO(bashi): Create correct outside fetch client settings object. We need
// to plumb parent's fetch client settings object from renderer.
// See crbug.com/937177.
params->outside_fetch_client_settings_object =
blink::mojom::FetchClientSettingsObject::New(
network::mojom::ReferrerPolicy::kDefault,
/*outgoing_referrer=*/params->script_url,
blink::mojom::InsecureRequestsPolicy::kDoNotUpgrade);
client_->StartWorker(std::move(params));
starting_phase_ = is_script_streaming ? SCRIPT_STREAMING : SENT_START_WORKER;
......
......@@ -175,6 +175,16 @@ EmbeddedWorkerInstanceClientImpl::BuildStartData(
? blink::WebEmbeddedWorkerStartData::kWaitForDebugger
: blink::WebEmbeddedWorkerStartData::kDontWaitForDebugger;
start_data->devtools_worker_token = params.devtools_worker_token;
// TODO(bashi): Consider to have a helper function to convert
// mojom::FetchClientSettingsObject to WebFetchClientSettingsObject.
start_data->outside_fetch_client_settings_object.referrer_policy =
params.outside_fetch_client_settings_object->referrer_policy;
start_data->outside_fetch_client_settings_object.outgoing_referrer =
params.outside_fetch_client_settings_object->outgoing_referrer;
start_data->outside_fetch_client_settings_object.insecure_requests_policy =
params.outside_fetch_client_settings_object->insecure_requests_policy;
return start_data;
}
......
......@@ -11,6 +11,7 @@ import "services/network/public/mojom/url_loader_factory.mojom";
import "third_party/blink/public/mojom/devtools/console_message.mojom";
import "third_party/blink/public/mojom/devtools/devtools_agent.mojom";
import "third_party/blink/public/mojom/worker/subresource_loader_updater.mojom";
import "third_party/blink/public/mojom/loader/fetch_client_settings_object.mojom";
import "third_party/blink/public/mojom/loader/url_loader_factory_bundle.mojom";
import "third_party/blink/public/mojom/renderer_preference_watcher.mojom";
import "third_party/blink/public/mojom/renderer_preferences.mojom";
......@@ -44,6 +45,10 @@ struct EmbeddedWorkerStartParams {
// https://w3c.github.io/ServiceWorker/#dfn-type
ScriptType script_type;
// The outside fetch client settings object. This is used for top-level script
// fetch.
FetchClientSettingsObject outside_fetch_client_settings_object;
// The string used for "user-agent" HTTP header.
string user_agent;
......
......@@ -25,6 +25,8 @@ struct WebFetchClientSettingsObject {
WebURL outgoing_referrer;
mojom::InsecureRequestsPolicy insecure_requests_policy;
WebFetchClientSettingsObject() {}
#if INSIDE_BLINK
explicit WebFetchClientSettingsObject(
const FetchClientSettingsObjectSnapshot& snapshot)
......
......@@ -35,6 +35,7 @@
#include "services/network/public/mojom/ip_address_space.mojom-shared.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom-shared.h"
#include "third_party/blink/public/platform/web_content_security_policy.h"
#include "third_party/blink/public/platform/web_fetch_client_settings_object.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url.h"
......@@ -55,6 +56,8 @@ struct WebEmbeddedWorkerStartData {
network::mojom::IPAddressSpace address_space;
WebFetchClientSettingsObject outside_fetch_client_settings_object;
WebEmbeddedWorkerStartData() : wait_for_debugger_mode(kDontWaitForDebugger) {}
};
......
......@@ -262,7 +262,8 @@ void WebEmbeddedWorkerImpl::StartWorkerThread(
std::unique_ptr<CrossThreadFetchClientSettingsObjectData>
fetch_client_setting_object_data = CreateFetchClientSettingsObjectData(
worker_start_data->script_url, starter_origin.get(),
starter_https_state, worker_start_data->address_space);
starter_https_state, worker_start_data->address_space,
worker_start_data->outside_fetch_client_settings_object);
// > Switching on job's worker type, run these substeps with the following
// > options:
......@@ -302,24 +303,30 @@ WebEmbeddedWorkerImpl::CreateFetchClientSettingsObjectData(
const KURL& script_url,
const SecurityOrigin* security_origin,
const HttpsState& https_state,
network::mojom::IPAddressSpace address_space) {
// TODO(crbug.com/967265): Currently we create an incomplete outside settings
// object from |worker_start_data| but we should create a proper outside
// settings objects depending on the situation. For new worker case, this
// should be the Document that called navigator.serviceWorker.register(). For
// ServiceWorkerRegistration#update() case, it should be the Document that
// called update(). For soft update case, it seems to be 'null' document.
//
// To get a correct settings, we need to make a way to pass the settings
// object over mojo IPCs.
network::mojom::IPAddressSpace address_space,
const WebFetchClientSettingsObject& passed_settings_object) {
// TODO(crbug.com/967265): Currently |passed_settings_object| doesn't contain
// enough parameters to create a complete outside settings object. Pass
// all necessary information from the parent execution context.
// For new worker case, the parent is the Document that called
// navigator.serviceWorker.register(). For ServiceWorkerRegistration#update()
// case, it should be the Document that called update(). For soft update case,
// it seems to be 'null' document.
WebInsecureRequestPolicy insecure_requests_policy =
passed_settings_object.insecure_requests_policy ==
mojom::InsecureRequestsPolicy::kUpgrade
? kUpgradeInsecureRequests
: kBlockAllMixedContent;
return std::make_unique<CrossThreadFetchClientSettingsObjectData>(
script_url.Copy() /* global_object_url */,
script_url.Copy() /* base_url */, security_origin->IsolatedCopy(),
network::mojom::ReferrerPolicy::kDefault,
script_url.GetString().IsolatedCopy() /* outgoing_referrer */,
passed_settings_object.referrer_policy,
KURL::CreateIsolated(
passed_settings_object.outgoing_referrer.GetString()),
https_state, AllowedByNosniff::MimeTypeCheck::kLax, address_space,
kBlockAllMixedContent /* insecure_requests_policy */,
insecure_requests_policy,
FetchClientSettingsObject::InsecureNavigationsSet(),
false /* mixed_autoupgrade_opt_out */);
}
......
......@@ -92,10 +92,12 @@ class MODULES_EXPORT WebEmbeddedWorkerImpl final : public WebEmbeddedWorker {
// Creates a cross-thread copyable outside settings object for top-level
// worker script fetch.
std::unique_ptr<CrossThreadFetchClientSettingsObjectData>
CreateFetchClientSettingsObjectData(const KURL& script_url,
CreateFetchClientSettingsObjectData(
const KURL& script_url,
const SecurityOrigin*,
const HttpsState&,
network::mojom::IPAddressSpace);
network::mojom::IPAddressSpace,
const WebFetchClientSettingsObject& passed_settings_object);
// Client must remain valid through the entire life time of the worker.
WebServiceWorkerContextClient* const worker_context_client_;
......
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