Commit 400a3fc7 authored by David Bienvenu's avatar David Bienvenu Committed by Commit Bot

Move --app-id command line handling to StartupBrowserCreator.

It doesn't need to be done for each profile in the multi-profile
session restore case, since --app-id should always have an associated
--profile-directory, since apps are profile-specific.

Bug: 1132578
Change-Id: I1a898b2b911c8962dd6400fc821d4b05cf85fb08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2520220
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827451}
parent 09fa43da
...@@ -1311,18 +1311,12 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, AppIdSwitch) { ...@@ -1311,18 +1311,12 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, AppIdSwitch) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
chrome::startup::IsFirstRun first_run = EXPECT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN command_line, base::FilePath(), /*process_startup=*/false,
: chrome::startup::IS_NOT_FIRST_RUN; browser()->profile(), {}));
StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
// The app should open as a tab.
EXPECT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(),
/*process_startup=*/false,
std::make_unique<LaunchModeRecorder>()));
{ {
// From startup_browser_creator_impl.cc: // From launch_mode_recorder.cc:
constexpr char kLaunchModesHistogram[] = "Launch.Modes"; constexpr char kLaunchModesHistogram[] = "Launch.Modes";
const base::HistogramBase::Sample LM_AS_WEBAPP_IN_TAB = 21; const base::HistogramBase::Sample LM_AS_WEBAPP_IN_TAB = 21;
......
...@@ -32,7 +32,10 @@ ...@@ -32,7 +32,10 @@
#include "build/branding_buildflags.h" #include "build/branding_buildflags.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/app_mode/app_mode_utils.h" #include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/platform_apps/app_load_service.h" #include "chrome/browser/apps/platform_apps/app_load_service.h"
#include "chrome/browser/apps/platform_apps/platform_app_launch.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_types.h" #include "chrome/browser/chromeos/app_mode/kiosk_app_types.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
...@@ -64,6 +67,7 @@ ...@@ -64,6 +67,7 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/search_engines/util.h" #include "components/search_engines/util.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h" #include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "components/url_formatter/url_fixer.h" #include "components/url_formatter/url_fixer.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
...@@ -297,6 +301,106 @@ bool IsSilentLaunchEnabled(const base::CommandLine& command_line, ...@@ -297,6 +301,106 @@ bool IsSilentLaunchEnabled(const base::CommandLine& command_line,
return false; return false;
} }
void FinalizeWebAppLaunch(
std::unique_ptr<LaunchModeRecorder> launch_mode_recorder,
Browser* browser,
apps::mojom::LaunchContainer container) {
LaunchMode mode;
switch (container) {
case apps::mojom::LaunchContainer::kLaunchContainerWindow:
DCHECK(browser->is_type_app());
mode = LaunchMode::kAsWebAppInWindow;
break;
case apps::mojom::LaunchContainer::kLaunchContainerTab:
DCHECK(!browser->is_type_app());
mode = LaunchMode::kAsWebAppInTab;
break;
case apps::mojom::LaunchContainer::kLaunchContainerPanelDeprecated:
NOTREACHED();
FALLTHROUGH;
case apps::mojom::LaunchContainer::kLaunchContainerNone:
DCHECK(!browser->is_type_app());
mode = LaunchMode::kUnknownWebApp;
break;
}
if (launch_mode_recorder)
launch_mode_recorder->SetLaunchMode(mode);
StartupBrowserCreatorImpl::MaybeToggleFullscreen(browser);
}
// If the process was launched with the web application command line flags,
// e.g. --app=http://www.google.com/ or --app_id=... return true.
// In this case |app_url| or |app_id| are populated if they're non-null.
bool IsAppLaunch(const base::CommandLine& command_line,
std::string* app_url,
std::string* app_id) {
if (command_line.HasSwitch(switches::kApp)) {
if (app_url)
*app_url = command_line.GetSwitchValueASCII(switches::kApp);
return true;
}
if (command_line.HasSwitch(switches::kAppId)) {
if (app_id)
*app_id = command_line.GetSwitchValueASCII(switches::kAppId);
return true;
}
return false;
}
// Opens an application window or tab if the process was launched with the web
// application command line switches. Returns true if launch succeeded (or is
// proceeding asynchronously); otherwise, returns false to indicate that
// normal browser startup should resume. Desktop web applications launch
// asynchronously, and fall back to launching a browser window.
bool MaybeLaunchApplication(
const base::CommandLine& command_line,
const base::FilePath& cur_dir,
Profile* profile,
std::unique_ptr<LaunchModeRecorder> launch_mode_recorder) {
std::string url_string, app_id;
if (!IsAppLaunch(command_line, &url_string, &app_id))
return false;
if (!app_id.empty()) {
// Opens an empty browser window if the app_id is invalid.
apps::AppServiceProxyFactory::GetForProfile(profile)
->BrowserAppLauncher()
->LaunchAppWithCallback(
app_id, command_line, cur_dir,
base::BindOnce(&FinalizeWebAppLaunch,
std::move(launch_mode_recorder)));
return true;
}
if (url_string.empty())
return false;
#if defined(OS_WIN) // Fix up Windows shortcuts.
base::ReplaceSubstringsAfterOffset(&url_string, 0, "\\x", "%");
#endif
GURL url(url_string);
// Restrict allowed URLs for --app switch.
if (!url.is_empty() && url.is_valid()) {
content::ChildProcessSecurityPolicy* policy =
content::ChildProcessSecurityPolicy::GetInstance();
if (policy->IsWebSafeScheme(url.scheme()) ||
url.SchemeIs(url::kFileScheme)) {
const content::WebContents* web_contents =
apps::OpenExtensionAppShortcutWindow(profile, url);
if (web_contents) {
FinalizeWebAppLaunch(
std::move(launch_mode_recorder),
chrome::FindBrowserWithWebContents(web_contents),
apps::mojom::LaunchContainer::kLaunchContainerWindow);
return true;
}
}
}
return false;
}
} // namespace } // namespace
StartupBrowserCreator::StartupBrowserCreator() = default; StartupBrowserCreator::StartupBrowserCreator() = default;
...@@ -808,6 +912,27 @@ bool StartupBrowserCreator::ProcessCmdLineImpl( ...@@ -808,6 +912,27 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
} }
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
if (command_line.HasSwitch(switches::kAppId)) {
std::string app_id = command_line.GetSwitchValueASCII(switches::kAppId);
// If |app_id| is a disabled or terminated platform app we handle it
// specially here, otherwise it will be handled below.
if (apps::OpenExtensionApplicationWithReenablePrompt(
last_used_profile, app_id, command_line, cur_dir)) {
return true;
}
}
// If we're being run as an application window or application tab, don't
// restore tabs or open initial URLs as the user has directly launched an app
// shortcut. In the first case, the user should see a standlone app window. In
// the second case, the tab should either open in an existing Chrome window
// for this profile, or spawn a new Chrome window without any NTP if no window
// exists (see crbug.com/528385).
if (MaybeLaunchApplication(command_line, cur_dir, last_used_profile,
std::make_unique<LaunchModeRecorder>())) {
return true;
}
return LaunchBrowserForLastProfiles(command_line, cur_dir, process_startup, return LaunchBrowserForLastProfiles(command_line, cur_dir, process_startup,
last_used_profile, last_opened_profiles); last_used_profile, last_opened_profiles);
} }
......
...@@ -23,6 +23,11 @@ namespace base { ...@@ -23,6 +23,11 @@ namespace base {
class CommandLine; class CommandLine;
} }
namespace web_app {
FORWARD_DECLARE_TEST(WebAppEngagementBrowserTest, CommandLineTab);
FORWARD_DECLARE_TEST(WebAppEngagementBrowserTest, CommandLineWindow);
} // namespace web_app
// class containing helpers for BrowserMain to spin up a new instance and // class containing helpers for BrowserMain to spin up a new instance and
// initialize the profile. // initialize the profile.
class StartupBrowserCreator { class StartupBrowserCreator {
...@@ -108,6 +113,7 @@ class StartupBrowserCreator { ...@@ -108,6 +113,7 @@ class StartupBrowserCreator {
friend class StartupBrowserCreatorImpl; friend class StartupBrowserCreatorImpl;
// TODO(crbug.com/642442): Remove this when first_run_tabs gets refactored. // TODO(crbug.com/642442): Remove this when first_run_tabs gets refactored.
friend class StartupTabProviderImpl; friend class StartupTabProviderImpl;
FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
ReadingWasRestartedAfterNormalStart); ReadingWasRestartedAfterNormalStart);
FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
...@@ -118,6 +124,15 @@ class StartupBrowserCreator { ...@@ -118,6 +124,15 @@ class StartupBrowserCreator {
ValidNotificationLaunchId); ValidNotificationLaunchId);
FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
InvalidNotificationLaunchId); InvalidNotificationLaunchId);
FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
OpenAppShortcutWindowPref);
FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppUrlShortcut);
FRIEND_TEST_ALL_PREFIXES(web_app::WebAppEngagementBrowserTest,
CommandLineTab);
FRIEND_TEST_ALL_PREFIXES(web_app::WebAppEngagementBrowserTest,
CommandLineWindow);
bool ProcessCmdLineImpl(const base::CommandLine& command_line, bool ProcessCmdLineImpl(const base::CommandLine& command_line,
const base::FilePath& cur_dir, const base::FilePath& cur_dir,
......
...@@ -416,12 +416,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppUrlShortcut) { ...@@ -416,12 +416,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppUrlShortcut) {
base::FilePath(FILE_PATH_LITERAL("title2.html"))); base::FilePath(FILE_PATH_LITERAL("title2.html")));
command_line.AppendSwitchASCII(switches::kApp, url.spec()); command_line.AppendSwitchASCII(switches::kApp, url.spec());
chrome::startup::IsFirstRun first_run = ASSERT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN command_line, base::FilePath(), /*process_startup=*/false,
: chrome::startup::IS_NOT_FIRST_RUN; browser()->profile(), {}));
StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
ASSERT_TRUE(
launch.Launch(browser()->profile(), std::vector<GURL>(), false, nullptr));
Browser* new_browser = FindOneOtherBrowser(browser()); Browser* new_browser = FindOneOtherBrowser(browser());
ASSERT_TRUE(new_browser); ASSERT_TRUE(new_browser);
...@@ -457,11 +454,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { ...@@ -457,11 +454,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? ASSERT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; command_line, base::FilePath(), /*process_startup=*/false,
StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); browser()->profile(), {}));
ASSERT_TRUE(
launch.Launch(browser()->profile(), std::vector<GURL>(), false, nullptr));
// No pref was set, so the app should have opened in a tab in the existing // No pref was set, so the app should have opened in a tab in the existing
// window. // window.
...@@ -483,11 +478,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { ...@@ -483,11 +478,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? ASSERT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; command_line, base::FilePath(), /*process_startup=*/false,
StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); browser()->profile(), {}));
ASSERT_TRUE(
launch.Launch(browser()->profile(), std::vector<GURL>(), false, nullptr));
// Pref was set to open in a window, so the app should have opened in a // Pref was set to open in a window, so the app should have opened in a
// window. The launch should have created a new browser. Find the new // window. The launch should have created a new browser. Find the new
...@@ -518,11 +511,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) { ...@@ -518,11 +511,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kAppId, extension_app->id()); command_line.AppendSwitchASCII(switches::kAppId, extension_app->id());
chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? ASSERT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; command_line, base::FilePath(), /*process_startup=*/false,
StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); browser()->profile(), {}));
ASSERT_TRUE(
launch.Launch(browser()->profile(), std::vector<GURL>(), false, nullptr));
// When an app shortcut is open and the pref indicates a tab should open, the // When an app shortcut is open and the pref indicates a tab should open, the
// tab is open in the existing browser window. // tab is open in the existing browser window.
...@@ -548,7 +539,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ValidNotificationLaunchId) { ...@@ -548,7 +539,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ValidNotificationLaunchId) {
L"1|1|0|Default|0|https://example.com/|notification_id"); L"1|1|0|Default|0|https://example.com/|notification_id");
ASSERT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl( ASSERT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
command_line, base::FilePath(), false, browser()->profile(), {})); command_line, base::FilePath(), /*process_startup=*/false,
browser()->profile(), {}));
// The launch delegates to the notification system and doesn't open any new // The launch delegates to the notification system and doesn't open any new
// browser window. // browser window.
...@@ -561,7 +553,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, InvalidNotificationLaunchId) { ...@@ -561,7 +553,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, InvalidNotificationLaunchId) {
command_line.AppendSwitchNative(switches::kNotificationLaunchId, L""); command_line.AppendSwitchNative(switches::kNotificationLaunchId, L"");
StartupBrowserCreator browser_creator; StartupBrowserCreator browser_creator;
ASSERT_FALSE(StartupBrowserCreator().ProcessCmdLineImpl( ASSERT_FALSE(StartupBrowserCreator().ProcessCmdLineImpl(
command_line, base::FilePath(), false, browser()->profile(), {})); command_line, base::FilePath(), /*process_startup=*/false,
browser()->profile(), {}));
// No new browser window is open. // No new browser window is open.
ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile()));
......
...@@ -18,10 +18,7 @@ ...@@ -18,10 +18,7 @@
#include "build/branding_buildflags.h" #include "build/branding_buildflags.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "build/chromeos_buildflags.h" #include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/platform_apps/install_chrome_app.h" #include "chrome/browser/apps/platform_apps/install_chrome_app.h"
#include "chrome/browser/apps/platform_apps/platform_app_launch.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
...@@ -58,7 +55,6 @@ ...@@ -58,7 +55,6 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/dom_storage_context.h" #include "content/public/browser/dom_storage_context.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
...@@ -96,43 +92,6 @@ namespace { ...@@ -96,43 +92,6 @@ namespace {
// Utility functions ---------------------------------------------------------- // Utility functions ----------------------------------------------------------
void MaybeToggleFullscreen(Browser* browser) {
// In kiosk mode, we want to always be fullscreen.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) ||
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kStartFullscreen)) {
chrome::ToggleFullscreenMode(browser);
}
}
void FinalizeWebAppLaunch(
std::unique_ptr<LaunchModeRecorder> launch_mode_recorder,
Browser* browser,
apps::mojom::LaunchContainer container) {
LaunchMode mode;
switch (container) {
case apps::mojom::LaunchContainer::kLaunchContainerWindow:
DCHECK(browser->is_type_app());
mode = LaunchMode::kAsWebAppInWindow;
break;
case apps::mojom::LaunchContainer::kLaunchContainerTab:
DCHECK(!browser->is_type_app());
mode = LaunchMode::kAsWebAppInTab;
break;
case apps::mojom::LaunchContainer::kLaunchContainerPanelDeprecated:
NOTREACHED();
FALLTHROUGH;
case apps::mojom::LaunchContainer::kLaunchContainerNone:
DCHECK(!browser->is_type_app());
mode = LaunchMode::kUnknownWebApp;
break;
}
if (launch_mode_recorder)
launch_mode_recorder->SetLaunchMode(mode);
MaybeToggleFullscreen(browser);
}
void UrlsToTabs(const std::vector<GURL>& urls, StartupTabs* tabs) { void UrlsToTabs(const std::vector<GURL>& urls, StartupTabs* tabs) {
for (const GURL& url : urls) { for (const GURL& url : urls) {
StartupTab tab; StartupTab tab;
...@@ -195,6 +154,16 @@ StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( ...@@ -195,6 +154,16 @@ StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
browser_creator_(browser_creator), browser_creator_(browser_creator),
is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) {} is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) {}
// static
void StartupBrowserCreatorImpl::MaybeToggleFullscreen(Browser* browser) {
// In kiosk mode, we want to always be fullscreen.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) ||
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kStartFullscreen)) {
chrome::ToggleFullscreenMode(browser);
}
}
bool StartupBrowserCreatorImpl::Launch( bool StartupBrowserCreatorImpl::Launch(
Profile* profile, Profile* profile,
const std::vector<GURL>& urls_to_open, const std::vector<GURL>& urls_to_open,
...@@ -203,24 +172,6 @@ bool StartupBrowserCreatorImpl::Launch( ...@@ -203,24 +172,6 @@ bool StartupBrowserCreatorImpl::Launch(
DCHECK(profile); DCHECK(profile);
profile_ = profile; profile_ = profile;
if (command_line_.HasSwitch(switches::kAppId)) {
std::string app_id = command_line_.GetSwitchValueASCII(switches::kAppId);
// If |app_id| is a disabled or terminated platform app we handle it
// specially here, otherwise it will be handled below.
if (apps::OpenExtensionApplicationWithReenablePrompt(
profile, app_id, command_line_, cur_dir_)) {
return true;
}
}
// Open the required browser windows and tabs. If we're being run as an
// application window or application tab, don't restore tabs or open initial
// URLs as the user has directly launched an app shortcut. In the first case,
// the user should see a standlone app window. In the second case, the tab
// should either open in an existing Chrome window for this profile, or spawn
// a new Chrome window without any NTP if no window exists (see
// crbug.com/528385).
if (!MaybeLaunchApplication(profile, launch_mode_recorder)) {
// Check the true process command line for --try-chrome-again=N rather than // Check the true process command line for --try-chrome-again=N rather than
// the one parsed for startup URLs and such. // the one parsed for startup URLs and such.
if (launch_mode_recorder) { if (launch_mode_recorder) {
...@@ -256,7 +207,6 @@ bool StartupBrowserCreatorImpl::Launch( ...@@ -256,7 +207,6 @@ bool StartupBrowserCreatorImpl::Launch(
Browser* browser = BrowserList::GetInstance()->GetLastActive(); Browser* browser = BrowserList::GetInstance()->GetLastActive();
if (browser) if (browser)
MaybeToggleFullscreen(browser); MaybeToggleFullscreen(browser);
}
return true; return true;
} }
...@@ -340,67 +290,6 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser, ...@@ -340,67 +290,6 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser,
return browser; return browser;
} }
bool StartupBrowserCreatorImpl::IsAppLaunch(std::string* app_url,
std::string* app_id) const {
if (command_line_.HasSwitch(switches::kApp)) {
if (app_url)
*app_url = command_line_.GetSwitchValueASCII(switches::kApp);
return true;
}
if (command_line_.HasSwitch(switches::kAppId)) {
if (app_id)
*app_id = command_line_.GetSwitchValueASCII(switches::kAppId);
return true;
}
return false;
}
bool StartupBrowserCreatorImpl::MaybeLaunchApplication(
Profile* profile,
std::unique_ptr<LaunchModeRecorder>& launch_mode_recorder) {
std::string url_string, app_id;
if (!IsAppLaunch(&url_string, &app_id))
return false;
if (!app_id.empty()) {
// Opens an empty browser window if the app_id is invalid.
apps::AppServiceProxyFactory::GetForProfile(profile)
->BrowserAppLauncher()
->LaunchAppWithCallback(
app_id, command_line_, cur_dir_,
base::BindOnce(&FinalizeWebAppLaunch,
std::move(launch_mode_recorder)));
return true;
}
if (url_string.empty())
return false;
#if defined(OS_WIN) // Fix up Windows shortcuts.
base::ReplaceSubstringsAfterOffset(&url_string, 0, "\\x", "%");
#endif
GURL url(url_string);
// Restrict allowed URLs for --app switch.
if (!url.is_empty() && url.is_valid()) {
content::ChildProcessSecurityPolicy* policy =
content::ChildProcessSecurityPolicy::GetInstance();
if (policy->IsWebSafeScheme(url.scheme()) ||
url.SchemeIs(url::kFileScheme)) {
const content::WebContents* web_contents =
apps::OpenExtensionAppShortcutWindow(profile, url);
if (web_contents) {
FinalizeWebAppLaunch(
std::move(launch_mode_recorder),
chrome::FindBrowserWithWebContents(web_contents),
apps::mojom::LaunchContainer::kLaunchContainerWindow);
return true;
}
}
}
return false;
}
void StartupBrowserCreatorImpl::DetermineURLsAndLaunch( void StartupBrowserCreatorImpl::DetermineURLsAndLaunch(
bool process_startup, bool process_startup,
const std::vector<GURL>& cmd_line_urls) { const std::vector<GURL>& cmd_line_urls) {
......
...@@ -53,6 +53,10 @@ class StartupBrowserCreatorImpl { ...@@ -53,6 +53,10 @@ class StartupBrowserCreatorImpl {
delete; delete;
~StartupBrowserCreatorImpl() = default; ~StartupBrowserCreatorImpl() = default;
// If command line specifies kiosk mode, or full screen mode, switch
// to full screen.
static void MaybeToggleFullscreen(Browser* browser);
// Creates the necessary windows for startup. Returns true on success, // Creates the necessary windows for startup. Returns true on success,
// false on failure. process_startup is true if Chrome is just // false on failure. process_startup is true if Chrome is just
// starting up. If process_startup is false, it indicates Chrome was // starting up. If process_startup is false, it indicates Chrome was
...@@ -127,22 +131,6 @@ class StartupBrowserCreatorImpl { ...@@ -127,22 +131,6 @@ class StartupBrowserCreatorImpl {
bool process_startup, bool process_startup,
const StartupTabs& tabs); const StartupTabs& tabs);
// If the process was launched with the web application command line flags,
// e.g. --app=http://www.google.com/ or --app_id=... return true.
// In this case |app_url| or |app_id| are populated if they're non-null.
bool IsAppLaunch(std::string* app_url, std::string* app_id) const;
// Opens an application window or tab if the process was launched with the web
// application command line switches. Returns true if launch succeeded (or is
// proceeding asynchronously); otherwise, returns false to indicate that
// normal browser startup should resume. Desktop web applications launch
// asynchronously, and fall back to launching a browser window.
// If the function returns true, |launch_mode_recorder| will be moved away,
// and the unique_ptr's value will be null.
bool MaybeLaunchApplication(
Profile* profile,
std::unique_ptr<LaunchModeRecorder>& launch_mode_recorder);
// Determines the URLs to be shown at startup by way of various policies // Determines the URLs to be shown at startup by way of various policies
// (welcome, pinned tabs, etc.), determines whether a session restore // (welcome, pinned tabs, etc.), determines whether a session restore
// is necessary, and opens the URLs in a new or restored browser accordingly. // is necessary, and opens the URLs in a new or restored browser accordingly.
......
...@@ -13,13 +13,10 @@ ...@@ -13,13 +13,10 @@
#include "base/test/bind.h" #include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/engagement/site_engagement_service.h" #include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.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_list.h"
#include "chrome/browser/ui/startup/launch_mode_recorder.h" #include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
#include "chrome/browser/ui/startup/startup_types.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h" #include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h" #include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h"
...@@ -504,15 +501,11 @@ IN_PROC_BROWSER_TEST_F(WebAppEngagementBrowserTest, CommandLineWindow) { ...@@ -504,15 +501,11 @@ IN_PROC_BROWSER_TEST_F(WebAppEngagementBrowserTest, CommandLineWindow) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kAppId, *app_id); command_line.AppendSwitchASCII(switches::kAppId, *app_id);
chrome::startup::IsFirstRun first_run =
first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN;
StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
// The app should open as a window. // The app should open as a window.
EXPECT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), EXPECT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
/*process_startup=*/false, command_line, base::FilePath(), /*process_startup=*/false,
std::make_unique<LaunchModeRecorder>())); browser()->profile(), {}));
app_loaded_observer.Wait(); app_loaded_observer.Wait();
Browser* const app_browser = BrowserList::GetInstance()->GetLastActive(); Browser* const app_browser = BrowserList::GetInstance()->GetLastActive();
...@@ -562,15 +555,10 @@ IN_PROC_BROWSER_TEST_F(WebAppEngagementBrowserTest, CommandLineTab) { ...@@ -562,15 +555,10 @@ IN_PROC_BROWSER_TEST_F(WebAppEngagementBrowserTest, CommandLineTab) {
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchASCII(switches::kAppId, *app_id); command_line.AppendSwitchASCII(switches::kAppId, *app_id);
chrome::startup::IsFirstRun first_run =
first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
: chrome::startup::IS_NOT_FIRST_RUN;
StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run);
// The app should open as a tab. // The app should open as a tab.
EXPECT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), EXPECT_TRUE(StartupBrowserCreator().ProcessCmdLineImpl(
/*process_startup=*/false, command_line, base::FilePath(), /*process_startup=*/false,
std::make_unique<LaunchModeRecorder>())); browser()->profile(), {}));
app_loaded_observer.Wait(); app_loaded_observer.Wait();
{ {
......
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