blob: 8502a7d40157056d609d8c85d4b123c059e9df14 [file] [log] [blame]
[email protected]66171ab2011-03-03 15:50:071// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]0f38ceae2009-05-08 19:01:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/icon_loader.h"
6
[email protected]09c6dec2009-06-16 19:57:227#import <AppKit/AppKit.h>
8
[email protected]0f38ceae2009-05-08 19:01:029#include "base/message_loop.h"
[email protected]34b99632011-01-01 01:01:0610#include "base/threading/thread.h"
[email protected]09c6dec2009-06-16 19:57:2211#include "base/sys_string_conversions.h"
12#include "skia/ext/skia_utils_mac.h"
13#include "third_party/skia/include/core/SkBitmap.h"
[email protected]0f38ceae2009-05-08 19:01:0214
15void IconLoader::ReadIcon() {
[email protected]09c6dec2009-06-16 19:57:2216 NSString* group = base::SysUTF8ToNSString(group_);
17 NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
18 NSImage* icon = [workspace iconForFileType:group];
19
[email protected]955c37b2011-06-08 21:26:3020 if (icon_size_ == ALL) {
21 // The NSImage already has all sizes.
22 image_.reset(new gfx::Image([icon retain]));
23 } else {
24 NSSize size = NSZeroSize;
25 switch (icon_size_) {
26 case IconLoader::SMALL:
27 size = NSMakeSize(16, 16);
28 break;
29 case IconLoader::NORMAL:
30 size = NSMakeSize(32, 32);
31 break;
32 default:
33 NOTREACHED();
34 }
35 image_.reset(new gfx::Image(new SkBitmap(
36 gfx::NSImageToSkBitmap(icon, size, false))));
37 }
[email protected]0f38ceae2009-05-08 19:01:0238
39 target_message_loop_->PostTask(FROM_HERE,
40 NewRunnableMethod(this, &IconLoader::NotifyDelegate));
41}