Truly independent web browser
UI/Qt: Let a crash review tab become an ordinary tab when it navigates
Jelle Raaijmakers5cd0bb67bfb0
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cppindex 1373fa83827..8d491cdf89e 100644--- a/UI/Qt/Application.cpp+++ b/UI/Qt/Application.cpp@@ -891,9 +891,8 @@ void Application::review_crash_report(ByteString const& report_name)// The tab is blank, so no web content runs behind the review, and it closes once the review is left.auto* current_tab = m_active_window->current_tab();auto& tab = m_active_window->new_tab_from_url(URL::about_blank(), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_current_tab());- if (current_tab)- tab.set_tab_to_activate_on_close(*current_tab);tab.view().review_hidden_crash_report(report_name);+ tab.enter_report_review(current_tab);}void Application::open_file()diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cppindex 5d852592cbc..64bebb47637 100644--- a/UI/Qt/Tab.cpp+++ b/UI/Qt/Tab.cpp@@ -1441,6 +1441,38 @@ QString Tab::title() constreturn QString("%1 [%2]").arg(m_title).arg(view().page().client().pid());}+// A tab opened only for a review shows it over a blank page, and closing it goes back to the tab it was opened from.+// That lasts until the user takes the tab somewhere else. The tab starts out loading about:blank, which is not somewhere+// else, but any page loaded after that is, about:blank included.+void Tab::enter_report_review(Tab* tab_to_activate_on_close)+{+ VERIFY(!m_report_review_navigation_listener.has_value());+ m_tab_to_activate_on_close = tab_to_activate_on_close;++ WebView::ViewImplementation::NavigationListener listener;+ listener.on_load_start = [this](URL::URL const& url) {+ if (m_has_loaded_report_review_page || url != URL::about_blank())+ leave_report_review();+ };+ listener.on_load_finish = [this](URL::URL const&) { m_has_loaded_report_review_page = true; };+ m_report_review_navigation_listener = view().add_navigation_listener(AK::move(listener));+}++// A report on its way keeps being sent, as it does when the tab closes.+void Tab::leave_report_review()+{+ if (!m_report_review_navigation_listener.has_value())+ return;++ view().leave_report_review();+ m_tab_to_activate_on_close = nullptr;++ // The view is still telling its listeners about this navigation, so the listener goes once it is done.+ QTimer::singleShot(0, this, [this, listener = m_report_review_navigation_listener.release_value()] {+ view().remove_navigation_listener(listener);+ });+}+void Tab::update_tab_title(){emit title_changed(tab_index(), title());diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.hindex 1a254ac2213..82a0ee1c86f 100644--- a/UI/Qt/Tab.h+++ b/UI/Qt/Tab.h@@ -122,7 +122,7 @@ public:void update_window_control_icons();void update_hover_label();- void set_tab_to_activate_on_close(Tab& tab) { m_tab_to_activate_on_close = &tab; }+ void enter_report_review(Tab* tab_to_activate_on_close);bool url_is_hidden() const { return m_location_edit->url_is_hidden(); }void set_url_is_hidden(bool url_is_hidden) { m_location_edit->set_url_is_hidden(url_is_hidden); }@@ -156,6 +156,7 @@ private:QToolButton* create_navigation_history_toolbar_button(QWidget& parent, QAction&, int direction);void update_chrome_style();void update_tab_title();+ void leave_report_review();void update_downloads_button();void update_downloads_popover();void show_downloads_popover();@@ -215,6 +216,8 @@ private:Optional<WakeLock::DisplaySleepInhibitor> m_screen_display_sleep_inhibitor;BrowserWindow* m_window { nullptr };QString m_title;+ Optional<u64> m_report_review_navigation_listener;+ bool m_has_loaded_report_review_page { false };HyperlinkLabel* m_hover_label { nullptr };QIcon m_favicon;QTimer* m_loading_animation_timer { nullptr };diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cppindex 44e5bc1470e..cad8e6e824d 100644--- a/UI/Qt/WebContentView.cpp+++ b/UI/Qt/WebContentView.cpp@@ -1435,6 +1435,13 @@ void WebContentView::review_hidden_crash_report(ByteString const& report_name)set_crash_overlay_visible(false);}+// A tab opened only for a review lets go of what it showed over its page once the user takes the tab elsewhere.+void WebContentView::leave_report_review()+{+ if (m_crash_overlay && !m_crash_overlay->isHidden() && !crash_overlay_active())+ set_crash_overlay_visible(false);+}+// Overlays are painted by Qt, underneath whatever presents the page on some platforms, which has to step aside for them.bool WebContentView::is_page_covered_by_overlay() const{diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.hindex 618fe3fe6b9..66e508ecb55 100644--- a/UI/Qt/WebContentView.h+++ b/UI/Qt/WebContentView.h@@ -144,6 +144,7 @@ public:void close_select_dropdown_after_crash();void cancel_mouse_press();void review_hidden_crash_report(ByteString const& report_name);+ void leave_report_review();enum class PaletteMode {Default,