LibWeb: Look into nested session histories to find max history step

Fixes bug when "navigate forward" button in UI is disabled after
performing following steps:
1. Load page with an iframe (top step = 0, iframe step = 0)
2. Navigate iframe to different document (top step = 0, iframe step = 1)
3. Navigate back from browser UI (top step = 0, iframe step = 0)

No test because change is only observable from browser UI.
This commit is contained in:
Aliaksandr Kalenik 2024-04-16 12:18:48 +02:00 committed by Alexander Kalenik
commit 9f4b922f1c
Notes: sideshowbarker 2024-07-17 00:57:24 +09:00
2 changed files with 25 additions and 1 deletions

View file

@ -784,7 +784,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
// Not in the spec:
auto back_enabled = m_current_session_history_step > 0;
VERIFY(m_session_history_entries.size() > 0);
auto forward_enabled = m_current_session_history_step < static_cast<int>(m_session_history_entries.size()) - 1;
auto forward_enabled = can_go_forward();
page().client().page_did_update_navigation_buttons_state(back_enabled, forward_enabled);
page().client().page_did_change_url(current_session_history_entry()->url());
@ -895,6 +895,28 @@ void TraversableNavigable::clear_the_forward_session_history()
}
}
bool TraversableNavigable::can_go_forward() const
{
auto step = current_session_history_step();
Vector<Vector<JS::NonnullGCPtr<SessionHistoryEntry>> const&> entry_lists;
entry_lists.append(session_history_entries());
while (!entry_lists.is_empty()) {
auto const& entry_list = entry_lists.take_first();
for (auto const& entry : entry_list) {
if (entry->step().template get<int>() > step)
return true;
for (auto& nested_history : entry->document_state()->nested_histories())
entry_lists.append(nested_history.entries);
}
}
return false;
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#traverse-the-history-by-a-delta
void TraversableNavigable::traverse_the_history_by_delta(int delta, Optional<DOM::Document&> source_document)
{