LibWeb: Give NavigationParams a constructor

This allows for NavigationParams to hold non-default constructable
types.
This commit is contained in:
Shannon Booth 2025-06-15 14:33:29 +12:00 committed by Jelle Raaijmakers
commit 0d905b1846
Notes: github-actions[bot] 2025-06-17 18:55:41 +00:00
4 changed files with 107 additions and 66 deletions

View file

@ -57,21 +57,21 @@ GC::Ref<DOM::Document> create_document_for_inline_content(GC::Ptr<HTML::Navigabl
// user involvement: userInvolvement
auto response = Fetch::Infrastructure::Response::create(vm);
response->url_list().append(URL::about_error()); // AD-HOC: https://github.com/whatwg/html/issues/9122
auto navigation_params = vm.heap().allocate<HTML::NavigationParams>();
navigation_params->id = move(navigation_id);
navigation_params->navigable = navigable;
navigation_params->request = nullptr;
navigation_params->response = response;
navigation_params->fetch_controller = nullptr;
navigation_params->commit_early_hints = nullptr;
navigation_params->coop_enforcement_result = move(coop_enforcement_result);
navigation_params->reserved_environment = {};
navigation_params->origin = move(origin);
navigation_params->policy_container = vm.heap().allocate<HTML::PolicyContainer>(vm.heap());
navigation_params->final_sandboxing_flag_set = HTML::SandboxingFlagSet {};
navigation_params->opener_policy = move(coop);
navigation_params->about_base_url = {};
navigation_params->user_involvement = user_involvement;
auto navigation_params = vm.heap().allocate<HTML::NavigationParams>(
move(navigation_id),
navigable,
nullptr,
response,
nullptr,
nullptr,
move(coop_enforcement_result),
nullptr,
move(origin),
vm.heap().allocate<HTML::PolicyContainer>(vm.heap()),
HTML::SandboxingFlagSet {},
move(coop),
OptionalNone {},
user_involvement);
// 5. Let document be the result of creating and initializing a Document object given "html", "text/html", and navigationParams.
auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors();

View file

@ -751,19 +751,21 @@ static GC::Ref<NavigationParams> create_navigation_params_from_a_srcdoc_resource
// FIXME: navigation timing type: navTimingType
// about base URL: entry's document state's about base URL
// user involvement: userInvolvement
auto navigation_params = vm.heap().allocate<NavigationParams>();
navigation_params->id = move(navigation_id);
navigation_params->navigable = navigable;
navigation_params->response = response;
navigation_params->coop_enforcement_result = move(coop_enforcement_result);
navigation_params->origin = move(response_origin);
navigation_params->policy_container = *policy_container;
navigation_params->final_sandboxing_flag_set = target_snapshot_params.sandboxing_flags;
navigation_params->opener_policy = move(coop);
navigation_params->about_base_url = entry->document_state()->about_base_url();
navigation_params->user_involvement = user_involvement;
return navigation_params;
return vm.heap().allocate<NavigationParams>(
move(navigation_id),
navigable,
nullptr,
response,
nullptr,
nullptr,
move(coop_enforcement_result),
nullptr,
move(response_origin),
*policy_container,
target_snapshot_params.sandboxing_flags,
move(coop),
entry->document_state()->about_base_url(),
user_involvement);
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching
@ -1165,22 +1167,21 @@ static WebIDL::ExceptionOr<Navigable::NavigationParamsVariant> create_navigation
// FIXME: navigation timing type: navTimingType
// about base URL: entry's document state's about base URL
// user involvement: userInvolvement
auto navigation_params = vm.heap().allocate<NavigationParams>();
navigation_params->id = navigation_id;
navigation_params->navigable = navigable;
navigation_params->request = request;
navigation_params->response = *response_holder->response();
navigation_params->fetch_controller = fetch_controller;
navigation_params->commit_early_hints = move(commit_early_hints);
navigation_params->coop_enforcement_result = coop_enforcement_result;
navigation_params->reserved_environment = request->reserved_client();
navigation_params->origin = *response_origin;
navigation_params->policy_container = result_policy_container;
navigation_params->final_sandboxing_flag_set = final_sandbox_flags;
navigation_params->opener_policy = response_coop;
navigation_params->about_base_url = entry->document_state()->about_base_url();
navigation_params->user_involvement = user_involvement;
return navigation_params;
return vm.heap().allocate<NavigationParams>(
navigation_id,
navigable,
request,
*response_holder->response(),
fetch_controller,
move(commit_early_hints),
coop_enforcement_result,
request->reserved_client(),
*response_origin,
result_policy_container,
final_sandbox_flags,
response_coop,
entry->document_state()->about_base_url(),
user_involvement);
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#attempt-to-populate-the-history-entry's-document
@ -1891,21 +1892,21 @@ GC::Ptr<DOM::Document> Navigable::evaluate_javascript_url(URL::URL const& url, U
// FIXME: navigation timing type: "navigate"
// about base URL: targetNavigable's active document's about base URL
// user involvement: userInvolvement
auto navigation_params = vm.heap().allocate<NavigationParams>();
navigation_params->id = navigation_id;
navigation_params->navigable = this;
navigation_params->request = {};
navigation_params->response = response;
navigation_params->fetch_controller = nullptr;
navigation_params->commit_early_hints = nullptr;
navigation_params->coop_enforcement_result = move(coop_enforcement_result);
navigation_params->reserved_environment = {};
navigation_params->origin = new_document_origin;
navigation_params->policy_container = policy_container;
navigation_params->final_sandboxing_flag_set = final_sandbox_flags;
navigation_params->opener_policy = coop;
navigation_params->about_base_url = active_document()->about_base_url();
navigation_params->user_involvement = user_involvement;
auto navigation_params = vm.heap().allocate<NavigationParams>(
navigation_id,
this,
nullptr,
response,
nullptr,
nullptr,
move(coop_enforcement_result),
nullptr,
new_document_origin,
policy_container,
final_sandbox_flags,
coop,
active_document()->about_base_url(),
user_involvement);
// 17. Return the result of loading an HTML document given navigationParams.
return load_document(navigation_params);

View file

@ -76,7 +76,40 @@ struct NavigationParams : GC::Cell {
// a user navigation involvement used when obtaining a browsing context for the new Document
UserNavigationInvolvement user_involvement;
protected:
void visit_edges(Visitor& visitor) override;
NavigationParams(
Optional<String> id,
GC::Ptr<Navigable> navigable,
GC::Ptr<Fetch::Infrastructure::Request> request,
GC::Ptr<Fetch::Infrastructure::Response> response,
GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller,
Function<void(DOM::Document&)> commit_early_hints,
OpenerPolicyEnforcementResult coop_enforcement_result,
Fetch::Infrastructure::Request::ReservedClientType reserved_environment,
URL::Origin origin,
GC::Ptr<PolicyContainer> policy_container,
SandboxingFlagSet final_sandboxing_flag_set,
OpenerPolicy opener_policy,
Optional<URL::URL> about_base_url,
UserNavigationInvolvement user_involvement)
: id(move(id))
, navigable(navigable)
, request(request)
, response(response)
, fetch_controller(fetch_controller)
, commit_early_hints(move(commit_early_hints))
, coop_enforcement_result(move(coop_enforcement_result))
, reserved_environment(reserved_environment)
, origin(move(origin))
, policy_container(policy_container)
, final_sandboxing_flag_set(final_sandboxing_flag_set)
, opener_policy(opener_policy)
, about_base_url(move(about_base_url))
, user_involvement(user_involvement)
{
}
};
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#non-fetch-scheme-navigation-params

View file

@ -37,13 +37,20 @@ ErrorOr<GC::Ref<SVGDecodedImageData>> SVGDecodedImageData::create(JS::Realm& rea
GC::Ref<HTML::Navigable> navigable = page->top_level_traversable();
auto response = Fetch::Infrastructure::Response::create(navigable->vm());
response->url_list().append(url);
auto navigation_params = navigable->heap().allocate<HTML::NavigationParams>();
navigation_params->navigable = navigable;
navigation_params->response = response;
navigation_params->origin = URL::Origin {};
navigation_params->policy_container = navigable->heap().allocate<HTML::PolicyContainer>(realm.heap());
navigation_params->final_sandboxing_flag_set = HTML::SandboxingFlagSet {};
navigation_params->opener_policy = HTML::OpenerPolicy {};
auto navigation_params = navigable->heap().allocate<HTML::NavigationParams>(OptionalNone {},
navigable,
nullptr,
response,
nullptr,
nullptr,
HTML::OpenerPolicyEnforcementResult {},
nullptr,
URL::Origin {},
navigable->heap().allocate<HTML::PolicyContainer>(realm.heap()),
HTML::SandboxingFlagSet {},
HTML::OpenerPolicy {},
OptionalNone {},
HTML::UserNavigationInvolvement::None);
// FIXME: Use Navigable::navigate() instead of manually replacing the navigable's document.
auto document = MUST(DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params));