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

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: Changes as requested 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
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 =
202 info_.favicon.ToImageSkia()->bitmaps();
203 for (size_t i = 0; i < bitmaps.size(); ++i) {
201 NSBitmapImageRep* image_rep = 204 NSBitmapImageRep* image_rep =
202 SkBitmapToImageRep(*info_.favicon.GetSkBitmapAtIndex(i)); 205 SkBitmapToImageRep(*bitmaps[i]);
Robert Sesek 2012/04/20 16:33:14 nit: can you join this with the nxt line?
203 if (!image_rep) 206 if (!image_rep)
204 continue; 207 continue;
205 208
206 // Missing an icon size is not fatal so don't fail if adding the bitmap 209 // Missing an icon size is not fatal so don't fail if adding the bitmap
207 // doesn't work. 210 // doesn't work.
208 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep)) 211 if (!AddBitmapImageRepToIconFamily(icon_family, image_rep))
209 continue; 212 continue;
210 213
211 image_added = true; 214 image_added = true;
212 } 215 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 const ShellIntegration::ShortcutInfo& shortcut_info) { 257 const ShellIntegration::ShortcutInfo& shortcut_info) {
255 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 258 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
256 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); 259 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID());
257 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info, 260 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info,
258 bundle_id); 261 bundle_id);
259 return shortcut_creator.CreateShortcut(); 262 return shortcut_creator.CreateShortcut();
260 } 263 }
261 264
262 } // namespace internals 265 } // namespace internals
263 } // namespace web_app 266 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698