From ec97acd2b850aed784d762dce1bcc3beee1d008f Mon Sep 17 00:00:00 2001 From: cdesouza-chromium Date: Mon, 11 Nov 2024 17:22:30 +0000 Subject: [PATCH] [DanglingPtr] Fix `WebUIBubbleManagerImpl` dangling patch (#26465) A patch was added to `WebUIBubbleManagerImpl` when enabling the dangling pointer detector on Linux, as a temporary measure. This change corrects the the underlying issue requiring this pointer to be marked as dangling. This particular dangling pointer occurred because the toolbar view was being passed as the achor for this browser data bubbles, the toolbar gets destroyed prior to these browser data bubbles being disposed. This PR adds checks during in the `BraveBrowserView` dtor, to make sure there are no dangling references to the toolbar view by the time the termination is cleaning up browser data. Resolves https://github.com/brave/brave-browser/issues/42196 --- browser/ui/views/frame/brave_browser_view.cc | 12 ++++++++++++ ...wser-ui-views-bubble-webui_bubble_manager.h.patch | 9 +++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/browser/ui/views/frame/brave_browser_view.cc b/browser/ui/views/frame/brave_browser_view.cc index 410cbf7a78cc..4b33bf79e78d 100644 --- a/browser/ui/views/frame/brave_browser_view.cc +++ b/browser/ui/views/frame/brave_browser_view.cc @@ -587,6 +587,18 @@ void BraveBrowserView::UpdateSearchTabsButtonState() { BraveBrowserView::~BraveBrowserView() { tab_cycling_event_handler_.reset(); + // Removes the bubble from the browser, as it uses the `ToolbarView` as an + // archor, and that leaves a dangling reference once the `TopContainerView` is + // destroyed before all `SupportsUserData` is cleared. + if (brave_shields::CookieListOptInBubbleHost::FromBrowser(browser_.get())) { + brave_shields::CookieListOptInBubbleHost::RemoveFromBrowser(browser_.get()); + } + + // Same as above. + if (brave_rewards::TipPanelBubbleHost::FromBrowser(browser_.get())) { + brave_rewards::TipPanelBubbleHost::RemoveFromBrowser(browser_.get()); + } + DCHECK(!tab_cycling_event_handler_); } diff --git a/patches/chrome-browser-ui-views-bubble-webui_bubble_manager.h.patch b/patches/chrome-browser-ui-views-bubble-webui_bubble_manager.h.patch index 37d93a862e57..8556d2313b6c 100644 --- a/patches/chrome-browser-ui-views-bubble-webui_bubble_manager.h.patch +++ b/patches/chrome-browser-ui-views-bubble-webui_bubble_manager.h.patch @@ -1,8 +1,8 @@ diff --git a/chrome/browser/ui/views/bubble/webui_bubble_manager.h b/chrome/browser/ui/views/bubble/webui_bubble_manager.h -index edd7d37a12e182cc663db4e565b8a9edb12e0c70..043ec6578181c02b4bad4d59769287cee6f91907 100644 +index edd7d37a12e182cc663db4e565b8a9edb12e0c70..e90187359fc82f33135212fb627ac07d495076d0 100644 --- a/chrome/browser/ui/views/bubble/webui_bubble_manager.h +++ b/chrome/browser/ui/views/bubble/webui_bubble_manager.h -@@ -165,11 +165,13 @@ class WebUIBubbleManagerImpl : public WebUIBubbleManager { +@@ -165,9 +165,11 @@ class WebUIBubbleManagerImpl : public WebUIBubbleManager { private: // WebUIBubbleManager: @@ -12,8 +12,5 @@ index edd7d37a12e182cc663db4e565b8a9edb12e0c70..043ec6578181c02b4bad4d59769287ce views::BubbleBorder::Arrow arrow) override; + private: -- const raw_ptr anchor_view_; -+ const raw_ptr anchor_view_; + const raw_ptr anchor_view_; const raw_ptr profile_; - const GURL webui_url_; - const int task_manager_string_id_;