Index: chrome/browser/extensions/app_shortcut_manager.cc |
diff --git a/chrome/browser/extensions/app_shortcut_manager.cc b/chrome/browser/extensions/app_shortcut_manager.cc |
index e24fc91fba9cef10810d052824db16c687cbd157..80ecfa0162067924f8f1f34ae502b4c5d0b6a45f 100644 |
--- a/chrome/browser/extensions/app_shortcut_manager.cc |
+++ b/chrome/browser/extensions/app_shortcut_manager.cc |
@@ -6,7 +6,6 @@ |
#include "base/command_line.h" |
#include "base/utf_string_conversions.h" |
-#include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/web_applications/web_app.h" |
#include "chrome/common/chrome_notification_types.h" |
@@ -15,12 +14,20 @@ |
#include "content/public/browser/notification_details.h" |
#include "content/public/browser/notification_source.h" |
#include "grit/theme_resources.h" |
+#include "skia/ext/image_operations.h" |
+#include "ui/base/resource/resource_bundle.h" |
namespace { |
- // Allow tests to disable shortcut creation, to prevent developers' desktops |
- // becoming overrun with shortcuts. |
- bool disable_shortcut_creation_for_tests = false; |
-} // 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}; |
+#else |
+const int kDesiredSizes[] = {32}; |
+#endif |
+} // namespace |
AppShortcutManager::AppShortcutManager(Profile* profile) |
: profile_(profile), |
@@ -29,15 +36,23 @@ AppShortcutManager::AppShortcutManager(Profile* profile) |
content::Source<Profile>(profile_)); |
} |
-void AppShortcutManager::OnImageLoaded(SkBitmap *image, |
- const ExtensionResource &resource, |
+void AppShortcutManager::OnImageLoaded(const gfx::Image& image, |
+ const std::string& extension_id, |
int index) { |
// If the image failed to load (e.g. if the resource being loaded was empty) |
// use the standard application icon. |
- if (!image || image->isNull()) |
- image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); |
+ if (image.IsEmpty()) { |
+ gfx::Image default_icon = |
+ ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); |
+ int size = kDesiredSizes[arraysize(kDesiredSizes) - 1]; |
+ SkBitmap bmp = skia::ImageOperations::Resize( |
+ *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, |
+ size, size); |
+ shortcut_info_.favicon = gfx::Image(bmp); |
+ } else { |
+ shortcut_info_.favicon = image; |
+ } |
- shortcut_info_.favicon = *image; |
web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); |
} |
@@ -65,8 +80,6 @@ void AppShortcutManager::InstallApplicationShortcuts( |
} |
#endif |
- const int kAppIconSize = 32; |
- |
shortcut_info_.extension_id = extension->id(); |
shortcut_info_.url = GURL(extension->launch_web_url()); |
shortcut_info_.title = UTF8ToUTF16(extension->name()); |
@@ -76,29 +89,36 @@ void AppShortcutManager::InstallApplicationShortcuts( |
shortcut_info_.create_in_quick_launch_bar = true; |
shortcut_info_.create_on_desktop = true; |
- // The icon will be resized to |max_size|. |
- const gfx::Size max_size(kAppIconSize, kAppIconSize); |
+ std::vector<ImageLoadingTracker::ImageInfo> info_list; |
+ for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) { |
+ int size = kDesiredSizes[i]; |
+ ExtensionResource resource = extension->GetIconResource( |
+ size, ExtensionIconSet::MATCH_EXACTLY); |
+ if (!resource.empty()) { |
+ info_list.push_back( |
+ ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size))); |
+ } |
+ } |
- // Look for an icon. If there is no icon at the ideal size, we will resize |
- // whatever we can get. Making a large icon smaller is prefered to making a |
- // small icon larger, so look for a larger icon first: |
- ExtensionResource icon_resource = extension->GetIconResource( |
- kAppIconSize, |
- ExtensionIconSet::MATCH_BIGGER); |
+ if (info_list.empty()) { |
+ size_t i = arraysize(kDesiredSizes) - 1; |
+ int size = kDesiredSizes[i]; |
- // If no icon exists that is the desired size or larger, get the |
- // largest icon available: |
- if (icon_resource.empty()) { |
- icon_resource = extension->GetIconResource( |
- kAppIconSize, |
- ExtensionIconSet::MATCH_SMALLER); |
+ // If there is no icon at the desired sizes, we will resize what we can get. |
+ // Making a large icon smaller is prefered to making a small icon larger, so |
+ // look for a larger icon first: |
+ ExtensionResource resource = extension->GetIconResource( |
+ size, ExtensionIconSet::MATCH_BIGGER); |
+ if (resource.empty()) { |
+ resource = extension->GetIconResource( |
+ size, ExtensionIconSet::MATCH_SMALLER); |
+ } |
+ info_list.push_back( |
+ ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size))); |
} |
- // icon_resource may still be empty at this point, in which case LoadImage |
- // which call the OnImageLoaded callback with a NULL image and exit |
+ // |icon_resources| may still be empty at this point, in which case LoadImage |
+ // will call the OnImageLoaded callback with an empty image and exit |
// immediately. |
- tracker_.LoadImage(extension, |
- icon_resource, |
- max_size, |
- ImageLoadingTracker::DONT_CACHE); |
+ tracker_.LoadImages(extension, info_list, ImageLoadingTracker::DONT_CACHE); |
} |