| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_win.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 "app/gfx/icon_util.h" | 10 #include "app/gfx/icon_util.h" |
| 11 #include "base/gfx/size.h" | 11 #include "base/gfx/size.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/thread.h" | 13 #include "base/thread.h" |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "skia/include/SkBitmap.h" | |
| 16 | 14 |
| 17 IconLoader* IconLoader::Create(const FilePath& path, IconSize size, | 15 void IconLoader::ReadIcon() { |
| 18 Delegate* delegate) { | |
| 19 return new IconLoaderWin(path, size, delegate); | |
| 20 } | |
| 21 | |
| 22 IconLoaderWin::IconLoaderWin(const FilePath& path, IconSize size, | |
| 23 Delegate* delegate) | |
| 24 : path_(path), | |
| 25 icon_size_(size), | |
| 26 bitmap_(NULL), | |
| 27 delegate_(delegate) { | |
| 28 } | |
| 29 | |
| 30 IconLoaderWin::~IconLoaderWin() { | |
| 31 delete bitmap_; | |
| 32 } | |
| 33 | |
| 34 void IconLoaderWin::Start() { | |
| 35 target_message_loop_ = MessageLoop::current(); | |
| 36 | |
| 37 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, | |
| 38 NewRunnableMethod(this, &IconLoaderWin::ReadIcon)); | |
| 39 } | |
| 40 | |
| 41 void IconLoaderWin::ReadIcon() { | |
| 42 int size = 0; | 16 int size = 0; |
| 43 switch (icon_size_) { | 17 switch (icon_size_) { |
| 44 case IconLoader::SMALL: | 18 case IconLoader::SMALL: |
| 45 size = SHGFI_SMALLICON; | 19 size = SHGFI_SMALLICON; |
| 46 break; | 20 break; |
| 47 case IconLoader::NORMAL: | 21 case IconLoader::NORMAL: |
| 48 size = 0; | 22 size = 0; |
| 49 break; | 23 break; |
| 50 case IconLoader::LARGE: | 24 case IconLoader::LARGE: |
| 51 size = SHGFI_LARGEICON; | 25 size = SHGFI_LARGEICON; |
| 52 break; | 26 break; |
| 53 default: | 27 default: |
| 54 NOTREACHED(); | 28 NOTREACHED(); |
| 55 } | 29 } |
| 56 SHFILEINFO file_info = { 0 }; | 30 SHFILEINFO file_info = { 0 }; |
| 57 if (!SHGetFileInfo(path_.value().c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, | 31 if (!SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, |
| 58 sizeof(SHFILEINFO), | 32 sizeof(SHFILEINFO), |
| 59 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) | 33 SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) |
| 60 return; | 34 return; |
| 61 | 35 |
| 62 ICONINFO icon_info = { 0 }; | 36 ICONINFO icon_info = { 0 }; |
| 63 BITMAP bitmap_info = { 0 }; | 37 BITMAP bitmap_info = { 0 }; |
| 64 | 38 |
| 65 BOOL r = ::GetIconInfo(file_info.hIcon, &icon_info); | 39 BOOL r = ::GetIconInfo(file_info.hIcon, &icon_info); |
| 66 DCHECK(r); | 40 DCHECK(r); |
| 67 r = ::GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); | 41 r = ::GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); |
| 68 DCHECK(r); | 42 DCHECK(r); |
| 69 | 43 |
| 70 gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight); | 44 gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight); |
| 71 bitmap_ = IconUtil::CreateSkBitmapFromHICON(file_info.hIcon, icon_size); | 45 bitmap_ = IconUtil::CreateSkBitmapFromHICON(file_info.hIcon, icon_size); |
| 72 | 46 |
| 73 target_message_loop_->PostTask(FROM_HERE, | 47 target_message_loop_->PostTask(FROM_HERE, |
| 74 NewRunnableMethod(this, &IconLoaderWin::NotifyDelegate)); | 48 NewRunnableMethod(this, &IconLoader::NotifyDelegate)); |
| 75 } | 49 } |
| 76 | |
| 77 void IconLoaderWin::NotifyDelegate() { | |
| 78 delegate_->OnBitmapLoaded(this, bitmap_); | |
| 79 bitmap_ = NULL; | |
| 80 } | |
| OLD | NEW |