Skip to content

Truly independent web browser

LibWeb+LibWebCommon+WebWorker: Use serialized settings as remote clients

Luke Wilde32e5328d67d2
diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
index 985c29b5464..d1a0a269ab8 100644
--- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp
+++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
@@ -624,7 +624,7 @@ void initialize_main_thread_vm(HTML::AgentType type)
auto destination = Fetch::Infrastructure::Request::Destination::Script;
// 12. Let fetchClient be settingsObject.
- GC::Ref fetch_client { settings_object };
+ HTML::FetchClient fetch_client { settings_object };
// 15. If loadState is not undefined, then:
HTML::PerformTheFetchHook perform_fetch;
@@ -700,7 +700,7 @@ void initialize_main_thread_vm(HTML::AgentType type)
// 16. Fetch a single imported module script given url, fetchClient, destination, fetchOptions, settingsObject, fetchReferrer,
// moduleRequest, and onSingleFetchComplete as defined below.
// If loadState is not undefined and loadState.[[PerformFetch]] is not null, pass loadState.[[PerformFetch]] along as well.
- HTML::fetch_single_imported_module_script(settings_object->realm(), url.release_value(), *fetch_client, destination, fetch_options, settings_object, fetch_referrer, module_request, perform_fetch, on_single_fetch_complete);
+ HTML::fetch_single_imported_module_script(settings_object->realm(), url.release_value(), fetch_client, destination, fetch_options, settings_object, fetch_referrer, module_request, perform_fetch, on_single_fetch_complete);
};
main_thread_vm_ptr()->host_unrecognized_date_string = [](Utf16View date) {
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index cba41956b74..5b303b7dfb1 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -626,8 +626,8 @@ set(SOURCES
HTML/Scripting/Agent.cpp
HTML/Scripting/ClassicScript.cpp
HTML/Scripting/Environments.cpp
- HTML/Scripting/EnvironmentSettingsSnapshot.cpp
HTML/Scripting/ExceptionReporter.cpp
+ HTML/Scripting/FetchClient.cpp
HTML/Scripting/Fetching.cpp
HTML/Scripting/ImportMap.cpp
HTML/Scripting/ImportMapParseResult.cpp
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
index d9a76314ccf..e412cefd3e3 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
@@ -7,6 +7,7 @@
#include <AK/AnyOf.h>
#include <LibGC/Heap.h>
+#include <LibWeb/Bindings/PrincipalHostDefined.h>
#include <LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h>
#include <LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h>
#include <LibWeb/ContentSecurityPolicy/Directives/HTMLIntegration.h>
@@ -21,9 +22,9 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
#include <LibWeb/HTML/LocalNavigable.h>
#include <LibWeb/HTML/PolicyContainers.h>
-#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
+#include <LibWeb/Page/Page.h>
#include <LibWeb/TrustedTypes/RequireTrustedTypesForDirective.h>
#include <LibWeb/TrustedTypes/TrustedScript.h>
#include <LibWeb/TrustedTypes/TrustedTypePolicy.h>
@@ -33,22 +34,37 @@
namespace Web::ContentSecurityPolicy {
-// AD-HOC: A client standing in for an environment another process hosts has its global object there, and its
-// violations belong to that global, so none is reported here unless the client reports them to that process.
-// FIXME: Report the violations of every such client in the process hosting its environment.
-static bool may_report_violations_for(GC::Ptr<HTML::EnvironmentSettingsObject const> client)
+// AD-HOC: A client another process hosts has its global object there, and its violations belong to that global, so
+// none is reported here.
+// FIXME: Report those violations in the process hosting the client's environment.
+static bool may_report_violations_for(Fetch::Infrastructure::Request const& request)
{
- if (!client)
- return true;
- auto const* snapshot = as_if<HTML::EnvironmentSettingsSnapshot>(*client);
- return !snapshot || snapshot->report_violation();
+ return !Fetch::Fetching::remote_client(request);
+}
+
+// AD-HOC: A client another process hosts has its global object there, so its page reports the violation to that
+// process, by the violated policy's index in the client's CSP list.
+// FIXME: WebContent's page drops the violation.
+static void report_a_violation_of_a_remote_client(Page& page, NonnullRefPtr<Fetch::Infrastructure::Request> const& request, Policy const& policy)
+{
+ // NB: Request's policy container is a clone of the client's, which lists the policies in the same order.
+ auto const& policies = request->policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->csp_list.policies();
+ auto policy_index = policies.find_first_index_if([&](auto const& candidate) { return candidate.ptr() == &policy; });
+ if (!policy_index.has_value())
+ return;
+
+ auto effective_directive = Directives::get_the_effective_directive_for_request(request);
+ VERIFY(effective_directive.has_value());
+ page.client().page_did_report_violation_of_remote_client(*policy_index, effective_directive->view().to_utf8_but_should_be_ported_to_utf16(), request->url());
}
ViolationReporter violation_reporter_for_request(JS::Realm& realm, NonnullRefPtr<Fetch::Infrastructure::Request> request)
{
return [&realm, request](NonnullRefPtr<Policy const> policy) {
- if (!may_report_violations_for(Fetch::Fetching::resolve_client(request)))
+ if (Fetch::Fetching::remote_client(request)) {
+ report_a_violation_of_a_remote_client(Bindings::principal_host_defined_page(realm), request, policy);
return;
+ }
auto violation = Violation::create_a_violation_object_for_request_and_policy(request, move(policy));
violation->report_a_violation(realm);
};
@@ -72,7 +88,7 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_co
if (directive_result == Directives::Directive::Result::Allowed)
continue;
- if (may_report_violations_for(client)) {
+ if (may_report_violations_for(*navigation_request)) {
// 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 = client->realm();
@@ -114,15 +130,15 @@ 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 = 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(client)) {
+ if (may_report_violations_for(*navigation_request)) {
// 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& 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());
// 4. Set violation’s resource to "inline".
@@ -187,7 +203,8 @@ 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 = client->realm();
+ // AD-HOC: Without a client of this process, target's active window's realm reports the violation.
+ auto& realm = client ? client->realm() : HTML::relevant_realm(*target->active_window());
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.
@@ -217,7 +234,7 @@ Directives::Directive::Result should_navigation_response_to_navigation_request_o
if (directive_result == Directives::Directive::Result::Allowed)
continue;
- if (may_report_violations_for(client)) {
+ if (may_report_violations_for(*navigation_request)) {
// 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 = 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());
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp
index 0df076ad55c..0445e05aeb2 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp
@@ -12,15 +12,12 @@
#include <LibWeb/Bindings/PrincipalHostDefined.h>
#include <LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.h>
#include <LibWeb/ContentSecurityPolicy/Directives/Names.h>
-#include <LibWeb/ContentSecurityPolicy/PolicyList.h>
#include <LibWeb/ContentSecurityPolicy/SecurityPolicyViolationEvent.h>
#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>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/Window.h>
@@ -112,22 +109,6 @@ GC::Ref<Violation> Violation::create_a_violation_object_for_request_and_policy(N
// targets to which the page MUST NOT be given access.
violation->m_resource = request->url();
- // 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>(*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) {
- if (policies[policy_index].ptr() != policy.ptr())
- continue;
- violation->m_report_in_other_process = GC::create_function(GC::Heap::the(), [report_violation = GC::Ref { *snapshot->report_violation() }, policy_index, effective_directive = String { violation->m_effective_directive.to_utf8() }, resource = request->url()] {
- report_violation->function()(policy_index, effective_directive, resource);
- });
- break;
- }
- }
-
// 4. Return violation.
return violation;
}
@@ -137,7 +118,6 @@ void Violation::visit_edges(Cell::Visitor& visitor)
Base::visit_edges(visitor);
visitor.visit(m_global_scope);
visitor.visit(m_element);
- visitor.visit(m_report_in_other_process);
}
// https://w3c.github.io/webappsec-csp/#violation-url
@@ -309,12 +289,6 @@ void Violation::report_a_violation(JS::Realm& realm)
obtain_the_blocked_uri_of_resource(),
m_effective_directive);
- // AD-HOC: See create_a_violation_object_for_request_and_policy().
- if (m_report_in_other_process) {
- m_report_in_other_process->function()();
- return;
- }
-
// 1. Let global be violation’s global object.
auto global_scope = m_global_scope;
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Violation.h b/Libraries/LibWeb/ContentSecurityPolicy/Violation.h
index 0a395654576..5663c16dbbc 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/Violation.h
+++ b/Libraries/LibWeb/ContentSecurityPolicy/Violation.h
@@ -8,7 +8,6 @@
#include <AK/Utf16String.h>
#include <LibGC/CellAllocator.h>
-#include <LibGC/Function.h>
#include <LibJS/Heap/Cell.h>
#include <LibURL/URL.h>
#include <LibWeb/ContentSecurityPolicy/Policy.h>
@@ -138,9 +137,6 @@ private:
// https://w3c.github.io/webappsec-csp/#violation-sample
// Each violation has a sample, which is a string. It is the empty string unless otherwise specified.
Utf16String m_sample;
-
- // Reports this violation to its global object in another process. See create_a_violation_object_for_request_and_policy().
- GC::Ptr<GC::Function<void()>> m_report_in_other_process;
};
}
diff --git a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cpp b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cpp
index 31fc765bc2a..bdb287a74a9 100644
--- a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.cpp
@@ -9,7 +9,6 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/LocalNavigable.h>
-#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WorkerGlobalScope.h>
@@ -19,28 +18,76 @@ namespace Web::Fetch::Fetching {
GC::Ptr<HTML::EnvironmentSettingsObject> resolve_client(Infrastructure::Request const& request)
{
- auto address = request.client();
- if (!address.has_value())
+ auto const& client = request.client();
+ if (!client.has_value())
return nullptr;
- auto client = HTML::environment_settings_object_at(*address);
- VERIFY(client);
- return client;
+ auto const* address = client->get_pointer<HTML::EnvironmentSettingsObjectAddress>();
+ if (!address)
+ return nullptr;
+ auto settings_object = HTML::environment_settings_object_at(*address);
+ VERIFY(settings_object);
+ return settings_object;
+}
+
+RefPtr<HTML::RemoteEnvironmentSettings const> remote_client(Infrastructure::Request const& request)
+{
+ auto const& client = request.client();
+ if (!client.has_value())
+ return nullptr;
+ if (auto const* settings = client->get_pointer<NonnullRefPtr<HTML::RemoteEnvironmentSettings const>>())
+ return *settings;
+ return nullptr;
+}
+
+Optional<HTML::FetchClient> resolve_fetch_client(Infrastructure::Request const& request)
+{
+ if (auto settings_object = resolve_client(request))
+ return HTML::FetchClient { *settings_object };
+ if (auto settings = remote_client(request))
+ return HTML::FetchClient { settings.release_nonnull() };
+ return {};
+}
+
+Infrastructure::Request::ClientType request_client(HTML::FetchClient const& fetch_client)
+{
+ return fetch_client.visit(
+ [](GC::Ref<HTML::EnvironmentSettingsObject> const& settings_object) -> Infrastructure::Request::ClientType {
+ return settings_object->address();
+ },
+ [](NonnullRefPtr<HTML::RemoteEnvironmentSettings const> const& settings) -> Infrastructure::Request::ClientType {
+ return settings;
+ });
}
// 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)
+// NB: The steps of the "client" case that read environment, for a client another process hosts.
+static Optional<URL::URL> referrer_source_of_client(HTML::SerializedEnvironmentSettingsObject const& environment)
{
- // NB: A snapshot of an environment another process hosts answers from the global object it was taken from.
- if (auto const* snapshot = as_if<HTML::EnvironmentSettingsSnapshot>(environment)) {
- if (auto const* window = snapshot->serialized_global().get_pointer<HTML::SerializedWindow>()) {
- if (snapshot->origin().is_opaque())
- return {};
- return window->associated_document.url;
- }
- return environment.creation_url;
+ // 2. If environment’s global object is a Window object, then
+ if (auto const* window = environment.global.get_pointer<HTML::SerializedWindow>()) {
+ // 1. Let document be the associated Document of environment’s global object.
+ auto const& document = window->associated_document;
+
+ // 2. If document’s origin is an opaque origin, return no referrer.
+ // NB: document's origin is environment's origin.
+ if (environment.origin.is_opaque())
+ return {};
+
+ // FIXME: 3. While document is an iframe srcdoc document, let document be document’s browsing context’s
+ // browsing context container’s node document.
+
+ // 4. Let referrerSource be document’s URL.
+ return document.url;
}
+ // 3. Otherwise, let referrerSource be environment’s creation URL.
+ return environment.creation_url;
+}
+
+// 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)
+{
// 2. If environment’s global object is a Window object, then
if (auto const* window = HTML::window_from_global_object(environment.global_object())) {
// 1. Let document be the associated Document of environment’s global object.
@@ -95,6 +142,36 @@ NonnullRefPtr<Infrastructure::ClientContextSnapshot const> snapshot_client_conte
});
}
+NonnullRefPtr<Infrastructure::ClientContextSnapshot const> snapshot_client_context(HTML::RemoteEnvironmentSettings const& client)
+{
+ using Context = Infrastructure::ClientContext;
+
+ auto const& settings = client.settings;
+ auto const* window = settings.global.get_pointer<HTML::SerializedWindow>();
+ auto relevant_settings_object_is_secure_context = window
+ ? window->associated_document.relevant_settings_object_is_secure_context
+ : settings.global.get<HTML::SerializedWorkerGlobalScope>().relevant_settings_object_is_secure_context;
+
+ // NB: A client another process hosts is never treated as loading bypassing the HTTP cache.
+ return make_ref_counted<Infrastructure::ClientContextSnapshot>(Context {
+ .origin = settings.origin,
+ .creation_url = settings.creation_url,
+ .top_level_creation_url = settings.top_level_creation_url,
+ .top_level_origin = settings.top_level_origin,
+ .global_kind = window ? Context::GlobalKind::Window : Context::GlobalKind::Worker,
+ .is_window_of_a_top_level_navigable = window && window->navigable_is_top_level ? Context::IsWindowOfATopLevelNavigable::Yes : Context::IsWindowOfATopLevelNavigable::No,
+ .has_cross_site_ancestor = settings.has_cross_site_ancestor ? Infrastructure::HasCrossSiteAncestor::Yes : Infrastructure::HasCrossSiteAncestor::No,
+ .cross_origin_isolated_capability = settings.cross_origin_isolated_capability,
+ .is_secure_context = relevant_settings_object_is_secure_context ? Context::IsSecureContext::Yes : Context::IsSecureContext::No,
+ .prohibits_mixed_security_contexts = settings.prohibits_mixed_security_contexts,
+ .time_origin = settings.time_origin,
+ .navigable_id = {},
+ .referrer_source = referrer_source_of_client(settings),
+ .content_blocker_source_url = window ? window->associated_document.url : settings.api_base_url,
+ .keepalive_quota_accountant = Infrastructure::KeepaliveQuotaAccountant::create(),
+ });
+}
+
static Variant<Infrastructure::ReservedClientContext::Environment, Infrastructure::ReservedClientContext::SettingsObject> reserved_client_kind(HTML::Environment const& reserved_client)
{
using Context = Infrastructure::ReservedClientContext;
diff --git a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.h b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.h
index bae8d5cda56..fcef9d33b85 100644
--- a/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.h
+++ b/Libraries/LibWeb/Fetch/Fetching/ClientContextSnapshots.h
@@ -10,13 +10,24 @@
#include <LibGC/Ptr.h>
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h>
+#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Forward.h>
+#include <LibWeb/HTML/Scripting/FetchClient.h>
namespace Web::Fetch::Fetching {
+// Request's client when it is a settings object of this process.
[[nodiscard]] WEB_API GC::Ptr<HTML::EnvironmentSettingsObject> resolve_client(Infrastructure::Request const&);
+// Request's client when another process hosts it.
+[[nodiscard]] WEB_API RefPtr<HTML::RemoteEnvironmentSettings const> remote_client(Infrastructure::Request const&);
+
+[[nodiscard]] WEB_API Optional<HTML::FetchClient> resolve_fetch_client(Infrastructure::Request const&);
+
+[[nodiscard]] WEB_API Infrastructure::Request::ClientType request_client(HTML::FetchClient const&);
+
[[nodiscard]] WEB_API NonnullRefPtr<Infrastructure::ClientContextSnapshot const> snapshot_client_context(HTML::EnvironmentSettingsObject&);
+[[nodiscard]] WEB_API NonnullRefPtr<Infrastructure::ClientContextSnapshot const> snapshot_client_context(HTML::RemoteEnvironmentSettings const&);
[[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.cpp
index 5e4b770d8d9..5fc55cf8d04 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -269,15 +269,19 @@ 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);
+ auto client = resolve_fetch_client(request);
// 4. Populate request from client given request.
populate_request_from_client(request, client);
// 5. If request’s client is non-null, then:
- if (client) {
+ if (client.has_value()) {
// 1. Set taskDestination to request’s client’s global object.
- task_destination = GC::Ref { client->global_object() };
+ // AD-HOC: A client another process hosts has its global object there, so the fetch's tasks run in the realm
+ // that started it.
+ task_destination = client->visit(
+ [](GC::Ref<HTML::EnvironmentSettingsObject> const& settings_object) { return GC::Ref { settings_object->global_object() }; },
+ [&](NonnullRefPtr<HTML::RemoteEnvironmentSettings const> const&) { return GC::Ref { realm.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;
@@ -318,7 +322,8 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
fetch_params->set_blob_url_entry(move(blob_url_entry));
}
- auto* client_window = client ? HTML::window_from_global_object(client->global_object()) : nullptr;
+ auto local_client = HTML::settings_object_of_fetch_client(client);
+ auto* client_window = local_client ? HTML::window_from_global_object(local_client->global_object()) : nullptr;
// 10. If all of the following conditions are true:
if (
@@ -327,6 +332,8 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
// - request’s mode is "same-origin", "cors", or "no-cors"
&& (request.mode() == Infrastructure::Request::Mode::SameOrigin || request.mode() == Infrastructure::Request::Mode::CORS || request.mode() == Infrastructure::Request::Mode::NoCORS)
// - request’s client is not null, and request’s client’s global object is a Window object
+ // AD-HOC: A request whose Window client another process hosts consumes no preloaded resource: the client's
+ // document, which holds its preloads, is in that process.
&& client_window
// - request’s method is `GET`
&& request.method().equals_ignoring_ascii_case("GET"sv)
@@ -446,7 +453,9 @@ 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.
- client->fetch_group().append(record);
+ // AD-HOC: A client another process hosts has its fetch group there.
+ if (local_client)
+ local_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.
@@ -470,8 +479,10 @@ 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, GC::Ptr<HTML::EnvironmentSettingsObject> client)
+void populate_request_from_client(Infrastructure::Request& request, Optional<HTML::FetchClient> const& client)
{
+ auto local_client = HTML::settings_object_of_fetch_client(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>();
if (traversable_for_user_prompts && *traversable_for_user_prompts == Infrastructure::Request::TraversableForUserPrompts::Client) {
@@ -479,9 +490,11 @@ void populate_request_from_client(Infrastructure::Request& request, GC::Ptr<HTML
request.set_traversable_for_user_prompts(Infrastructure::Request::TraversableForUserPrompts::NoTraversable);
// 2. If request’s client is non-null:
- if (client) {
+ // AD-HOC: The settings of a client another process hosts do not name its global object's navigable, so its
+ // requests have no traversable for user prompts.
+ if (local_client) {
// 1. Let global be request’s client’s global object.
- auto& global = client->global_object();
+ auto& global = local_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.
@@ -496,10 +509,10 @@ void populate_request_from_client(Infrastructure::Request& request, GC::Ptr<HTML
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(client);
+ VERIFY(client.has_value());
// 2. Set request’s origin to request’s client’s origin.
- request.set_origin(client->origin());
+ request.set_origin(HTML::origin_of_fetch_client(*client));
}
// 3. If request’s policy container is "client":
@@ -507,17 +520,23 @@ void populate_request_from_client(Infrastructure::Request& request, GC::Ptr<HTML
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 (client)
- request.set_policy_container(client->policy_container()->clone());
+ if (client.has_value()) {
+ request.set_policy_container(client->visit(
+ [](GC::Ref<HTML::EnvironmentSettingsObject> const& settings_object) { return settings_object->policy_container()->clone(); },
+ [](NonnullRefPtr<HTML::RemoteEnvironmentSettings const> const& settings) {
+ return HTML::create_a_policy_container_from_serialized_policy_container(settings->settings.policy_container);
+ }));
+ }
// 2. Otherwise, set request’s policy container to a new policy container.
- else
+ else {
request.set_policy_container(HTML::PolicyContainer::create());
+ }
}
// 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 (client)
- request.set_client_snapshot(snapshot_client_context(*client));
+ if (client.has_value())
+ request.set_client_snapshot(client->visit([](auto const& client) { return snapshot_client_context(*client); }));
}
// https://fetch.spec.whatwg.org/#concept-main-fetch
@@ -1052,11 +1071,17 @@ 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.
+ // AD-HOC: The global object of a client another process hosts is in that process, so the fetch reports its
+ // timing to the global object of the realm that started it.
auto const* task_destination_global_object = fetch_params.task_destination().get_pointer<GC::Ref<JS::Object>>();
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());
+ auto client = resolve_fetch_client(fetch_params.request());
+ auto client_global_is_task_destination = client.has_value()
+ && client->visit(
+ [&](GC::Ref<HTML::EnvironmentSettingsObject> const& settings_object) { return &settings_object->global_object() == task_destination_global_object->ptr(); },
+ [](NonnullRefPtr<HTML::RemoteEnvironmentSettings const> const&) { return true; });
+ if (client_global_is_task_destination)
+ fetch_params.controller()->report_timing(**task_destination_global_object);
}
};
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.h b/Libraries/LibWeb/Fetch/Fetching/Fetching.h
index 6409068cd12..8dd3cd48305 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.h
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.h
@@ -18,6 +18,7 @@
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Infrastructure/NetworkPartitionKey.h>
#include <LibWeb/Forward.h>
+#include <LibWeb/HTML/Scripting/FetchClient.h>
namespace Web::Fetch::Fetching {
@@ -47,7 +48,7 @@ ENUMERATE_BOOL_PARAMS
WEB_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&, GC::Ptr<HTML::EnvironmentSettingsObject> client);
+void populate_request_from_client(Infrastructure::Request&, Optional<HTML::FetchClient> const& 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/ClientContextSnapshot.h b/Libraries/LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h
index 15646c8af89..ae0c7735b98 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h
@@ -13,9 +13,9 @@
#include <LibURL/URL.h>
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Infrastructure/KeepaliveQuotaAccountant.h>
-#include <LibWeb/MixedContent/ProhibitsMixedSecurityContexts.h>
#include <LibWebCommon/HTML/CrossProcessId.h>
#include <LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
+#include <LibWebCommon/MixedContent/ProhibitsMixedSecurityContexts.h>
namespace Web::Fetch::Infrastructure {
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
index d6ba2bc7e20..aff05532a47 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/Bodies.h>
#include <LibWeb/Fetch/Infrastructure/KeepaliveQuotaAccountant.h>
#include <LibWeb/HTML/Scripting/EnvironmentSettingsObjectAddress.h>
+#include <LibWeb/HTML/Scripting/RemoteEnvironmentSettings.h>
#include <LibWebCommon/Fetch/Infrastructure/HTTP/RequestPriority.h>
#include <LibWebCommon/Fetch/Infrastructure/HTTP/RequestReferrer.h>
#include <LibWebCommon/HTML/CrossProcessId.h>
@@ -168,6 +169,7 @@ public:
using PolicyContainerType = Variant<PolicyContainer, NonnullRefPtr<HTML::PolicyContainer const>>;
using ReferrerType = RequestReferrerType;
using TraversableForUserPromptsType = Variant<TraversableForUserPrompts, HTML::CrossProcessId>;
+ using ClientType = Variant<HTML::EnvironmentSettingsObjectAddress, NonnullRefPtr<HTML::RemoteEnvironmentSettings const>>;
[[nodiscard]] static NonnullRefPtr<Request> create();
~Request();
@@ -193,8 +195,8 @@ public:
m_body = move(body);
}
- [[nodiscard]] Optional<HTML::EnvironmentSettingsObjectAddress> client() const { return m_client; }
- void set_client(Optional<HTML::EnvironmentSettingsObjectAddress> client) { m_client = client; }
+ [[nodiscard]] Optional<ClientType> const& client() const { return m_client; }
+ void set_client(Optional<ClientType> client) { m_client = move(client); }
[[nodiscard]] RefPtr<ClientContextSnapshot const> const& client_snapshot() const { return m_client_snapshot; }
void set_client_snapshot(RefPtr<ClientContextSnapshot const> client_snapshot) { m_client_snapshot = move(client_snapshot); }
@@ -374,7 +376,8 @@ private:
// https://fetch.spec.whatwg.org/#concept-request-client
// A request has an associated client (null or an environment settings object).
- Optional<HTML::EnvironmentSettingsObjectAddress> m_client;
+ // NB: A settings object of this process is held by its address.
+ Optional<ClientType> m_client;
// What fetching reads from the client, null when the client is.
RefPtr<ClientContextSnapshot const> m_client_snapshot;
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 41a2297bfe8..e0db1143b53 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -2546,8 +2546,8 @@ static void create_navigation_params_by_fetching(
// traversable for user prompts: navigable's top-level traversable
auto request = Fetch::Infrastructure::Request::create();
request->set_url(entry.url);
- if (source_snapshot_params->fetch_client)
- request->set_client(source_snapshot_params->fetch_client->address());
+ if (source_snapshot_params->fetch_client.has_value())
+ request->set_client(Fetch::Fetching::request_client(*source_snapshot_params->fetch_client));
request->set_destination(Fetch::Infrastructure::Request::Destination::Document);
request->set_credentials_mode(Fetch::Infrastructure::Request::CredentialsMode::Include);
request->set_use_url_credentials(true);
@@ -2708,8 +2708,9 @@ static void create_navigation_params_by_fetching(
// then set request's initiator type to navigable's container's local name.
// NOTE: This ensure that only container-initiated navigations are reported to resource timing.
// FIXME: A container document in another process is not here, and the fetch client of a navigation it started
- // is a snapshot, so its resource timing is not told of the navigation.
- if (auto container_document = navigable->container_document(); container_document && source_snapshot_params->fetch_client.ptr() == &container_document->relevant_settings_object()) {
+ // is that process's, so its resource timing is not told of the navigation.
+ auto fetch_client = settings_object_of_fetch_client(source_snapshot_params->fetch_client);
+ if (auto container_document = navigable->container_document(); container_document && fetch_client.ptr() == &container_document->relevant_settings_object()) {
// FIXME: Are there other container types? If so, we need a helper here
request->set_initiator_type(container_is_iframe ? Web::Fetch::Infrastructure::Request::InitiatorType::IFrame
: Web::Fetch::Infrastructure::Request::InitiatorType::Object);
@@ -3484,8 +3485,8 @@ void LocalNavigable::navigate_to_a_javascript_url_from_ui_process(URL::URL const
request->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.
- if (source_snapshot_params->fetch_client)
- request->set_client(source_snapshot_params->fetch_client->address());
+ if (source_snapshot_params->fetch_client.has_value())
+ request->set_client(Fetch::Fetching::request_client(*source_snapshot_params->fetch_client));
// 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,
@@ -3668,8 +3669,8 @@ void LocalNavigable::begin_navigation(PreparedNavigation navigation)
// URL operates on a request. It will never hit the network.
auto request = Fetch::Infrastructure::Request::create();
request->set_url(url);
- if (source_snapshot_params->fetch_client)
- request->set_client(source_snapshot_params->fetch_client->address());
+ if (source_snapshot_params->fetch_client.has_value())
+ request->set_client(Fetch::Fetching::request_client(*source_snapshot_params->fetch_client));
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.
diff --git a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
index 0f7a82a85ff..9b9140d4199 100644
--- a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
+++ b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp
@@ -35,9 +35,11 @@ static SerializedPolicyContainer serialize_request_policy_container(Fetch::Infra
{
return request.policy_container().visit(
[&request](Fetch::Infrastructure::Request::PolicyContainer) {
- auto client = Fetch::Fetching::resolve_client(request);
- VERIFY(client);
- return client->policy_container()->serialize();
+ auto client = Fetch::Fetching::resolve_fetch_client(request);
+ VERIFY(client.has_value());
+ return client->visit(
+ [](GC::Ref<EnvironmentSettingsObject> const& settings_object) { return settings_object->policy_container()->serialize(); },
+ [](NonnullRefPtr<RemoteEnvironmentSettings const> const& settings) { return settings->settings.policy_container; });
},
[](NonnullRefPtr<PolicyContainer const> const& policy_container) {
return policy_container->serialize();
diff --git a/Libraries/LibWeb/HTML/NavigationSourceSnapshot.cpp b/Libraries/LibWeb/HTML/NavigationSourceSnapshot.cpp
index 1d610f48ed8..280c27d8d9b 100644
--- a/Libraries/LibWeb/HTML/NavigationSourceSnapshot.cpp
+++ b/Libraries/LibWeb/HTML/NavigationSourceSnapshot.cpp
@@ -5,11 +5,10 @@
*/
#include <LibJS/Runtime/Realm.h>
-#include <LibWeb/Bindings/PrincipalHostDefined.h>
#include <LibWeb/HTML/NavigationSourceSnapshot.h>
#include <LibWeb/HTML/PolicyContainers.h>
-#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/Scripting/FetchClient.h>
#include <LibWeb/HTML/SourceSnapshotParams.h>
namespace Web::HTML {
@@ -20,7 +19,11 @@ NavigationSourceSnapshot create_navigation_source_snapshot(SourceSnapshotParams
.has_transient_activation = snapshot.has_transient_activation,
.sandboxing_flags = snapshot.sandboxing_flags,
.allows_downloading = snapshot.allows_downloading,
- .fetch_client = snapshot.fetch_client ? Optional<SerializedEnvironmentSettingsObject> { snapshot.fetch_client->serialize() } : Optional<SerializedEnvironmentSettingsObject> {},
+ .fetch_client = snapshot.fetch_client.map([](FetchClient const& fetch_client) {
+ return fetch_client.visit(
+ [](GC::Ref<EnvironmentSettingsObject> const& settings_object) { return settings_object->serialize(); },
+ [](NonnullRefPtr<RemoteEnvironmentSettings const> const& settings) { return settings->settings; });
+ }),
.source_policy_container = snapshot.source_policy_container->serialize(),
.text_directive_user_activation = snapshot.text_directive_user_activation,
.browsing_context_group_has_multiple_contexts = snapshot.browsing_context_group_has_multiple_contexts,
@@ -31,13 +34,11 @@ NavigationSourceSnapshot create_navigation_source_snapshot(SourceSnapshotParams
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#snapshotting-source-snapshot-params
GC::Ref<SourceSnapshotParams> create_source_snapshot_params_from_navigation_source_snapshot(JS::Realm& realm, NavigationSourceSnapshot const& snapshot)
{
- auto& heap = realm.heap();
-
- GC::Ptr<EnvironmentSettingsObject> fetch_client;
+ Optional<FetchClient> fetch_client;
if (snapshot.fetch_client.has_value())
- fetch_client = heap.allocate<EnvironmentSettingsSnapshot>(Bindings::principal_host_defined_environment_settings_object(realm).realm_execution_context().copy(), *snapshot.fetch_client);
+ fetch_client = RemoteEnvironmentSettings::create(*snapshot.fetch_client);
- return heap.allocate<SourceSnapshotParams>(
+ return realm.heap().allocate<SourceSnapshotParams>(
snapshot.has_transient_activation,
snapshot.sandboxing_flags,
snapshot.allows_downloading,
diff --git a/Libraries/LibWeb/HTML/RemoteNavigable.cpp b/Libraries/LibWeb/HTML/RemoteNavigable.cpp
index 88b417ca35e..0b3a7dd2ea8 100644
--- a/Libraries/LibWeb/HTML/RemoteNavigable.cpp
+++ b/Libraries/LibWeb/HTML/RemoteNavigable.cpp
@@ -13,6 +13,7 @@
#include <LibWeb/HTML/RemoteNavigable.h>
#include <LibWeb/HTML/RemoteWindow.h>
#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/Scripting/FetchClient.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/Layout/Node.h>
@@ -240,7 +241,7 @@ WebIDL::ExceptionOr<void> RemoteNavigable::continue_navigation_in_active_documen
// window to continue these steps.
// NB: The active window lives in the process hosting the active document, so the task is a request to the UI
// process, which forwards it to that process.
- auto fetch_client = navigation.source_snapshot_params->fetch_client;
+ auto fetch_client = settings_object_of_fetch_client(navigation.source_snapshot_params->fetch_client);
if (!fetch_client)
return {};
auto& source_document = window_from_global_object(fetch_client->global_object())->associated_document();
diff --git a/Libraries/LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.cpp b/Libraries/LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.cpp
deleted file mode 100644
index fe579d8f4f8..00000000000
--- a/Libraries/LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2024, Andrew Kaster <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
-
-namespace Web::HTML {
-
-GC_DEFINE_ALLOCATOR(EnvironmentSettingsSnapshot);
-
-EnvironmentSettingsSnapshot::EnvironmentSettingsSnapshot(NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& serialized_settings)
- : EnvironmentSettingsObject(move(execution_context))
- , m_url(serialized_settings.api_base_url)
- , m_origin(serialized_settings.origin)
- , m_has_cross_site_ancestor(serialized_settings.has_cross_site_ancestor)
- , m_policy_container(create_a_policy_container_from_serialized_policy_container(serialized_settings.policy_container))
- , m_cross_origin_isolated_capability(serialized_settings.cross_origin_isolated_capability)
- , m_agent_cluster_id(serialized_settings.agent_cluster_id)
- , m_agent_cluster_cross_origin_isolation_mode(serialized_settings.agent_cluster_cross_origin_isolation_mode)
- , m_time_origin(serialized_settings.time_origin)
- , m_serialized_global(serialized_settings.global)
-{
- // Why can't we put these in the init list? grandparent class members are strange it seems
- this->id = serialized_settings.id;
- this->creation_url = serialized_settings.creation_url;
- this->top_level_creation_url = serialized_settings.top_level_creation_url;
- this->top_level_origin = serialized_settings.top_level_origin;
-}
-
-// Out of line to ensure this class has a key function
-EnvironmentSettingsSnapshot::~EnvironmentSettingsSnapshot() = default;
-
-void EnvironmentSettingsSnapshot::visit_edges(Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_report_violation);
-}
-
-}
diff --git a/Libraries/LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h b/Libraries/LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h
deleted file mode 100644
index 1cf13425a89..00000000000
--- a/Libraries/LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2024, Andrew Kaster <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibGC/Function.h>
-#include <LibWeb/Export.h>
-#include <LibWeb/HTML/PolicyContainers.h>
-#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
-
-namespace Web::HTML {
-
-class WEB_API EnvironmentSettingsSnapshot final
- : public EnvironmentSettingsObject {
- GC_CELL(EnvironmentSettingsSnapshot, EnvironmentSettingsObject);
- GC_DECLARE_ALLOCATOR(EnvironmentSettingsSnapshot);
-
-public:
- EnvironmentSettingsSnapshot(NonnullOwnPtr<JS::ExecutionContext>, SerializedEnvironmentSettingsObject const&);
-
- virtual ~EnvironmentSettingsSnapshot() override;
-
- virtual GC::Ptr<DOM::Document> responsible_document() override { return nullptr; }
- virtual URL::URL api_base_url() const override { return m_url; }
- virtual URL::Origin origin() const override { return m_origin; }
- virtual bool has_cross_site_ancestor() const override { return m_has_cross_site_ancestor; }
- virtual NonnullRefPtr<PolicyContainer> policy_container() const override { return m_policy_container; }
- virtual CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability() const override { return m_cross_origin_isolated_capability; }
- virtual Optional<u64> agent_cluster_id() const override { return m_agent_cluster_id; }
- virtual CrossOriginIsolationMode agent_cluster_cross_origin_isolation_mode() const override { return m_agent_cluster_cross_origin_isolation_mode; }
- virtual double time_origin() const override { return m_time_origin; }
-
- // The global object of the environment this was taken from, which its own global object isn't: A snapshot runs in
- // a realm of the process it's used in.
- SerializedGlobal const& serialized_global() const { return m_serialized_global; }
-
- // The violations of this environment's policies need to be reported to its global object, in the process it's
- // from. If this is set, it does that, given the index of the violated policy in this environment's CSP list, the
- // violation's effective directive, and its resource.
- using ReportViolation = GC::Function<void(u64 policy_index, String effective_directive, URL::URL resource)>;
- GC::Ptr<ReportViolation> report_violation() const { return m_report_violation; }
- void set_report_violation(GC::Ref<ReportViolation> report_violation) { m_report_violation = report_violation; }
-
-protected:
- virtual void visit_edges(Cell::Visitor&) override;
-
-private:
- URL::URL m_url;
- URL::Origin m_origin;
- bool m_has_cross_site_ancestor;
- NonnullRefPtr<PolicyContainer> m_policy_container;
- CanUseCrossOriginIsolatedAPIs m_cross_origin_isolated_capability { CanUseCrossOriginIsolatedAPIs::No };
- Optional<u64> m_agent_cluster_id;
- CrossOriginIsolationMode m_agent_cluster_cross_origin_isolation_mode { CrossOriginIsolationMode::None };
- double m_time_origin { 0 };
- SerializedGlobal m_serialized_global;
- GC::Ptr<ReportViolation> m_report_violation;
-};
-
-}
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
index 5aa7e640328..30f4e3db492 100644
--- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
@@ -22,9 +22,9 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/DedicatedWorkerGlobalScope.h>
+#include <LibWeb/HTML/LocalNavigable.h>
#include <LibWeb/HTML/PolicyContainers.h>
#include <LibWeb/HTML/Scripting/Agent.h>
-#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>
@@ -34,6 +34,7 @@
#include <LibWeb/HTML/WorkerGlobalScope.h>
#include <LibWeb/HTML/WorkletGlobalScope.h>
#include <LibWeb/Infra/SerializedURL.h>
+#include <LibWeb/MixedContent/AbstractOperations.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/ServiceWorker/ServiceWorker.h>
#include <LibWeb/ServiceWorker/ServiceWorkerRegistration.h>
@@ -722,18 +723,18 @@ bool is_non_secure_context(Environment const& environment)
SerializedEnvironmentSettingsObject EnvironmentSettingsObject::serialize()
{
auto serialized_global = [this]() -> SerializedGlobal {
- if (auto const* snapshot = as_if<EnvironmentSettingsSnapshot>(*this))
- return snapshot->serialized_global();
bool relevant_settings_object_is_secure_context = is_secure_context(*this);
auto relevant_settings_object_policy_container = policy_container()->serialize();
auto& global = global_object();
if (auto const* window = window_from_global_object(global)) {
+ auto navigable = window->navigable();
return SerializedWindow {
.associated_document {
.url = window->associated_document().url(),
.relevant_settings_object_is_secure_context = relevant_settings_object_is_secure_context,
.relevant_settings_object_policy_container = move(relevant_settings_object_policy_container),
- }
+ },
+ .navigable_is_top_level = navigable && navigable->is_top_level_traversable(),
};
}
VERIFY(Bindings::worker_global_scope_from_global_object(global));
@@ -757,6 +758,7 @@ SerializedEnvironmentSettingsObject EnvironmentSettingsObject::serialize()
.has_cross_site_ancestor = has_cross_site_ancestor(),
.policy_container = policy_container()->serialize(),
.cross_origin_isolated_capability = cross_origin_isolated_capability(),
+ .prohibits_mixed_security_contexts = MixedContent::does_settings_prohibit_mixed_security_contexts(*this),
.agent_cluster_id = agent_cluster_id(),
.agent_cluster_cross_origin_isolation_mode = agent_cluster_cross_origin_isolation_mode(),
.time_origin = this->time_origin(),
diff --git a/Libraries/LibWeb/HTML/Scripting/FetchClient.cpp b/Libraries/LibWeb/HTML/Scripting/FetchClient.cpp
new file mode 100644
index 00000000000..19c9d5ee711
--- /dev/null
+++ b/Libraries/LibWeb/HTML/Scripting/FetchClient.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/Scripting/FetchClient.h>
+
+namespace Web::HTML {
+
+URL::Origin origin_of_fetch_client(FetchClient const& fetch_client)
+{
+ return fetch_client.visit(
+ [](GC::Ref<EnvironmentSettingsObject> const& settings_object) { return settings_object->origin(); },
+ [](NonnullRefPtr<RemoteEnvironmentSettings const> const& settings) { return settings->settings.origin; });
+}
+
+GC::Ptr<EnvironmentSettingsObject> settings_object_of_fetch_client(Optional<FetchClient> const& fetch_client)
+{
+ if (!fetch_client.has_value())
+ return {};
+ if (auto const* settings_object = fetch_client->get_pointer<GC::Ref<EnvironmentSettingsObject>>())
+ return *settings_object;
+ return {};
+}
+
+}
diff --git a/Libraries/LibWeb/HTML/Scripting/FetchClient.h b/Libraries/LibWeb/HTML/Scripting/FetchClient.h
new file mode 100644
index 00000000000..f8c86de25ed
--- /dev/null
+++ b/Libraries/LibWeb/HTML/Scripting/FetchClient.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/NonnullRefPtr.h>
+#include <AK/Optional.h>
+#include <AK/Variant.h>
+#include <LibGC/Ptr.h>
+#include <LibURL/Origin.h>
+#include <LibWeb/Export.h>
+#include <LibWeb/Forward.h>
+#include <LibWeb/HTML/Scripting/RemoteEnvironmentSettings.h>
+
+namespace Web::HTML {
+
+// A fetch client: a settings object of this process, or the settings of one another process hosts.
+using FetchClient = Variant<GC::Ref<EnvironmentSettingsObject>, NonnullRefPtr<RemoteEnvironmentSettings const>>;
+
+WEB_API URL::Origin origin_of_fetch_client(FetchClient const&);
+WEB_API GC::Ptr<EnvironmentSettingsObject> settings_object_of_fetch_client(Optional<FetchClient> const&);
+
+}
diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
index e6fb74fde45..b4f0d9a0356 100644
--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
@@ -28,6 +28,7 @@
#include <LibWeb/Bindings/PrincipalHostDefined.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/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>
@@ -815,7 +816,7 @@ void fetch_classic_script(GC::Ref<HTMLScriptElement> element, URL::URL const& ur
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-worker-script
-WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const& url, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete)
+WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const& url, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete)
{
auto& realm = settings_object.realm();
// 1. Let request be a new request whose URL is url, client is fetchClient, destination is destination, initiator type is "other",
@@ -823,7 +824,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.address());
+ request->set_client(Fetch::Fetching::request_client(fetch_client));
request->set_destination(destination);
request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Other);
request->set_mode(Fetch::Infrastructure::Request::Mode::SameOrigin);
@@ -963,13 +964,13 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scri
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-worker-script-tree
-WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const& url, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete)
+WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const& url, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete)
{
return fetch_worklet_module_worker_script_graph(url, fetch_client, destination, settings_object, move(perform_fetch), move(on_complete));
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph
-WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const& url, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete, Fetch::Infrastructure::Request::CredentialsMode credentials_mode)
+WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const& url, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch, OnFetchScriptComplete on_complete, Fetch::Infrastructure::Request::CredentialsMode credentials_mode)
{
auto& realm = settings_object.realm();
@@ -986,7 +987,7 @@ WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL cons
};
// onSingleFetchComplete given result is the following algorithm:
- auto on_single_fetch_complete = create_on_fetch_script_complete(GC::Heap::the(), [&realm, &fetch_client, destination, perform_fetch = perform_fetch, on_complete = move(on_complete)](auto result) mutable {
+ auto on_single_fetch_complete = create_on_fetch_script_complete(GC::Heap::the(), [&realm, fetch_client, destination, perform_fetch = perform_fetch, on_complete = move(on_complete)](auto result) mutable {
// 1. If result is null, run onComplete with null, and abort these steps.
if (!result) {
dbgln("on single fetch complete with nool");
@@ -1027,7 +1028,7 @@ Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(F
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
void fetch_single_module_script(JS::Realm& realm,
URL::URL const& url,
- EnvironmentSettingsObject& fetch_client,
+ FetchClient const& fetch_client,
Fetch::Infrastructure::Request::Destination destination,
ScriptFetchOptions const& options,
EnvironmentSettingsObject& settings_object,
@@ -1078,7 +1079,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.address());
+ request->set_client(Fetch::Fetching::request_client(fetch_client));
// 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()));
@@ -1312,11 +1313,11 @@ void fetch_external_module_script_graph(JS::Realm& realm, URL::URL const& url, E
// 2. Fetch the descendants of and link result given settingsObject, "script", and onComplete.
auto& module_script = as<ModuleScript>(*result);
- fetch_descendants_of_and_link_a_module_script(realm, module_script, settings_object, Fetch::Infrastructure::Request::Destination::Script, nullptr, on_complete);
+ fetch_descendants_of_and_link_a_module_script(realm, module_script, GC::Ref { settings_object }, Fetch::Infrastructure::Request::Destination::Script, nullptr, on_complete);
});
// 1. Fetch a single module script given url, settingsObject, "script", options, settingsObject, "client", true, and with the following steps given result:
- fetch_single_module_script(realm, url, settings_object, Fetch::Infrastructure::Request::Destination::Script, options, settings_object, Web::Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, nullptr, steps);
+ fetch_single_module_script(realm, url, GC::Ref { settings_object }, Fetch::Infrastructure::Request::Destination::Script, options, settings_object, Web::Fetch::Infrastructure::Request::Referrer::Client, {}, TopLevelModule::Yes, nullptr, steps);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-modulepreload-module-script-graph
@@ -1333,7 +1334,7 @@ void fetch_modulepreload_module_script_graph(JS::Realm& realm, URL::URL const& u
// destination, and an empty algorithm.
if (result) {
auto on_descendants_complete = create_on_fetch_script_complete(GC::Heap::the(), [](auto) { });
- fetch_descendants_of_and_link_a_module_script(realm, as<ModuleScript>(*result), settings_object, destination, nullptr, on_descendants_complete);
+ fetch_descendants_of_and_link_a_module_script(realm, as<ModuleScript>(*result), GC::Ref { settings_object }, destination, nullptr, on_descendants_complete);
}
});
@@ -1353,7 +1354,7 @@ void fetch_modulepreload_module_script_graph(JS::Realm& realm, URL::URL const& u
module_request.emplace();
module_request->add_attribute("type"_utf16, "text"_utf16);
}
- fetch_single_module_script(realm, url, settings_object, destination, options, settings_object, Web::Fetch::Infrastructure::Request::Referrer::Client, module_request, TopLevelModule::Yes, nullptr, steps);
+ fetch_single_module_script(realm, url, GC::Ref { settings_object }, destination, options, settings_object, Web::Fetch::Infrastructure::Request::Referrer::Client, module_request, TopLevelModule::Yes, nullptr, steps);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-an-inline-module-script-graph
@@ -1364,13 +1365,13 @@ void fetch_inline_module_script_graph(JS::Realm& realm, ByteString const& filena
script->set_fetch_options(options);
// 2. Fetch the descendants of and link script, given settingsObject, "script", and onComplete.
- fetch_descendants_of_and_link_a_module_script(realm, *script, settings_object, Fetch::Infrastructure::Request::Destination::Script, nullptr, on_complete);
+ fetch_descendants_of_and_link_a_module_script(realm, *script, GC::Ref { settings_object }, Fetch::Infrastructure::Request::Destination::Script, nullptr, on_complete);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-imported-module-script
void fetch_single_imported_module_script(JS::Realm& realm,
URL::URL const& url,
- EnvironmentSettingsObject& fetch_client,
+ FetchClient const& fetch_client,
Fetch::Infrastructure::Request::Destination destination,
ScriptFetchOptions const& options,
EnvironmentSettingsObject& settings_object,
@@ -1402,7 +1403,7 @@ void fetch_single_imported_module_script(JS::Realm& realm,
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-and-link-a-module-script
void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm,
ModuleScript& module_script,
- EnvironmentSettingsObject& fetch_client,
+ FetchClient const& fetch_client,
Fetch::Infrastructure::Request::Destination destination,
PerformTheFetchHook perform_fetch,
OnFetchScriptComplete on_complete)
@@ -1430,13 +1431,18 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm,
// FIXME: These should most likely be steps in the spec.
// NOTE: For reasons beyond my understanding, we cannot use TemporaryExecutionContext here.
- // Calling perform_a_microtask_checkpoint() on the fetch_client's responsible_event_loop
+ // Calling perform_a_microtask_checkpoint() on the callback settings' responsible_event_loop
// prevents this from functioning properly. HTMLParser::the_end would be run before
// HTMLScriptElement::prepare_script had a chance to setup the callback to mark_done properly,
// resulting in the event loop hanging forever awaiting for the script to be ready for parser
// execution.
- realm.vm().push_execution_context(fetch_client.realm_execution_context());
- prepare_to_run_callback(fetch_client);
+ // AD-HOC: A fetch client another process hosts has no realm here, so the callback runs in the module script's
+ // settings object.
+ auto& callback_settings = fetch_client.visit(
+ [](GC::Ref<EnvironmentSettingsObject> const& settings_object) -> EnvironmentSettingsObject& { return settings_object; },
+ [&](NonnullRefPtr<RemoteEnvironmentSettings const> const&) -> EnvironmentSettingsObject& { return module_script.settings_object(); });
+ realm.vm().push_execution_context(callback_settings.realm_execution_context());
+ prepare_to_run_callback(callback_settings);
// 5. Let loadingPromise be record.LoadRequestedModules(state).
auto loading_promise = record.visit(
@@ -1478,7 +1484,7 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm,
return JS::js_undefined();
}));
- clean_up_after_running_callback(fetch_client);
+ clean_up_after_running_callback(callback_settings);
realm.vm().pop_execution_context();
}
diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.h b/Libraries/LibWeb/HTML/Scripting/Fetching.h
index bb60f7c0c27..dfc6c231db2 100644
--- a/Libraries/LibWeb/HTML/Scripting/Fetching.h
+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.h
@@ -11,6 +11,7 @@
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/HTML/CORSSettingAttribute.h>
+#include <LibWeb/HTML/Scripting/FetchClient.h>
#include <LibWeb/HTML/Scripting/ImportMap.h>
#include <LibWeb/HTML/Scripting/ModuleMap.h>
#include <LibWeb/HTML/Scripting/ModuleScript.h>
@@ -38,10 +39,10 @@ public:
JS::Value error_to_rethrow; // [[ErrorToRethrow]]
Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
PerformTheFetchHook perform_fetch; // [[PerformFetch]]
- GC::Ref<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
+ FetchClient fetch_client; // [[FetchClient]]
private:
- FetchContext(JS::Value error_to_rethrow, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client)
+ FetchContext(JS::Value error_to_rethrow, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, FetchClient const& fetch_client)
: error_to_rethrow(error_to_rethrow)
, destination(destination)
, perform_fetch(perform_fetch)
@@ -66,19 +67,19 @@ ScriptFetchOptions get_descendant_script_fetch_options(ScriptFetchOptions const&
Utf16String resolve_a_module_integrity_metadata(URL::URL const& url, EnvironmentSettingsObject& settings_object);
void set_up_module_script_request(Fetch::Infrastructure::Request&, ScriptFetchOptions const&);
void fetch_classic_script(GC::Ref<HTMLScriptElement>, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, Utf16String character_encoding, OnFetchScriptComplete on_complete);
-WEB_API WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
+WEB_API WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_script(URL::URL const&, HTML::EnvironmentSettingsObject&, PerformTheFetchHook = nullptr);
-WEB_API WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
-WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete, Fetch::Infrastructure::Request::CredentialsMode = Fetch::Infrastructure::Request::CredentialsMode::SameOrigin);
+WEB_API WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
+WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete, Fetch::Infrastructure::Request::CredentialsMode = Fetch::Infrastructure::Request::CredentialsMode::SameOrigin);
void fetch_external_module_script_graph(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);
void fetch_modulepreload_module_script_graph(JS::Realm&, URL::URL const&, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const&, OnFetchScriptComplete on_complete);
void fetch_inline_module_script_graph(JS::Realm&, ByteString const& filename, Utf16View source_text, URL::URL const& base_url, EnvironmentSettingsObject& settings_object, ScriptFetchOptions const& options, size_t source_line_number, OnFetchScriptComplete on_complete);
-void fetch_single_imported_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::ReferrerType, JS::ModuleRequest const&, PerformTheFetchHook, OnFetchScriptComplete on_complete);
+void fetch_single_imported_module_script(JS::Realm&, URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::ReferrerType, JS::ModuleRequest const&, PerformTheFetchHook, OnFetchScriptComplete on_complete);
-void fetch_descendants_of_and_link_a_module_script(JS::Realm&, ModuleScript&, EnvironmentSettingsObject&, Fetch::Infrastructure::Request::Destination, PerformTheFetchHook, OnFetchScriptComplete on_complete);
+void fetch_descendants_of_and_link_a_module_script(JS::Realm&, ModuleScript&, FetchClient const&, Fetch::Infrastructure::Request::Destination, PerformTheFetchHook, OnFetchScriptComplete on_complete);
Fetch::Infrastructure::Request::Destination fetch_destination_from_module_type(Fetch::Infrastructure::Request::Destination, Utf16View);
-void fetch_single_module_script(JS::Realm&, URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject&, Web::Fetch::Infrastructure::Request::ReferrerType const&, Optional<JS::ModuleRequest> const&, TopLevelModule, PerformTheFetchHook, OnFetchScriptComplete callback);
+void fetch_single_module_script(JS::Realm&, URL::URL const&, FetchClient const& fetch_client, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, EnvironmentSettingsObject&, Web::Fetch::Infrastructure::Request::ReferrerType const&, Optional<JS::ModuleRequest> const&, TopLevelModule, PerformTheFetchHook, OnFetchScriptComplete callback);
}
diff --git a/Libraries/LibWeb/HTML/Scripting/RemoteEnvironmentSettings.h b/Libraries/LibWeb/HTML/Scripting/RemoteEnvironmentSettings.h
new file mode 100644
index 00000000000..21c68b0bc93
--- /dev/null
+++ b/Libraries/LibWeb/HTML/Scripting/RemoteEnvironmentSettings.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/AtomicRefCounted.h>
+#include <LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.h>
+
+namespace Web::HTML {
+
+// The settings of an environment another process hosts, as that process serialized them.
+struct RemoteEnvironmentSettings final : public AtomicRefCounted<RemoteEnvironmentSettings> {
+ static NonnullRefPtr<RemoteEnvironmentSettings const> create(SerializedEnvironmentSettingsObject settings)
+ {
+ return adopt_ref(*new RemoteEnvironmentSettings(move(settings)));
+ }
+
+ SerializedEnvironmentSettingsObject const settings;
+
+private:
+ explicit RemoteEnvironmentSettings(SerializedEnvironmentSettingsObject settings)
+ : settings(move(settings))
+ {
+ }
+};
+
+}
diff --git a/Libraries/LibWeb/HTML/SourceSnapshotParams.cpp b/Libraries/LibWeb/HTML/SourceSnapshotParams.cpp
index 9b2b6846f56..4f4c0bf9962 100644
--- a/Libraries/LibWeb/HTML/SourceSnapshotParams.cpp
+++ b/Libraries/LibWeb/HTML/SourceSnapshotParams.cpp
@@ -33,7 +33,7 @@ GC::Ref<SourceSnapshotParams> snapshot_source_snapshot_params(GC::Ptr<DOM::Docum
true,
// fetch client
// null
- nullptr,
+ OptionalNone {},
// source policy container
// a new policy container
PolicyContainer::create());
@@ -56,7 +56,7 @@ GC::Ref<SourceSnapshotParams> snapshot_source_snapshot_params(GC::Ptr<DOM::Docum
// fetch client
// sourceDocument's relevant settings object
- relevant_settings_object(*source_document),
+ GC::Ref { relevant_settings_object(*source_document) },
// source policy container
// a clone of sourceDocument's policy container
diff --git a/Libraries/LibWeb/HTML/SourceSnapshotParams.h b/Libraries/LibWeb/HTML/SourceSnapshotParams.h
index 03cfbfacca8..09b8bdbe8e8 100644
--- a/Libraries/LibWeb/HTML/SourceSnapshotParams.h
+++ b/Libraries/LibWeb/HTML/SourceSnapshotParams.h
@@ -9,6 +9,7 @@
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/PolicyContainers.h>
+#include <LibWeb/HTML/Scripting/FetchClient.h>
#include <LibWebCommon/HTML/SandboxingFlagSet.h>
namespace Web::HTML {
@@ -19,11 +20,11 @@ struct SourceSnapshotParams : public GC::Cell {
GC_DECLARE_ALLOCATOR(SourceSnapshotParams);
public:
- SourceSnapshotParams(bool has_transient_activation, SandboxingFlagSet sandboxing_flags, bool allows_downloading, GC::Ptr<EnvironmentSettingsObject> fetch_client, NonnullRefPtr<PolicyContainer> source_policy_container, bool text_directive_user_activation = false, bool browsing_context_group_has_multiple_contexts = false, bool browsing_context_group_has_remote_contexts = false)
+ SourceSnapshotParams(bool has_transient_activation, SandboxingFlagSet sandboxing_flags, bool allows_downloading, Optional<FetchClient> fetch_client, NonnullRefPtr<PolicyContainer> source_policy_container, bool text_directive_user_activation = false, bool browsing_context_group_has_multiple_contexts = false, bool browsing_context_group_has_remote_contexts = false)
: has_transient_activation(has_transient_activation)
, sandboxing_flags(sandboxing_flags)
, allows_downloading(allows_downloading)
- , fetch_client(fetch_client)
+ , fetch_client(move(fetch_client))
, source_policy_container(source_policy_container)
, text_directive_user_activation(text_directive_user_activation)
, browsing_context_group_has_multiple_contexts(browsing_context_group_has_multiple_contexts)
@@ -43,7 +44,7 @@ public:
bool allows_downloading;
// an environment settings object or null, only to be used as a request client
- GC::Ptr<EnvironmentSettingsObject> fetch_client;
+ Optional<FetchClient> fetch_client;
// a policy container
NonnullRefPtr<PolicyContainer> source_policy_container;
diff --git a/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
index 3a0d4adf784..03e48cc4019 100644
--- a/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
+++ b/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp
@@ -225,8 +225,8 @@ void WorkerGlobalScope::initialize_policy_container(GC::Ref<Fetch::Infrastructur
}
// https://html.spec.whatwg.org/multipage/browsers.html#check-a-global-object's-embedder-policy
-// NB: response is only used for violation reports, which are not queued.
-bool WorkerGlobalScope::check_embedder_policy(EnvironmentSettingsObject const& owner) const
+// NB: response is only used for violation reports, which are not queued. owner is given as its embedder policy.
+bool WorkerGlobalScope::check_embedder_policy(EmbedderPolicy const& owner_policy) const
{
// 1. If workerGlobalScope is not a DedicatedWorkerGlobalScope object, then return true.
if (!is<DedicatedWorkerGlobalScope>(*this))
@@ -238,7 +238,6 @@ bool WorkerGlobalScope::check_embedder_policy(EnvironmentSettingsObject const& o
auto const& policy = policy_container()->embedder_policy;
// 3. Let ownerPolicy be owner's policy container's embedder policy.
- auto const& owner_policy = owner.policy_container()->embedder_policy;
// FIXME: 4. If ownerPolicy's report-only value is compatible with cross-origin isolation and policy's value is
// not, then queue a cross-origin embedder policy inheritance violation with response, "worker
diff --git a/Libraries/LibWeb/HTML/WorkerGlobalScope.h b/Libraries/LibWeb/HTML/WorkerGlobalScope.h
index 0889a427ee2..65f53877868 100644
--- a/Libraries/LibWeb/HTML/WorkerGlobalScope.h
+++ b/Libraries/LibWeb/HTML/WorkerGlobalScope.h
@@ -136,7 +136,7 @@ public:
bool is_closing() const { return m_closing; }
void initialize_policy_container(GC::Ref<Fetch::Infrastructure::Response const> response, GC::Ref<EnvironmentSettingsObject> environment);
- [[nodiscard]] bool check_embedder_policy(EnvironmentSettingsObject const& owner) const;
+ [[nodiscard]] bool check_embedder_policy(EmbedderPolicy const& owner_policy) const;
[[nodiscard]] ContentSecurityPolicy::Directives::Directive::Result run_csp_initialization() const;
auto& owner_set() { return m_owner_set; }
diff --git a/Libraries/LibWeb/HTML/Worklet.cpp b/Libraries/LibWeb/HTML/Worklet.cpp
index 6defd41d692..16286597917 100644
--- a/Libraries/LibWeb/HTML/Worklet.cpp
+++ b/Libraries/LibWeb/HTML/Worklet.cpp
@@ -112,7 +112,7 @@ GC::Ref<WebIDL::Promise> Worklet::add_module(Utf16String const& module_url, Bind
});
auto fetch_result = fetch_worklet_module_worker_script_graph(
- *module_url_record, outside_settings, worklet_destination(), inside_settings, nullptr, on_complete, static_cast<Fetch::Infrastructure::Request::CredentialsMode>(options.credentials));
+ *module_url_record, GC::Ref { outside_settings }, worklet_destination(), inside_settings, nullptr, on_complete, static_cast<Fetch::Infrastructure::Request::CredentialsMode>(options.credentials));
if (fetch_result.is_exception())
WebIDL::reject_promise_with_exception(realm, promise, fetch_result.release_error());
diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
index 789f8a0effd..2a19c4ec3ac 100644
--- a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
+++ b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
@@ -71,8 +71,6 @@ ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(HT
return ProhibitsMixedSecurityContexts::ProhibitsMixedSecurityContexts;
// 2. If settings’ global object is a window, then:
- // FIXME: A settings object standing in for an environment another process hosts reads the global object it
- // borrows here, not the one of the environment it stands for.
if (auto* window = HTML::window_from_global_object(settings.global_object())) {
// 1. Set document to settings’ global object's associated Document.
auto document = window->document();
diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.h b/Libraries/LibWeb/MixedContent/AbstractOperations.h
index 48a018a6132..8417ad156c3 100644
--- a/Libraries/LibWeb/MixedContent/AbstractOperations.h
+++ b/Libraries/LibWeb/MixedContent/AbstractOperations.h
@@ -10,7 +10,7 @@
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Infrastructure/RequestOrResponseBlocking.h>
#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/MixedContent/ProhibitsMixedSecurityContexts.h>
+#include <LibWebCommon/MixedContent/ProhibitsMixedSecurityContexts.h>
namespace Web::MixedContent {
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 16cace48b60..f7cc8a00840 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -914,6 +914,8 @@ public:
virtual void page_did_receive_network_response_body([[maybe_unused]] u64 request_id, [[maybe_unused]] ReadonlyBytes data) { }
virtual void page_did_finish_network_request([[maybe_unused]] u64 request_id, [[maybe_unused]] u64 body_size, [[maybe_unused]] Requests::RequestTimingInfo const& timing_info, [[maybe_unused]] Optional<Requests::NetworkError> const& network_error) { }
virtual void page_did_report_worker_exception([[maybe_unused]] Utf16String const& message, [[maybe_unused]] Utf16String const& filename, [[maybe_unused]] u32 lineno, [[maybe_unused]] u32 colno) { }
+ // A fetch whose client another process hosts violated the policy at policy_index in that client's CSP list.
+ virtual void page_did_report_violation_of_remote_client([[maybe_unused]] u64 policy_index, [[maybe_unused]] String effective_directive, [[maybe_unused]] URL::URL resource) { }
virtual void page_did_register_javascript_source([[maybe_unused]] DOM::Document&, [[maybe_unused]] HTML::ScriptRegistry::Description const&) { }
virtual void page_did_post_broadcast_channel_message([[maybe_unused]] HTML::PostedBroadcastChannelMessage const& message) { }
diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cpp
index d92efc7cae9..5b4f40c5d86 100644
--- a/Libraries/LibWeb/ServiceWorker/Job.cpp
+++ b/Libraries/LibWeb/ServiceWorker/Job.cpp
@@ -454,13 +454,13 @@ static void update(JS::VM& vm, GC::Ref<Job> job)
// 1. Fetch a classic worker script given job’s serialized script url, job’s client, "serviceworker", and the to-be-created environment settings object for this service worker.
// FIXME: Credentials mode
// FIXME: Use a 'stub' service worker ESO as the fetch "environment"
- (void)HTML::fetch_classic_worker_script(job->script_url, *job->client, Fetch::Infrastructure::Request::Destination::ServiceWorker, *job->client, perform_the_fetch_hook, on_fetch_complete);
+ (void)HTML::fetch_classic_worker_script(job->script_url, GC::Ref { *job->client }, Fetch::Infrastructure::Request::Destination::ServiceWorker, *job->client, perform_the_fetch_hook, on_fetch_complete);
break;
case WorkerType::Module:
// 2. Fetch a module worker script graph given job’s serialized script url, job’s client, "serviceworker", "omit", and the to-be-created environment settings object for this service worker.
// FIXME: Credentials mode
// FIXME: Use a 'stub' service worker ESO as the fetch "environment"
- (void)HTML::fetch_module_worker_script_graph(job->script_url, *job->client, Fetch::Infrastructure::Request::Destination::ServiceWorker, *job->client, perform_the_fetch_hook, on_fetch_complete);
+ (void)HTML::fetch_module_worker_script_graph(job->script_url, GC::Ref { *job->client }, Fetch::Infrastructure::Request::Destination::ServiceWorker, *job->client, perform_the_fetch_hook, on_fetch_complete);
break;
}
}
diff --git a/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cpp b/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cpp
index 24255777a7a..dbb4afcb111 100644
--- a/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cpp
+++ b/Libraries/LibWeb/TrustedTypes/RequireTrustedTypesForDirective.cpp
@@ -70,6 +70,11 @@ ContentSecurityPolicy::Directives::Directive::Result require_trusted_types_for_p
// 3. Let encodedScriptSource be the result of removing the leading "javascript:" from urlString.
auto const encoded_script_source = MUST(url_string.substring_from_byte_offset("javascript:"sv.length()));
+ // AD-HOC: The global object of a client another process hosts is in that process, so its default policy cannot
+ // convert the script source here.
+ if (Fetch::Fetching::remote_client(request))
+ return Result::Blocked;
+
// 4. Let convertedScriptSource be the result of executing Process value with a default policy algorithm, with the following arguments:
// expectedType:
// TrustedScript
diff --git a/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.cpp b/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.cpp
index 295b18d8490..1411e7e8159 100644
--- a/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.cpp
+++ b/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.cpp
@@ -17,6 +17,7 @@ ErrorOr<void> encode(Encoder& encoder, Web::HTML::SerializedWindow const& window
TRY(encoder.encode(window.associated_document.url));
TRY(encoder.encode(window.associated_document.relevant_settings_object_is_secure_context));
TRY(encoder.encode(window.associated_document.relevant_settings_object_policy_container));
+ TRY(encoder.encode(window.navigable_is_top_level));
return {};
}
@@ -30,6 +31,7 @@ ErrorOr<Web::HTML::SerializedWindow> decode(Decoder& decoder)
.relevant_settings_object_is_secure_context = TRY(decoder.decode<bool>()),
.relevant_settings_object_policy_container = TRY(decoder.decode<Web::HTML::SerializedPolicyContainer>()),
},
+ .navigable_is_top_level = TRY(decoder.decode<bool>()),
};
}
@@ -64,6 +66,7 @@ ErrorOr<void> encode(Encoder& encoder, Web::HTML::SerializedEnvironmentSettingsO
TRY(encoder.encode(object.has_cross_site_ancestor));
TRY(encoder.encode(object.policy_container));
TRY(encoder.encode(object.cross_origin_isolated_capability));
+ TRY(encoder.encode(object.prohibits_mixed_security_contexts));
TRY(encoder.encode(object.agent_cluster_id));
TRY(encoder.encode(object.agent_cluster_cross_origin_isolation_mode));
TRY(encoder.encode(object.time_origin));
@@ -85,6 +88,7 @@ ErrorOr<Web::HTML::SerializedEnvironmentSettingsObject> decode(Decoder& decoder)
.has_cross_site_ancestor = TRY(decoder.decode<bool>()),
.policy_container = TRY(decoder.decode<Web::HTML::SerializedPolicyContainer>()),
.cross_origin_isolated_capability = TRY(decoder.decode<Web::HTML::CanUseCrossOriginIsolatedAPIs>()),
+ .prohibits_mixed_security_contexts = TRY(decoder.decode<Web::MixedContent::ProhibitsMixedSecurityContexts>()),
.agent_cluster_id = TRY(decoder.decode<Optional<u64>>()),
.agent_cluster_cross_origin_isolation_mode = TRY(decoder.decode<Web::HTML::CrossOriginIsolationMode>()),
.time_origin = TRY(decoder.decode<double>()),
diff --git a/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.h b/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.h
index fd094e4f094..63f53cfed52 100644
--- a/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.h
+++ b/Libraries/LibWebCommon/HTML/Scripting/SerializedEnvironmentSettingsObject.h
@@ -14,6 +14,7 @@
#include <LibWebCommon/HTML/CrossOriginIsolationMode.h>
#include <LibWebCommon/HTML/Scripting/EnvironmentId.h>
#include <LibWebCommon/HTML/SerializedPolicyContainer.h>
+#include <LibWebCommon/MixedContent/ProhibitsMixedSecurityContexts.h>
namespace Web::HTML {
@@ -30,6 +31,9 @@ struct SerializedDocument {
struct SerializedWindow {
SerializedDocument associated_document;
+
+ // Whether the window's navigable is non-null and has no parent.
+ bool navigable_is_top_level { false };
};
struct SerializedWorkerGlobalScope {
@@ -56,6 +60,9 @@ struct SerializedEnvironmentSettingsObject {
bool has_cross_site_ancestor;
SerializedPolicyContainer policy_container;
CanUseCrossOriginIsolatedAPIs cross_origin_isolated_capability;
+
+ // https://w3c.github.io/webappsec-mixed-content/#categorize-settings-object
+ MixedContent::ProhibitsMixedSecurityContexts prohibits_mixed_security_contexts;
Optional<u64> agent_cluster_id;
CrossOriginIsolationMode agent_cluster_cross_origin_isolation_mode;
double time_origin;
diff --git a/Libraries/LibWeb/MixedContent/ProhibitsMixedSecurityContexts.h b/Libraries/LibWebCommon/MixedContent/ProhibitsMixedSecurityContexts.h
similarity index 100%
rename from Libraries/LibWeb/MixedContent/ProhibitsMixedSecurityContexts.h
rename to Libraries/LibWebCommon/MixedContent/ProhibitsMixedSecurityContexts.h
diff --git a/Services/WebWorker/PageHost.cpp b/Services/WebWorker/PageHost.cpp
index 02fd58a7ee6..fdcdeb88d3a 100644
--- a/Services/WebWorker/PageHost.cpp
+++ b/Services/WebWorker/PageHost.cpp
@@ -104,7 +104,8 @@ void PageHost::page_did_report_worker_exception(Utf16String const& message, Utf1
m_client.async_did_report_worker_exception(message, filename, lineno, colno);
}
-void PageHost::did_report_outside_settings_content_security_policy_violation(u64 policy_index, String effective_directive, URL::URL resource)
+// NB: The worker's only client another process hosts is outside settings, whose violations its owner reports.
+void PageHost::page_did_report_violation_of_remote_client(u64 policy_index, String effective_directive, URL::URL resource)
{
m_client.async_did_report_outside_settings_content_security_policy_violation(policy_index, effective_directive, resource);
}
diff --git a/Services/WebWorker/PageHost.h b/Services/WebWorker/PageHost.h
index cd2aacec166..bca145f6ef7 100644
--- a/Services/WebWorker/PageHost.h
+++ b/Services/WebWorker/PageHost.h
@@ -41,6 +41,7 @@ public:
virtual HTTP::Cookie::VersionedCookie page_did_request_cookie(Optional<Web::HTML::EnvironmentId> const&, URL::URL const&, HTTP::Cookie::Source) override;
virtual bool page_did_is_known_hsts_host(String const&) override;
virtual void page_did_report_worker_exception(Utf16String const& message, Utf16String const& filename, u32 lineno, u32 colno) override;
+ virtual void page_did_report_violation_of_remote_client(u64 policy_index, String effective_directive, URL::URL resource) override;
virtual void page_did_post_broadcast_channel_message(Web::HTML::PostedBroadcastChannelMessage const& message) override;
virtual void request_file(Web::FileRequest) override;
virtual URL::BlobURLEntry::Token page_did_add_blob_url_entry(Web::HTML::EnvironmentSettingsObject const&, Utf16String const& url, Web::FileAPI::SerializedBlobURLEntry const&) override;
@@ -61,7 +62,6 @@ public:
void set_maximum_frames_per_second(double maximum_frames_per_second) { m_maximum_frames_per_second = maximum_frames_per_second; }
void did_finish_loading_worker_script(bool worker_is_secure_context);
void did_fail_loading_worker_script();
- void did_report_outside_settings_content_security_policy_violation(u64 policy_index, String effective_directive, URL::URL resource);
private:
explicit PageHost(ConnectionFromClient&);
diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cpp
index a0eb3db5881..e6f74409bb9 100644
--- a/Services/WebWorker/WorkerHost.cpp
+++ b/Services/WebWorker/WorkerHost.cpp
@@ -21,9 +21,9 @@
#include <LibWeb/HTML/MessagePort.h>
#include <LibWeb/HTML/PolicyContainers.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
-#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/Fetching.h>
+#include <LibWeb/HTML/Scripting/RemoteEnvironmentSettings.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/Scripting/WorkerEnvironmentSettingsObject.h>
#include <LibWeb/HTML/SharedWorkerGlobalScope.h>
@@ -121,21 +121,13 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
// 8. Set worker global scope's name to options["name"].
worker_global_scope->set_name(m_name);
- // IMPLEMENTATION DEFINED: We need an object to represent the fetch response's client
- auto 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.
- outside_settings->set_report_violation(GC::create_function(GC::Heap::the(), [page](u64 policy_index, String effective_directive, URL::URL resource) {
- as<WebWorker::PageHost>(page->client()).did_report_outside_settings_content_security_policy_violation(policy_index, move(effective_directive), move(resource));
- }));
+ auto outside_settings = Web::HTML::RemoteEnvironmentSettings::create(outside_settings_snapshot);
// 10. If is shared is true, then:
if (is_shared) {
auto& shared_global_scope = static_cast<Web::HTML::SharedWorkerGlobalScope&>(*worker_global_scope);
// 1. Set worker global scope's constructor origin to outside settings's origin.
- shared_global_scope.set_constructor_origin(outside_settings->origin());
+ shared_global_scope.set_constructor_origin(outside_settings->settings.origin);
// 2. Set worker global scope's constructor URL to url.
shared_global_scope.set_constructor_url(m_url);
@@ -204,7 +196,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
// 6. If the result of checking a global object's embedder policy with worker global scope, outside settings,
// and response is false, then set response to a network error.
- if (!worker_global_scope->check_embedder_policy(*outside_settings))
+ if (!worker_global_scope->check_embedder_policy(outside_settings->settings.policy_container.embedder_policy))
response = Web::Fetch::Infrastructure::Response::network_error("Blocked by Cross-Origin-Embedder-Policy"_string);
// 7. Set worker global scope's cross-origin isolated capability to true if agent's agent cluster's
@@ -215,7 +207,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
// 8. If is shared is false and owner's cross-origin isolated capability is false, then set worker
// global scope's cross-origin isolated capability to false.
// NB: owner's relevant settings object is outside settings.
- if (outside_settings->cross_origin_isolated_capability() == Web::HTML::CanUseCrossOriginIsolatedAPIs::No)
+ if (outside_settings->settings.cross_origin_isolated_capability == Web::HTML::CanUseCrossOriginIsolatedAPIs::No)
worker_global_scope->set_cross_origin_isolated_capability(false);
// 9. If is shared is false and response's URL's scheme is "data", then set worker global scope's
diff --git a/Services/WebWorker/WorkerHost.h b/Services/WebWorker/WorkerHost.h
index 49ebe79608c..271d7f7a029 100644
--- a/Services/WebWorker/WorkerHost.h
+++ b/Services/WebWorker/WorkerHost.h
@@ -12,7 +12,6 @@
#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>
@@ -45,7 +44,6 @@ 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;
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index e23d70556c6..0a00e814717 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -1091,6 +1091,8 @@ Text/input/wpt-import/css/css-animations/event-dispatch.tentative.html
[LoadFromInsecureOrigin]
Text/input/HTML/page-from-an-insecure-origin-is-not-a-secure-context.html
+; A frame nested in its localhost iframe prohibits mixed security contexts while this page does not.
+Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.html
; Upstream serves it from a page that is not potentially trustworthy, where its data: frame's blob: worker is not mixed content.
Text/input/wpt-import/webmessaging/broadcastchannel/opaque-origin.html
diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-navigation-blocked-by-frame-ancestors.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-navigation-blocked-by-frame-ancestors.txt
new file mode 100644
index 00000000000..dd2184b7e1b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-navigation-blocked-by-frame-ancestors.txt
@@ -0,0 +1,4 @@
+messages: none
+WebContent#0
+ iframe#0: remote WebContent#1
+ iframe#1: remote WebContent#2
diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.txt
new file mode 100644
index 00000000000..047fab8b45b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.txt
@@ -0,0 +1,6 @@
+this page is a secure context: false
+sibling navigated
+WebContent#0
+ iframe#0: remote WebContent#1
+ iframe#1: remote WebContent#2
+ iframe#0: local
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-navigation-blocked-by-frame-ancestors.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-navigation-blocked-by-frame-ancestors.html
new file mode 100644
index 00000000000..17066f1df9b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-navigation-blocked-by-frame-ancestors.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script>
+ // An isolated iframe navigates a sibling that another process hosts to a response whose policy forbids framing.
+ // The sibling's process reports the violation without the source's settings object, and the response does not
+ // load as a document.
+ promiseTest(async () => {
+ const httpServer = httpTestServer();
+ const runId = uniqueID();
+ const targetHostname = uniqueLocalhostHostname("frame-ancestors-target");
+
+ const echo = async (path, headers, body, hostname) => {
+ const url = new URL(
+ await httpServer.createEcho("GET", path, {
+ status: 200,
+ headers: { "Content-Type": "text/html", ...headers },
+ body,
+ })
+ );
+ url.hostname = hostname;
+ return url;
+ };
+
+ const targetFirstUrl = await echo(`/frame-ancestors-target-first-${runId}`, {}, "<!DOCTYPE html>first", targetHostname);
+ const forbiddenUrl = await echo(
+ `/frame-ancestors-forbidden-${runId}`,
+ { "Content-Security-Policy": "frame-ancestors 'none'" },
+ `<!DOCTYPE html><script>top.postMessage("the framed response loaded as a document", "*");<\/script>`,
+ targetHostname
+ );
+ const sourceUrl = await echo(
+ `/frame-ancestors-source-${runId}`,
+ {},
+ `<!DOCTYPE html><a id="link" target="target" href="${forbiddenUrl.href}">link</a>
+ <script>document.getElementById("link").click();<\/script>`,
+ uniqueLocalhostHostname("frame-ancestors-source")
+ );
+
+ const target = document.createElement("iframe");
+ target.name = "target";
+ target.src = targetFirstUrl;
+ document.body.appendChild(target);
+ await new Promise(resolve => (target.onload = resolve));
+
+ const messages = [];
+ addEventListener("message", event => messages.push(event.data));
+ const navigated = new Promise(resolve => target.addEventListener("load", resolve, { once: true }));
+
+ const source = document.createElement("iframe");
+ source.src = sourceUrl;
+ document.body.appendChild(source);
+ await navigated;
+ await timeout(0);
+
+ println(`messages: ${messages.length ? messages.join(", ") : "none"}`);
+ println(internals.dumpSiteIsolationProcessTree().trimEnd());
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.html
new file mode 100644
index 00000000000..7f9d49ac34f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.html
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script>
+ // This page is not a secure context. A data: frame, whose opaque origin is not potentially trustworthy, sits in an
+ // iframe on a localhost name, which is, so the data: frame prohibits mixed security contexts. Its navigation of a
+ // sibling of that iframe, which another process hosts, to a URL that is not potentially trustworthy is blocked as
+ // mixed content, as it would be in the data: frame's own process.
+ promiseTest(async () => {
+ const httpServer = httpTestServer();
+ const runId = uniqueID();
+ const targetHostname = uniqueTestHostname("mixed-content-target");
+
+ const echo = async (path, body, hostname) => {
+ const url = new URL(
+ await httpServer.createEcho("GET", path, {
+ status: 200,
+ headers: { "Content-Type": "text/html" },
+ body,
+ })
+ );
+ url.hostname = hostname;
+ return url;
+ };
+
+ const targetFirstUrl = await echo(`/mixed-content-target-first-${runId}`, "<!DOCTYPE html>first", targetHostname);
+ const blockedUrl = await echo(
+ `/mixed-content-blocked-${runId}`,
+ `<!DOCTYPE html><script>top.postMessage("navigation to an insecure URL went through", "*");<\/script>`,
+ targetHostname
+ );
+ const allowedUrl = await echo(
+ `/mixed-content-allowed-${runId}`,
+ `<!DOCTYPE html><script>top.postMessage("sibling navigated", "*");<\/script>`,
+ uniqueLocalhostHostname("mixed-content-allowed")
+ );
+ const sourceUrl = `data:text/html,${encodeURIComponent(`<!DOCTYPE html>
+ <a id="blocked" target="target" href="${blockedUrl.href}">blocked</a>
+ <a id="allowed" target="target" href="${allowedUrl.href}">allowed</a>
+ <script>
+ addEventListener("message", () => document.getElementById("allowed").click());
+ document.getElementById("blocked").click();
+ <\/script>`)}`;
+ const secureFrameUrl = await echo(
+ `/mixed-content-secure-frame-${runId}`,
+ `<!DOCTYPE html><iframe src="${sourceUrl}"></iframe>`,
+ uniqueLocalhostHostname("mixed-content-secure-frame")
+ );
+
+ const target = document.createElement("iframe");
+ target.name = "target";
+ target.src = targetFirstUrl;
+ document.body.appendChild(target);
+ await new Promise(resolve => (target.onload = resolve));
+
+ const messages = [];
+ let resolveNavigated;
+ const navigated = new Promise(resolve => (resolveNavigated = resolve));
+ addEventListener("message", event => {
+ messages.push(event.data);
+ if (event.data === "sibling navigated")
+ resolveNavigated();
+ });
+
+ // The first navigation the source starts loads either its document or an error page.
+ const firstNavigationLoaded = new Promise(resolve => target.addEventListener("load", resolve, { once: true }));
+ const secureFrame = document.createElement("iframe");
+ secureFrame.src = secureFrameUrl;
+ document.body.appendChild(secureFrame);
+ await firstNavigationLoaded;
+ await timeout(0);
+
+ frames[1].frames[0].postMessage("navigate to the allowed URL", "*");
+ await navigated;
+
+ println(`this page is a secure context: ${isSecureContext}`);
+ for (const message of messages)
+ println(message);
+ println(internals.dumpSiteIsolationProcessTree().trimEnd());
+ });
+</script>