Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1544)

Unified Diff: chrome/browser/ui/web_applications/web_app_ui.cc

Issue 12881003: ShortcutInfo::favicon is now a gfx::ImageFamily instead of gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/web_applications/web_app_ui.cc
diff --git a/chrome/browser/ui/web_applications/web_app_ui.cc b/chrome/browser/ui/web_applications/web_app_ui.cc
index 754004c3613f7b0f96757a363e38481559996f0d..3d67c6f79c6b6c79f73c347a85aeb1267afe7b9e 100644
--- a/chrome/browser/ui/web_applications/web_app_ui.cc
+++ b/chrome/browser/ui/web_applications/web_app_ui.cc
@@ -29,6 +29,9 @@
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image.h"
+#include "ui/gfx/image/image_family.h"
+#include "ui/gfx/image/image_skia.h"
#if defined(OS_POSIX) && !defined(OS_MACOSX)
#include "base/environment.h"
@@ -195,8 +198,8 @@ void UpdateShortcutWorker::DidDownloadFavicon(
if (!bitmaps.empty() && !bitmaps[closest_index].isNull()) {
// Update icon with download image and update shortcut.
- shortcut_info_.favicon =
- gfx::Image::CreateFrom1xBitmap(bitmaps[closest_index]);
+ shortcut_info_.favicon.Add(
+ gfx::Image::CreateFrom1xBitmap(bitmaps[closest_index]));
extensions::TabHelper* extensions_tab_helper =
extensions::TabHelper::FromWebContents(web_contents_);
extensions_tab_helper->SetAppIcon(bitmaps[closest_index]);
@@ -270,8 +273,7 @@ void UpdateShortcutWorker::UpdateShortcutsOnFileThread() {
base::FilePath icon_file = web_app_path.Append(file_name_).ReplaceExtension(
FILE_PATH_LITERAL(".ico"));
- web_app::internals::CheckAndSaveIcon(icon_file,
- *shortcut_info_.favicon.ToSkBitmap());
+ web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info_.favicon);
// Update existing shortcuts' description, icon and app id.
CheckExistingShortcuts();
@@ -332,9 +334,25 @@ void OnImageLoaded(ShellIntegration::ShortcutInfo shortcut_info,
SkBitmap bmp = skia::ImageOperations::Resize(
*default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST,
size, size);
- shortcut_info.favicon = gfx::Image::CreateFrom1xBitmap(bmp);
+ shortcut_info.favicon.Add(gfx::Image::CreateFrom1xBitmap(bmp));
} else {
- shortcut_info.favicon = image;
+ // As described in UpdateShortcutInfoAndIconForApp, image contains all of
+ // the icons, hackily put into a single ImageSkia. Separate them out into
+ // individual ImageSkias and insert them into the icon family.
+ const gfx::ImageSkia& multires_image_skia = *(image.ToImageSkia());
+ // NOTE: Do not call ImageSkia::EnsureRepsForSupportedScaleFactors here.
+ // The image reps here are not really scale factors (ImageSkia is just being
+ // used as a handy container for multiple images), so it doesn't make sense
+ // to get other supported scale factors.
+ std::vector<gfx::ImageSkiaRep> image_reps =
+ multires_image_skia.image_reps();
+ for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
+ it != image_reps.end(); ++it) {
+ const gfx::ImageSkiaRep& image = *it;
+ gfx::ImageSkia image_skia(image);
+ image_skia.MakeThreadSafe();
+ shortcut_info.favicon.Add(image_skia);
+ }
}
callback.Run(shortcut_info);
@@ -368,7 +386,7 @@ void GetShortcutInfoForTab(WebContents* web_contents,
web_contents->GetTitle()) :
app_info.title;
info->description = app_info.description;
- info->favicon = gfx::Image(favicon_tab_helper->GetFavicon());
+ info->favicon.Add(favicon_tab_helper->GetFavicon());
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
@@ -402,6 +420,11 @@ void UpdateShortcutInfoAndIconForApp(
ShellIntegration::ShortcutInfo shortcut_info =
ShortcutInfoForExtensionAndProfile(&extension, profile);
+ // We want to load each icon into a separate ImageSkia to insert into an
+ // ImageFamily, but LoadImagesAsync currently only builds a single ImageSkia.
+ // Hack around this by loading all images into the ImageSkia as 100%
+ // representations, and later (in OnImageLoaded), pulling them out and
+ // individually inserting them into an ImageFamily.
benwells 2013/04/04 04:58:30 Should we change LoadImagesAsync to use ImageFamil
Matt Giuca 2013/04/04 05:15:36 Yes, I intend to do this in a separate CL.
std::vector<extensions::ImageLoader::ImageRepresentation> info_list;
for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) {
int size = kDesiredSizes[i];

Powered by Google App Engine
This is Rietveld 408576698