| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/icon_loader.h" | 5 #include "chrome/browser/icon_loader.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "ui/gfx/icon_util.h" | 14 #include "ui/gfx/icon_util.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
| 16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 | 17 |
| 18 void IconLoader::ReadIcon() { | 18 void IconLoader::ReadIcon(const IconGroupID& group) { |
| 19 int size = 0; | 19 int size = 0; |
| 20 switch (icon_size_) { | 20 switch (icon_size_) { |
| 21 case IconLoader::SMALL: | 21 case IconLoader::SMALL: |
| 22 size = SHGFI_SMALLICON; | 22 size = SHGFI_SMALLICON; |
| 23 break; | 23 break; |
| 24 case IconLoader::NORMAL: | 24 case IconLoader::NORMAL: |
| 25 size = 0; | 25 size = 0; |
| 26 break; | 26 break; |
| 27 case IconLoader::LARGE: | 27 case IconLoader::LARGE: |
| 28 size = SHGFI_LARGEICON; | 28 size = SHGFI_LARGEICON; |
| 29 break; | 29 break; |
| 30 default: | 30 default: |
| 31 NOTREACHED(); | 31 NOTREACHED(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 image_.reset(); | 34 image_.reset(); |
| 35 | 35 |
| 36 SHFILEINFO file_info = { 0 }; | 36 SHFILEINFO file_info = { 0 }; |
| 37 if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, | 37 if (SHGetFileInfo(group.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, |
| 38 sizeof(SHFILEINFO), | 38 sizeof(SHFILEINFO), |
| 39 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) { | 39 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) { |
| 40 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON( | 40 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON( |
| 41 file_info.hIcon)); | 41 file_info.hIcon)); |
| 42 if (bitmap.get()) { | 42 if (bitmap.get()) { |
| 43 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap); | 43 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap); |
| 44 image_skia.MakeThreadSafe(); | 44 image_skia.MakeThreadSafe(); |
| 45 image_.reset(new gfx::Image(image_skia)); | 45 image_.reset(new gfx::Image(image_skia)); |
| 46 DestroyIcon(file_info.hIcon); | 46 DestroyIcon(file_info.hIcon); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Always notify the delegate, regardless of success. | 50 // Always notify the delegate, regardless of success. |
| 51 target_message_loop_->PostTask(FROM_HERE, | 51 target_message_loop_->PostTask(FROM_HERE, |
| 52 base::Bind(&IconLoader::NotifyDelegate, this)); | 52 base::Bind(&IconLoader::NotifyDelegate, this)); |
| 53 } | 53 } |
| OLD | NEW |