Skip to content

Commit

Permalink
Fix minimized browser window not being activated when handling applic…
Browse files Browse the repository at this point in the history
…ation:openURLs: on Mac.

Change Ie4e20156607a76ccac424d310806e6b135b0500e introduced a behavior
that prefers not activating the browser window when handing
-[NSApplicationDelegate application:openURLs:] and leaves the task to
the LaunchServices.  The minimized browser windows should be an
exception since the OS won't activate such windows. This CL fixes this
regression issue and adds related tests.

(cherry picked from commit fc00be1)

Bug: 1401678
Change-Id: I1610d9c6e86c672eacfcd05ed2755cbcb8ece6d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4111828
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: Tommy Martino <tmartino@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1085480}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4145539
Cr-Commit-Position: refs/branch-heads/5481@{#288}
Cr-Branched-From: 130f3e4-refs/heads/main@{#1084008}
  • Loading branch information
GetToSet authored and Chromium LUCI CQ committed Jan 13, 2023
1 parent 62bab07 commit 4e19bfa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions chrome/browser/app_controller_mac_interactive_uitest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@

TabStripModel* tab_strip = new_browser->tab_strip_model();
EXPECT_EQ(2, tab_strip->count());

// Minimized browser windows should be treated as exceptions and have to be
// activated since they won't receive activation events from the OS.
new_browser->window()->Minimize();

base::RunLoop().RunUntilIdle();
EXPECT_TRUE(new_browser->window()->IsMinimized());
EXPECT_FALSE(new_browser->window()->IsActive());

[ac application:NSApp
openURLs:@[ [NSURL URLWithString:@"http://example.com"] ]];

EXPECT_TRUE(new_browser->window()->IsActive());
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(new_browser->window()->IsMinimized());
}

} // namespace
7 changes: 4 additions & 3 deletions chrome/browser/ui/startup/startup_browser_creator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,11 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(

#if BUILDFLAG(IS_MAC)
// On Mac, LaunchServices will send activation events if necessary.
// Prefer not activating the browser window when opening new tabs, leaving the
// activation task to the system.
// Prefer not activating non-minimized browser window when opening new tabs,
// leaving the activation task to the system.
if (process_startup == chrome::startup::IsProcessStartup::kNo &&
BrowserList::GetInstance()->GetLastActive() == browser) {
BrowserList::GetInstance()->GetLastActive() == browser &&
!browser->window()->IsMinimized()) {
browser->window()->ShowInactive();
} else {
#endif
Expand Down

0 comments on commit 4e19bfa

Please sign in to comment.