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.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"
19 IconGroupID
IconLoader::ReadGroupIDFromFilepath(
20 const base::FilePath
& filepath
) {
21 if (!IsIconMutableFromFilepath(filepath
))
22 return filepath
.Extension();
23 return filepath
.value();
26 bool IconLoader::IsIconMutableFromFilepath(const base::FilePath
& filepath
) {
27 base::FilePath::StringType extension
= filepath
.Extension();
28 return extension
== L
".exe" || extension
== L
".dll" || extension
== L
".ico";
31 void IconLoader::ReadIcon() {
34 case IconLoader::SMALL
:
35 size
= SHGFI_SMALLICON
;
37 case IconLoader::NORMAL
:
40 case IconLoader::LARGE
:
41 size
= SHGFI_LARGEICON
;
49 SHFILEINFO file_info
= { 0 };
50 if (SHGetFileInfo(group_
.c_str(), FILE_ATTRIBUTE_NORMAL
, &file_info
,
52 SHGFI_ICON
| size
| SHGFI_USEFILEATTRIBUTES
)) {
53 scoped_ptr
<SkBitmap
> bitmap(IconUtil::CreateSkBitmapFromHICON(
56 gfx::ImageSkia image_skia
= gfx::ImageSkia::CreateFrom1xBitmap(*bitmap
);
57 image_skia
.MakeThreadSafe();
58 image_
.reset(new gfx::Image(image_skia
));
59 DestroyIcon(file_info
.hIcon
);
63 // Always notify the delegate, regardless of success.
64 target_message_loop_
->PostTask(FROM_HERE
,
65 base::Bind(&IconLoader::NotifyDelegate
, this));