[cr149] IsWebContentsVisible cannot be override through Browser

Browser doesn't inherit from `ChromeWebModalDialogManagerDelegate`
anymore. This change fixes our code by directly patching
`ChromeWebModalDialogManagerDelegate` to have an override for this
method.

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/083c2a8b08fff93b74aac4f4acd89c5d1fb206ea

commit 083c2a8b08fff93b74aac4f4acd89c5d1fb206ea
Author: Qikai <qikaizhong@microsoft.com>
Date:   Tue Apr 21 22:53:26 2026 -0700

    [bedrock] Move ChromeWebModalDialogManagerDelegate to BrowserWindowFeatures

    Extract ChromeWebModalDialogManagerDelegate from Browser into a new
    BrowserWindowModalDialogDelegate owned by BrowserWindowFeatures. The
    new class manages per-tab WebContentsModalDialogManager delegate
    registration via TabStripModelObserver and handles tab blocking,
    fullscreen exit, and dialog host lookup.

    Browser retains a thin SetWebContentsBlocked() override for
    DesktopBrowserWindowCapabilitiesDelegate, forwarding to the feature.
    DevTools scrim visibility uses a callback pattern subscribed by
    BrowserView.

    Bug: 496674143
    Change-Id: Ia8aea00b733e113c5ca9e9e79d28a37061eb8ced
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7738543
    Reviewed-by: Thomas Lukaszewicz <tluk@chromium.org>
    Commit-Queue: Qikai Zhong <qikaizhong@microsoft.com>
    Cr-Commit-Position: refs/heads/main@{#1618668}
This commit is contained in:
Claudio DeSouza
2026-05-22 16:25:09 -04:00
committed by Max Karolinskiy
parent c74b5da1ec
commit abbf8cc947
5 changed files with 47 additions and 22 deletions
-14
View File
@@ -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;
-8
View File
@@ -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;
@@ -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 <chrome/browser/ui/web_modal/browser_window_modal_dialog_delegate.cc>
// 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;
}
@@ -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(
@@ -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'''