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
3 // found in the LICENSE file.
5 #include "chrome/browser/icon_loader.h"
10 #include "base/bind.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/threading/thread.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/icon_util.h"
15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/gfx/size.h"
17 #include "ui/gfx/win/dpi.h"
20 IconGroupID
IconLoader::ReadGroupIDFromFilepath(
21 const base::FilePath
& filepath
) {
22 if (!IsIconMutableFromFilepath(filepath
))
23 return filepath
.Extension();
24 return filepath
.value();
28 bool IconLoader::IsIconMutableFromFilepath(const base::FilePath
& filepath
) {
29 return filepath
.MatchesExtension(L
".exe") ||
30 filepath
.MatchesExtension(L
".dll") ||
31 filepath
.MatchesExtension(L
".ico");
35 content::BrowserThread::ID
IconLoader::ReadIconThreadID() {
36 return content::BrowserThread::FILE;
39 void IconLoader::ReadIcon() {
42 case IconLoader::SMALL
:
43 size
= SHGFI_SMALLICON
;
45 case IconLoader::NORMAL
:
48 case IconLoader::LARGE
:
49 size
= SHGFI_LARGEICON
;
57 SHFILEINFO file_info
= { 0 };
58 if (SHGetFileInfo(group_
.c_str(), FILE_ATTRIBUTE_NORMAL
, &file_info
,
60 SHGFI_ICON
| size
| SHGFI_USEFILEATTRIBUTES
)) {
61 scoped_ptr
<SkBitmap
> bitmap(IconUtil::CreateSkBitmapFromHICON(
64 gfx::ImageSkia
image_skia(gfx::ImageSkiaRep(
65 *bitmap
, gfx::win::GetDeviceScaleFactor()));
66 image_skia
.MakeThreadSafe();
67 image_
.reset(new gfx::Image(image_skia
));
68 DestroyIcon(file_info
.hIcon
);
72 // Always notify the delegate, regardless of success.
73 target_message_loop_
->PostTask(FROM_HERE
,
74 base::Bind(&IconLoader::NotifyDelegate
, this));