LibWeb: Implement fire a download request navigate event

This commit is contained in:
Andrew Kaster 2023-09-22 19:31:58 -06:00 committed by Alexander Kalenik
parent 67bc3629a9
commit 0f8ae12d44
Notes: sideshowbarker 2024-07-17 08:43:11 +09:00
2 changed files with 32 additions and 0 deletions

View File

@ -1294,4 +1294,35 @@ bool Navigation::fire_a_push_replace_reload_navigate_event(
return inner_navigate_event_firing_algorithm(navigation_type, destination, user_involvement, move(form_data_entry_list), {}, move(classic_history_api_state));
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#fire-a-download-request-navigate-event
bool Navigation::fire_a_download_request_navigate_event(AK::URL destination_url, UserNavigationInvolvement user_involvement, String filename)
{
auto& realm = relevant_realm(*this);
auto& vm = this->vm();
// 1. Let event be the result of creating an event given NavigateEvent, in navigation's relevant realm.
// 2. Set event's classic history API state to classicHistoryAPIState.
// AD-HOC: These are handled in the inner algorithm
// 3. Let destination be a new NavigationDestination created in navigation's relevant realm.
auto destination = NavigationDestination::create(realm);
// 4. Set destination's URL to destinationURL.
destination->set_url(destination_url);
// 5. Set destination's entry to null.
destination->set_entry(nullptr);
// 6. Set destination's state to StructuredSerializeForStorage(null).
destination->set_state(MUST(structured_serialize_for_storage(vm, JS::js_null())));
// 7. Set destination's is same document to false.
destination->set_is_same_document(false);
// 8. Return the result of performing the inner navigate event firing algorithm given navigation,
// "push", event, destination, userInvolvement, null, and filename.
// AD-HOC: We don't pass the event, but we do pass the classic_history_api state at the end to be set later
return inner_navigate_event_firing_algorithm(Bindings::NavigationType::Push, destination, user_involvement, {}, move(filename), {});
}
}

View File

@ -118,6 +118,7 @@ public:
Optional<Vector<XHR::FormDataEntry>&> form_data_entry_list = {},
Optional<SerializationRecord> navigation_api_state = {},
Optional<SerializationRecord> classic_history_api_state = {});
bool fire_a_download_request_navigate_event(AK::URL destination_url, UserNavigationInvolvement user_involvement, String filename);
virtual ~Navigation() override;