Commit 11beac02 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

desktop-pwas: Add shortcuts even if there is no browser window

Some clients like Default Apps and Policy Apps install apps without
a Browser window. Some steps can be skipped for these clients, like
sending the install event to the page, but other are needed for
example creating shortcuts.

Changes BookmarkAppHelper to not return early if there is no Browser
window but still skip some unnecessary steps.

Bug: 844278

Change-Id: I24003ff51d47937dc349aafca67912224db1eab2
Reviewed-on: https://chromium-review.googlesource.com/1164160Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581165}
parent 3a80a7da
......@@ -779,13 +779,11 @@ void BookmarkAppHelper::FinishInstallation(const Extension* extension) {
base::Time::Now());
Browser* browser = chrome::FindBrowserWithWebContents(contents_);
if (!browser) {
// The browser can be null in tests.
callback_.Run(extension, web_app_info_);
return;
}
// If there is no browser, it means that the app is being installed in the
// background. We skip some steps in this case.
const bool silent_install = !browser;
if (banners::AppBannerManagerDesktop::IsEnabled() &&
if (!silent_install && banners::AppBannerManagerDesktop::IsEnabled() &&
web_app_info_.open_as_window) {
banners::AppBannerManagerDesktop::FromWebContents(contents_)->OnInstall(
false /* is_native app */, blink::kWebDisplayModeStandalone);
......@@ -812,20 +810,24 @@ void BookmarkAppHelper::FinishInstallation(const Extension* extension) {
web_app::CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER,
creation_locations, current_profile, extension);
#else
ChromeLauncherController::instance()->shelf_model()->PinAppWithID(
extension->id());
// ChromeLauncherController does not exist in unit tests.
if (ChromeLauncherController::instance()) {
ChromeLauncherController::instance()->shelf_model()->PinAppWithID(
extension->id());
}
#endif // !defined(OS_CHROMEOS)
// Reparent the tab into an app window immediately when opening as a window.
if (base::FeatureList::IsEnabled(::features::kDesktopPWAWindowing) &&
if (!silent_install &&
base::FeatureList::IsEnabled(::features::kDesktopPWAWindowing) &&
launch_type == LAUNCH_TYPE_WINDOW && !profile_->IsOffTheRecord()) {
ReparentWebContentsIntoAppBrowser(contents_, extension);
}
#endif // !defined(OS_MACOSX)
#if defined(OS_MACOSX)
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kDisableHostedAppShimCreation)) {
if (!silent_install && !base::CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kDisableHostedAppShimCreation)) {
web_app::RevealAppShimInFinderForApp(current_profile, extension);
}
#endif
......
......@@ -113,6 +113,10 @@ void CreateShortcutsWithInfo(ShortcutCreationReason reason,
// If the shortcut is for an application shortcut with the new bookmark app
// flow disabled, there will be no corresponding extension.
if (!shortcut_info->extension_id.empty()) {
// The profile manager does not exist in some unit tests.
if (!g_browser_process->profile_manager())
return;
// It's possible for the extension to be deleted before we get here.
// For example, creating a hosted app from a website. Double check that
// it still exists.
......
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