diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 4c53deb285daac..7e92e7860d79ac 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -4174,8 +4174,10 @@ void Document::restore_the_history_object_state(JS::NonnullGCPtr entry, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional>> entries_for_navigation_api, bool update_navigation_api) +void Document::update_for_history_step_application(JS::NonnullGCPtr entry, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional navigation_type, Optional>> entries_for_navigation_api, Optional> previous_entry_for_activation, bool update_navigation_api) { + (void)previous_entry_for_activation; + // 1. Let documentIsNew be true if document's latest entry is null; otherwise false. auto document_is_new = !m_latest_entry; @@ -4188,7 +4190,10 @@ void Document::update_for_history_step_application(JS::NonnullGCPtrm_length = script_history_length; - // 5. If documentsEntryChanged is true, then: + // 5. Let navigation be history's relevant global object's navigation API. + auto navigation = verify_cast(HTML::relevant_global_object(*this)).navigation(); + + // 6. If documentsEntryChanged is true, then: // NOTE: documentsEntryChanged can be false for one of two reasons: either we are restoring from bfcache, // or we are asynchronously finishing up a synchronous navigation which already synchronously set document's latest entry. // The doNotReactivate argument distinguishes between these two cases. @@ -4202,21 +4207,21 @@ void Document::update_for_history_step_application(JS::NonnullGCPtr(HTML::relevant_global_object(*this)).navigation(); - - // 5. If documentIsNew is false, then: + // 4. If documentIsNew is false, then: if (!document_is_new) { // NOTE: Not in the spec, but otherwise document's url won't be updated in case of a same-document back/forward navigation. set_url(entry->url()); + // 1. Assert: navigationType is not null. + VERIFY(navigation_type.has_value()); + // AD HOC: Skip this in situations the spec steps don't account for if (update_navigation_api) { - // 1. Update the navigation API entries for a same-document navigation given navigation, entry, and "traverse". - navigation->update_the_navigation_api_entries_for_a_same_document_navigation(entry, Bindings::NavigationType::Traverse); + // 2. Update the navigation API entries for a same-document navigation given navigation, entry, and navigationType. + navigation->update_the_navigation_api_entries_for_a_same_document_navigation(entry, navigation_type.value()); } - // 2. Fire an event named popstate at document's relevant global object, using PopStateEvent, + // 3. Fire an event named popstate at document's relevant global object, using PopStateEvent, // with the state attribute initialized to document's history object's state and hasUAVisualTransition initialized to true // if a visual transition, to display a cached rendered state of the latest entry, was done by the user agent. // FIXME: Initialise hasUAVisualTransition @@ -4226,9 +4231,9 @@ void Document::update_for_history_step_application(JS::NonnullGCPtr #include #include +#include #include #include #include @@ -593,7 +594,7 @@ class Document HTML::SourceSnapshotParams snapshot_source_snapshot_params() const; - void update_for_history_step_application(JS::NonnullGCPtr, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional>> entries_for_navigation_api = {}, bool update_navigation_api = true); + void update_for_history_step_application(JS::NonnullGCPtr, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional navigation_type, Optional>> entries_for_navigation_api = {}, Optional> previous_entry_for_activation = {}, bool update_navigation_api = true); HashMap>& shared_image_requests(); diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index 2270f034cac2f7..1ad33d5c61d532 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -1525,7 +1525,7 @@ WebIDL::ExceptionOr Navigable::navigate_to_a_fragment(URL::URL const& url, // 13. Update document for history step application given navigable's active document, historyEntry, true, scriptHistoryIndex, and scriptHistoryLength. // AD HOC: Skip updating the navigation api entries twice here - active_document()->update_for_history_step_application(*history_entry, true, script_history_length, script_history_index, {}, false); + active_document()->update_for_history_step_application(*history_entry, true, script_history_length, script_history_index, navigation_type, {}, {}, false); // 14. Update the navigation API entries for a same-document navigation given navigation, historyEntry, and historyHandling. navigation->update_the_navigation_api_entries_for_a_same_document_navigation(history_entry, navigation_type); diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index aec597347a7683..8147dca21c83e9 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -689,7 +689,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ bool const update_only = changing_navigable_continuation->update_only; JS::GCPtr const target_entry = changing_navigable_continuation->target_entry; bool const populated_cloned_target_session_history_entry = changing_navigable_continuation->populated_cloned_target_session_history_entry; - auto after_potential_unload = JS::create_heap_function(this->heap(), [navigable, update_only, target_entry, populated_target_entry, populated_cloned_target_session_history_entry, displayed_document, &completed_change_jobs, script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), &heap = this->heap()] { + auto after_potential_unload = JS::create_heap_function(this->heap(), [navigable, update_only, target_entry, populated_target_entry, populated_cloned_target_session_history_entry, displayed_document, &completed_change_jobs, script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), &heap = this->heap(), navigation_type] { if (populated_cloned_target_session_history_entry) { target_entry->set_document_state(populated_target_entry->document_state()); target_entry->set_url(populated_target_entry->url()); @@ -703,8 +703,8 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // 2. Let updateDocument be an algorithm step which performs update document for history step application given // targetEntry's document, targetEntry, changingNavigableContinuation's update-only, scriptHistoryLength, // scriptHistoryIndex, navigationType, entriesForNavigationAPI, and displayedEntry. - auto update_document = [script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), target_entry, update_only] { - target_entry->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, entries_for_navigation_api); + auto update_document = [script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), target_entry, update_only, navigation_type] { + target_entry->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, navigation_type, entries_for_navigation_api); }; // 3. If targetEntry's document is equal to displayedDocument, then perform updateDocument.