LibWeb: Replace request's "window" with "traversable for user prompts"

User prompts are not tied to specific Windows or the client's Window.
They are tied to a traversable navigable (browser tab).
This commit is contained in:
Kenneth Myhra 2025-08-07 10:54:40 +02:00 committed by Sam Atkins
commit 70cafc558e
Notes: github-actions[bot] 2025-08-08 10:14:14 +00:00
5 changed files with 41 additions and 38 deletions

View file

@ -132,12 +132,12 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
// 9. If requests window is "client", then set requests window to requests client, if requests clients global
// object is a Window object; otherwise "no-window".
auto const* window = request.window().get_pointer<Infrastructure::Request::Window>();
if (window && *window == Infrastructure::Request::Window::Client) {
auto const* window = request.traversable_for_user_prompts().get_pointer<Infrastructure::Request::TraversableForUserPrompts>();
if (window && *window == Infrastructure::Request::TraversableForUserPrompts::Client) {
if (is<HTML::Window>(request.client()->global_object())) {
request.set_window(request.client());
request.set_traversable_for_user_prompts(request.client());
} else {
request.set_window(Infrastructure::Request::Window::NoWindow);
request.set_traversable_for_user_prompts(Infrastructure::Request::TraversableForUserPrompts::NoTraversable);
}
}
@ -153,7 +153,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
// - requests 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)
// - requests window is an environment settings object
&& request.window().has<GC::Ptr<HTML::EnvironmentSettingsObject>>()
&& request.traversable_for_user_prompts().has<GC::Ptr<HTML::EnvironmentSettingsObject>>()
// - requests method is `GET`
&& StringView { request.method() }.equals_ignoring_ascii_case("GET"sv)
// - requests unsafe-request flag is not set or requests header list is empty
@ -1707,10 +1707,10 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> http_network_or_cache_fetch(JS::Re
aborted = true;
};
// 1. If requests window is "no-window" and requests redirect mode is "error", then set httpFetchParams to
// fetchParams and httpRequest to request.
if (request->window().has<Infrastructure::Request::Window>()
&& request->window().get<Infrastructure::Request::Window>() == Infrastructure::Request::Window::NoWindow
// 1. If requests traversable for user prompts is "no-traversable" and requests redirect mode is "error",
// then set httpFetchParams to fetchParams and httpRequest to request.
if (request->traversable_for_user_prompts().has<Infrastructure::Request::TraversableForUserPrompts>()
&& request->traversable_for_user_prompts().get<Infrastructure::Request::TraversableForUserPrompts>() == Infrastructure::Request::TraversableForUserPrompts::NoTraversable
&& request->redirect_mode() == Infrastructure::Request::RedirectMode::Error) {
http_fetch_params = fetch_params;
http_request = request;
@ -2123,11 +2123,11 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> http_network_or_cache_fetch(JS::Re
auto inner_pending_response = PendingResponse::create(vm, request, *response);
// 14. If responses status is 401, httpRequests response tainting is not "cors", includeCredentials is true,
// and requests window is an environment settings object, then:
// and requests traversable for user prompts is a traversable navigable:
if (response->status() == 401
&& http_request->response_tainting() != Infrastructure::Request::ResponseTainting::CORS
&& include_credentials == IncludeCredentials::Yes
&& request->window().has<GC::Ptr<HTML::EnvironmentSettingsObject>>()
&& request->traversable_for_user_prompts().has<GC::Ptr<HTML::TraversableNavigable>>()
// AD-HOC: Require at least one WWW-Authenticate header to be set before automatically retrying an authenticated
// request (see rule 1 below). See: https://github.com/whatwg/fetch/issues/1766
&& request->header_list()->contains("WWW-Authenticate"sv.bytes())) {
@ -2181,9 +2181,9 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> http_network_or_cache_fetch(JS::Re
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'HTTP network-or-cache fetch' inner_pending_response load callback");
// 15. If responses status is 407, then:
if (response->status() == 407) {
// 1. If requests window is "no-window", then return a network error.
if (request->window().has<Infrastructure::Request::Window>()
&& request->window().get<Infrastructure::Request::Window>() == Infrastructure::Request::Window::NoWindow) {
// 1. If requests traversable for user prompts is "no-traversable", then return a network error.
if (request->traversable_for_user_prompts().has<Infrastructure::Request::TraversableForUserPrompts>()
&& request->traversable_for_user_prompts().get<Infrastructure::Request::TraversableForUserPrompts>() == Infrastructure::Request::TraversableForUserPrompts::NoTraversable) {
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "Request requires proxy authentication but has 'no-window' set"_string));
return;
}