Truly independent web browser
LibWebView+UI/Qt: Add a “Reload Without Cache” action
sideshowbarkerb7b781e8de04
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cppindex c49f00db752..dec319faf69 100644--- a/Libraries/LibWebView/Application.cpp+++ b/Libraries/LibWebView/Application.cpp@@ -2511,6 +2511,10 @@ void Application::initialize_actions()if (auto view = active_web_view(); view.has_value())view->reload();});+ m_reload_bypassing_cache_action = Action::create("Reload Without Cache"sv, ActionID::ReloadBypassingCache, [this]() {+ if (auto view = active_web_view(); view.has_value())+ view->reload(BypassCache::Yes);+ });m_undo_action = Action::create("Undo"sv, ActionID::Undo, [this]() {if (auto view = active_web_view(); view.has_value())diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.hindex fcdc09247d8..97855467bf8 100644--- a/Libraries/LibWebView/Application.h+++ b/Libraries/LibWebView/Application.h@@ -348,6 +348,7 @@ public:NonnullRefPtr<Core::Promise<Empty>> clear_browsing_data(ClearBrowsingDataOptions const&);Action& reload_action() { return *m_reload_action; }+ Action& reload_bypassing_cache_action() { return *m_reload_bypassing_cache_action; }Action& copy_selection_action() { return *m_copy_selection_action; }Action& undo_action() { return *m_undo_action; }Action& redo_action() { return *m_redo_action; }@@ -670,6 +671,7 @@ private:OwnPtr<ProcessManager> m_process_manager;RefPtr<Action> m_reload_action;+ RefPtr<Action> m_reload_bypassing_cache_action;RefPtr<Action> m_copy_selection_action;RefPtr<Action> m_undo_action;RefPtr<Action> m_redo_action;diff --git a/Libraries/LibWebView/Menu.h b/Libraries/LibWebView/Menu.hindex 9b944dd0764..8f31943d603 100644--- a/Libraries/LibWebView/Menu.h+++ b/Libraries/LibWebView/Menu.h@@ -28,6 +28,7 @@ enum class ActionID {NavigateBack,NavigateForward,Reload,+ ReloadBypassingCache,ViewDownloads,ViewHistory,ClearBrowsingData,diff --git a/UI/Qt/Menu.cpp b/UI/Qt/Menu.cppindex 066f6a8a8e9..123e5759eeb 100644--- a/UI/Qt/Menu.cpp+++ b/UI/Qt/Menu.cpp@@ -111,7 +111,7 @@ private:action->set_checked(checked);action->activate();- if (first_is_one_of(action->id(), WebView::ActionID::BookmarkItem, WebView::ActionID::Reload)) {+ if (first_is_one_of(action->id(), WebView::ActionID::BookmarkItem, WebView::ActionID::Reload, WebView::ActionID::ReloadBypassingCache)) {if (auto* active_tab = Application::the().active_tab())active_tab->view().setFocus();}@@ -176,6 +176,13 @@ static void initialize_native_control(WebView::Action& action, QAction& qaction,qaction.setIcon(create_chrome_icon(ChromeIcon::Reload, palette));qaction.setShortcuts({ QKeySequence(Qt::CTRL | Qt::Key_R), QKeySequence(Qt::Key_F5) });break;+ case WebView::ActionID::ReloadBypassingCache:+#if defined(AK_OS_MACOS)+ qaction.setShortcuts({ QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_R), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_R) });+#else+ qaction.setShortcuts({ QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_R), QKeySequence(Qt::CTRL | Qt::Key_F5) });+#endif+ break;case WebView::ActionID::ViewDownloads:if (include_action_icon == IncludeActionIcon::Yes)qaction.setIcon(create_chrome_icon(ChromeIcon::Download, palette));diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cppindex d441c4d40a4..458ab658058 100644--- a/UI/Qt/Tab.cpp+++ b/UI/Qt/Tab.cpp@@ -141,9 +141,10 @@ public:});}- void set_actions(QAction& reload_action, QAction& stop_action)+ void set_actions(QAction& reload_action, QAction& reload_bypassing_cache_action, QAction& stop_action){m_reload_action = &reload_action;+ m_reload_bypassing_cache_action = &reload_bypassing_cache_action;m_stop_action = &stop_action;}@@ -159,6 +160,17 @@ protected:change_mode(m_intended_mode, ForceChange::Yes);}+ // A Shift-click on the reload button reloads bypassing the HTTP cache, and one on the stop button stops the load as+ // any other click there does. QToolButton triggers its default action from here, once a click has completed.+ virtual void nextCheckState() override+ {+ if (m_visible_mode == Mode::Reload && QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {+ m_reload_bypassing_cache_action->trigger();+ return;+ }+ ToolbarButton::nextCheckState();+ }+private:static constexpr int STOP_TO_RELOAD_DELAY_MS = 1000;@@ -190,6 +202,7 @@ private:}QAction* m_reload_action { nullptr };+ QAction* m_reload_bypassing_cache_action { nullptr };QAction* m_stop_action { nullptr };Mode m_visible_mode { Mode::Reload };Mode m_intended_mode { Mode::Reload };@@ -798,6 +811,8 @@ void Tab::initialize(Optional<WebView::CanonicalTraversable&> traversable)m_navigate_back_action = create_application_action(*this, view().navigate_back_action());m_navigate_forward_action = create_application_action(*this, view().navigate_forward_action());m_reload_action = create_application_action(*this, application.reload_action());+ m_reload_bypassing_cache_action = create_application_action(*this, application.reload_bypassing_cache_action());+ addAction(m_reload_bypassing_cache_action);m_stop_action = new QAction("Stop", this);m_stop_action->setToolTip("Stop loading this page");QObject::connect(m_stop_action, &QAction::triggered, this, [this] {@@ -899,7 +914,7 @@ void Tab::initialize(Optional<WebView::CanonicalTraversable&> traversable)navigation_button_layout->addWidget(create_navigation_history_toolbar_button(*navigation_button_cluster, *m_navigate_back_action, -1));navigation_button_layout->addWidget(create_navigation_history_toolbar_button(*navigation_button_cluster, *m_navigate_forward_action, 1));m_reload_button = create_toolbar_button<ReloadButton>(*navigation_button_cluster, *m_reload_action);- m_reload_button->set_actions(*m_reload_action, *m_stop_action);+ m_reload_button->set_actions(*m_reload_action, *m_reload_bypassing_cache_action, *m_stop_action);navigation_button_layout->addWidget(m_reload_button);auto* location_edit_container = new QWidget(m_toolbar);diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.hindex 19f2565a5c1..b1f52ac8b08 100644--- a/UI/Qt/Tab.h+++ b/UI/Qt/Tab.h@@ -296,6 +296,7 @@ private:QAction* m_navigate_back_action { nullptr };QAction* m_navigate_forward_action { nullptr };QAction* m_reload_action { nullptr };+ QAction* m_reload_bypassing_cache_action { nullptr };QAction* m_stop_action { nullptr };ReloadButton* m_reload_button { nullptr };QAction* m_open_downloads_page_action { nullptr };