diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index 03f590b337d..b648577a340 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -190,6 +190,38 @@ int TraversableNavigable::get_the_used_step(int step) const return result.value(); } +// https://html.spec.whatwg.org/multipage/browsing-the-web.html#get-all-navigables-whose-current-session-history-entry-will-change-or-reload +Vector> TraversableNavigable::get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int target_step) const +{ + // 1. Let results be an empty list. + Vector> results; + + // 2. Let navigablesToCheck be « traversable ». + Vector> navigables_to_check; + navigables_to_check.append(const_cast(*this)); + + // 3. For each navigable of navigablesToCheck: + while (!navigables_to_check.is_empty()) { + auto navigable = navigables_to_check.take_first(); + + // 1. Let targetEntry be the result of getting the target history entry given navigable and targetStep. + auto target_entry = navigable->get_the_target_history_entry(target_step); + + // 2. If targetEntry is not navigable's current session history entry or targetEntry's document state's reload pending is true, then append navigable to results. + if (target_entry != navigable->current_session_history_entry() || target_entry->document_state->reload_pending()) { + results.append(*navigable); + } + + // 3. If targetEntry's document is navigable's document, and targetEntry's document state's reload pending is false, then extend navigablesToCheck with the child navigables of navigable. + if (target_entry->document_state->document() == navigable->active_document() && !target_entry->document_state->reload_pending()) { + navigables_to_check.extend(navigable->child_navigables()); + } + } + + // 4. Return results. + return results; +} + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history void TraversableNavigable::clear_the_forward_session_history() { diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h index 74ee782fb10..66fa313a181 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h @@ -37,6 +37,7 @@ public: HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const; int get_the_used_step(int step) const; + Vector> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const; Vector get_all_used_history_steps() const; void clear_the_forward_session_history();