summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 09:59:44 +0000
committerbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 09:59:44 +0000
commite66ba95f9045eb7fd37498cdd4a9405e4b52480d (patch)
tree07d2b31620b874fa7e102b91770946bdb2936caf
parentee36e2d509db33c7e3f7fa7c2a1b98a825efb327 (diff)
downloadchromium_src-e66ba95f9045eb7fd37498cdd4a9405e4b52480d.zip
chromium_src-e66ba95f9045eb7fd37498cdd4a9405e4b52480d.tar.gz
chromium_src-e66ba95f9045eb7fd37498cdd4a9405e4b52480d.tar.bz2
Stop auto creating shortcuts when v2 packaged apps are installed.
This change also updates the icon of any shortcuts when apps are updated. BUG=139140, 146071, 153981 Review URL: https://chromiumcodereview.appspot.com/11035025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160814 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/app_shortcut_manager.cc22
-rw-r--r--chrome/browser/extensions/app_shortcut_manager.h6
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc5
-rw-r--r--chrome/browser/web_applications/web_app.cc19
-rw-r--r--chrome/browser/web_applications/web_app.h15
-rw-r--r--chrome/browser/web_applications/web_app_android.cc4
-rw-r--r--chrome/browser/web_applications/web_app_linux.cc8
-rw-r--r--chrome/browser/web_applications/web_app_mac.mm9
-rw-r--r--chrome/browser/web_applications/web_app_win.cc17
9 files changed, 79 insertions, 26 deletions
diff --git a/chrome/browser/extensions/app_shortcut_manager.cc b/chrome/browser/extensions/app_shortcut_manager.cc
index e1f5f5d..7d1f275 100644
--- a/chrome/browser/extensions/app_shortcut_manager.cc
+++ b/chrome/browser/extensions/app_shortcut_manager.cc
@@ -20,9 +20,6 @@
namespace extensions {
namespace {
-// Allow tests to disable shortcut creation, to prevent developers' desktops
-// becoming overrun with shortcuts.
-bool disable_shortcut_creation_for_tests = false;
#if defined(OS_MACOSX)
const int kDesiredSizes[] = {16, 32, 128, 256, 512};
@@ -73,7 +70,7 @@ void AppShortcutManager::OnImageLoaded(const gfx::Image& image,
shortcut_info_.favicon = image;
}
- web_app::CreateShortcuts(shortcut_info_);
+ web_app::UpdateAllShortcuts(shortcut_info_);
}
void AppShortcutManager::Observe(int type,
@@ -84,18 +81,14 @@ void AppShortcutManager::Observe(int type,
case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
const Extension* extension = content::Details<const Extension>(
details).ptr();
- if (!disable_shortcut_creation_for_tests &&
- extension->is_platform_app() &&
- extension->location() != Extension::LOAD) {
- InstallApplicationShortcuts(extension);
- }
+ if (extension->is_platform_app())
+ UpdateApplicationShortcuts(extension);
break;
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
const Extension* extension = content::Details<const Extension>(
details).ptr();
- if (!disable_shortcut_creation_for_tests)
- DeleteApplicationShortcuts(extension);
+ DeleteApplicationShortcuts(extension);
break;
}
default:
@@ -104,12 +97,7 @@ void AppShortcutManager::Observe(int type,
#endif
}
-// static
-void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) {
- disable_shortcut_creation_for_tests = disabled;
-}
-
-void AppShortcutManager::InstallApplicationShortcuts(
+void AppShortcutManager::UpdateApplicationShortcuts(
const Extension* extension) {
shortcut_info_ = ShortcutInfoForExtensionAndProfile(extension, profile_);
diff --git a/chrome/browser/extensions/app_shortcut_manager.h b/chrome/browser/extensions/app_shortcut_manager.h
index 872cd73..bc78b24 100644
--- a/chrome/browser/extensions/app_shortcut_manager.h
+++ b/chrome/browser/extensions/app_shortcut_manager.h
@@ -14,6 +14,7 @@
class Profile;
namespace extensions {
+
// This class manages the installation of shortcuts for platform apps.
class AppShortcutManager : public ImageLoadingTracker::Observer,
public content::NotificationObserver {
@@ -33,10 +34,8 @@ class AppShortcutManager : public ImageLoadingTracker::Observer,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- static void SetShortcutCreationDisabledForTesting(bool disabled);
private:
- // Install the shortcuts for an application.
- void InstallApplicationShortcuts(const Extension* extension);
+ void UpdateApplicationShortcuts(const Extension* extension);
void DeleteApplicationShortcuts(const Extension* extension);
content::NotificationRegistrar registrar_;
@@ -48,6 +47,7 @@ class AppShortcutManager : public ImageLoadingTracker::Observer,
DISALLOW_COPY_AND_ASSIGN(AppShortcutManager);
};
+
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_APP_SHORTCUT_MANAGER_H_
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index bbb3aa5..481aa5d 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -51,12 +51,9 @@ ExtensionBrowserTest::ExtensionBrowserTest()
target_visible_page_action_count_(-1),
current_channel_(chrome::VersionInfo::CHANNEL_DEV) {
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
- extensions::AppShortcutManager::SetShortcutCreationDisabledForTesting(true);
}
-ExtensionBrowserTest::~ExtensionBrowserTest() {
- extensions::AppShortcutManager::SetShortcutCreationDisabledForTesting(false);
-}
+ExtensionBrowserTest::~ExtensionBrowserTest() {}
void ExtensionBrowserTest::SetUpCommandLine(CommandLine* command_line) {
PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc
index e7558e5..654299e 100644
--- a/chrome/browser/web_applications/web_app.cc
+++ b/chrome/browser/web_applications/web_app.cc
@@ -38,6 +38,16 @@ void DeleteShortcutsOnFileThread(
shortcut_data_dir, shortcut_info);
}
+void UpdateShortcutsOnFileThread(
+ const ShellIntegration::ShortcutInfo& shortcut_info) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory(
+ shortcut_info.profile_path, shortcut_info.extension_id, GURL());
+ return web_app::internals::UpdatePlatformShortcuts(
+ shortcut_data_dir, shortcut_info);
+}
+
} // namespace
namespace web_app {
@@ -148,6 +158,15 @@ void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info) {
base::Bind(&DeleteShortcutsOnFileThread, shortcut_info));
}
+void UpdateAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&UpdateShortcutsOnFileThread, shortcut_info));
+}
+
bool CreateShortcutsOnFileThread(
const ShellIntegration::ShortcutInfo& shortcut_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h
index 2322504..56b6612 100644
--- a/chrome/browser/web_applications/web_app.h
+++ b/chrome/browser/web_applications/web_app.h
@@ -47,13 +47,17 @@ std::string GenerateApplicationNameFromExtensionId(const std::string& id);
std::string GetExtensionIdFromApplicationName(const std::string& app_name);
// Creates shortcuts for web application based on given shortcut data.
-// |shortcut_info| contains information about the shortcut to create.
+// |shortcut_info| contains information about the shortcuts to create.
void CreateShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info);
// Delete all the shortcuts that have been created for the given
// |shortcut_data| in the profile with |profile_path|.
void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info);
+// Updates shortcuts for web application based on given shortcut data.
+// |shortcut_info| contains information about the shortcuts to update.
+void UpdateAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info);
+
// Creates a shortcut. Must be called on the file thread. This is used to
// implement CreateShortcuts() above, and can also be used directly from the
// file thread. |shortcut_info| contains info about the shortcut to create.
@@ -95,11 +99,18 @@ bool CreatePlatformShortcuts(
// Delete all the shortcuts we have added for this extension. This is the
// platform specific implementation of the DeleteAllShortcuts function, and
-// is executed on the FILE thread..
+// is executed on the FILE thread.
void DeletePlatformShortcuts(
const FilePath& shortcut_data_path,
const ShellIntegration::ShortcutInfo& shortcut_info);
+// Updates all the shortcuts we have added for this extension. This is the
+// platform specific implementation of the UpdateAllShortcuts function, and
+// is executed on the FILE thread.
+void UpdatePlatformShortcuts(
+ const FilePath& shortcut_data_path,
+ const ShellIntegration::ShortcutInfo& shortcut_info);
+
// Sanitizes |name| and returns a version of it that is safe to use as an
// on-disk file name .
FilePath GetSanitizedFileName(const string16& name);
diff --git a/chrome/browser/web_applications/web_app_android.cc b/chrome/browser/web_applications/web_app_android.cc
index b5f00cf..2008ece 100644
--- a/chrome/browser/web_applications/web_app_android.cc
+++ b/chrome/browser/web_applications/web_app_android.cc
@@ -17,5 +17,9 @@ void DeletePlatformShortcuts(
const FilePath& web_app_path,
const ShellIntegration::ShortcutInfo& shortcut_info) {}
+void UpdatePlatformShortcuts(
+ const FilePath& web_app_path,
+ const ShellIntegration::ShortcutInfo& shortcut_info) {}
+
} // namespace internals
} // namespace web_app
diff --git a/chrome/browser/web_applications/web_app_linux.cc b/chrome/browser/web_applications/web_app_linux.cc
index c66968d..18ac835 100644
--- a/chrome/browser/web_applications/web_app_linux.cc
+++ b/chrome/browser/web_applications/web_app_linux.cc
@@ -10,6 +10,7 @@
#include "content/public/browser/browser_thread.h"
namespace web_app {
+
namespace internals {
bool CreatePlatformShortcuts(
@@ -35,5 +36,12 @@ void DeletePlatformShortcuts(
shortcut_info.extension_id);
}
+void UpdatePlatformShortcuts(
+ const FilePath& web_app_path,
+ const ShellIntegration::ShortcutInfo& shortcut_info) {
+ // TODO(benwells): Implement this.
+}
+
} // namespace internals
+
} // namespace web_app
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index f373076..2ab8560 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -250,6 +250,7 @@ void WebAppShortcutCreator::RevealGeneratedBundleInFinder(
} // namespace
namespace web_app {
+
namespace internals {
bool CreatePlatformShortcuts(
@@ -269,5 +270,13 @@ void DeletePlatformShortcuts(
// mac.
}
+void UpdatePlatformShortcuts(
+ const FilePath& web_app_path,
+ const ShellIntegration::ShortcutInfo& shortcut_info) {
+ // TODO(benwells): Implement this when shortcuts / weblings are enabled on
+ // mac.
+}
+
} // namespace internals
+
} // namespace web_app
diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc
index d1d5634..f1df116 100644
--- a/chrome/browser/web_applications/web_app_win.cc
+++ b/chrome/browser/web_applications/web_app_win.cc
@@ -296,6 +296,23 @@ bool CreatePlatformShortcuts(
return success;
}
+void UpdatePlatformShortcuts(
+ const FilePath& web_app_path,
+ const ShellIntegration::ShortcutInfo& shortcut_info) {
+ // Generates file name to use with persisted ico and shortcut file.
+ FilePath file_name =
+ web_app::internals::GetSanitizedFileName(shortcut_info.title);
+
+ // If an icon file exists, and is out of date, replace it with the new icon
+ // and let the shell know the icon has been modified.
+ FilePath icon_file = web_app_path.Append(file_name).ReplaceExtension(
+ FILE_PATH_LITERAL(".ico"));
+ if (file_util::PathExists(icon_file)) {
+ web_app::internals::CheckAndSaveIcon(icon_file,
+ *shortcut_info.favicon.ToSkBitmap());
+ }
+}
+
void DeletePlatformShortcuts(
const FilePath& web_app_path,
const ShellIntegration::ShortcutInfo& shortcut_info) {