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/strings/sys_string_conversions.h" | 17 #include "base/strings/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/image/image_skia.h" | 27 #include "ui/gfx/image/image_family.h" |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Creates a NSBitmapImageRep from |bitmap|. | 31 // Creates a NSBitmapImageRep from |bitmap|. |
32 NSBitmapImageRep* SkBitmapToImageRep(const SkBitmap& bitmap) { | 32 NSBitmapImageRep* SkBitmapToImageRep(const SkBitmap& bitmap) { |
33 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 33 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
34 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 34 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
35 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( | 35 NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( |
36 bitmap, color_space.get()); | 36 bitmap, color_space.get()); |
37 return base::mac::ObjCCast<NSBitmapImageRep>( | 37 return base::mac::ObjCCast<NSBitmapImageRep>( |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 [plist setObject:GetBundleIdentifier(plist) | 204 [plist setObject:GetBundleIdentifier(plist) |
205 forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; | 205 forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; |
206 [plist setObject:base::mac::FilePathToNSString(user_data_dir_) | 206 [plist setObject:base::mac::FilePathToNSString(user_data_dir_) |
207 forKey:app_mode::kCrAppModeUserDataDirKey]; | 207 forKey:app_mode::kCrAppModeUserDataDirKey]; |
208 [plist setObject:base::mac::FilePathToNSString(info_.profile_path.BaseName()) | 208 [plist setObject:base::mac::FilePathToNSString(info_.profile_path.BaseName()) |
209 forKey:app_mode::kCrAppModeProfileDirKey]; | 209 forKey:app_mode::kCrAppModeProfileDirKey]; |
210 return [plist writeToFile:plist_path atomically:YES]; | 210 return [plist writeToFile:plist_path atomically:YES]; |
211 } | 211 } |
212 | 212 |
213 bool WebAppShortcutCreator::UpdateIcon(const base::FilePath& app_path) const { | 213 bool WebAppShortcutCreator::UpdateIcon(const base::FilePath& app_path) const { |
214 if (info_.favicon.IsEmpty()) | 214 if (info_.favicon.empty()) |
215 return true; | 215 return true; |
216 | 216 |
217 scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); | 217 scoped_nsobject<IconFamily> icon_family([[IconFamily alloc] init]); |
218 bool image_added = false; | 218 bool image_added = false; |
219 info_.favicon.ToImageSkia()->EnsureRepsForSupportedScaleFactors(); | 219 for (gfx::ImageFamily::const_iterator it = info_.favicon.begin(); |
220 std::vector<gfx::ImageSkiaRep> image_reps = | 220 it != info_.favicon.end(); ++it) { |
221 info_.favicon.ToImageSkia()->image_reps(); | 221 it->EnsureRepsForSupportedScaleFactors(); |
pkotwicz
2013/04/04 18:34:40
EnsureRepsForSupportedScaleFactors() is not necess
Matt Giuca
2013/04/05 06:30:13
:O I thought I removed this.
| |
222 for (size_t i = 0; i < image_reps.size(); ++i) { | 222 if (it->IsEmpty()) |
223 NSBitmapImageRep* image_rep = SkBitmapToImageRep( | 223 continue; |
224 image_reps[i].sk_bitmap()); | 224 NSBitmapImageRep* image_rep = SkBitmapToImageRep(*it->ToSkBitmap()); |
Robert Sesek
2013/04/04 18:39:02
ToNSImage and get the bitmap reps via the NSImage
Matt Giuca
2013/04/05 06:30:13
Done. But note that SkBitmapToImageRep called SkBi
| |
225 if (!image_rep) | 225 if (!image_rep) |
226 continue; | 226 continue; |
227 | 227 |
228 // Missing an icon size is not fatal so don't fail if adding the bitmap | 228 // Missing an icon size is not fatal so don't fail if adding the bitmap |
229 // doesn't work. | 229 // doesn't work. |
230 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) | 230 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) |
231 continue; | 231 continue; |
232 | 232 |
233 image_added = true; | 233 image_added = true; |
234 } | 234 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 void UpdatePlatformShortcuts( | 314 void UpdatePlatformShortcuts( |
315 const base::FilePath& web_app_path, | 315 const base::FilePath& web_app_path, |
316 const ShellIntegration::ShortcutInfo& shortcut_info) { | 316 const ShellIntegration::ShortcutInfo& shortcut_info) { |
317 // TODO(benwells): Implement this when shortcuts / weblings are enabled on | 317 // TODO(benwells): Implement this when shortcuts / weblings are enabled on |
318 // mac. | 318 // mac. |
319 } | 319 } |
320 | 320 |
321 } // namespace internals | 321 } // namespace internals |
322 | 322 |
323 } // namespace web_app | 323 } // namespace web_app |
OLD | NEW |