diff --git a/chrome/browser/ui/webui/history_clusters/history_clusters_handler.cc b/chrome/browser/ui/webui/history_clusters/history_clusters_handler.cc index 961b2d701aafb3..7d317186b1ff7b 100644 --- a/chrome/browser/ui/webui/history_clusters/history_clusters_handler.cc +++ b/chrome/browser/ui/webui/history_clusters/history_clusters_handler.cc @@ -73,11 +73,12 @@ void InvokeAction(actions::ActionId id, actions::ActionItem* scope) { // Returns the current browser window, regardless of whether this instance is // tab-scoped or window-scoped. BrowserWindowInterface* GetBrowserWindowInterface( - std::variant interface) { - if (std::holds_alternative(interface)) { - return std::get(interface); + const HistoryClustersHandler::ContextInterface& interface) { + if (std::holds_alternative>(interface)) { + return std::get>(interface); } - return std::get(interface)->GetBrowserWindowInterface(); + return std::get>(interface) + ->GetBrowserWindowInterface(); } class HistoryClustersSidePanelContextMenu @@ -85,7 +86,7 @@ class HistoryClustersSidePanelContextMenu public ui::SimpleMenuModel::Delegate { public: HistoryClustersSidePanelContextMenu( - std::variant interface, + HistoryClustersHandler::ContextInterface interface, GURL url) : ui::SimpleMenuModel(this), interface_(interface), url_(std::move(url)) { AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, @@ -100,7 +101,7 @@ class HistoryClustersSidePanelContextMenu IDS_HISTORY_CLUSTERS_COPY_LINK); } HistoryClustersSidePanelContextMenu( - std::variant interface, + HistoryClustersHandler::ContextInterface interface, std::string query) : ui::SimpleMenuModel(this), interface_(interface), query_(query) { AddItemWithStringId(IDC_CUT, IDS_HISTORY_CLUSTERS_CUT); @@ -177,7 +178,7 @@ class HistoryClustersSidePanelContextMenu private: // Exactly one of `browser_window_interface_` and `tab_interface_` will be // non-nullptr. - std::variant interface_; + HistoryClustersHandler::ContextInterface interface_; std::string query_; GURL url_; }; diff --git a/chrome/browser/ui/webui/history_clusters/history_clusters_handler.h b/chrome/browser/ui/webui/history_clusters/history_clusters_handler.h index 82a1eaddc83fe9..de481960e36c33 100644 --- a/chrome/browser/ui/webui/history_clusters/history_clusters_handler.h +++ b/chrome/browser/ui/webui/history_clusters/history_clusters_handler.h @@ -90,8 +90,12 @@ class HistoryClustersHandler : public mojom::PageHandler, void SetSidePanelUIEmbedder( base::WeakPtr side_panel_embedder); + // Use raw_ptr inside the variant so that MiraclePtr (BackupRefPtr) + // protects the cached pointers. The TabInterface can be destroyed while this + // handler is still alive (e.g. when a popup hosting chrome://history is + // converted to a tab via ConvertPopupToTabbedBrowser). using ContextInterface = - std::variant; + std::variant, raw_ptr>; void SetContextInterface(ContextInterface interface); // Used to set the in-page query from the browser.