1 // Copyright (c) 2011 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.
4
5 #include "chrome/browser/icon_loader.h"
6
7 #include <windows.h>
8 #include <shellapi.h>
9
10 #include "base/message_loop.h"
11 #include "base/threading/thread.h"
12 #include "ui/gfx/icon_util.h"
13 #include "ui/gfx/size.h"
14
ReadIcon()15 void IconLoader::ReadIcon() {
16 int size = 0;
17 switch (icon_size_) {
18 case IconLoader::SMALL:
19 size = SHGFI_SMALLICON;
20 break;
21 case IconLoader::NORMAL:
22 size = 0;
23 break;
24 case IconLoader::LARGE:
25 size = SHGFI_LARGEICON;
26 break;
27 default:
28 NOTREACHED();
29 }
30 SHFILEINFO file_info = { 0 };
31 if (!SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info,
32 sizeof(SHFILEINFO),
33 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES))
34 return;
35
36 ICONINFO icon_info = { 0 };
37 BITMAP bitmap_info = { 0 };
38
39 BOOL r = ::GetIconInfo(file_info.hIcon, &icon_info);
40 DCHECK(r);
41 r = ::GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info);
42 DCHECK(r);
43
44 gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight);
45 image_.reset(new gfx::Image(
46 IconUtil::CreateSkBitmapFromHICON(file_info.hIcon, icon_size)));
47
48 target_message_loop_->PostTask(FROM_HERE,
49 NewRunnableMethod(this, &IconLoader::NotifyDelegate));
50 }
51