Commit f5d6ae4c authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Desktop PWAs: New window command on Mac opens web apps

On Mac, the New Window command could already open bookmark apps.

We now also open web application windows, using the LaunchService.
This change ensures behavior is preserved when we ship BMO -
Desktop PWAs without Extensions crbug.com/877898

Bug: 913360,953540
Change-Id: I6575f4a9f78af474d48da2ed6baaf7e4887dbfde
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2107031
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751571}
parent ed0e1dd5
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h" #include "chrome/browser/browsing_data/browsing_data_helper.h"
...@@ -60,7 +62,12 @@ ...@@ -60,7 +62,12 @@
#include "chrome/browser/ui/tabs/tab_group.h" #include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h" #include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/upgrade_detector/upgrade_detector.h" #include "chrome/browser/upgrade_detector/upgrade_detector.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/content_restriction.h" #include "chrome/common/content_restriction.h"
...@@ -76,6 +83,7 @@ ...@@ -76,6 +83,7 @@
#include "components/find_in_page/find_types.h" #include "components/find_in_page/find_types.h"
#include "components/google/core/common/google_util.h" #include "components/google/core/common/google_util.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "components/sessions/core/live_tab_context.h" #include "components/sessions/core/live_tab_context.h"
#include "components/sessions/core/tab_restore_service.h" #include "components/sessions/core/tab_restore_service.h"
#include "components/tab_groups/tab_group_id.h" #include "components/tab_groups/tab_group_id.h"
...@@ -103,6 +111,7 @@ ...@@ -103,6 +111,7 @@
#include "rlz/buildflags/buildflags.h" #include "rlz/buildflags/buildflags.h"
#include "ui/base/clipboard/clipboard_buffer.h" #include "ui/base/clipboard/clipboard_buffer.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/window_open_disposition.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/url_constants.h" #include "url/url_constants.h"
...@@ -626,21 +635,41 @@ void Stop(Browser* browser) { ...@@ -626,21 +635,41 @@ void Stop(Browser* browser) {
} }
void NewWindow(Browser* browser) { void NewWindow(Browser* browser) {
Profile* const profile = browser->profile();
#if BUILDFLAG(ENABLE_EXTENSIONS) && defined(OS_MACOSX) #if BUILDFLAG(ENABLE_EXTENSIONS) && defined(OS_MACOSX)
// With bookmark apps enabled, hosted apps should open a window to their // Web apps should open a window to their launch page.
// launch page. if (browser->app_controller() && browser->app_controller()->HasAppId()) {
const web_app::AppId app_id = browser->app_controller()->GetAppId();
auto launch_container =
apps::mojom::LaunchContainer::kLaunchContainerWindow;
if (web_app::WebAppProviderBase::GetProviderBase(profile)
->registrar()
.GetAppEffectiveDisplayMode(app_id) ==
blink::mojom::DisplayMode::kBrowser) {
launch_container = apps::mojom::LaunchContainer::kLaunchContainerTab;
}
const apps::AppLaunchParams params = apps::AppLaunchParams(
app_id, launch_container, WindowOpenDisposition::NEW_WINDOW,
apps::mojom::AppLaunchSource::kSourceKeyboard);
apps::LaunchService::Get(profile)->OpenApplication(params);
return;
}
// Hosted apps should open a window to their launch page.
const extensions::Extension* extension = GetExtensionForBrowser(browser); const extensions::Extension* extension = GetExtensionForBrowser(browser);
if (extension && extension->is_hosted_app()) { if (extension && extension->is_hosted_app()) {
DCHECK(!extension->from_bookmark());
const auto app_launch_params = CreateAppLaunchParamsUserContainer( const auto app_launch_params = CreateAppLaunchParamsUserContainer(
browser->profile(), extension, WindowOpenDisposition::NEW_WINDOW, profile, extension, WindowOpenDisposition::NEW_WINDOW,
extensions::AppLaunchSource::kSourceKeyboard); extensions::AppLaunchSource::kSourceKeyboard);
OpenApplicationWindow( OpenApplicationWindow(
browser->profile(), app_launch_params, profile, app_launch_params,
extensions::AppLaunchInfo::GetLaunchWebURL(extension)); extensions::AppLaunchInfo::GetLaunchWebURL(extension));
return; return;
} }
#endif #endif
NewEmptyWindow(browser->profile()->GetOriginalProfile()); NewEmptyWindow(profile->GetOriginalProfile());
} }
void NewIncognitoWindow(Profile* profile) { void NewIncognitoWindow(Profile* profile) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h" #include "base/test/metrics/user_action_tester.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h" #include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/page_info/page_info_dialog.h" #include "chrome/browser/ui/page_info/page_info_dialog.h"
...@@ -772,6 +774,37 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, SubframeRedirectsToWebApp) { ...@@ -772,6 +774,37 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, SubframeRedirectsToWebApp) {
EvalJs(subframe, "document.body.innerText.trim();").ExtractString()); EvalJs(subframe, "document.body.innerText.trim();").ExtractString());
} }
#if defined(OS_MACOSX)
IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, NewAppWindow) {
BrowserList* const browser_list = BrowserList::GetInstance();
const GURL app_url = GetSecureAppURL();
const AppId app_id = InstallPWA(app_url);
Browser* const app_browser = LaunchWebAppBrowser(app_id);
EXPECT_EQ(browser_list->size(), 2U);
EXPECT_TRUE(chrome::ExecuteCommand(app_browser, IDC_NEW_WINDOW));
EXPECT_EQ(browser_list->size(), 3U);
Browser* const new_browser = browser_list->GetLastActive();
EXPECT_NE(new_browser, browser());
EXPECT_NE(new_browser, app_browser);
EXPECT_TRUE(new_browser->is_type_app());
EXPECT_EQ(new_browser->app_controller()->GetAppId(), app_id);
WebAppProviderBase::GetProviderBase(profile())
->registry_controller()
.SetAppUserDisplayMode(app_id, DisplayMode::kBrowser);
EXPECT_EQ(browser()->tab_strip_model()->count(), 1);
EXPECT_TRUE(chrome::ExecuteCommand(app_browser, IDC_NEW_WINDOW));
EXPECT_EQ(browser_list->GetLastActive(), browser());
EXPECT_EQ(browser()->tab_strip_model()->count(), 2);
EXPECT_EQ(
browser()->tab_strip_model()->GetActiveWebContents()->GetVisibleURL(),
app_url);
}
#endif
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
All, All,
WebAppBrowserTest, WebAppBrowserTest,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment