1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:17:35 +00:00

Browser: Simplify the History class and fix back/forward history push

This code was previously relying on the PageView::on_load_start hook
firing synchronously when calling PageView::load(). This was not
happening with WebContentView, so it broke the back/forward history.

Instead, we now differentiate between history navigations and normal
loads in Tab::load(). History navigations don't push new entries into
history, but instead just move the history pointer.
This commit is contained in:
Andreas Kling 2020-07-07 15:04:05 +02:00
parent b5e04cb070
commit 1493dd9dc6
5 changed files with 119 additions and 76 deletions

View file

@ -88,36 +88,14 @@ Tab::Tab(Type type)
else
m_web_content_view = widget.add<WebContentView>();
m_go_back_action = GUI::CommonActions::make_go_back_action([this](auto&) {
m_history.go_back();
update_actions();
TemporaryChange<bool> change(m_should_push_loads_to_history, false);
load(m_history.current());
},
this);
m_go_forward_action = GUI::CommonActions::make_go_forward_action([this](auto&) {
m_history.go_forward();
update_actions();
TemporaryChange<bool> change(m_should_push_loads_to_history, false);
load(m_history.current());
},
this);
m_go_back_action = GUI::CommonActions::make_go_back_action( [this](auto&) { go_back(); }, this);
m_go_forward_action = GUI::CommonActions::make_go_forward_action([this](auto&) { go_forward(); }, this);
toolbar.add_action(*m_go_back_action);
toolbar.add_action(*m_go_forward_action);
toolbar.add_action(GUI::CommonActions::make_go_home_action([this](auto&) {
load(g_home_url);
},
this));
m_reload_action = GUI::CommonActions::make_reload_action(
[this](auto&) {
TemporaryChange<bool> change(m_should_push_loads_to_history, false);
reload();
},
this);
toolbar.add_action(GUI::CommonActions::make_go_home_action([this](auto&) { load(g_home_url); }, this));
m_reload_action = GUI::CommonActions::make_reload_action( [this](auto&) { reload(); }, this);
toolbar.add_action(*m_reload_action);
@ -155,8 +133,6 @@ Tab::Tab(Type type)
hooks().on_load_start = [this](auto& url) {
m_location_box->set_icon(nullptr);
m_location_box->set_text(url.to_string());
if (m_should_push_loads_to_history)
m_history.push(url);
update_actions();
update_bookmark_button(url.to_string());
};
@ -369,6 +345,9 @@ Tab::Tab(Type type)
}
},
this));
debug_menu.add_action(GUI::Action::create("Dump history", { Mod_Ctrl, Key_H }, [&](auto&) {
m_history.dump();
}));
debug_menu.add_separator();
auto line_box_borders_action = GUI::Action::create_checkable(
"Line box borders", [this](auto& action) {
@ -413,8 +392,11 @@ Tab::~Tab()
{
}
void Tab::load(const URL& url)
void Tab::load(const URL& url, LoadType load_type)
{
if (load_type == LoadType::Normal)
m_history.push(url);
if (m_type == Type::InProcessWebView)
m_page_view->load(url);
else
@ -433,6 +415,20 @@ void Tab::reload()
load(url());
}
void Tab::go_back()
{
m_history.go_back();
update_actions();
load(m_history.current(), LoadType::HistoryNavigation);
}
void Tab::go_forward()
{
m_history.go_forward();
update_actions();
load(m_history.current(), LoadType::HistoryNavigation);
}
void Tab::update_actions()
{
m_go_back_action->set_enabled(m_history.can_go_back());
@ -497,5 +493,6 @@ Web::WebViewHooks& Tab::hooks()
{
if (m_type == Type::InProcessWebView)
return *m_page_view;
return *m_web_content_view;}
return *m_web_content_view;
}
}