Truly independent web browser
LibWeb: Name a fetch request's client by its address
Luke Wildee563b9ba7bc7
diff --git a/Libraries/LibWeb/CSS/Fetch.cpp b/Libraries/LibWeb/CSS/Fetch.cppindex 991be75a5a2..7320f934944 100644--- a/Libraries/LibWeb/CSS/Fetch.cpp+++ b/Libraries/LibWeb/CSS/Fetch.cpp@@ -103,7 +103,7 @@ static GC::Ptr<Fetch::Infrastructure::Request> fetch_a_style_resource_impl(Stylerequest->set_origin(environment_settings.origin());request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::SameOrigin);request->set_use_url_credentials(true);- request->set_client(&environment_settings);+ request->set_client(environment_settings.address());request->set_referrer(Fetch::Infrastructure::Request::Referrer::Client);// 4. If corsMode is "no-cors", set req’s credentials mode to "include".diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cppindex 9731509f043..36062bcadf8 100644--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp@@ -16,6 +16,7 @@#include <LibWeb/ContentSecurityPolicy/Violation.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Element.h>+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>#include <LibWeb/HTML/LocalNavigable.h>@@ -46,7 +47,7 @@ static bool may_report_violations_for(GC::Ptr<HTML::EnvironmentSettingsObject coViolationReporter violation_reporter_for_request(JS::Realm& realm, GC::Ref<Fetch::Infrastructure::Request> request){return [&realm, request](NonnullRefPtr<Policy const> policy) {- if (!may_report_violations_for(request->client()))+ if (!may_report_violations_for(Fetch::Fetching::resolve_client(request)))return;auto violation = Violation::create_a_violation_object_for_request_and_policy(request, move(policy));violation->report_a_violation(realm);@@ -59,6 +60,8 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_co// 1. Let result be "Allowed".auto result = Directives::Directive::Result::Allowed;+ auto client = Fetch::Fetching::resolve_client(navigation_request);+// 2. For each policy of navigation request’s policy container’s CSP list:auto policy_container = navigation_request->policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>();for (auto const& policy : policy_container->csp_list.policies()) {@@ -69,11 +72,11 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_coif (directive_result == Directives::Directive::Result::Allowed)continue;- if (may_report_violations_for(navigation_request->client())) {+ if (may_report_violations_for(client)) {// 2. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive on navigation request’s// client’s global object, policy, and directive’s name.- auto& realm = navigation_request->client()->realm();- auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());+ auto& realm = client->realm();+ auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(client->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());// 3. Set violation’s resource to navigation request’s URL.violation->set_resource(navigation_request->url());@@ -111,16 +114,16 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_co// navigation request’s current URL, skip to the next directive.// FIXME: File spec issue that current URL is a URL object and not a string, therefore they must use a// spec operation to serialize the URL.- auto& realm = navigation_request->client()->realm();+ auto& realm = client->realm();auto serialized_url = navigation_request->current_url().to_string();auto serialized_url_utf16 = Utf16String::from_utf8(serialized_url);if (Directives::inline_check(directive, nullptr, Directives::Directive::InlineType::Navigation, policy, serialized_url_utf16.utf16_view()) == Directives::Directive::Result::Allowed)continue;- if (may_report_violations_for(navigation_request->client())) {+ if (may_report_violations_for(client)) {// 3. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global,// policy, and directive on navigation request’s client’s global object, policy, and directive-name.- auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive_name.view().to_utf8_but_should_be_ported_to_utf16());+ auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(client->global_object(), policy, directive_name.view().to_utf8_but_should_be_ported_to_utf16());// 4. Set violation’s resource to "inline".violation->set_resource(Violation::Resource::Inline);@@ -155,6 +158,8 @@ Directives::Directive::Result should_navigation_response_to_navigation_request_oif (!navigation_request)return result;+ auto client = Fetch::Fetching::resolve_client(*navigation_request);+// NB: Only frame-ancestors reads the target's container documents. Each is the next parent navigable's active// document, and a parent navigable answers for a document hosted in another process.auto has_frame_ancestors = any_of(response_csp_list.policies(), [](auto const& policy) {@@ -182,7 +187,7 @@ Directives::Directive::Result should_navigation_response_to_navigation_request_o// 2. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive on null, policy, and directive’s name.// Spec Note: We use null for the global object, as no global exists: we haven’t processed the navigation to create a Document yet.// FIXME: What should the realm be here?- auto& realm = navigation_request->client()->realm();+ auto& realm = client->realm();auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(nullptr, policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());// 3. Set violation’s resource to navigation response’s URL.@@ -212,10 +217,10 @@ Directives::Directive::Result should_navigation_response_to_navigation_request_oif (directive_result == Directives::Directive::Result::Allowed)continue;- if (may_report_violations_for(navigation_request->client())) {+ if (may_report_violations_for(client)) {// 2. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive on navigation request’s client’s global object, policy, and directive’s name.- auto& realm = navigation_request->client()->realm();- auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());+ auto& realm = client->realm();+ auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(client->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());// 3. Set violation’s resource to navigation request’s URL.violation->set_resource(navigation_request->url());diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cppindex 67a3637910b..a59d70bb6a7 100644--- a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp+++ b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp@@ -17,6 +17,7 @@#include <LibWeb/ContentSecurityPolicy/Violation.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOMURL/DOMURL.h>+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Fetching/Fetching.h>#include <LibWeb/HTML/PolicyContainers.h>#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>@@ -103,7 +104,8 @@ GC::Ref<Violation> Violation::create_a_violation_object_for_request_and_policy(G// 2. Let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive// on request’s client’s global object, policy, and directive.- auto violation = create_a_violation_object_for_global_policy_and_directive(request->client()->global_object(), policy, String { directive->view().to_utf8_but_should_be_ported_to_utf16() });+ auto client = Fetch::Fetching::resolve_client(request);+ auto violation = create_a_violation_object_for_global_policy_and_directive(client->global_object(), policy, String { directive->view().to_utf8_but_should_be_ported_to_utf16() });// 3. Set violation’s resource to request’s url.// Spec Note: We use request’s url, and not its current url, as the latter might contain information about redirect@@ -113,7 +115,7 @@ GC::Ref<Violation> Violation::create_a_violation_object_for_request_and_policy(G// AD-HOC: A request whose client is a snapshot of an environment in another process, such as a worker's outside// settings when the worker fetches its script, violates that environment's policies. Its global object is// in that process, so the violation is reported there.- if (auto const* snapshot = as_if<HTML::EnvironmentSettingsSnapshot>(*request->client()); snapshot && snapshot->report_violation()) {+ if (auto const* snapshot = as_if<HTML::EnvironmentSettingsSnapshot>(*client); snapshot && snapshot->report_violation()) {// NB: Request's policy container is a clone of the snapshot's, which lists the policies in the same order.auto const& policies = request->policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->csp_list.policies();for (size_t policy_index = 0; policy_index < policies.size(); ++policy_index) {@@ -462,7 +464,7 @@ void Violation::report_a_violation(JS::Realm& realm)// client// violation's global object's relevant settings object- request->set_client(&environment_settings_object);+ request->set_client(environment_settings_object.address());// destination// "report"diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 4e21c91c061..dd877fe64d9 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -600,7 +600,7 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type|| request.referrer().get<Fetch::Infrastructure::Request::Referrer>() != Fetch::Infrastructure::Request::Referrer::NoReferrer;// - navigation TAO check given navigationParams's response and navigationParams's origin returns success,- may_expose_redirect_count = (!request.client() || request_has_eligible_referrer)+ may_expose_redirect_count = (!request.client().has_value() || request_has_eligible_referrer)&& Fetch::Fetching::navigation_tao_check(*navigation_params.response, navigation_params.origin);}diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex 18cb2822cba..6be821587bf 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -774,7 +774,7 @@ void Element::download_the_hyperlink(Optional<Utf16String> hyperlink_suffix, HTM// document's relevant settings object is used as the request client instead.auto request = Fetch::Infrastructure::Request::create();request->set_url(url);- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());request->set_initiator(Fetch::Infrastructure::Request::Initiator::Download);request->set_use_url_credentials(true);// NB: The synchronous flag is not set; the response is instead processed asynchronously on the main thread.diff --git a/Libraries/LibWeb/Fetch/FetchMethod.cpp b/Libraries/LibWeb/Fetch/FetchMethod.cppindex 660ffa1bfcb..30d3df8644e 100644--- a/Libraries/LibWeb/Fetch/FetchMethod.cpp+++ b/Libraries/LibWeb/Fetch/FetchMethod.cpp@@ -12,6 +12,7 @@#include <LibWeb/Bindings/WrapperWorld.h>#include <LibWeb/DOM/AbortSignal.h>#include <LibWeb/Fetch/FetchMethod.h>+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Fetching/Fetching.h>#include <LibWeb/Fetch/Fetching/RefCountedFlag.h>#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>@@ -97,7 +98,7 @@ GC::Ref<WebIDL::Promise> fetch(JS::Realm& realm, RequestInfo const& input, Bindi}// 5. Let globalObject be request’s client’s global object.- auto& global_object = request->client()->global_object();+ auto& global_object = Fetching::resolve_client(request)->global_object();// FIXME: 6. If globalObject is a ServiceWorkerGlobalScope object, then set request’s service-workers mode to "none".(void)global_object;diff --git a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cpp b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cppindex 15926f7081f..31fc765bc2a 100644--- a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cpp@@ -6,6 +6,7 @@#include <LibWeb/DOM/Document.h>#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>#include <LibWeb/HTML/BrowsingContext.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>@@ -16,6 +17,16 @@namespace Web::Fetch::Fetching {+GC::Ptr<HTML::EnvironmentSettingsObject> resolve_client(Infrastructure::Request const& request)+{+ auto address = request.client();+ if (!address.has_value())+ return nullptr;+ auto client = HTML::environment_settings_object_at(*address);+ VERIFY(client);+ return client;+}+// https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer// NB: The steps of the "client" case that read environment, which is non-null.static Optional<URL::URL> referrer_source_of_client(HTML::EnvironmentSettingsObject& environment)diff --git a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.h b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.hindex ba79dd5f9be..bae8d5cda56 100644--- a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.h+++ b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.h@@ -7,12 +7,15 @@#pragma once#include <AK/NonnullRefPtr.h>+#include <LibGC/Ptr.h>#include <LibWeb/Export.h>#include <LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h>#include <LibWeb/Forward.h>namespace Web::Fetch::Fetching {+[[nodiscard]] WEB_API GC::Ptr<HTML::EnvironmentSettingsObject> resolve_client(Infrastructure::Request const&);+[[nodiscard]] WEB_API NonnullRefPtr<Infrastructure::ClientContextSnapshot const> snapshot_client_context(HTML::EnvironmentSettingsObject&);[[nodiscard]] WEB_API NonnullRefPtr<Infrastructure::ReservedClientContextSnapshot const> snapshot_reserved_client_context(HTML::Environment const&);diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex 227e47afbfd..1dd80671b63 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -269,13 +269,15 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:// 3. Let crossOriginIsolatedCapability be false.auto cross_origin_isolated_capability = HTML::CanUseCrossOriginIsolatedAPIs::No;+ auto client = resolve_client(request);+// 4. Populate request from client given request.- populate_request_from_client(request);+ populate_request_from_client(request, client);// 5. If request’s client is non-null, then:- if (request.client() != nullptr) {+ if (client) {// 1. Set taskDestination to request’s client’s global object.- task_destination = GC::Ref { request.client()->global_object() };+ task_destination = GC::Ref { client->global_object() };// 2. Set crossOriginIsolatedCapability to request’s client’s cross-origin isolated capability.cross_origin_isolated_capability = request.client_snapshot()->cross_origin_isolated_capability;@@ -316,7 +318,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:fetch_params->set_blob_url_entry(move(blob_url_entry));}- auto* client_window = request.client() ? HTML::window_from_global_object(request.client()->global_object()) : nullptr;+ auto* client_window = client ? HTML::window_from_global_object(client->global_object()) : nullptr;// 10. If all of the following conditions are true:if (@@ -444,7 +446,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:auto record = Infrastructure::FetchRecord::create(request, fetch_params->controller());// 2. Append record to request’s client’s fetch group’s fetch records.- request.client()->fetch_group().append(record);+ client->fetch_group().append(record);// AD-HOC: A keepalive request's body length counts toward its fetch group's keepalive quota from here until// its done flag is set or its body is null, since its fetch record can be collected before then.@@ -468,7 +470,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:}// https://fetch.spec.whatwg.org/#populate-request-from-client-void populate_request_from_client(Infrastructure::Request& request)+void populate_request_from_client(Infrastructure::Request& request, GC::Ptr<HTML::EnvironmentSettingsObject> client){// 1. If request’s traversable for user prompts is "client":auto const* traversable_for_user_prompts = request.traversable_for_user_prompts().get_pointer<Infrastructure::Request::TraversableForUserPrompts>();@@ -477,9 +479,9 @@ void populate_request_from_client(Infrastructure::Request& request)request.set_traversable_for_user_prompts(Infrastructure::Request::TraversableForUserPrompts::NoTraversable);// 2. If request’s client is non-null:- if (request.client()) {+ if (client) {// 1. Let global be request’s client’s global object.- auto& global = request.client()->global_object();+ auto& global = client->global_object();// 2. If global is a Window object and global’s navigable is not null, then set request’s traversable for// user prompts to global’s navigable’s traversable navigable.@@ -494,10 +496,10 @@ void populate_request_from_client(Infrastructure::Request& request)auto const* origin = request.origin().get_pointer<Infrastructure::Request::Origin>();if (origin && *origin == Infrastructure::Request::Origin::Client) {// 1. Assert: request’s client is non-null.- VERIFY(request.client());+ VERIFY(client);// 2. Set request’s origin to request’s client’s origin.- request.set_origin(request.client()->origin());+ request.set_origin(client->origin());}// 3. If request’s policy container is "client":@@ -505,8 +507,8 @@ void populate_request_from_client(Infrastructure::Request& request)if (policy_container && *policy_container == Infrastructure::Request::PolicyContainer::Client) {// 1. If request’s client is non-null, then set request’s policy container to a clone of request’s client’s// policy container.- if (request.client())- request.set_policy_container(request.client()->policy_container()->clone());+ if (client)+ request.set_policy_container(client->policy_container()->clone());// 2. Otherwise, set request’s policy container to a new policy container.elserequest.set_policy_container(HTML::PolicyContainer::create());@@ -514,8 +516,8 @@ void populate_request_from_client(Infrastructure::Request& request)// AD-HOC: Fetching reads the client through a snapshot of it, taken here, so that it needs neither the settings// object nor its global object.- if (request.client())- request.set_client_snapshot(snapshot_client_context(*request.client()));+ if (client)+ request.set_client_snapshot(snapshot_client_context(*client));}// https://fetch.spec.whatwg.org/#concept-main-fetch@@ -1050,10 +1052,10 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// given fetchParams’s request’s client’s global object.// AD-HOC: Not when this fetch consumed a preload that reports its own timing. Other engines report a single// entry for a preloaded resource and its consumer.- auto client = fetch_params.request()->client();auto const* task_destination_global_object = fetch_params.task_destination().get_pointer<GC::Ref<JS::Object>>();- if (client != nullptr && task_destination_global_object != nullptr && !fetch_params.preload_reports_timing()) {- if (fetch_params.request()->initiator_type().has_value() && &client->global_object() == task_destination_global_object->ptr())+ if (task_destination_global_object != nullptr && fetch_params.request()->initiator_type().has_value() && !fetch_params.preload_reports_timing()) {+ auto client = resolve_client(fetch_params.request());+ if (client != nullptr && &client->global_object() == task_destination_global_object->ptr())fetch_params.controller()->report_timing(client->global_object());}};diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.h b/Libraries/LibWeb/Fetch/Fetching/Fetching.hindex dd5519161ef..3804da16dca 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.h+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.h@@ -47,7 +47,7 @@ ENUMERATE_BOOL_PARAMSWEB_API GC::Ref<Infrastructure::FetchController> fetch(JS::Realm&, Infrastructure::Request&, Infrastructure::FetchAlgorithms const&, UseParallelQueue use_parallel_queue = UseParallelQueue::No, CreateResponseBodyTransferLease = CreateResponseBodyTransferLease::No);GC::Ptr<PendingResponse> main_fetch(JS::Realm&, Infrastructure::FetchParams const&, Recursive recursive = Recursive::No);-void populate_request_from_client(Infrastructure::Request&);+void populate_request_from_client(Infrastructure::Request&, GC::Ptr<HTML::EnvironmentSettingsObject> client);void fetch_response_handover(JS::Realm&, Infrastructure::FetchParams const&, Infrastructure::Response&);GC::Ref<PendingResponse> scheme_fetch(JS::Realm&, Infrastructure::FetchParams const&);GC::Ref<PendingResponse> http_fetch(JS::Realm&, Infrastructure::FetchParams const&, MakeCORSPreflight make_cors_preflight = MakeCORSPreflight::No);diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cppindex 21c104b0e52..bd8ab6215f7 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp@@ -43,7 +43,6 @@ Request::Request(NonnullRefPtr<HTTP::HeaderList> header_list)void Request::visit_edges(JS::Cell::Visitor& visitor){Base::visit_edges(visitor);- visitor.visit(m_client);visitor.visit(m_body);visitor.visit(m_reserved_client);visitor.visit(m_traversable_for_user_prompts);@@ -392,7 +391,7 @@ bool Request::cross_origin_embedder_policy_allows_credentials() constreturn true;// 3. If request’s client is null, then return true.- if (m_client == nullptr)+ if (!m_client.has_value())return true;// 4. If request’s client’s policy container’s embedder policy’s value is not "credentialless", then return true.diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.hindex 1922d5d2d4d..bc65e6ee5b9 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h@@ -30,6 +30,7 @@#include <LibWeb/Fetch/Infrastructure/HTTP.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>#include <LibWeb/Fetch/Infrastructure/KeepaliveQuotaAccountant.h>+#include <LibWeb/HTML/Scripting/EnvironmentSettingsObjectAddress.h>#include <LibWebCommon/Fetch/Infrastructure/HTTP/RequestPriority.h>#include <LibWebCommon/Fetch/Infrastructure/HTTP/RequestReferrer.h>#include <LibWebCommon/HTML/Scripting/EnvironmentId.h>@@ -196,9 +197,8 @@ public:m_body = move(body);}- [[nodiscard]] GC::Ptr<HTML::EnvironmentSettingsObject const> client() const { return m_client; }- [[nodiscard]] GC::Ptr<HTML::EnvironmentSettingsObject> client() { return m_client; }- void set_client(GC::Ptr<HTML::EnvironmentSettingsObject> client) { m_client = client; }+ [[nodiscard]] Optional<HTML::EnvironmentSettingsObjectAddress> client() const { return m_client; }+ void set_client(Optional<HTML::EnvironmentSettingsObjectAddress> client) { m_client = client; }[[nodiscard]] ReservedClientType const& reserved_client() const { return m_reserved_client; }[[nodiscard]] ReservedClientType& reserved_client() { return m_reserved_client; }@@ -400,7 +400,7 @@ private:// https://fetch.spec.whatwg.org/#concept-request-client// A request has an associated client (null or an environment settings object).- GC::Ptr<HTML::EnvironmentSettingsObject> m_client;+ Optional<HTML::EnvironmentSettingsObjectAddress> m_client;// https://fetch.spec.whatwg.org/#concept-request-reserved-client// A request has an associated reserved client (null, an environment, or an environment settings object). Unlessdiff --git a/Libraries/LibWeb/Fetch/Request.cpp b/Libraries/LibWeb/Fetch/Request.cppindex 9e9c4ebab44..2c444e3a628 100644--- a/Libraries/LibWeb/Fetch/Request.cpp+++ b/Libraries/LibWeb/Fetch/Request.cpp@@ -384,7 +384,7 @@ WebIDL::ExceptionOr<GC::Ref<Request>> Request::create_with_settings(HTML::Enviro// client// This’s relevant settings object.- request->set_client(&relevant_settings_object);+ request->set_client(relevant_settings_object.address());// traversable for user prompts// traversableForUserPrompts.diff --git a/Libraries/LibWeb/HTML/EventSource.cpp b/Libraries/LibWeb/HTML/EventSource.cppindex 964e48950a3..a721e0dc7a0 100644--- a/Libraries/LibWeb/HTML/EventSource.cpp+++ b/Libraries/LibWeb/HTML/EventSource.cpp@@ -99,7 +99,7 @@ WebIDL::ExceptionOr<GC::Ref<EventSource>> EventSource::create(WindowOrWorkerGlobauto request = create_potential_CORS_request(event_source->m_url, {}, cors_attribute_state);// 9. Set request's client to settings.- request->set_client(&settings);+ request->set_client(settings.address());// 10. User agents may set (`Accept`, `text/event-stream`) in request's header list.request->header_list()->set({ "Accept"sv, "text/event-stream"sv });diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cppindex 94542c5e613..cffed0d4086 100644--- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp@@ -1209,7 +1209,7 @@ after_step_7:auto request = create_potential_CORS_request(*url_record, Fetch::Infrastructure::Request::Destination::Image, m_cors_setting);// 20. Set request's client to the element's node document's relevant settings object.- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());// AD-HOC: The spec doesn't set an initiator type for img requests, so they would never report resource timing.// Spec PR: https://github.com/whatwg/html/pull/13101@@ -1487,7 +1487,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()auto request = create_potential_CORS_request(*url_record, Fetch::Infrastructure::Request::Destination::Image, m_cors_setting);// 2. Set request's client to client, set request's initiator to "imageset", and set request's synchronous flag.- request->set_client(&client);+ request->set_client(client.address());request->set_initiator(Fetch::Infrastructure::Request::Initiator::ImageSet);// AD-HOC: The spec doesn't set an initiator type for img requests, so they would never report resource timing.diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cppindex 0c0fa32dae5..5cc5eeae6b5 100644--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp@@ -1862,7 +1862,7 @@ WebIDL::ExceptionOr<void> HTMLInputElement::handle_src_attribute(Utf16View value// use-URL-credentials flag is set.auto request = Fetch::Infrastructure::Request::create();request->set_url(url.release_value());- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());request->set_destination(Fetch::Infrastructure::Request::Destination::Image);request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Input);request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include);diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cppindex fee09aec2c0..4e88085d42e 100644--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp@@ -470,7 +470,7 @@ GC::Ptr<Fetch::Infrastructure::Request> HTMLLinkElement::create_link_request(HTMrequest->set_referrer_policy(options.referrer_policy);// 10. Set request's client to options's environment.- request->set_client(options.environment);+ request->set_client(options.environment->address());// 11. Set request's priority to options's fetch priority.request->set_priority(options.fetch_priority);@@ -1656,7 +1656,7 @@ void HTMLLinkElement::load_fallback_favicon_if_needed(GC::Ref<DOM::Document> docauto request = Fetch::Infrastructure::Request::create();request->set_url(favicon_url.release_value());- request->set_client(&document->relevant_settings_object());+ request->set_client(document->relevant_settings_object().address());request->set_destination(Fetch::Infrastructure::Request::Destination::Image);request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include);request->set_use_url_credentials(true);diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex a70bfc1e149..d901be04c27 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -1635,7 +1635,7 @@ void HTMLMediaElement::run_remote_mode_resource_fetch_steps(ByteRange byte_rangeauto request = create_potential_CORS_request(url_record, destination, m_crossorigin);// 4. Set request's client to the media element's node document's relevant settings object.- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());// 5. Set request's initiator type to destination.request->set_initiator_type(destination == Fetch::Infrastructure::Request::Destination::Audiodiff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cppindex 6c2be912142..641a37733b5 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp@@ -273,7 +273,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()// "object", and whose use-URL-credentials flag is set.auto request = Fetch::Infrastructure::Request::create();request->set_url(url.release_value());- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());request->set_destination(Fetch::Infrastructure::Request::Destination::Object);request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include);request->set_mode(Fetch::Infrastructure::Request::Mode::Navigate);@@ -570,7 +570,7 @@ void HTMLObjectElement::load_image()if (m_resource_request->needs_fetching()) {auto request = HTML::create_potential_CORS_request(*url, Fetch::Infrastructure::Request::Destination::Image, HTML::CORSSettingAttribute::NoCORS);- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());m_resource_request->fetch_resource(request);}}diff --git a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp b/Libraries/LibWeb/HTML/HTMLTrackElement.cppindex 8238cbcfa27..663aad66e00 100644--- a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLTrackElement.cpp@@ -269,7 +269,7 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps()auto request = create_potential_CORS_request(parsed_url.release_value(), Fetch::Infrastructure::Request::Destination::Track, cors_attribute_state, SameOriginFallbackFlag::Yes);// 2. Set request's client to the track element's node document's relevant settings object.- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());// 3. Set request's initiator type to "track".request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Track);diff --git a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp b/Libraries/LibWeb/HTML/HTMLVideoElement.cppindex 9e011ab892e..8e49a8774b8 100644--- a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLVideoElement.cpp@@ -300,7 +300,7 @@ WebIDL::ExceptionOr<void> HTMLVideoElement::determine_element_poster_frame(Optio// and whose use-URL-credentials flag is set.auto request = Fetch::Infrastructure::Request::create();request->set_url(url_record.release_value());- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());request->set_destination(Fetch::Infrastructure::Request::Destination::Image);request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Video);request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include);diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex afbf6c41018..bf2ae1edeb4 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -2543,7 +2543,8 @@ static void create_navigation_params_by_fetching(// policy container: sourceSnapshotParams's source policy containerauto request = Fetch::Infrastructure::Request::create(vm);request->set_url(entry.url);- request->set_client(source_snapshot_params->fetch_client);+ if (source_snapshot_params->fetch_client)+ request->set_client(source_snapshot_params->fetch_client->address());request->set_destination(Fetch::Infrastructure::Request::Destination::Document);request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include);request->set_use_url_credentials(true);@@ -2565,7 +2566,7 @@ static void create_navigation_params_by_fetching(request->set_top_level_navigation_initiator_origin(document_state.initiator_origin);// 5. If request's client is null:- if (request->client() == nullptr) {+ if (!request->client().has_value()) {// Note: This only occurs in the case of a browser UI-initiated navigation.// 1. Set request's origin to a new opaque origin.@@ -3479,14 +3480,16 @@ void LocalNavigable::navigate_to_a_javascript_url_from_ui_process(URL::URL constrequest->set_policy_container(source_snapshot_params->source_policy_container);// AD-HOC: See https://github.com/whatwg/html/issues/4651, requires some investigation to figure out what we should be setting here.- request->set_client(source_snapshot_params->fetch_client);+ if (source_snapshot_params->fetch_client)+ request->set_client(source_snapshot_params->fetch_client->address());// 2. Queue a global task on the navigation and traversal task source given navigable's active window to// navigate to a javascript: URL given navigable, request, historyHandling, initiatorOriginSnapshot,// userInvolvement, cspNavigationType, initialInsertion, and navigationId.// NB: initialInsertion is false for a navigation the UI process runs: it never inserts a container.+ // NB: The task holds request's client until it runs.m_queued_javascript_url_navigations.append(navigation_id);- queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(*window), GC::create_function(heap(), [this, request, history_handling, initiator_origin, user_involvement, csp_navigation_type, navigation_id = move(navigation_id)] {+ queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(*window), GC::create_function(heap(), [this, request, client = source_snapshot_params->fetch_client, history_handling, initiator_origin, user_involvement, csp_navigation_type, navigation_id = move(navigation_id)] {navigate_to_a_javascript_url(request, history_handling, initiator_origin, user_involvement, csp_navigation_type, InitialInsertion::No, navigation_id);}));}@@ -3661,13 +3664,15 @@ void LocalNavigable::begin_navigation(PreparedNavigation navigation)// URL operates on a request. It will never hit the network.auto request = Fetch::Infrastructure::Request::create(vm);request->set_url(url);- request->set_client(source_snapshot_params->fetch_client);+ if (source_snapshot_params->fetch_client)+ request->set_client(source_snapshot_params->fetch_client->address());request->set_policy_container(source_snapshot_params->source_policy_container);// 2. Queue a global task on the navigation and traversal task source given navigable's active window to navigate to a javascript: URL given navigable, request, historyHandling, initiatorOriginSnapshot, userInvolvement, cspNavigationType, initialInsertion, and navigationId.+ // NB: The task holds request's client until it runs.VERIFY(active_window());m_queued_javascript_url_navigations.append(navigation_id);- queue_global_task(Task::Source::NavigationAndTraversal, HTML::relevant_global_object(*active_window()), GC::create_function(heap(), [this, request, history_handling, initiator_origin_snapshot, user_involvement, csp_navigation_type, initial_insertion, navigation_id] {+ queue_global_task(Task::Source::NavigationAndTraversal, HTML::relevant_global_object(*active_window()), GC::create_function(heap(), [this, request, client = source_snapshot_params->fetch_client, history_handling, initiator_origin_snapshot, user_involvement, csp_navigation_type, initial_insertion, navigation_id] {navigate_to_a_javascript_url(request, to_history_handling_behavior(history_handling), initiator_origin_snapshot, user_involvement, csp_navigation_type, initial_insertion, navigation_id);}));diff --git a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cppindex a37575e68a4..c62bad40667 100644--- a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp+++ b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp@@ -11,6 +11,7 @@#include <LibRequests/RequestClient.h>#include <LibWeb/Bindings/PrincipalHostDefined.h>#include <LibWeb/DOM/Document.h>+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Fetching/FetchedDataReceiver.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>@@ -34,8 +35,9 @@ static SerializedPolicyContainer serialize_request_policy_container(Fetch::Infra{return request.policy_container().visit([&request](Fetch::Infrastructure::Request::PolicyContainer) {- VERIFY(request.client());- return request.client()->policy_container()->serialize();+ auto client = Fetch::Fetching::resolve_client(request);+ VERIFY(client);+ return client->policy_container()->serialize();},[](NonnullRefPtr<PolicyContainer const> const& policy_container) {return policy_container->serialize();@@ -47,7 +49,7 @@ static NavigationRequestDescriptor create_navigation_request_descriptor(Fetch::Ireturn {.url_list = request.url_list(),.method = request.method(),- .client_is_null = !request.client(),+ .client_is_null = !request.client().has_value(),.referrer = request.referrer(),.referrer_policy = request.referrer_policy(),.policy_container = serialize_request_policy_container(request),@@ -239,7 +241,7 @@ static GC::Ptr<Fetch::Infrastructure::Request> create_navigation_request_from_derequest->set_url_list(descriptor->url_list);request->set_method(descriptor->method);if (!descriptor->client_is_null)- request->set_client(&navigable.active_document()->relevant_settings_object());+ request->set_client(navigable.active_document()->relevant_settings_object().address());request->set_referrer(descriptor->referrer);request->set_referrer_policy(descriptor->referrer_policy);request->set_policy_container(create_a_policy_container_from_serialized_policy_container(descriptor->policy_container));diff --git a/Libraries/LibWeb/HTML/NavigatorBeacon.cpp b/Libraries/LibWeb/HTML/NavigatorBeacon.cppindex 6ece6508e74..322b76a5c7b 100644--- a/Libraries/LibWeb/HTML/NavigatorBeacon.cpp+++ b/Libraries/LibWeb/HTML/NavigatorBeacon.cpp@@ -72,12 +72,12 @@ WebIDL::ExceptionOr<bool> NavigatorBeaconPartial::send_beacon(Utf16View url, Fet// 7.1 Let req be a new request, initialized as follows:auto req = Fetch::Infrastructure::Request::create();- req->set_method("POST"sv); // method: POST- req->set_client(&relevant_settings_object); // client: this's relevant settings object- req->set_url_list({ parsed_url.release_value() }); // url: parsedUrl- req->set_header_list(header_list); // header list: headerList- req->set_origin(origin); // origin: origin- req->set_keepalive(true); // keepalive: true+ req->set_method("POST"sv); // method: POST+ req->set_client(relevant_settings_object.address()); // client: this's relevant settings object+ req->set_url_list({ parsed_url.release_value() }); // url: parsedUrl+ req->set_header_list(header_list); // header list: headerList+ req->set_origin(origin); // origin: origin+ req->set_keepalive(true); // keepalive: trueif (transmitted_data)req->set_body(GC::Ref<Fetch::Infrastructure::Body> { *transmitted_data }); // body: transmittedDatareq->set_mode(cors_mode); // mode: corsModediff --git a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cppindex 619bab21c3e..557c9019086 100644--- a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp+++ b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp@@ -138,7 +138,7 @@ CORSSettingAttribute cors_setting_from_preload_scanner(RustFfiPreloadScannerCorsvoid issue_speculative_fetch(JS::Realm& realm, DOM::Document& document, URL::URL url, Optional<Fetch::Infrastructure::Request::Destination> destination, CORSSettingAttribute cors_setting){auto request = create_potential_CORS_request(url, destination, cors_setting);- request->set_client(&document.relevant_settings_object());+ request->set_client(document.relevant_settings_object().address());// AD-HOC: The spec expects caching rules, which are not yet fully specified, to stop the normal parser from fetching// the same resource again. A response the HTTP cache can't store would be fetched twice, so once the@@ -226,7 +226,7 @@ void issue_speculative_module_fetch(DOM::Document& document, URL::URL const& urlrequest->set_url(url);request->set_mode(Fetch::Infrastructure::Request::Mode::CORS);request->set_referrer(Fetch::Infrastructure::Request::Referrer::Client);- request->set_client(&settings_object);+ request->set_client(settings_object.address());request->set_destination(destination);if (first_is_one_of(destination,Fetch::Infrastructure::Request::Destination::Worker,diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cppindex 54ba555897e..8d6669a8c24 100644--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp@@ -644,7 +644,7 @@ void fetch_classic_script(GC::Ref<HTMLScriptElement> element, URL::URL const& urauto request = create_potential_CORS_request(url, Fetch::Infrastructure::Request::Destination::Script, cors_setting);// 2. Set request's client to settings object.- request->set_client(&settings_object);+ request->set_client(settings_object.address());// 3. Set request's initiator type to "script".request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Script);@@ -823,7 +823,7 @@ WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const& url, Envir// and whose use-URL-credentials flag is set.auto request = Fetch::Infrastructure::Request::create();request->set_url(url);- request->set_client(&fetch_client);+ request->set_client(fetch_client.address());request->set_destination(destination);request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Other);request->set_mode(Fetch::Infrastructure::Request::Mode::SameOrigin);@@ -902,7 +902,7 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scri// parser metadata is "not parser-inserted", and whose use-URL-credentials flag is set.auto request = Fetch::Infrastructure::Request::create();request->set_url(url);- request->set_client(&settings_object);+ request->set_client(settings_object.address());request->set_destination(Fetch::Infrastructure::Request::Destination::Script);request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Other);request->set_parser_metadata(Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted);@@ -1078,7 +1078,7 @@ void fetch_single_module_script(JS::Realm& realm,request->set_url(url);request->set_mode(Fetch::Infrastructure::Request::Mode::CORS);request->set_referrer(referrer);- request->set_client(&fetch_client);+ request->set_client(fetch_client.address());// 9. Set request's destination to the result of running the fetch destination from module type steps given destination and moduleType.request->set_destination(fetch_destination_from_module_type(destination, module_type.utf16_view()));diff --git a/Libraries/LibWeb/SVG/SVGFEImageElement.cpp b/Libraries/LibWeb/SVG/SVGFEImageElement.cppindex 50fc6ffb850..7858134860b 100644--- a/Libraries/LibWeb/SVG/SVGFEImageElement.cpp+++ b/Libraries/LibWeb/SVG/SVGFEImageElement.cpp@@ -95,7 +95,7 @@ void SVGFEImageElement::process_href(Optional<Utf16String> const& href)if (m_resource_request->needs_fetching()) {auto request = HTML::create_potential_CORS_request(*m_href, Fetch::Infrastructure::Request::Destination::Image, HTML::CORSSettingAttribute::NoCORS);- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());m_resource_request->fetch_resource(request);}}diff --git a/Libraries/LibWeb/SVG/SVGImageElement.cpp b/Libraries/LibWeb/SVG/SVGImageElement.cppindex 26980179be6..d280a7d104b 100644--- a/Libraries/LibWeb/SVG/SVGImageElement.cpp+++ b/Libraries/LibWeb/SVG/SVGImageElement.cpp@@ -191,7 +191,7 @@ void SVGImageElement::fetch_the_document(URL::URL const& url)if (resource_request->needs_fetching()) {auto request = HTML::create_potential_CORS_request(url, Fetch::Infrastructure::Request::Destination::Image, HTML::CORSSettingAttribute::NoCORS);- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());resource_request->fetch_resource(request);}}diff --git a/Libraries/LibWeb/SVG/SVGScriptElement.cpp b/Libraries/LibWeb/SVG/SVGScriptElement.cppindex 685e7f9dd43..6fad881ddb0 100644--- a/Libraries/LibWeb/SVG/SVGScriptElement.cpp+++ b/Libraries/LibWeb/SVG/SVGScriptElement.cpp@@ -115,7 +115,7 @@ void SVGScriptElement::process_the_script_element()// FIXME: Use CORS state specified by the ‘crossorigin’ attribute.request->set_mode(Fetch::Infrastructure::Request::Mode::NoCORS);request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::SameOrigin);- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());request->set_parser_metadata(m_parser_inserted? Fetch::Infrastructure::Request::ParserMetadata::ParserInserted: Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted);diff --git a/Libraries/LibWeb/SVG/SVGUseElement.cpp b/Libraries/LibWeb/SVG/SVGUseElement.cppindex 532c45afae7..7b3b38b222c 100644--- a/Libraries/LibWeb/SVG/SVGUseElement.cpp+++ b/Libraries/LibWeb/SVG/SVGUseElement.cpp@@ -293,7 +293,7 @@ void SVGUseElement::fetch_the_document(URL::URL const& url)if (m_resource_request->needs_fetching()) {auto request = HTML::create_potential_CORS_request(url, Fetch::Infrastructure::Request::Destination::Image, HTML::CORSSettingAttribute::NoCORS);- request->set_client(&document().relevant_settings_object());+ request->set_client(document().relevant_settings_object().address());m_resource_request->fetch_resource(request);}}diff --git a/Libraries/LibWeb/ServiceWorker/Cache.cpp b/Libraries/LibWeb/ServiceWorker/Cache.cppindex 29b95f59095..9909a2f84e3 100644--- a/Libraries/LibWeb/ServiceWorker/Cache.cpp+++ b/Libraries/LibWeb/ServiceWorker/Cache.cpp@@ -9,6 +9,7 @@#include <LibWeb/Bindings/Wrappable.h>#include <LibWeb/Bindings/WrapperWorld.h>#include <LibWeb/DOM/AbortSignal.h>+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Fetching/Fetching.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>@@ -274,7 +275,8 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,}// 3. If r’s client’s global object is a ServiceWorkerGlobalScope object, set request’s service-workers mode to "none".- if (Bindings::service_worker_global_scope_from_global_object(inner_request->client()->global_object()))+ auto client = Fetch::Fetching::resolve_client(inner_request);+ if (Bindings::service_worker_global_scope_from_global_object(client->global_object()))inner_request->set_service_workers_mode(Fetch::Infrastructure::Request::ServiceWorkersMode::None);// 4. Add r to requestList.diff --git a/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cpp b/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cppindex e3fea7c416a..24255777a7a 100644--- a/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cpp+++ b/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cpp@@ -12,6 +12,7 @@#include <LibWeb/ContentSecurityPolicy/Violation.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOMURL/DOMURL.h>+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>#include <LibWeb/HTML/PolicyContainers.h>#include <LibWeb/HTML/Scripting/Environments.h>@@ -78,9 +79,10 @@ ContentSecurityPolicy::Directives::Directive::Result require_trusted_types_for_p// encodedScriptSource:// sink:// "Location href":+ auto client = Fetch::Fetching::resolve_client(request);auto converted_script_source = process_value_with_a_default_policy(TrustedTypeName::TrustedScript,- request.client()->global_object(),+ client->global_object(),Utf16String::from_utf8(encoded_script_source),InjectionSink::Location_href);diff --git a/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Libraries/LibWeb/WebSockets/WebSocket.cppindex a05ba5ba7ee..815a027d93a 100644--- a/Libraries/LibWeb/WebSockets/WebSocket.cpp+++ b/Libraries/LibWeb/WebSockets/WebSocket.cpp@@ -187,7 +187,7 @@ ErrorOr<void> WebSocket::establish_web_socket_connection(URL::URL const& url_rec// redirect mode is "error".auto request = Fetch::Infrastructure::Request::create(client.vm());request->set_url(move(request_url));- request->set_client(&client);+ request->set_client(client.address());request->set_service_workers_mode(Fetch::Infrastructure::Request::ServiceWorkersMode::None);request->set_referrer(Fetch::Infrastructure::Request::Referrer::NoReferrer);request->set_mode(Fetch::Infrastructure::Request::Mode::WebSocket);diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cppindex f1f58b5a182..05604aa3db7 100644--- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp+++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp@@ -802,7 +802,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB// client// This’s relevant settings object.- request->set_client(&relevant_settings_object());+ request->set_client(relevant_settings_object().address());// mode// "cors".diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cppindex 165125a7978..fe617b1ef3d 100644--- a/Services/WebWorker/WorkerHost.cpp+++ b/Services/WebWorker/WorkerHost.cpp@@ -123,6 +123,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes// IMPLEMENTATION DEFINED: We need an object to represent the fetch response's clientauto outside_settings = GC::Heap::the().allocate<Web::HTML::EnvironmentSettingsSnapshot>(inside_settings->realm_execution_context().copy(), outside_settings_snapshot);+ m_outside_settings = outside_settings;// AD-HOC: Outside settings' global object is in the owner's process, so the violations of its policies, such as by// the worker script fetch, are reported to the owner.diff --git a/Services/WebWorker/WorkerHost.h b/Services/WebWorker/WorkerHost.hindex 271d7f7a029..49ebe79608c 100644--- a/Services/WebWorker/WorkerHost.h+++ b/Services/WebWorker/WorkerHost.h@@ -12,6 +12,7 @@#include <LibURL/URL.h>#include <LibWeb/Bindings/MainThreadVM.h>#include <LibWeb/Forward.h>+#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>#include <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h>#include <LibWeb/HTML/StructuredSerialize.h>#include <LibWeb/HTML/WorkerGlobalScope.h>@@ -44,6 +45,7 @@ private:GC::Root<Web::HTML::WorkerDebugConsoleClient> m_console;GC::Root<Web::HTML::WorkerGlobalScope> m_worker_global_scope;GC::Root<Web::HTML::WorkerEnvironmentSettingsObject> m_inside_settings;+ GC::Root<Web::HTML::EnvironmentSettingsSnapshot> m_outside_settings;URL::URL m_url;Web::HTML::WorkerType m_type;