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

Side by Side Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 10086023: Expose array of bitmaps contained by gfx::Image similar to NSImage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nicer diff Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/themes/browser_theme_pack.cc ('k') | ui/gfx/canvas.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 std::vector<const SkBitmap*>& bitmaps =
201 NSBitmapImageRep* image_rep = 202 info_.favicon.ToImageSkia()->bitmaps();
202 SkBitmapToImageRep(*info_.favicon.GetSkBitmapAtIndex(i)); 203 for (size_t i = 0; i < bitmaps.size(); ++i) {
204 NSBitmapImageRep* image_rep = SkBitmapToImageRep(*bitmaps[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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 const ShellIntegration::ShortcutInfo& shortcut_info) { 256 const ShellIntegration::ShortcutInfo& shortcut_info) {
255 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 257 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
256 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); 258 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID());
257 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info, 259 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info,
258 bundle_id); 260 bundle_id);
259 return shortcut_creator.CreateShortcut(); 261 return shortcut_creator.CreateShortcut();
260 } 262 }
261 263
262 } // namespace internals 264 } // namespace internals
263 } // namespace web_app 265 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/themes/browser_theme_pack.cc ('k') | ui/gfx/canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698