LibWeb: Implement AO populate request from client

This commit is contained in:
Kenneth Myhra 2025-08-06 21:27:17 +02:00 committed by Sam Atkins
commit 593ee1ae0a
Notes: github-actions[bot] 2025-08-08 10:14:08 +00:00
2 changed files with 50 additions and 0 deletions

View file

@ -4,6 +4,7 @@
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
* Copyright (c) 2025, Kenneth Myhra <kennethmyhra@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -270,6 +271,54 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
return fetch_params->controller();
}
// https://fetch.spec.whatwg.org/#populate-request-from-client
void populate_request_from_client(JS::Realm const& realm, Infrastructure::Request& request)
{
auto& heap = realm.heap();
// 1. If requests 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) {
// 1. Set requests traversable for user prompts to "no-traversable".
request.set_traversable_for_user_prompts(Infrastructure::Request::TraversableForUserPrompts::NoTraversable);
// 2. If requests client is non-null:
if (request.client()) {
// 1. Let global be requests clients global object.
auto& global = request.client()->global_object();
// 2. If global is a Window object and globals navigable is not null, then set requests traversable for
// user prompts to globals navigables traversable navigable.
if (auto const* window = as_if<HTML::Window>(global)) {
if (window->navigable())
request.set_traversable_for_user_prompts(window->navigable()->traversable_navigable());
}
}
}
// 2. If requests origin is "client":
auto const* origin = request.origin().get_pointer<Infrastructure::Request::Origin>();
if (origin && *origin == Infrastructure::Request::Origin::Client) {
// 1. Assert: requests client is non-null.
VERIFY(request.client());
// 2. Set requests origin to requests clients origin.
request.set_origin(request.client()->origin());
}
// 3. If requests policy container is "client":
auto const* policy_container = request.policy_container().get_pointer<Infrastructure::Request::PolicyContainer>();
if (policy_container && *policy_container == Infrastructure::Request::PolicyContainer::Client) {
// 1. If requests client is non-null, then set requests policy container to a clone of requests clients
// policy container.
if (request.client())
request.set_policy_container(request.client()->policy_container()->clone(heap));
// 2. Otherwise, set requests policy container to a new policy container.
else
request.set_policy_container(heap.allocate<HTML::PolicyContainer>(heap));
}
}
// https://fetch.spec.whatwg.org/#concept-main-fetch
WebIDL::ExceptionOr<GC::Ptr<PendingResponse>> main_fetch(JS::Realm& realm, Infrastructure::FetchParams const& fetch_params, Recursive recursive)
{