diff --git a/browser/ui/brave_browser.cc b/browser/ui/brave_browser.cc index ec8f93156b6..5402ca7b6ba 100644 --- a/browser/ui/brave_browser.cc +++ b/browser/ui/brave_browser.cc @@ -323,20 +323,6 @@ bool BraveBrowser::NormalBrowserSupportsWindowFeature( check_can_support); } -bool BraveBrowser::IsWebContentsVisible(content::WebContents* web_contents) { - const auto original_visible = Browser::IsWebContentsVisible(web_contents); - auto* tab = tabs::TabInterface::MaybeGetFromContents(web_contents); - if (!tab) { - return original_visible; - } - - if (original_visible && !tab->IsActivated()) { - return false; - } - - return original_visible; -} - void BraveBrowser::UpdateTargetURL(content::WebContents* source, const GURL& url) { GURL target_url = url; diff --git a/browser/ui/brave_browser.h b/browser/ui/brave_browser.h index d106c100d04..98a5311b0a6 100644 --- a/browser/ui/brave_browser.h +++ b/browser/ui/brave_browser.h @@ -55,14 +55,6 @@ class BraveBrowser : public Browser { bool user_gesture, bool* was_blocked) override; - // This overrides ChromeWebModalDialogManagerDelegate::IsWebContentsVisible() - // and it's called from WebContentsModalDialogManager. - // That manager prevents web modal dialog when web contents is not visible. - // As we have visible but inactive tabs in split tab, this should return false - // when it's inactive tab. Otherwse, web modal from inactive split tab can be - // shown. - bool IsWebContentsVisible(content::WebContents* web_contents) override; - void OnTabClosing(content::WebContents* contents) override; void TabStripEmpty() override; diff --git a/chromium_src/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.cc b/chromium_src/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.cc new file mode 100644 index 00000000000..f76087ad195 --- /dev/null +++ b/chromium_src/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.cc @@ -0,0 +1,26 @@ +/* Copyright (c) 2025 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "components/tabs/public/tab_interface.h" + +#include + +// Overrides ChromeWebModalDialogManagerDelegate::IsWebContentsVisible() to +// suppress web modal dialogs on inactive split tabs. A split tab can be +// visible (i.e. rendered) but not activated, and without this override a modal +// dialog from the inactive pane would incorrectly appear. +bool BrowserWindowModalDialogDelegate::IsWebContentsVisible( + content::WebContents* web_contents) { + const bool original_visible = + ChromeWebModalDialogManagerDelegate::IsWebContentsVisible(web_contents); + auto* tab = tabs::TabInterface::MaybeGetFromContents(web_contents); + if (!tab) { + return original_visible; + } + if (original_visible && !tab->IsActivated()) { + return false; + } + return original_visible; +} diff --git a/patches/chrome-browser-ui-web_modal-browser_window_modal_dialog_delegate.h.patch b/patches/chrome-browser-ui-web_modal-browser_window_modal_dialog_delegate.h.patch new file mode 100644 index 00000000000..38da21d6475 --- /dev/null +++ b/patches/chrome-browser-ui-web_modal-browser_window_modal_dialog_delegate.h.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.h b/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.h +index b72d333bb51b47a2e5e1baaaab7659bc2ff7963a..f58b1f1a660d2405eadbf2737ca5f29720490ecf 100644 +--- a/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.h ++++ b/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.h +@@ -31,6 +31,7 @@ class BrowserWindowModalDialogDelegate + BrowserWindowInterface* browser); + + // ChromeWebModalDialogManagerDelegate: ++ bool IsWebContentsVisible(content::WebContents* web_contents) override; + void SetWebContentsBlocked(content::WebContents* web_contents, + bool blocked) override; + web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost( diff --git a/rewrite/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.h.toml b/rewrite/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.h.toml new file mode 100644 index 00000000000..2773ce52f0c --- /dev/null +++ b/rewrite/chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.h.toml @@ -0,0 +1,9 @@ +# Copyright (c) 2025 The Brave Authors. All rights reserved. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at https://mozilla.org/MPL/2.0/. + +[[substitution]] +description = '''IsWebContentsVisible override for inactive split tabs'''' +re_pattern = '( // ChromeWebModalDialogManagerDelegate:\n)' +replace = '''\1 bool IsWebContentsVisible(content::WebContents* web_contents) override;\n'''