blob: 6abeb4734b6aa759fa01aacdce6229f8e56054ec [file] [log] [blame]
[email protected]92614aaee2012-03-15 00:54:491// Copyright (c) 2012 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]a27a2bc2011-11-15 21:25:519#include "base/bind.h"
[email protected]bc0147b2013-04-03 20:50:5910#include "base/files/file_path.h"
[email protected]467a106e2013-07-18 12:07:1911#include "base/message_loop/message_loop.h"
[email protected]3268d7b72013-03-28 17:41:4312#include "base/strings/sys_string_conversions.h"
[email protected]467a106e2013-07-18 12:07:1913#include "base/threading/thread.h"
[email protected]679facce2012-07-25 16:13:1214#include "ui/gfx/image/image_skia.h"
15#include "ui/gfx/image/image_skia_util_mac.h"
[email protected]0f38ceae2009-05-08 19:01:0216
[email protected]bc0147b2013-04-03 20:50:5917// static
18IconGroupID IconLoader::ReadGroupIDFromFilepath(
19 const base::FilePath& filepath) {
20 return filepath.Extension();
21}
22
[email protected]b3b6a372014-03-12 01:48:0423// static
[email protected]681b4b82013-04-09 23:34:2124bool IconLoader::IsIconMutableFromFilepath(const base::FilePath&) {
25 return false;
26}
27
[email protected]b3b6a372014-03-12 01:48:0428// static
29content::BrowserThread::ID IconLoader::ReadIconThreadID() {
30 return content::BrowserThread::FILE;
31}
32
[email protected]0f38ceae2009-05-08 19:01:0233void IconLoader::ReadIcon() {
[email protected]09c6dec2009-06-16 19:57:2234 NSString* group = base::SysUTF8ToNSString(group_);
35 NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
36 NSImage* icon = [workspace iconForFileType:group];
37
[email protected]955c37b2011-06-08 21:26:3038 if (icon_size_ == ALL) {
39 // The NSImage already has all sizes.
40 image_.reset(new gfx::Image([icon retain]));
41 } else {
42 NSSize size = NSZeroSize;
43 switch (icon_size_) {
44 case IconLoader::SMALL:
45 size = NSMakeSize(16, 16);
46 break;
47 case IconLoader::NORMAL:
48 size = NSMakeSize(32, 32);
49 break;
50 default:
51 NOTREACHED();
52 }
[email protected]2b8ac342012-08-29 03:46:2753 gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size));
[email protected]6021d942012-11-14 01:44:3954 if (!image_skia.isNull()) {
55 image_skia.MakeThreadSafe();
56 image_.reset(new gfx::Image(image_skia));
57 }
[email protected]955c37b2011-06-08 21:26:3058 }
[email protected]0f38ceae2009-05-08 19:01:0259
pranay.kumar4b8db4d2015-04-29 11:12:0460 target_task_runner_->PostTask(FROM_HERE,
[email protected]a27a2bc2011-11-15 21:25:5161 base::Bind(&IconLoader::NotifyDelegate, this));
[email protected]0f38ceae2009-05-08 19:01:0262}