[email protected] | 92614aaee | 2012-03-15 00:54:49 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 2 | // 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] | 09c6dec | 2009-06-16 19:57:22 | [diff] [blame] | 7 | #import <AppKit/AppKit.h> |
8 | |||||
[email protected] | a27a2bc | 2011-11-15 21:25:51 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
[email protected] | 467a106e | 2013-07-18 12:07:19 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
[email protected] | 3268d7b7 | 2013-03-28 17:41:43 | [diff] [blame] | 12 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 467a106e | 2013-07-18 12:07:19 | [diff] [blame] | 13 | #include "base/threading/thread.h" |
[email protected] | 679facce | 2012-07-25 16:13:12 | [diff] [blame] | 14 | #include "ui/gfx/image/image_skia.h" |
15 | #include "ui/gfx/image/image_skia_util_mac.h" | ||||
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 16 | |
[email protected] | bc0147b | 2013-04-03 20:50:59 | [diff] [blame] | 17 | // static |
18 | IconGroupID IconLoader::ReadGroupIDFromFilepath( | ||||
19 | const base::FilePath& filepath) { | ||||
20 | return filepath.Extension(); | ||||
21 | } | ||||
22 | |||||
[email protected] | b3b6a37 | 2014-03-12 01:48:04 | [diff] [blame] | 23 | // static |
[email protected] | 681b4b8 | 2013-04-09 23:34:21 | [diff] [blame] | 24 | bool IconLoader::IsIconMutableFromFilepath(const base::FilePath&) { |
25 | return false; | ||||
26 | } | ||||
27 | |||||
[email protected] | b3b6a37 | 2014-03-12 01:48:04 | [diff] [blame] | 28 | // static |
29 | content::BrowserThread::ID IconLoader::ReadIconThreadID() { | ||||
30 | return content::BrowserThread::FILE; | ||||
31 | } | ||||
32 | |||||
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 33 | void IconLoader::ReadIcon() { |
[email protected] | 09c6dec | 2009-06-16 19:57:22 | [diff] [blame] | 34 | NSString* group = base::SysUTF8ToNSString(group_); |
35 | NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; | ||||
36 | NSImage* icon = [workspace iconForFileType:group]; | ||||
37 | |||||
[email protected] | 955c37b | 2011-06-08 21:26:30 | [diff] [blame] | 38 | 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] | 2b8ac34 | 2012-08-29 03:46:27 | [diff] [blame] | 53 | gfx::ImageSkia image_skia(gfx::ImageSkiaFromResizedNSImage(icon, size)); |
[email protected] | 6021d94 | 2012-11-14 01:44:39 | [diff] [blame] | 54 | if (!image_skia.isNull()) { |
55 | image_skia.MakeThreadSafe(); | ||||
56 | image_.reset(new gfx::Image(image_skia)); | ||||
57 | } | ||||
[email protected] | 955c37b | 2011-06-08 21:26:30 | [diff] [blame] | 58 | } |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 59 | |
pranay.kumar | 4b8db4d | 2015-04-29 11:12:04 | [diff] [blame] | 60 | target_task_runner_->PostTask(FROM_HERE, |
[email protected] | a27a2bc | 2011-11-15 21:25:51 | [diff] [blame] | 61 | base::Bind(&IconLoader::NotifyDelegate, this)); |
[email protected] | 0f38ceae | 2009-05-08 19:01:02 | [diff] [blame] | 62 | } |