diff options
author | Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> | 2023-04-06 12:24:09 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-08 17:53:59 +0200 |
commit | 0444df1a7c951df17c0e4f581718df16ecba98c2 (patch) | |
tree | f9ed171a1adc5d10491ec2062cd2ba1bacfd2f77 | |
parent | 1ebae7a779a4dfabaeb836b6b44f1b3c5ed896c1 (diff) | |
download | serenity-0444df1a7c951df17c0e4f581718df16ecba98c2.zip |
LibWeb: Implement "clear the forward session history" for traversable
https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp | 31 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/TraversableNavigable.h | 1 |
2 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index 6cd0efefe7..4322ee43a5 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -149,4 +149,35 @@ Vector<int> TraversableNavigable::get_all_used_history_steps() const return sorted_steps; } +// https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history +void TraversableNavigable::clear_the_forward_session_history() +{ + // FIXME: 1. Assert: this is running within navigable's session history traversal queue. + + // 2. Let step be the navigable's current session history step. + auto step = current_session_history_step(); + + // 3. Let entryLists be the ordered set ยซ navigable's session history entries ยป. + Vector<Vector<JS::NonnullGCPtr<SessionHistoryEntry>>&> entry_lists; + entry_lists.append(session_history_entries()); + + // 4. For each entryList of entryLists: + while (!entry_lists.is_empty()) { + auto& entry_list = entry_lists.take_first(); + + // 1. Remove every session history entry from entryList that has a step greater than step. + entry_list.remove_all_matching([step](auto& entry) { + return entry->step.template get<int>() > step; + }); + + // 2. For each entry of entryList: + for (auto& entry : entry_list) { + // 1. For each nestedHistory of entry's document state's nested histories, append nestedHistory's entries list to entryLists. + for (auto& nested_history : entry->document_state->nested_histories()) { + entry_lists.append(nested_history.entries); + } + } + } +} + } diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h index 80b2c685d9..cbfad5964f 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.h @@ -31,6 +31,7 @@ public: VisibilityState system_visibility_state() const { return m_system_visibility_state; }; Vector<int> get_all_used_history_steps() const; + void clear_the_forward_session_history(); private: TraversableNavigable(); |