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/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
13 #include "base/mac/mac_logging.h" | 13 #include "base/mac/mac_logging.h" |
14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
16 #include "base/memory/scoped_nsobject.h" | 16 #include "base/memory/scoped_nsobject.h" |
17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "chrome/browser/web_applications/web_app.h" | 19 #include "chrome/browser/web_applications/web_app.h" |
20 #include "chrome/common/chrome_paths_internal.h" | 20 #include "chrome/common/chrome_paths_internal.h" |
21 #include "chrome/common/mac/app_mode_common.h" | 21 #include "chrome/common/mac/app_mode_common.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
24 #include "skia/ext/skia_utils_mac.h" | 24 #include "skia/ext/skia_utils_mac.h" |
25 #include "third_party/icon_family/IconFamily.h" | 25 #include "third_party/icon_family/IconFamily.h" |
26 #include "ui/base/l10n/l10n_util_mac.h" | 26 #include "ui/base/l10n/l10n_util_mac.h" |
27 #include "ui/gfx/icon_family.h" | |
27 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // Creates a NSBitmapImageRep from |bitmap|. | 32 // Creates a NSBitmapImageRep from |bitmap|. |
32 NSBitmapImageRep* SkBitmapToImageRep(const SkBitmap& bitmap) { | 33 NSBitmapImageRep* SkBitmapToImageRep(const SkBitmap& bitmap) { |
33 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 34 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
34 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 35 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
35 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( | 36 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( |
36 bitmap, color_space.get()); | 37 bitmap, color_space.get()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 [plist setObject:GetBundleIdentifier(plist) | 191 [plist setObject:GetBundleIdentifier(plist) |
191 forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; | 192 forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; |
192 [plist setObject:base::mac::FilePathToNSString(user_data_dir_) | 193 [plist setObject:base::mac::FilePathToNSString(user_data_dir_) |
193 forKey:app_mode::kCrAppModeUserDataDirKey]; | 194 forKey:app_mode::kCrAppModeUserDataDirKey]; |
194 [plist setObject:base::mac::FilePathToNSString(info_.profile_path.BaseName()) | 195 [plist setObject:base::mac::FilePathToNSString(info_.profile_path.BaseName()) |
195 forKey:app_mode::kCrAppModeProfileDirKey]; | 196 forKey:app_mode::kCrAppModeProfileDirKey]; |
196 return [plist writeToFile:plist_path atomically:YES]; | 197 return [plist writeToFile:plist_path atomically:YES]; |
197 } | 198 } |
198 | 199 |
199 bool WebAppShortcutCreator::UpdateIcon(const base::FilePath& app_path) const { | 200 bool WebAppShortcutCreator::UpdateIcon(const base::FilePath& app_path) const { |
200 if (info_.favicon.IsEmpty()) | 201 if (info_.favicon.empty()) |
201 return true; | 202 return true; |
202 | 203 |
203 scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); | 204 scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); |
204 bool image_added = false; | 205 bool image_added = false; |
205 info_.favicon.ToImageSkia()->EnsureRepsForSupportedScaleFactors(); | 206 for (gfx::IconFamily::const_iterator it = info_.favicon.begin(); |
206 std::vector<gfx::ImageSkiaRep> image_reps = | 207 it != info_.favicon.end(); ++it) { |
207 info_.favicon.ToImageSkia()->image_reps(); | 208 // TODO(mgiuca): Do we want to do this? DO NOT SUBMIT. |
208 for (size_t i = 0; i < image_reps.size(); ++i) { | 209 // it->EnsureRepsForSupportedScaleFactors(); |
209 NSBitmapImageRep* image_rep = SkBitmapToImageRep( | 210 const SkBitmap& bitmap = *it->bitmap(); |
210 image_reps[i].sk_bitmap()); | 211 NSBitmapImageRep* image_rep = SkBitmapToImageRep(bitmap); |
pkotwicz
2013/03/20 22:19:52
There is one case where |favicon| can have an Imag
| |
211 if (!image_rep) | 212 if (!image_rep) |
212 continue; | 213 continue; |
213 | 214 |
214 // Missing an icon size is not fatal so don't fail if adding the bitmap | 215 // Missing an icon size is not fatal so don't fail if adding the bitmap |
215 // doesn't work. | 216 // doesn't work. |
216 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) | 217 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) |
217 continue; | 218 continue; |
218 | 219 |
219 image_added = true; | 220 image_added = true; |
220 } | 221 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 void UpdatePlatformShortcuts( | 301 void UpdatePlatformShortcuts( |
301 const base::FilePath& web_app_path, | 302 const base::FilePath& web_app_path, |
302 const ShellIntegration::ShortcutInfo& shortcut_info) { | 303 const ShellIntegration::ShortcutInfo& shortcut_info) { |
303 // TODO(benwells): Implement this when shortcuts / weblings are enabled on | 304 // TODO(benwells): Implement this when shortcuts / weblings are enabled on |
304 // mac. | 305 // mac. |
305 } | 306 } |
306 | 307 |
307 } // namespace internals | 308 } // namespace internals |
308 | 309 |
309 } // namespace web_app | 310 } // namespace web_app |
OLD | NEW |