Browser: Replace history entry if loading URL because of a redirect

We now replace the current history entry if the page-load has been
caused because of a redirect. This makes it able to traverse the
history if one of the entries redirects you, which previously
caused an infinite history traversion loop.
This commit is contained in:
Baitinq 2022-11-24 01:18:11 +01:00 committed by Andreas Kling
parent b447e486b5
commit f1205b608f
Notes: sideshowbarker 2024-07-17 04:21:32 +09:00
3 changed files with 11 additions and 5 deletions

View file

@ -202,10 +202,16 @@ Tab::Tab(BrowserWindow& window)
m_bookmark_button->set_icon(g_icon_bag.bookmark_contour);
m_bookmark_button->set_fixed_size(22, 22);
view().on_load_start = [this](auto& url) {
view().on_load_start = [this](auto& url, bool is_redirect) {
m_navigating_url = url;
m_loaded = false;
// If we are loading due to a redirect, we replace the current history entry
// with the loaded URL
if (is_redirect) {
m_history.replace_current(url, title());
}
update_status();
m_location_box->set_icon(nullptr);

View file

@ -298,11 +298,11 @@ void OutOfProcessWebView::notify_server_did_middle_click_link(Badge<WebContentCl
on_link_middle_click(url, target, modifiers);
}
void OutOfProcessWebView::notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL& url, bool)
void OutOfProcessWebView::notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL& url, bool is_redirect)
{
m_url = url;
if (on_load_start)
on_load_start(url);
on_load_start(url, is_redirect);
}
void OutOfProcessWebView::notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL& url)

View file

@ -86,7 +86,7 @@ public:
Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_middle_click;
Function<void(const AK::URL&)> on_link_hover;
Function<void(String const&)> on_title_change;
Function<void(const AK::URL&)> on_load_start;
Function<void(const AK::URL&, bool)> on_load_start;
Function<void(const AK::URL&)> on_load_finish;
Function<void()> on_navigate_back;
Function<void()> on_navigate_forward;
@ -151,7 +151,7 @@ private:
virtual void notify_server_did_unhover_link(Badge<WebContentClient>) override;
virtual void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers) override;
virtual void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers) override;
virtual void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&, bool is_redirect) override;
virtual void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&, bool) override;
virtual void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&) override;
virtual void notify_server_did_request_navigate_back(Badge<WebContentClient>) override;
virtual void notify_server_did_request_navigate_forward(Badge<WebContentClient>) override;