| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
| 11 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
| 12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 13 #include "base/memory/scoped_nsobject.h" | 13 #include "base/memory/scoped_nsobject.h" |
| 14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/web_applications/web_app.h" | 17 #include "chrome/browser/web_applications/web_app.h" |
| 18 #include "chrome/common/chrome_paths_internal.h" | 18 #include "chrome/common/chrome_paths_internal.h" |
| 19 #include "chrome/common/mac/app_mode_common.h" | 19 #include "chrome/common/mac/app_mode_common.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
| 22 #include "skia/ext/skia_utils_mac.h" | 22 #include "skia/ext/skia_utils_mac.h" |
| 23 #include "third_party/icon_family/IconFamily.h" | 23 #include "third_party/icon_family/IconFamily.h" |
| 24 #include "ui/base/l10n/l10n_util_mac.h" | 24 #include "ui/base/l10n/l10n_util_mac.h" |
| 25 #include "ui/gfx/image/image_skia.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Creates a NSBitmapImageRep from |bitmap|. | 29 // Creates a NSBitmapImageRep from |bitmap|. |
| 29 NSBitmapImageRep* SkBitmapToImageRep(const SkBitmap& bitmap) { | 30 NSBitmapImageRep* SkBitmapToImageRep(const SkBitmap& bitmap) { |
| 30 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 31 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
| 31 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 32 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
| 32 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( | 33 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( |
| 33 bitmap, color_space.get()); | 34 bitmap, color_space.get()); |
| 34 return base::mac::ObjCCast<NSBitmapImageRep>( | 35 return base::mac::ObjCCast<NSBitmapImageRep>( |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 forKey:app_mode::kCrAppModeExtensionPathKey]; | 191 forKey:app_mode::kCrAppModeExtensionPathKey]; |
| 191 return [plist writeToFile:plist_path atomically:YES]; | 192 return [plist writeToFile:plist_path atomically:YES]; |
| 192 } | 193 } |
| 193 | 194 |
| 194 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { | 195 bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const { |
| 195 if (info_.favicon.IsEmpty()) | 196 if (info_.favicon.IsEmpty()) |
| 196 return true; | 197 return true; |
| 197 | 198 |
| 198 scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); | 199 scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); |
| 199 bool image_added = false; | 200 bool image_added = false; |
| 200 for (size_t i = 0; i < info_.favicon.GetNumberOfSkBitmaps(); ++i) { | 201 const gfx::ImageSkia* image_skia = info_.favicon.ToImageSkia(); |
| 202 for (size_t i = 0; i < image_skia->GetNumberOfBitmaps(); ++i) { |
| 201 NSBitmapImageRep* image_rep = | 203 NSBitmapImageRep* image_rep = |
| 202 SkBitmapToImageRep(*info_.favicon.GetSkBitmapAtIndex(i)); | 204 SkBitmapToImageRep(*image_skia->GetBitmapAtIndex(i)); |
| 203 if (!image_rep) | 205 if (!image_rep) |
| 204 continue; | 206 continue; |
| 205 | 207 |
| 206 // Missing an icon size is not fatal so don't fail if adding the bitmap | 208 // Missing an icon size is not fatal so don't fail if adding the bitmap |
| 207 // doesn't work. | 209 // doesn't work. |
| 208 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) | 210 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) |
| 209 continue; | 211 continue; |
| 210 | 212 |
| 211 image_added = true; | 213 image_added = true; |
| 212 } | 214 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 const ShellIntegration::ShortcutInfo& shortcut_info) { | 255 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 254 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 256 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 255 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); | 257 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); |
| 256 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info, | 258 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info, |
| 257 bundle_id); | 259 bundle_id); |
| 258 shortcut_creator.CreateShortcut(); | 260 shortcut_creator.CreateShortcut(); |
| 259 } | 261 } |
| 260 | 262 |
| 261 } // namespace internals | 263 } // namespace internals |
| 262 } // namespace web_app | 264 } // namespace web_app |
| OLD | NEW |