1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/icon_loader.h"
#include <windows.h>
#include <shellapi.h>
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/icon_util.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/win/dpi.h"
// static
IconGroupID IconLoader::ReadGroupIDFromFilepath(
const base::FilePath& filepath) {
if (!IsIconMutableFromFilepath(filepath))
return filepath.Extension();
return filepath.value();
}
// static
bool IconLoader::IsIconMutableFromFilepath(const base::FilePath& filepath) {
return filepath.MatchesExtension(L".exe") ||
filepath.MatchesExtension(L".dll") ||
filepath.MatchesExtension(L".ico");
}
// static
content::BrowserThread::ID IconLoader::ReadIconThreadID() {
return content::BrowserThread::FILE;
}
void IconLoader::ReadIcon() {
int size = 0;
switch (icon_size_) {
case IconLoader::SMALL:
size = SHGFI_SMALLICON;
break;
case IconLoader::NORMAL:
size = 0;
break;
case IconLoader::LARGE:
size = SHGFI_LARGEICON;
break;
default:
NOTREACHED();
}
image_.reset();
SHFILEINFO file_info = { 0 };
if (SHGetFileInfo(group_.c_str(), FILE_ATTRIBUTE_NORMAL, &file_info,
sizeof(SHFILEINFO),
SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) {
scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(
file_info.hIcon));
if (bitmap.get()) {
gfx::ImageSkia image_skia(gfx::ImageSkiaRep(*bitmap, gfx::GetDPIScale()));
image_skia.MakeThreadSafe();
image_.reset(new gfx::Image(image_skia));
DestroyIcon(file_info.hIcon);
}
}
// Always notify the delegate, regardless of success.
target_message_loop_->PostTask(FROM_HERE,
base::Bind(&IconLoader::NotifyDelegate, this));
}
|