From 0f8ae12d4421c8760afe292fef91540aabf7ba89 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 22 Sep 2023 19:31:58 -0600 Subject: [PATCH] LibWeb: Implement fire a download request navigate event --- Userland/Libraries/LibWeb/HTML/Navigation.cpp | 31 +++++++++++++++++++ Userland/Libraries/LibWeb/HTML/Navigation.h | 1 + 2 files changed, 32 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.cpp b/Userland/Libraries/LibWeb/HTML/Navigation.cpp index 2f7e535cfe..121354475b 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigation.cpp @@ -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), {}); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.h b/Userland/Libraries/LibWeb/HTML/Navigation.h index d39f08e7f2..3952256ee8 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.h +++ b/Userland/Libraries/LibWeb/HTML/Navigation.h @@ -118,6 +118,7 @@ public: Optional&> form_data_entry_list = {}, Optional navigation_api_state = {}, Optional classic_history_api_state = {}); + bool fire_a_download_request_navigate_event(AK::URL destination_url, UserNavigationInvolvement user_involvement, String filename); virtual ~Navigation() override;