Ensure ephemeral apps have dock icons on mac
App shims are now created for ephemeral apps in the user data directory
to ensure that they have dock icons. App shims are not copied to the
Applications folder as ephemeral apps should be hidden from the OS.
BUG=375027
TEST=Launch an app ephemerally and ensure it has a dock icon, but does
not appear in Spotlight search results. Install the app fully and
ensure it now has both a dock icon and appears in Spotlight.
Review URL: https://codereview.chromium.org/311293002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276436 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/apps/shortcut_manager.cc b/chrome/browser/apps/shortcut_manager.cc
index 0da0a8d..9d47a5e 100644
--- a/chrome/browser/apps/shortcut_manager.cc
+++ b/chrome/browser/apps/shortcut_manager.cc
@@ -24,6 +24,7 @@
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extension_util.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/one_shot_event.h"
@@ -39,14 +40,21 @@
// Delay in seconds before running UpdateShortcutsForAllApps.
const int kUpdateShortcutsForAllAppsDelay = 10;
-// Creates a shortcut for an application in the applications menu, if there is
-// not already one present.
-void CreateShortcutsInApplicationsMenu(Profile* profile,
- const Extension* app) {
+void CreateShortcutsForApp(Profile* profile, const Extension* app) {
web_app::ShortcutLocations creation_locations;
- // Create the shortcut in the Chrome Apps subdir.
- creation_locations.applications_menu_location =
- web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS;
+
+ if (extensions::util::IsEphemeralApp(app->id(), profile)) {
+ // Ephemeral apps should not have visible shortcuts, but may still require
+ // platform-specific handling.
+ creation_locations.applications_menu_location =
+ web_app::APP_MENU_LOCATION_HIDDEN;
+ } else {
+ // Creates a shortcut for an app in the Chrome Apps subdir of the
+ // applications menu, if there is not already one present.
+ creation_locations.applications_menu_location =
+ web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS;
+ }
+
web_app::CreateShortcuts(
web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app);
}
@@ -120,7 +128,7 @@
web_app::UpdateAllShortcuts(
base::UTF8ToUTF16(old_name), profile_, extension);
} else {
- CreateShortcutsInApplicationsMenu(profile_, extension);
+ CreateShortcutsForApp(profile_, extension);
}
}
diff --git a/chrome/browser/extensions/extension_ui_util.cc b/chrome/browser/extensions/extension_ui_util.cc
index ab8c5ac..32b9e80d 100644
--- a/chrome/browser/extensions/extension_ui_util.cc
+++ b/chrome/browser/extensions/extension_ui_util.cc
@@ -30,9 +30,14 @@
bool ShouldDisplayInAppLauncher(const Extension* extension,
content::BrowserContext* context) {
+ return CanDisplayInAppLauncher(extension, context) &&
+ !util::IsEphemeralApp(extension->id(), context);
+}
+
+bool CanDisplayInAppLauncher(const Extension* extension,
+ content::BrowserContext* context) {
return extension->ShouldDisplayInAppLauncher() &&
- !IsBlockedByPolicy(extension, context) &&
- !util::IsEphemeralApp(extension->id(), context);
+ !IsBlockedByPolicy(extension, context);
}
bool ShouldDisplayInNewTabPage(const Extension* extension,
diff --git a/chrome/browser/extensions/extension_ui_util.h b/chrome/browser/extensions/extension_ui_util.h
index f9add92..c49c2bc 100644
--- a/chrome/browser/extensions/extension_ui_util.h
+++ b/chrome/browser/extensions/extension_ui_util.h
@@ -21,6 +21,12 @@
bool ShouldDisplayInAppLauncher(const Extension* extension,
content::BrowserContext* context);
+// Returns true if the extension can be displayed in the app launcher.
+// Checks whether the extension should be hidden due to policy, but does not
+// exclude ephemeral apps.
+bool CanDisplayInAppLauncher(const Extension* extension,
+ content::BrowserContext* context);
+
// Returns true if the extension should be displayed in the browser NTP.
// Checks whether the extension is an ephemeral app or should be hidden due to
// policy.
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc
index 958520b..e594589 100644
--- a/chrome/browser/web_applications/web_app.cc
+++ b/chrome/browser/web_applications/web_app.cc
@@ -294,8 +294,8 @@
bool ShouldCreateShortcutFor(Profile* profile,
const extensions::Extension* extension) {
return extension->is_platform_app() &&
- extension->location() != extensions::Manifest::COMPONENT &&
- extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile);
+ extension->location() != extensions::Manifest::COMPONENT &&
+ extensions::ui_util::CanDisplayInAppLauncher(extension, profile);
}
base::FilePath GetWebAppDataDirectory(const base::FilePath& profile_path,
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index 9199441..7bfa3d3 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -599,8 +599,13 @@
} else {
paths.push_back(app_data_dir_);
}
- paths.push_back(applications_dir);
+ bool shortcut_visible =
+ creation_locations.applications_menu_location != APP_MENU_LOCATION_HIDDEN;
+ if (shortcut_visible)
+ paths.push_back(applications_dir);
+
+ DCHECK(!paths.empty());
size_t success_count = CreateShortcutsIn(paths);
if (success_count == 0)
return false;
@@ -611,7 +616,8 @@
if (success_count != paths.size())
return false;
- if (creation_locations.in_quick_launch_bar && path_to_add_to_dock) {
+ if (creation_locations.in_quick_launch_bar && path_to_add_to_dock &&
+ shortcut_visible) {
switch (dock::AddIcon(path_to_add_to_dock, nil)) {
case dock::IconAddFailure:
// If adding the icon failed, instead reveal the Finder window.
diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc
index ddc8f0d..26317e9 100644
--- a/chrome/browser/web_applications/web_app_win.cc
+++ b/chrome/browser/web_applications/web_app_win.cc
@@ -448,6 +448,10 @@
ShortcutCreationReason creation_reason) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+ // Nothing to do on Windows for hidden apps.
+ if (creation_locations.applications_menu_location == APP_MENU_LOCATION_HIDDEN)
+ return true;
+
// Shortcut paths under which to create shortcuts.
std::vector<base::FilePath> shortcut_paths =
GetShortcutPaths(creation_locations);