Skip to content

Truly independent web browser

LibWeb: Read a fetch's client through its snapshot

Luke Wilde8bd4233602a2
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index 31fe7c3a230..1b6d157bafb 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -31,6 +31,7 @@
#include <LibWeb/Fetch/Engine/WholeBodyTransport.h>
#include <LibWeb/Fetch/Fetching/BodyStreamPullSource.h>
#include <LibWeb/Fetch/Fetching/Checks.h>
+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>
#include <LibWeb/Fetch/Fetching/Fetching.h>
#include <LibWeb/Fetch/Fetching/NetworkBodyPump.h>
#include <LibWeb/Fetch/Fetching/PendingResponse.h>
@@ -277,7 +278,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
task_destination = GC::Ref { request.client()->global_object() };
// 2. Set crossOriginIsolatedCapability to request’s client’s cross-origin isolated capability.
- cross_origin_isolated_capability = request.client()->cross_origin_isolated_capability();
+ cross_origin_isolated_capability = request.client_snapshot()->cross_origin_isolated_capability;
}
// 6. If useParallelQueue is true, then set taskDestination to the result of starting a new parallel queue.
@@ -322,7 +323,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
// - request’s unsafe-request flag is not set or request’s header list is empty
&& (!request.unsafe_request() || request.header_list()->is_empty())) {
// 1. Assert: request’s origin is same origin with request’s client’s origin.
- VERIFY(request.origin().has<URL::Origin>() && request.origin().get<URL::Origin>().is_same_origin(request.client()->origin()));
+ VERIFY(request.origin().has<URL::Origin>() && request.origin().get<URL::Origin>().is_same_origin(request.client_snapshot()->origin));
// 2. Let onPreloadedResponseAvailable be an algorithm that runs the following step given a response
// response: set fetchParams’s preloaded response candidate to response.
@@ -444,7 +445,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
[](Empty) -> u64 { return 0; },
[](ByteBuffer const& buffer) -> u64 { return buffer.size(); },
[](GC::Ref<Infrastructure::Body> body) -> u64 { return body->length().value_or(0); });
- request.set_keepalive_quota_reservation(request.client()->keepalive_quota_accountant().reserve(body_length));
+ request.set_keepalive_quota_reservation(request.client_snapshot()->keepalive_quota_accountant->reserve(body_length));
}
}
@@ -502,6 +503,11 @@ void populate_request_from_client(Infrastructure::Request& request)
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 (request.client())
+ request.set_client_snapshot(snapshot_client_context(*request.client()));
}
// https://fetch.spec.whatwg.org/#concept-main-fetch
@@ -879,19 +885,39 @@ GC::Ptr<PendingResponse> main_fetch(JS::Realm& realm, Infrastructure::FetchParam
return GC::Ptr<PendingResponse> {};
}
+using RequestEnvironment = Variant<Empty, NonnullRefPtr<Infrastructure::ReservedClientContextSnapshot const>, NonnullRefPtr<Infrastructure::ClientContextSnapshot const>>;
+
// https://fetch.spec.whatwg.org/#request-determine-the-environment
-static GC::Ptr<HTML::Environment> determine_the_environment(GC::Ref<Infrastructure::Request> request)
+static RequestEnvironment determine_the_environment(Infrastructure::Request const& request)
{
// 1. If request’s reserved client is non-null, then return request’s reserved client.
- if (request->reserved_client())
- return request->reserved_client();
+ if (auto const& reserved_client = request.reserved_client_snapshot())
+ return NonnullRefPtr { *reserved_client };
// 2. If request’s client is non-null, then return request’s client.
- if (request->client())
- return request->client();
+ if (auto const& client = request.client_snapshot())
+ return NonnullRefPtr { *client };
// 3. Return null.
- return {};
+ return Empty {};
+}
+
+// https://storage.spec.whatwg.org/#obtain-a-storage-key-for-non-storage-purposes
+static StorageAPI::StorageKey obtain_a_storage_key_for_non_storage_purposes(RequestEnvironment const& environment)
+{
+ // 1. Let origin be environment’s origin if environment is an environment settings object; otherwise environment’s
+ // creation URL’s origin.
+ auto origin = environment.visit(
+ [](Empty) -> URL::Origin { VERIFY_NOT_REACHED(); },
+ [](NonnullRefPtr<Infrastructure::ReservedClientContextSnapshot const> const& environment) {
+ return environment->kind.visit(
+ [](Infrastructure::ReservedClientContext::SettingsObject const& settings_object) { return settings_object.origin; },
+ [&](Infrastructure::ReservedClientContext::Environment const&) { return environment->creation_url.origin(); });
+ },
+ [](NonnullRefPtr<Infrastructure::ClientContextSnapshot const> const& settings) { return settings->origin; });
+
+ // 2. Return a tuple consisting of origin.
+ return { move(origin) };
}
// https://fetch.spec.whatwg.org/#fetch-finale
@@ -921,8 +947,11 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// `Timing-Allow-Origin` header.
// INTEROP: A navigation's reserved client describes its destination context. Use it so entry-point navigations
// collect timing headers even without an initiating client.
- auto client = determine_the_environment(fetch_params.request());
- if (!response.is_network_error() && client != nullptr && HTML::is_secure_context(*client)) {
+ auto request_environment = determine_the_environment(fetch_params.request());
+ auto is_secure_context = request_environment.visit(
+ [](Empty) { return false; },
+ [](auto const& environment) { return environment->is_secure_context == Infrastructure::ClientContext::IsSecureContext::Yes; });
+ if (!response.is_network_error() && is_secure_context) {
if (auto server_timing_headers = response.unsafe_response()->header_list()->get_decode_and_split("Server-Timing"sv); server_timing_headers.has_value())
timing_info->set_server_timing_headers(server_timing_headers.release_value());
}
@@ -1301,26 +1330,27 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
bool is_top_level_self_fetch = false;
// 5. If request’s client is non-null:
- if (request->client() != nullptr) {
+ if (auto const& client = request->client_snapshot()) {
// 1. Let global be request’s client’s global object.
- auto const* global_window = HTML::window_from_global_object(request->client()->global_object());
+ // AD-HOC: The client's snapshot holds what the next step reads from global.
+ auto request_environment_creation_url = request_environment.visit(
+ [](Empty) -> URL::URL { VERIFY_NOT_REACHED(); },
+ [](auto const& environment) { return environment->creation_url; });
// 2. If all of the following conditions are true:
if (
// global is a Window object;
- global_window != nullptr &&
// global’s navigable is not null;
- global_window->navigable() != nullptr &&
// global’s navigable’s parent is null; and
- global_window->navigable()->parent() == nullptr &&
+ client->is_window_of_a_top_level_navigable == Infrastructure::ClientContextSnapshot::IsWindowOfATopLevelNavigable::Yes &&
// requestEnvironment’s creation URL equals request’s current URL,
- request_environment->creation_url == request->current_url())
+ request_environment_creation_url == request->current_url())
// then set isTopLevelSelfFetch to true.
is_top_level_self_fetch = true;
}
// 6. Let stringOrEnvironment be the result of these steps:
- auto string_or_environment = [&]() -> Variant<GC::Ref<HTML::Environment>, FileAPI::TopLevelNavigation, FileAPI::TopLevelSelfFetch> {
+ auto string_or_environment = [&]() -> Variant<StorageAPI::StorageKey, FileAPI::TopLevelNavigation, FileAPI::TopLevelSelfFetch> {
// 1. If request’s destination is "document", then return "top-level-navigation".
if (request->destination() == Infrastructure::Request::Destination::Document)
return FileAPI::TopLevelNavigation();
@@ -1330,7 +1360,9 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
return FileAPI::TopLevelSelfFetch();
// 3. Return requestEnvironment.
- return GC::Ref(*request_environment);
+ // AD-HOC: requestEnvironment is given as its storage key for non-storage purposes, the only part of it that
+ // obtaining a blob object reads.
+ return obtain_a_storage_key_for_non_storage_purposes(request_environment);
}();
// 7. Let blob be the result of obtaining a blob object given blobURLEntry and navigationOrEnvironment.
@@ -1500,7 +1532,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar
return origin->is_opaque() || origin->scheme() == "file"sv || origin->scheme() == "resource"sv;
};
- bool browser_initiated_navigation = request->client() == nullptr && request->mode() == Infrastructure::Request::Mode::Navigate;
+ bool browser_initiated_navigation = !request->client_snapshot() && request->mode() == Infrastructure::Request::Mode::Navigate;
if (!browser_initiated_navigation && !origin_is_allowed())
return error;
@@ -1691,9 +1723,9 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam
// NOTE: The cross-origin resource policy check runs for responses coming from the network and responses coming
// from the service worker. This is different from the CORS check, as request’s client and the service
// worker can have different embedder policies.
- // AD-HOC: request's client can be null, which the check does not allow for. Such a request is checked against a
- // new embedder policy.
- auto client_embedder_policy = request->client() ? request->client()->policy_container()->embedder_policy : HTML::EmbedderPolicy {};
+ // NB: request's policy container is a clone of its client's, taken at fetch start, or a new one when it has no
+ // client.
+ auto const& client_embedder_policy = request->policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->embedder_policy;
if ((request->response_tainting() == Infrastructure::Request::ResponseTainting::Opaque || response->type() == Infrastructure::Response::Type::Opaque)
&& cross_origin_resource_policy_check(request->origin().get<URL::Origin>(), client_embedder_policy, *internal_response) == Infrastructure::RequestOrResponseBlocking::Blocked) {
stop_discarded_response_body(*fetch_params.controller(), *internal_response);
@@ -2024,7 +2056,7 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// 2. Increment inflightKeepaliveBytes by inflightRequest’s body’s length.
// AD-HOC: The fetch group's keepalive quota accountant holds this sum, so a request whose fetch record was
// collected still counts.
- auto inflight_keep_alive_bytes = http_request->client()->keepalive_quota_accountant().in_flight_byte_count();
+ auto inflight_keep_alive_bytes = http_request->client_snapshot()->keepalive_quota_accountant->in_flight_byte_count();
// 5. If the sum of contentLength and inflightKeepaliveBytes is greater than 64 kibibytes, then return a network error.
if ((content_length.value() + inflight_keep_alive_bytes) > keepalive_maximum_size)
@@ -2071,8 +2103,9 @@ GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm& realm, Infrastru
// AD-HOC: While a document loads bypassing the HTTP cache, so do the requests it makes without a cache mode of
// their own, as do its child navigables' navigations (see create navigation params by fetching).
- if (http_request->cache_mode() == HTTP::CacheMode::Default && http_request->mode() != Infrastructure::Request::Mode::Navigate && http_request->client()) {
- if (auto* window = HTML::window_from_global_object(http_request->client()->global_object()); window && window->associated_document().is_loading_bypassing_cache())
+ if (http_request->cache_mode() == HTTP::CacheMode::Default && http_request->mode() != Infrastructure::Request::Mode::Navigate) {
+ auto const& client_snapshot = http_request->client_snapshot();
+ if (client_snapshot && client_snapshot->is_loading_bypassing_cache == Infrastructure::ClientContext::IsLoadingBypassingCache::Yes)
http_request->set_cache_mode(HTTP::CacheMode::Reload);
}
@@ -2445,11 +2478,8 @@ static URL::URL content_blocker_source_url_for_request(Infrastructure::Request&
if (request.destination().has_value() && request.destination().value() == Infrastructure::Request::Destination::Document)
return request.current_url();
- if (auto client = request.client()) {
- if (auto document = client->responsible_document())
- return document->fallback_base_url();
- return client->api_base_url();
- }
+ if (auto const& client = request.client_snapshot())
+ return client->content_blocker_source_url;
return request.current_url();
}
@@ -2502,9 +2532,9 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
load_request.set_source_url(content_blocker_source_url_for_request(*request));
load_request.set_network_isolation_key(Infrastructure::determine_the_network_partition_key(*request));
- if (auto environment = request->reserved_client())
- load_request.set_top_level_creation_url(environment->top_level_creation_url);
- else if (auto client = request->client())
+ if (auto const& reserved_client = request->reserved_client_snapshot())
+ load_request.set_top_level_creation_url(reserved_client->top_level_creation_url);
+ else if (auto const& client = request->client_snapshot())
load_request.set_top_level_creation_url(client->top_level_creation_url);
if (auto const* body = request->body().get_pointer<GC::Ref<Infrastructure::Body>>()) {
@@ -2777,6 +2807,7 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::
preflight->set_method("OPTIONS"sv);
preflight->set_url_list(request.url_list());
preflight->set_client(request.client());
+ preflight->set_client_snapshot(request.client_snapshot());
preflight->set_initiator(request.initiator());
preflight->set_initiator_type(request.initiator_type());
preflight->set_destination(request.destination());
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
index 60b39857791..21c104b0e52 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
@@ -18,7 +18,6 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
#include <LibWeb/HTML/LocalTraversableNavigable.h>
#include <LibWeb/HTML/PolicyContainers.h>
-#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/WebDriver/BiDi/Network.h>
namespace Web::Fetch::Infrastructure {
@@ -157,15 +156,6 @@ bool Request::is_navigation_request() const
});
}
-// Mixed Content refers to a request's target browsing context, which Fetch does not define. A navigation request targets
-// its reserved client's target browsing context: the navigable's active browsing context when the client was reserved.
-GC::Ptr<HTML::BrowsingContext> Request::target_browsing_context() const
-{
- if (!m_reserved_client)
- return {};
- return m_reserved_client->target_browsing_context.ptr();
-}
-
// https://fetch.spec.whatwg.org/#concept-request-tainted-origin
RedirectTaint Request::redirect_taint() const
{
@@ -246,6 +236,8 @@ GC::Ref<Request> Request::clone(JS::Realm& realm, BodyCloning body_cloning) cons
new_request->set_unsafe_request(m_unsafe_request);
new_request->set_client(m_client);
new_request->set_reserved_client(m_reserved_client);
+ new_request->set_client_snapshot(m_client_snapshot);
+ new_request->set_reserved_client_snapshot(m_reserved_client_snapshot);
new_request->set_replaces_client_id(m_replaces_client_id);
new_request->set_traversable_for_user_prompts(m_traversable_for_user_prompts);
new_request->set_keepalive(m_keepalive);
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
index e1de48b6aaf..1922d5d2d4d 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
@@ -26,10 +26,10 @@
#include <LibURL/Origin.h>
#include <LibURL/URL.h>
#include <LibWeb/Export.h>
+#include <LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h>
#include <LibWeb/Fetch/Infrastructure/HTTP.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
#include <LibWeb/Fetch/Infrastructure/KeepaliveQuotaAccountant.h>
-#include <LibWeb/Forward.h>
#include <LibWebCommon/Fetch/Infrastructure/HTTP/RequestPriority.h>
#include <LibWebCommon/Fetch/Infrastructure/HTTP/RequestReferrer.h>
#include <LibWebCommon/HTML/Scripting/EnvironmentId.h>
@@ -204,6 +204,12 @@ public:
[[nodiscard]] ReservedClientType& reserved_client() { return m_reserved_client; }
void set_reserved_client(ReservedClientType reserved_client) { m_reserved_client = move(reserved_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); }
+
+ [[nodiscard]] RefPtr<ReservedClientContextSnapshot const> const& reserved_client_snapshot() const { return m_reserved_client_snapshot; }
+ void set_reserved_client_snapshot(RefPtr<ReservedClientContextSnapshot const> reserved_client_snapshot) { m_reserved_client_snapshot = move(reserved_client_snapshot); }
+
[[nodiscard]] HTML::EnvironmentId const& replaces_client_id() const { return m_replaces_client_id; }
void set_replaces_client_id(HTML::EnvironmentId replaces_client_id) { m_replaces_client_id = move(replaces_client_id); }
@@ -333,7 +339,6 @@ public:
[[nodiscard]] bool is_subresource_request() const;
[[nodiscard]] bool is_navigation_request() const;
- [[nodiscard]] GC::Ptr<HTML::BrowsingContext> target_browsing_context() const;
[[nodiscard]] RedirectTaint redirect_taint() const;
@@ -402,6 +407,10 @@ private:
// stated otherwise it is null.
ReservedClientType m_reserved_client;
+ // What fetching reads from the client and the reserved client, null when the respective one is.
+ RefPtr<ClientContextSnapshot const> m_client_snapshot;
+ RefPtr<ReservedClientContextSnapshot const> m_reserved_client_snapshot;
+
// https://fetch.spec.whatwg.org/#concept-request-replaces-client-id
// A request has an associated replaces client id (a string). Unless stated otherwise it is the empty string.
HTML::EnvironmentId m_replaces_client_id;
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/NetworkPartitionKey.cpp b/Libraries/LibWeb/Fetch/Infrastructure/NetworkPartitionKey.cpp
index 5e835dfe245..786e74c7ea7 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/NetworkPartitionKey.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/NetworkPartitionKey.cpp
@@ -5,18 +5,17 @@
*/
#include <LibURL/Site.h>
-#include <LibWeb/DOM/Document.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/NetworkPartitionKey.h>
-#include <LibWeb/Fetch/Request.h>
-#include <LibWeb/HTML/BrowsingContext.h>
-#include <LibWeb/HTML/LocalNavigable.h>
#include <LibWeb/HTML/Scripting/Environments.h>
namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#determine-the-network-partition-key
-Optional<NetworkPartitionKey> determine_the_network_partition_key(HTML::Environment const& environment)
+// NB: The frame site is that of the environment's document or worker, or, for an environment that is not yet a
+// settings object, that of the document it is being created for.
+template<typename EnvironmentType>
+static Optional<NetworkPartitionKey> determine_the_network_partition_key(EnvironmentType const& environment, URL::Origin const& frame_origin, HasCrossSiteAncestor has_cross_site_ancestor)
{
// 1. Let topLevelOrigin be environment’s top-level origin.
auto top_level_origin = environment.top_level_origin;
@@ -33,21 +32,40 @@ Optional<NetworkPartitionKey> determine_the_network_partition_key(HTML::Environm
return {};
// 5. Let secondKey be null or an implementation-defined value.
- // NB: The frame site is that of the environment's document or worker, or, for an environment that is not yet a
- // settings object, that of the document it is being created for.
- auto const* settings_object = as_if<HTML::EnvironmentSettingsObject>(environment);
- auto frame_origin = settings_object ? settings_object->origin() : environment.creation_url.origin();
-
// 6. Return (topLevelSite, secondKey).
return NetworkPartitionKey {
.top_level_site = top_level_site.release_value(),
.frame_site = URL::Site::serialize_for_partitioning(frame_origin),
.is_subframe_document = false,
.is_cross_site_main_frame_navigation = false,
- .has_cross_site_ancestor = settings_object && settings_object->has_cross_site_ancestor(),
+ .has_cross_site_ancestor = has_cross_site_ancestor == HasCrossSiteAncestor::Yes,
};
}
+Optional<NetworkPartitionKey> determine_the_network_partition_key(HTML::Environment const& environment)
+{
+ auto const* settings_object = as_if<HTML::EnvironmentSettingsObject>(environment);
+ auto frame_origin = settings_object ? settings_object->origin() : environment.creation_url.origin();
+ auto has_cross_site_ancestor = (settings_object && settings_object->has_cross_site_ancestor()) ? HasCrossSiteAncestor::Yes : HasCrossSiteAncestor::No;
+ return determine_the_network_partition_key(environment, frame_origin, has_cross_site_ancestor);
+}
+
+static Optional<NetworkPartitionKey> determine_the_network_partition_key(ClientContextSnapshot const& client)
+{
+ return determine_the_network_partition_key(client, client.origin, client.has_cross_site_ancestor);
+}
+
+static Optional<NetworkPartitionKey> determine_the_network_partition_key(ReservedClientContextSnapshot const& reserved_client)
+{
+ return reserved_client.kind.visit(
+ [&](ReservedClientContext::SettingsObject const& settings_object) {
+ return determine_the_network_partition_key(reserved_client, settings_object.origin, settings_object.has_cross_site_ancestor);
+ },
+ [&](ReservedClientContext::Environment const&) {
+ return determine_the_network_partition_key(reserved_client, reserved_client.creation_url.origin(), HasCrossSiteAncestor::No);
+ });
+}
+
// https://fetch.spec.whatwg.org/#request-determine-the-network-partition-key
Optional<NetworkPartitionKey> determine_the_network_partition_key(Infrastructure::Request const& request)
{
@@ -76,11 +94,11 @@ Optional<NetworkPartitionKey> determine_the_network_partition_key(Infrastructure
Optional<NetworkPartitionKey> key;
// 1. If request’s reserved client is non-null, then return the result of determining the network partition key given request’s reserved client.
- if (auto reserved_client = request.reserved_client())
+ if (auto const& reserved_client = request.reserved_client_snapshot())
key = determine_the_network_partition_key(*reserved_client);
// 2. If request’s client is non-null, then return the result of determining the network partition key given request’s client.
- else if (auto client = request.client())
+ else if (auto const& client = request.client_snapshot())
key = determine_the_network_partition_key(*client);
// 3. Return null.
@@ -94,26 +112,15 @@ Optional<NetworkPartitionKey> determine_the_network_partition_key(Infrastructure
key->frame_site = URL::Site::serialize_for_partitioning(current_url_origin);
key->is_subframe_document = true;
key->has_cross_site_ancestor = [&] {
- auto target_browsing_context = request.target_browsing_context();
- if (!target_browsing_context)
- return false;
- auto const* document = target_browsing_context->active_document();
- auto navigable = document ? document->navigable() : nullptr;
- auto parent = navigable ? navigable->parent() : nullptr;
- if (!parent)
+ auto const& reserved_client = request.reserved_client_snapshot();
+ auto const* environment = reserved_client ? reserved_client->kind.get_pointer<ReservedClientContext::Environment>() : nullptr;
+ if (!environment || !environment->parent.has_value())
return false;
- auto parent_origin = parent->active_document_origin();
- return parent->active_document_has_cross_site_ancestor() || !parent_origin.has_value() || !parent_origin->is_same_site(current_url_origin);
+ auto const& parent = *environment->parent;
+ return parent.active_document_has_cross_site_ancestor == HasCrossSiteAncestor::Yes || !parent.active_document_origin.has_value() || !parent.active_document_origin->is_same_site(current_url_origin);
}();
}
- // AD-HOC: A request a worker makes for its own script has the worker's environment as its reserved client, which is
- // not yet a settings object. The worker shares its creator's ancestors.
- else if (request.reserved_client() && !is<HTML::EnvironmentSettingsObject>(*request.reserved_client())) {
- if (auto client = request.client())
- key->has_cross_site_ancestor = client->has_cross_site_ancestor();
- }
-
return key;
}
diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp
index 0cfd1872f30..4fd4869d1e9 100644
--- a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp
+++ b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp
@@ -113,14 +113,16 @@ bool check_for_same_partition_blob_url_usage(URL::Origin const& blob_url_entry_o
}
// https://www.w3.org/TR/FileAPI/#blob-url-obtain-object
-Optional<SerializedBlobURLEntry::Object> obtain_a_blob_object(SerializedBlobURLEntry const& blob_url_entry, Variant<GC::Ref<HTML::Environment>, TopLevelNavigation, TopLevelSelfFetch> environment)
+Optional<SerializedBlobURLEntry::Object> obtain_a_blob_object(SerializedBlobURLEntry const& blob_url_entry, Variant<StorageAPI::StorageKey, TopLevelNavigation, TopLevelSelfFetch> environment)
{
// 1. Let isAuthorized be true.
bool is_authorized = true;
- // 2. If environment is an environment settings object, then set isAuthorized to the result of checking for same-partition blob URL usage with blobUrlEntry and environment.
- if (environment.has<GC::Ref<HTML::Environment>>())
- is_authorized = check_for_same_partition_blob_url_usage(blob_url_entry.origin, environment.get<GC::Ref<HTML::Environment>>());
+ // 2. If environment is an environment, then set isAuthorized to the result of checking for same-partition blob URL usage with blobUrlEntry and environment.
+ // AD-HOC: An environment is given as its storage key for non-storage purposes, the only part of it that checking for
+ // same-partition blob URL usage reads.
+ if (auto const* environment_storage_key = environment.get_pointer<StorageAPI::StorageKey>())
+ is_authorized = check_for_same_partition_blob_url_usage(blob_url_entry.origin, environment_storage_key->origin);
// 3. If isAuthorized is false, then return failure.
if (!is_authorized)
diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.h b/Libraries/LibWeb/FileAPI/BlobURLStore.h
index beb4bcd3909..d5fdd59fad1 100644
--- a/Libraries/LibWeb/FileAPI/BlobURLStore.h
+++ b/Libraries/LibWeb/FileAPI/BlobURLStore.h
@@ -12,6 +12,7 @@
#include <LibWeb/Forward.h>
#include <LibWebCommon/FileAPI/BlobURLStore.h>
#include <LibWebCommon/FileAPI/SerializedBlobURLEntry.h>
+#include <LibWebCommon/StorageAPI/StorageKey.h>
namespace Web::FileAPI {
@@ -31,7 +32,7 @@ ErrorOr<Utf16String> add_entry_to_blob_url_store(BlobURLEntry::Object);
bool check_for_same_partition_blob_url_usage(URL::Origin const& blob_url_entry_origin, GC::Ref<HTML::Environment>);
struct TopLevelNavigation { };
struct TopLevelSelfFetch { };
-WEB_API Optional<SerializedBlobURLEntry::Object> obtain_a_blob_object(SerializedBlobURLEntry const&, Variant<GC::Ref<HTML::Environment>, TopLevelNavigation, TopLevelSelfFetch> environment);
+WEB_API Optional<SerializedBlobURLEntry::Object> obtain_a_blob_object(SerializedBlobURLEntry const&, Variant<StorageAPI::StorageKey, TopLevelNavigation, TopLevelSelfFetch> environment);
WEB_API void remove_entry_from_blob_url_store(URL::URL const& url);
Optional<URL::BlobURLEntry> resolve_a_blob_url(URL::URL const&);
WEB_API Optional<SerializedBlobURLEntry> blob_url_entry_in_the_user_agent_store(Page&, URL::URL const&);
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 536058a07a4..a70bfc1e149 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -67,6 +67,7 @@
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/PaintFacts.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
+#include <LibWeb/StorageAPI/StorageKey.h>
#include <LibWeb/WebIDL/Promise.h>
#include <LibWebCommon/HTML/AudioPlayState.h>
#include <LibWebCommon/MimeSniff/MimeType.h>
@@ -1378,10 +1379,12 @@ void HTMLMediaElement::load_url_resource(URL::URL const& url_record, Function<vo
}
// 5. Let stringOrEnvironment be "top-level-self-fetch" if isTopLevelSelfFetch is true; otherwise settingsObject.
- auto string_or_environment = [&] -> Variant<GC::Ref<HTML::Environment>, FileAPI::TopLevelSelfFetch> {
+ // AD-HOC: settingsObject is given as its storage key for non-storage purposes, the only part of it that
+ // obtaining a blob object reads.
+ auto string_or_environment = [&] -> Variant<StorageAPI::StorageKey, FileAPI::TopLevelSelfFetch> {
if (is_top_level_self_fetch)
return FileAPI::TopLevelSelfFetch();
- return { settings_object };
+ return StorageAPI::obtain_a_storage_key_for_non_storage_purposes(settings_object);
}();
// 6. Let object be the result of obtaining a blob object using the URL record's blob URL entry and stringOrEnvironment.
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 8f2464ca0d5..afbf6c41018 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -43,6 +43,7 @@
#include <LibWeb/Editing/SpellCheckController.h>
#include <LibWeb/Editing/WritingSuggestionController.h>
#include <LibWeb/Fetch/Fetching/Checks.h>
+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>
#include <LibWeb/Fetch/Fetching/Fetching.h>
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/Fetch/Infrastructure/FetchController.h>
@@ -2243,6 +2244,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation
// 2. Set request's reserved client to null.
state_holder->request->set_reserved_client(nullptr);
+ state_holder->request->set_reserved_client_snapshot(nullptr);
// 3. Set commitEarlyHints to null.
state_holder->commit_early_hints = nullptr;
@@ -2283,7 +2285,9 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation
// creation URL is currentURL,
// top-level creation URL is topLevelCreationURL,
// and top-level origin is topLevelOrigin.
- state_holder->request->set_reserved_client(realm.create<Environment>(EnvironmentId::generate(), state_holder->current_url, top_level_creation_url, top_level_origin, state_holder->navigable->active_browsing_context()));
+ auto reserved_client = realm.create<Environment>(EnvironmentId::generate(), state_holder->current_url, top_level_creation_url, top_level_origin, state_holder->navigable->active_browsing_context());
+ state_holder->request->set_reserved_client(reserved_client);
+ state_holder->request->set_reserved_client_snapshot(Fetch::Fetching::snapshot_reserved_client_context(reserved_client));
}
// 3. If the result of should navigation request of type be blocked by Content Security Policy? given request and cspNavigationType is "Blocked", then set response to a network error and break. [CSP]
diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
index e10069e1b09..789f8a0effd 100644
--- a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
+++ b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp
@@ -15,6 +15,15 @@
namespace Web::MixedContent {
+// NB: The client's snapshot holds the result of § 4.3 Does settings prohibit mixed security contexts? for it.
+static ProhibitsMixedSecurityContexts does_client_prohibit_mixed_security_contexts(Fetch::Infrastructure::Request const& request)
+{
+ // AD-HOC: Fetch requests initiated by the browser UI have no client. Treat that as not restricting mixed content.
+ if (auto const& client = request.client_snapshot())
+ return client->prohibits_mixed_security_contexts;
+ return ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts;
+}
+
// https://w3c.github.io/webappsec-mixed-content/#upgrade-algorithm
void upgrade_a_mixed_content_request_to_a_potentially_trustworthy_url_if_appropriate(Fetch::Infrastructure::Request& request)
{
@@ -31,7 +40,7 @@ void upgrade_a_mixed_content_request_to_a_potentially_trustworthy_url_if_appropr
|| (url.host().has_value() && (url.host()->has<IPv4Address>() || url.host()->has<IPv6Address>()))
// 3. § 4.3 Does settings prohibit mixed security contexts? returns "Does Not Restrict Mixed Security Contents" when applied to request’s client.
- || does_settings_prohibit_mixed_security_contexts(request.client()) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts
+ || does_client_prohibit_mixed_security_contexts(request) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts
// 4. request’s destination is not "image", "audio", or "video".
|| (request.destination() != Fetch::Infrastructure::Request::Destination::Image
@@ -55,21 +64,16 @@ void upgrade_a_mixed_content_request_to_a_potentially_trustworthy_url_if_appropr
}
// https://w3c.github.io/webappsec-mixed-content/#categorize-settings-object
-ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(GC::Ptr<HTML::EnvironmentSettingsObject> settings)
+ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(HTML::EnvironmentSettingsObject& settings)
{
- // AD-HOC: Fetch requests initiated by the browser UI have no client. Treat that as not restricting mixed content;
- // callers also rely on this result before inspecting the client's browsing context.
- if (!settings)
- return ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts;
-
// 1. If settings’ origin is a potentially trustworthy origin, then return "Prohibits Mixed Security Contexts".
- if (SecureContexts::is_origin_potentially_trustworthy(settings->origin()) == SecureContexts::Trustworthiness::PotentiallyTrustworthy)
+ if (SecureContexts::is_origin_potentially_trustworthy(settings.origin()) == SecureContexts::Trustworthiness::PotentiallyTrustworthy)
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())) {
+ 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();
@@ -85,13 +89,22 @@ ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(GC
return ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts;
}
+// NB: A navigation request's target browsing context is the one its reserved client names.
+static bool target_browsing_context_is_top_level(Fetch::Infrastructure::Request const& request)
+{
+ using Context = Fetch::Infrastructure::ReservedClientContext;
+ auto const& reserved_client = request.reserved_client_snapshot();
+ auto const* environment = reserved_client ? reserved_client->kind.get_pointer<Context::Environment>() : nullptr;
+ return environment && environment->target_browsing_context == Context::TargetBrowsingContext::TopLevel;
+}
+
// https://w3c.github.io/webappsec-mixed-content/#should-block-fetch
Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request& request)
{
// 1. Return allowed if one or more of the following conditions are met:
if (
// 1. § 4.3 Does settings prohibit mixed security contexts? returns "Does Not Restrict Mixed Security Contexts" when applied to request’s client.
- does_settings_prohibit_mixed_security_contexts(request.client()) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts
+ does_client_prohibit_mixed_security_contexts(request) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts
// 2. request’s URL is a potentially trustworthy URL.
// INTEROP: Main fetch runs this algorithm again for every redirect. We check request's current URL rather than
@@ -103,7 +116,7 @@ Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_bloc
// 4. request’s destination is "document", and request’s target browsing context has no parent browsing context.
// TODO: "parent browsing context" doesn't exist anymore and is a spec bug, seems like it should be `is_top_level`
- || (request.destination() == Fetch::Infrastructure::Request::Destination::Document && request.target_browsing_context() && request.target_browsing_context()->is_top_level())) {
+ || (request.destination() == Fetch::Infrastructure::Request::Destination::Document && target_browsing_context_is_top_level(request))) {
return Fetch::Infrastructure::RequestOrResponseBlocking::Allowed;
}
@@ -118,7 +131,7 @@ Web::Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request
// 1. Return allowed if one or more of the following conditions are met:
if (
// 1. § 4.3 Does settings prohibit mixed security contexts? returns Does Not Restrict Mixed Content when applied to request’s client.
- does_settings_prohibit_mixed_security_contexts(request.client()) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts
+ does_client_prohibit_mixed_security_contexts(request) == ProhibitsMixedSecurityContexts::DoesNotRestrictMixedSecurityContexts
// 2. response’s url is a potentially trustworthy URL.
|| (response->url().has_value() && SecureContexts::is_url_potentially_trustworthy(response->url().value()) == SecureContexts::Trustworthiness::PotentiallyTrustworthy)
@@ -128,7 +141,7 @@ Web::Fetch::Infrastructure::RequestOrResponseBlocking should_response_to_request
// 4. request’s destination is "document", and request’s target browsing context has no parent browsing context.
// TODO: "parent browsing context" doesn't exist anymore and is a spec bug, seems like it should be `is_top_level`
- || (request.destination() == Fetch::Infrastructure::Request::Destination::Document && request.target_browsing_context() && request.target_browsing_context()->is_top_level())) {
+ || (request.destination() == Fetch::Infrastructure::Request::Destination::Document && target_browsing_context_is_top_level(request))) {
return Fetch::Infrastructure::RequestOrResponseBlocking::Allowed;
}
diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.h b/Libraries/LibWeb/MixedContent/AbstractOperations.h
index 400723d9e90..48a018a6132 100644
--- a/Libraries/LibWeb/MixedContent/AbstractOperations.h
+++ b/Libraries/LibWeb/MixedContent/AbstractOperations.h
@@ -16,7 +16,7 @@ namespace Web::MixedContent {
WEB_API void upgrade_a_mixed_content_request_to_a_potentially_trustworthy_url_if_appropriate(Fetch::Infrastructure::Request&);
-ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(GC::Ptr<HTML::EnvironmentSettingsObject>);
+ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(HTML::EnvironmentSettingsObject&);
WEB_API Fetch::Infrastructure::RequestOrResponseBlocking should_fetching_request_be_blocked_as_mixed_content(Fetch::Infrastructure::Request&);
diff --git a/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp b/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp
index 0c51303d1ff..b11f4689257 100644
--- a/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp
+++ b/Libraries/LibWeb/ReferrerPolicy/AbstractOperations.cpp
@@ -6,13 +6,9 @@
*/
#include <LibURL/URL.h>
-#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOMURL/DOMURL.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
-#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>
-#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/HTML/Window.h>
#include <LibWeb/ReferrerPolicy/AbstractOperations.h>
#include <LibWebCommon/Fetch/Infrastructure/URL.h>
#include <LibWebCommon/ReferrerPolicy/ReferrerPolicy.h>
@@ -61,7 +57,7 @@ Optional<URL::URL> determine_requests_referrer(Fetch::Infrastructure::Request co
auto const& policy = request.referrer_policy();
// 2. Let environment be request’s client.
- auto environment = request.client();
+ auto const& environment = request.client_snapshot();
// 3. Switch on request’s referrer:
auto referrer_source = request.referrer().visit(
@@ -70,47 +66,19 @@ Optional<URL::URL> determine_requests_referrer(Fetch::Infrastructure::Request co
// Note: If request’s referrer is "no-referrer", Fetch will not call into this algorithm.
VERIFY(referrer == Fetch::Infrastructure::Request::Referrer::Client);
- // NB: A snapshot of an environment in another process — a navigation's fetch client, once the navigation
- // continues in the process hosting its target — has a global object from this process, so it 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;
- }
-
- // FIXME: Add a const global_object() getter to ESO
- auto& global_object = const_cast<HTML::EnvironmentSettingsObject&>(*environment).global_object();
-
- // 1. If environment’s global object is a Window object, then
- if (auto const* window = HTML::window_from_global_object(global_object)) {
- // 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.
- if (document.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();
- }
- // 2. Otherwise, let referrerSource be environment’s creation URL.
- else {
- return environment->creation_url;
- }
+ // 1. If environment is null, then return no referrer.
+ if (!environment)
+ return {};
+
+ // AD-HOC: Steps 2 and 3 ran when the client's snapshot was taken, which holds their result.
+ return environment->referrer_source;
},
// a URL
[&](URL::URL const& url) -> Optional<URL::URL> {
// Let referrerSource be request’s referrer.
return url;
});
- // NOTE: This only happens in step 1.2. of the "client" case above.
+ // NOTE: This only happens in steps 1 and 2.2. of the "client" case above.
if (!referrer_source.has_value())
return {};
diff --git a/Libraries/LibWeb/SRI/IntegrityPolicy.cpp b/Libraries/LibWeb/SRI/IntegrityPolicy.cpp
index fbc4a1d1a7c..43e43180b04 100644
--- a/Libraries/LibWeb/SRI/IntegrityPolicy.cpp
+++ b/Libraries/LibWeb/SRI/IntegrityPolicy.cpp
@@ -6,8 +6,6 @@
*/
#include <LibWeb/HTML/PolicyContainers.h>
-#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/HTML/Window.h>
#include <LibWeb/SRI/IntegrityPolicy.h>
#include <LibWeb/SRI/SRI.h>
#include <LibWebCommon/Fetch/Infrastructure/URL.h>
@@ -44,10 +42,10 @@ ContentSecurityPolicy::Directives::Directive::Result should_request_be_blocked_b
return ContentSecurityPolicy::Directives::Directive::Result::Allowed;
// 8. Let global be request’s client’s global object.
- auto& global = request->client()->global_object();
+ auto global_kind = request->client_snapshot()->global_kind;
// 9. If global is not a Window nor a WorkerGlobalScope, return "Allowed".
- if (!HTML::window_or_worker_global_scope_from_global_object(global))
+ if (global_kind != Fetch::Infrastructure::ClientContextSnapshot::GlobalKind::Window && global_kind != Fetch::Infrastructure::ClientContextSnapshot::GlobalKind::Worker)
return ContentSecurityPolicy::Directives::Directive::Result::Allowed;
// 10. Let block be a boolean, initially false.
diff --git a/Libraries/LibWeb/UpgradeInsecureRequests/AbstractOperations.cpp b/Libraries/LibWeb/UpgradeInsecureRequests/AbstractOperations.cpp
index b6be9e1a0eb..3b0c0cf082a 100644
--- a/Libraries/LibWeb/UpgradeInsecureRequests/AbstractOperations.cpp
+++ b/Libraries/LibWeb/UpgradeInsecureRequests/AbstractOperations.cpp
@@ -5,13 +5,22 @@
*/
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
-#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/PolicyContainers.h>
#include <LibWeb/UpgradeInsecureRequests/AbstractOperations.h>
#include <LibWebCommon/SecureContexts/AbstractOperations.h>
namespace Web::UpgradeInsecureRequests {
+// AD-HOC: Upgrade Insecure Requests reads request's client's target browsing context, but means the browsing context
+// being navigated, which request's reserved client names.
+static bool target_browsing_context_is_nested(Fetch::Infrastructure::Request const& request)
+{
+ using Context = Fetch::Infrastructure::ReservedClientContext;
+ auto const& reserved_client = request.reserved_client_snapshot();
+ auto const* environment = reserved_client ? reserved_client->kind.get_pointer<Context::Environment>() : nullptr;
+ return environment && environment->target_browsing_context == Context::TargetBrowsingContext::Nested;
+}
+
// https://w3c.github.io/webappsec-upgrade-insecure-requests/#upgrade-request
void upgrade_request_to_a_potentially_trustworthy_url_if_appropriate(Fetch::Infrastructure::Request& request)
{
@@ -37,9 +46,7 @@ void upgrade_request_to_a_potentially_trustworthy_url_if_appropriate(Fetch::Infr
// 1. If request is a form submission, skip the remaining substeps, and continue upgrading request.
// 2. If request's client's target browsing context is a nested browsing context, skip the remaining substeps
// and continue upgrading request.
- // NB: A navigation request's target browsing context is its reserved client's.
- auto target_browsing_context = request.target_browsing_context();
- if (!request.is_form_submission() && (!target_browsing_context || target_browsing_context->is_top_level())) {
+ if (!request.is_form_submission() && !target_browsing_context_is_nested(request)) {
// 3. Let tuple be a tuple of request's URL's host and port.
// 4. If tuple is contained in client's upgrade insecure navigations set, then skip the remaining
// substeps, and continue upgrading request.
diff --git a/Libraries/LibWeb/WebDriver/BiDi/Network.cpp b/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
index dec76dd78b0..702befe9b4e 100644
--- a/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
+++ b/Libraries/LibWeb/WebDriver/BiDi/Network.cpp
@@ -12,14 +12,12 @@
#include <AK/Time.h>
#include <LibGC/Heap.h>
#include <LibRequests/Request.h>
-#include <LibWeb/DOM/Document.h>
+#include <LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h>
#include <LibWeb/Fetch/Infrastructure/FetchParams.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
#include <LibWeb/HTML/LocalNavigable.h>
-#include <LibWeb/HTML/Scripting/Environments.h>
-#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/WebDriver/BiDi/BiDi.h>
#include <LibWeb/WebDriver/BiDi/Network.h>
@@ -42,17 +40,22 @@ void initialize_network_request(Request& request, GC::Ptr<HTML::Navigable> navig
if (!g_network_events_enabled || request.webdriver_bidi_network_request())
return;
auto state = GC::Heap::the().allocate<NetworkRequest>();
- if (navigable) {
- state->navigable = navigable;
- } else if (auto client = request.client()) {
- if (auto* window = HTML::window_from_global_object(client->global_object()))
- state->navigable = window->associated_document().navigable();
- }
+ if (navigable)
+ state->navigable_id = navigable->id();
+ else if (auto const& client = request.client_snapshot())
+ state->navigable_id = client->navigable_id;
if (navigation.has_value())
state->navigation = navigation->to_utf8();
request.set_webdriver_bidi_network_request(state);
}
+static GC::Ptr<HTML::LocalNavigable> navigable_of(NetworkRequest const& state)
+{
+ if (!state.navigable_id.has_value())
+ return {};
+ return HTML::local_navigable_with_id(*state.navigable_id);
+}
+
// https://w3c.github.io/webdriver-bidi/#serialize-protocol-bytes
static JsonObject serialize_protocol_bytes(StringView bytes)
{
@@ -118,8 +121,10 @@ static JsonObject get_the_fetch_timings(FetchTimingInfo const& timings, Optional
static JsonObject get_the_fetch_timings(Request const& request, FetchTimingInfo const& timings)
{
- auto client = request.client();
- return get_the_fetch_timings(timings, client ? Optional<double>(client->time_origin()) : Optional<double> {}, client ? HighResolutionTime::get_time_origin_timestamp(client->global_object()) : 0);
+ auto const& client = request.client_snapshot();
+ if (!client)
+ return get_the_fetch_timings(timings, {}, 0);
+ return get_the_fetch_timings(timings, client->time_origin, client->time_origin - HighResolutionTime::estimated_monotonic_time_of_the_unix_epoch());
}
// https://w3c.github.io/webdriver-bidi/#get-the-request-data
@@ -242,11 +247,11 @@ static JsonObject get_the_response_data(Response const& response, FetchTimingInf
}
// https://w3c.github.io/webdriver-bidi/#process-a-network-event
-static JsonObject process_a_network_event(Request const& request, FetchTimingInfo const& timing_info)
+static JsonObject process_a_network_event(HTML::Navigable const& navigable, Request const& request, FetchTimingInfo const& timing_info)
{
auto state = request.webdriver_bidi_network_request();
JsonObject params;
- params.set("context"sv, navigable_id(*state->navigable));
+ params.set("context"sv, navigable_id(navigable));
params.set("userContext"sv, "default"sv);
params.set("isBlocked"sv, false);
params.set("navigation"sv, state->navigation.has_value() ? JsonValue(*state->navigation) : JsonValue {});
@@ -268,14 +273,17 @@ void network_before_request_sent(FetchParams const& fetch_params)
auto request = fetch_params.request();
initialize_network_request(*request);
auto state = request->webdriver_bidi_network_request();
- if (!state || !state->navigable || state->before_request_sent.contains(request->redirect_count()))
+ if (!state || state->before_request_sent.contains(request->redirect_count()))
+ return;
+ auto navigable = navigable_of(*state);
+ if (!navigable)
return;
// 4. Let redirect count be request's redirect count.
// 5. Add redirect count to before request sent map[request].
state->before_request_sent.set(request->redirect_count());
state->request_data.set(request->redirect_count(), get_the_request_data(*request, *fetch_params.timing_info()));
if (is_event_enabled("network.beforeRequestSent"sv))
- emit_event(*state->navigable, "network.beforeRequestSent"_string, process_a_network_event(*fetch_params.request(), *fetch_params.timing_info()));
+ emit_event(*navigable, "network.beforeRequestSent"_string, process_a_network_event(*navigable, *fetch_params.request(), *fetch_params.timing_info()));
}
// https://w3c.github.io/webdriver-bidi/#event-network-responseStarted
@@ -284,14 +292,17 @@ void network_response_started(FetchParams const& fetch_params, Response& respons
network_before_request_sent(fetch_params);
auto request = fetch_params.request();
auto state = request->webdriver_bidi_network_request();
- if (!state || !state->navigable || state->response_started.contains(request->redirect_count()) || response.is_network_error())
+ if (!state || state->response_started.contains(request->redirect_count()) || response.is_network_error())
+ return;
+ auto navigable = navigable_of(*state);
+ if (!navigable)
return;
state->response_started.set(request->redirect_count());
// 5. Let sessions be the set of sessions for which an event is enabled given "network.responseStarted" and related navigables.
if (is_event_enabled("network.responseStarted"sv)) {
- auto params = process_a_network_event(*fetch_params.request(), *fetch_params.timing_info());
+ auto params = process_a_network_event(*navigable, *fetch_params.request(), *fetch_params.timing_info());
params.set("response"sv, get_the_response_data(response, *fetch_params.timing_info()));
- emit_event(*state->navigable, "network.responseStarted"_string, move(params));
+ emit_event(*navigable, "network.responseStarted"_string, move(params));
}
}
@@ -300,7 +311,10 @@ void network_response_completed(FetchParams const& fetch_params, Response const&
{
auto request = fetch_params.request();
auto state = request->webdriver_bidi_network_request();
- if (!state || !state->navigable || (state->completed.contains(request->redirect_count()) || state->transferred.contains(request->redirect_count())))
+ if (!state || (state->completed.contains(request->redirect_count()) || state->transferred.contains(request->redirect_count())))
+ return;
+ auto navigable = navigable_of(*state);
+ if (!navigable)
return;
state->completed.set(request->redirect_count());
if (!fetch_params.timing_info()->end_time())
@@ -308,9 +322,9 @@ void network_response_completed(FetchParams const& fetch_params, Response const&
// 5. Let sessions be the set of sessions for which an event is enabled given "network.responseCompleted" and related navigables.
if (!is_event_enabled("network.responseCompleted"sv))
return;
- auto params = process_a_network_event(*fetch_params.request(), *fetch_params.timing_info());
+ auto params = process_a_network_event(*navigable, *fetch_params.request(), *fetch_params.timing_info());
params.set("response"sv, get_the_response_data(response, *fetch_params.timing_info()));
- emit_event(*state->navigable, "network.responseCompleted"_string, move(params));
+ emit_event(*navigable, "network.responseCompleted"_string, move(params));
}
// https://w3c.github.io/webdriver-bidi/#event-network-fetchError
@@ -320,15 +334,18 @@ void network_fetch_error(FetchParams const& fetch_params, StringView error_text)
network_before_request_sent(fetch_params);
auto request = fetch_params.request();
auto state = request->webdriver_bidi_network_request();
- if (!state || !state->navigable || (state->completed.contains(request->redirect_count()) || state->transferred.contains(request->redirect_count())))
+ if (!state || (state->completed.contains(request->redirect_count()) || state->transferred.contains(request->redirect_count())))
+ return;
+ auto navigable = navigable_of(*state);
+ if (!navigable)
return;
state->completed.set(request->redirect_count());
if (!is_event_enabled("network.fetchError"sv))
return;
- auto params = process_a_network_event(*fetch_params.request(), *fetch_params.timing_info());
+ auto params = process_a_network_event(*navigable, *fetch_params.request(), *fetch_params.timing_info());
// 4.2. Set the errorText field of params to an implementation-defined string describing the error which caused the request to be aborted.
params.set("errorText"sv, String::from_utf8_with_replacement_character(error_text));
- emit_event(*state->navigable, "network.fetchError"_string, move(params));
+ emit_event(*navigable, "network.fetchError"_string, move(params));
}
Optional<JsonObject> network_response_for_navigation(Request const& request, FetchTimingInfo const& timing_info,
@@ -337,14 +354,18 @@ Optional<JsonObject> network_response_for_navigation(Request const& request, Fet
if (!g_network_events_enabled)
return {};
auto state = request.webdriver_bidi_network_request();
- if (!state || !state->navigable || state->completed.contains(request.redirect_count()))
+ if (!state || state->completed.contains(request.redirect_count()))
+ return {};
+ auto navigable = navigable_of(*state);
+ if (!navigable)
return {};
state->transferred.set(request.redirect_count());
JsonObject result;
- result.set("parameters"sv, process_a_network_event(request, timing_info));
+ result.set("parameters"sv, process_a_network_event(*navigable, request, timing_info));
result.set("response"sv, get_the_response_data(response, timing_info));
result.set("postRedirectStartTime"sv, timing_info.post_redirect_start_time());
- result.set("timeOrigin"sv, request.client() ? JsonValue(request.client()->time_origin()) : JsonValue {});
+ auto const& client = request.client_snapshot();
+ result.set("timeOrigin"sv, client ? JsonValue(client->time_origin) : JsonValue {});
return result;
}
diff --git a/Libraries/LibWeb/WebDriver/BiDi/Network.h b/Libraries/LibWeb/WebDriver/BiDi/Network.h
index 2c9601fa902..2351e86ff24 100644
--- a/Libraries/LibWeb/WebDriver/BiDi/Network.h
+++ b/Libraries/LibWeb/WebDriver/BiDi/Network.h
@@ -12,9 +12,9 @@
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Utf16String.h>
-#include <LibGC/Weak.h>
#include <LibJS/Heap/Cell.h>
#include <LibWeb/Forward.h>
+#include <LibWebCommon/HTML/CrossProcessId.h>
namespace Web::WebDriver::BiDi {
@@ -26,8 +26,8 @@ class NetworkRequest final : public JS::Cell {
public:
String id;
- // NB: An observed request must not keep a navigable or its load-event delayer alive.
- GC::Weak<HTML::Navigable> navigable;
+ // The navigable the request's events go to.
+ Optional<HTML::CrossProcessId> navigable_id;
Optional<String> navigation;
HashTable<u8> before_request_sent;
HashTable<u8> response_started;
diff --git a/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Libraries/LibWeb/WebSockets/WebSocket.cpp
index dfd67e92356..a05ba5ba7ee 100644
--- a/Libraries/LibWeb/WebSockets/WebSocket.cpp
+++ b/Libraries/LibWeb/WebSockets/WebSocket.cpp
@@ -22,6 +22,7 @@
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/DOM/IDLEventListener.h>
#include <LibWeb/DOMURL/DOMURL.h>
+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/NetworkPartitionKey.h>
#include <LibWeb/Fetch/Infrastructure/PortBlocking.h>
@@ -197,6 +198,7 @@ ErrorOr<void> WebSocket::establish_web_socket_connection(URL::URL const& url_rec
// FIXME: Fetch request as per the remaining steps of https://websockets.spec.whatwg.org/#concept-websocket-establish
// AD-HOC: Until the opening handshake goes through fetch, run the blocking checks of main fetch here.
request->set_policy_container(client.policy_container()->clone());
+ request->set_client_snapshot(Fetch::Fetching::snapshot_client_context(client));
auto report_violation = ContentSecurityPolicy::violation_reporter_for_request(client.realm(), request);
ContentSecurityPolicy::report_content_security_policy_violations_for_request(request, report_violation);
UpgradeInsecureRequests::upgrade_request_to_a_potentially_trustworthy_url_if_appropriate(request);
diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cpp
index 47f89381f94..165125a7978 100644
--- a/Services/WebWorker/WorkerHost.cpp
+++ b/Services/WebWorker/WorkerHost.cpp
@@ -12,6 +12,7 @@
#include <LibWeb/Bindings/MessageEvent.h>
#include <LibWeb/Bindings/SharedWorkerGlobalScope.h>
#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>
#include <LibWeb/Fetch/Fetching/Fetching.h>
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
@@ -167,6 +168,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes
// 2. Set request's reserved client to inside settings.
request->set_reserved_client(GC::Ptr<Web::HTML::EnvironmentSettingsObject>(inside_settings));
+ request->set_reserved_client_snapshot(Web::Fetch::Fetching::snapshot_reserved_client_context(*inside_settings));
// NB: We need to store the process custom fetch response function on the heap here, because we're storing it
// in another heap function