| Index: chrome/browser/web_applications/web_app_mac.mm
|
| diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
|
| index d18f323d29a8e20ab16e6e4010c6d7a7a7f110c5..a86b03c5f7b9cd7ed2f71742f1f96b1594a34606 100644
|
| --- a/chrome/browser/web_applications/web_app_mac.mm
|
| +++ b/chrome/browser/web_applications/web_app_mac.mm
|
| @@ -66,6 +66,48 @@ NSBitmapImageRep* SkBitmapToRGBAImageRep(const SkBitmap& bitmap) {
|
| return [image_rep.release() autorelease];
|
| }
|
|
|
| +// Adds |image_rep| to |icon_family|. Returns true on success, false on failure.
|
| +bool AddBitmapImageRepToIconFamily(IconFamily* icon_family,
|
| + NSBitmapImageRep* image_rep) {
|
| + NSSize size = [image_rep size];
|
| + if (size.width != size.height)
|
| + return false;
|
| +
|
| + switch ((int)size.width) {
|
| + case 512:
|
| + return [icon_family setIconFamilyElement:kIconServices512PixelDataARGB
|
| + fromBitmapImageRep:image_rep];
|
| + case 256:
|
| + return [icon_family setIconFamilyElement:kIconServices256PixelDataARGB
|
| + fromBitmapImageRep:image_rep];
|
| + case 128:
|
| + return [icon_family setIconFamilyElement:kThumbnail32BitData
|
| + fromBitmapImageRep:image_rep] &&
|
| + [icon_family setIconFamilyElement:kThumbnail8BitMask
|
| + fromBitmapImageRep:image_rep];
|
| + case 32:
|
| + return [icon_family setIconFamilyElement:kLarge32BitData
|
| + fromBitmapImageRep:image_rep] &&
|
| + [icon_family setIconFamilyElement:kLarge8BitData
|
| + fromBitmapImageRep:image_rep] &&
|
| + [icon_family setIconFamilyElement:kLarge8BitMask
|
| + fromBitmapImageRep:image_rep] &&
|
| + [icon_family setIconFamilyElement:kLarge1BitMask
|
| + fromBitmapImageRep:image_rep];
|
| + case 16:
|
| + return [icon_family setIconFamilyElement:kSmall32BitData
|
| + fromBitmapImageRep:image_rep] &&
|
| + [icon_family setIconFamilyElement:kSmall8BitData
|
| + fromBitmapImageRep:image_rep] &&
|
| + [icon_family setIconFamilyElement:kSmall8BitMask
|
| + fromBitmapImageRep:image_rep] &&
|
| + [icon_family setIconFamilyElement:kSmall1BitMask
|
| + fromBitmapImageRep:image_rep];
|
| + default:
|
| + return false;
|
| + }
|
| +}
|
| +
|
| } // namespace
|
|
|
|
|
| @@ -182,31 +224,30 @@ bool WebAppShortcutCreator::UpdatePlist(const FilePath& app_path) const {
|
| }
|
|
|
| bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const {
|
| - // TODO(sail): Add support for multiple icon sizes.
|
| - if (info_.favicon.empty() || info_.favicon.width() != 32 ||
|
| - info_.favicon.height() != 32) {
|
| + if (info_.favicon.IsEmpty())
|
| return true;
|
| - }
|
| -
|
| - NSBitmapImageRep* image_rep = SkBitmapToRGBAImageRep(info_.favicon);
|
| - if (!image_rep)
|
| - return false;
|
|
|
| scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]);
|
| - bool success = [icon_family setIconFamilyElement:kLarge32BitData
|
| - fromBitmapImageRep:image_rep] &&
|
| - [icon_family setIconFamilyElement:kLarge8BitData
|
| - fromBitmapImageRep:image_rep] &&
|
| - [icon_family setIconFamilyElement:kLarge8BitMask
|
| - fromBitmapImageRep:image_rep] &&
|
| - [icon_family setIconFamilyElement:kLarge1BitMask
|
| - fromBitmapImageRep:image_rep];
|
| - if (!success)
|
| + bool image_added = false;
|
| + for (size_t i = 0; i < info_.favicon.GetNumberOfSkBitmaps(); ++i) {
|
| + NSBitmapImageRep* image_rep =
|
| + SkBitmapToRGBAImageRep(*info_.favicon.GetSkBitmapAtIndex(i));
|
| + if (!image_rep)
|
| + continue;
|
| +
|
| + if (!AddBitmapImageRepToIconFamily(icon_family, image_rep))
|
| + continue;
|
| +
|
| + image_added = true;
|
| + }
|
| +
|
| + if (!image_added)
|
| return false;
|
|
|
| FilePath resources_path = app_path.Append("Contents").Append("Resources");
|
| if (!file_util::CreateDirectory(resources_path))
|
| return false;
|
| +
|
| FilePath icon_path = resources_path.Append("app.icns");
|
| return [icon_family writeToFile:base::mac::FilePathToNSString(icon_path)];
|
| }
|
|
|