| Index: chrome/browser/extensions/extension_icon_manager.cc
|
| diff --git a/chrome/browser/extensions/extension_icon_manager.cc b/chrome/browser/extensions/extension_icon_manager.cc
|
| index 561d02b14d39cbb1ec40501b15d46e0564c5d4be..6d07d747a9ee2c89f021abebbba3e962eb9fefab 100644
|
| --- a/chrome/browser/extensions/extension_icon_manager.cc
|
| +++ b/chrome/browser/extensions/extension_icon_manager.cc
|
| @@ -21,32 +21,12 @@
|
| #include "ui/gfx/favicon_size.h"
|
| #include "ui/gfx/geometry/size.h"
|
| #include "ui/gfx/image/image.h"
|
| +#include "ui/gfx/image/image_skia_operations.h"
|
| #include "ui/gfx/paint_vector_icon.h"
|
| -#include "ui/gfx/skbitmap_operations.h"
|
| #include "ui/gfx/vector_icons_public.h"
|
| #include "ui/native_theme/common_theme.h"
|
| #include "ui/native_theme/native_theme.h"
|
|
|
| -namespace {
|
| -
|
| -// Helper function to create a new bitmap with |padding| amount of empty space
|
| -// around the original bitmap.
|
| -static SkBitmap ApplyPadding(const SkBitmap& source,
|
| - const gfx::Insets& padding) {
|
| - std::unique_ptr<gfx::Canvas> result(
|
| - new gfx::Canvas(gfx::Size(source.width() + padding.width(),
|
| - source.height() + padding.height()),
|
| - 1.0f, false));
|
| - result->DrawImageInt(
|
| - gfx::ImageSkia::CreateFrom1xBitmap(source),
|
| - 0, 0, source.width(), source.height(),
|
| - padding.left(), padding.top(), source.width(), source.height(),
|
| - false);
|
| - return result->ExtractImageRep().sk_bitmap();
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| ExtensionIconManager::ExtensionIconManager()
|
| : monochrome_(false),
|
| weak_ptr_factory_(this) {
|
| @@ -57,36 +37,29 @@ ExtensionIconManager::~ExtensionIconManager() {
|
|
|
| void ExtensionIconManager::LoadIcon(content::BrowserContext* context,
|
| const extensions::Extension* extension) {
|
| - extensions::ExtensionResource icon_resource =
|
| - extensions::IconsInfo::GetIconResource(
|
| - extension,
|
| - extension_misc::EXTENSION_ICON_BITTY,
|
| - ExtensionIconSet::MATCH_BIGGER);
|
| - if (!icon_resource.extension_root().empty()) {
|
| - // Insert into pending_icons_ first because LoadImage can call us back
|
| - // synchronously if the image is already cached.
|
| - pending_icons_.insert(extension->id());
|
| - extensions::ImageLoader* loader = extensions::ImageLoader::Get(context);
|
| - loader->LoadImageAsync(extension, icon_resource,
|
| - gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize),
|
| - base::Bind(
|
| - &ExtensionIconManager::OnImageLoaded,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - extension->id()));
|
| - }
|
| + // Insert into pending_icons_ first because LoadImage can call us back
|
| + // synchronously if the image is already cached.
|
| + pending_icons_.insert(extension->id());
|
| + extensions::ImageLoader* loader = extensions::ImageLoader::Get(context);
|
| + loader->LoadImageAtEveryScaleFactorAsync(
|
| + extension, gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize),
|
| + base::Bind(&ExtensionIconManager::OnImageLoaded,
|
| + weak_ptr_factory_.GetWeakPtr(), extension->id()));
|
| }
|
|
|
| -const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) {
|
| - const SkBitmap* result = NULL;
|
| - if (base::ContainsKey(icons_, extension_id)) {
|
| - result = &icons_[extension_id];
|
| - } else {
|
| +gfx::Image ExtensionIconManager::GetIcon(const std::string& extension_id) {
|
| + auto iter = icons_.find(extension_id);
|
| + gfx::Image* result = nullptr;
|
| + if (iter == icons_.end()) {
|
| EnsureDefaultIcon();
|
| result = &default_icon_;
|
| + } else {
|
| + result = &iter->second;
|
| }
|
| +
|
| DCHECK(result);
|
| - DCHECK_EQ(gfx::kFaviconSize + padding_.width(), result->width());
|
| - DCHECK_EQ(gfx::kFaviconSize + padding_.height(), result->height());
|
| + DCHECK_EQ(gfx::kFaviconSize, result->Width());
|
| + DCHECK_EQ(gfx::kFaviconSize, result->Height());
|
| return *result;
|
| }
|
|
|
| @@ -102,41 +75,21 @@ void ExtensionIconManager::OnImageLoaded(const std::string& extension_id,
|
|
|
| // We may have removed the icon while waiting for it to load. In that case,
|
| // do nothing.
|
| - if (!base::ContainsKey(pending_icons_, extension_id))
|
| + if (pending_icons_.erase(extension_id) == 0)
|
| return;
|
|
|
| - pending_icons_.erase(extension_id);
|
| - icons_[extension_id] = ApplyTransforms(*image.ToSkBitmap());
|
| -}
|
| -
|
| -void ExtensionIconManager::EnsureDefaultIcon() {
|
| - if (default_icon_.empty()) {
|
| - // TODO(estade): use correct scale factor instead of 1x.
|
| - default_icon_ = ApplyPadding(
|
| - *gfx::CreateVectorIcon(gfx::VectorIconId::EXTENSION, gfx::kFaviconSize,
|
| - gfx::kChromeIconGrey)
|
| - .bitmap(),
|
| - padding_);
|
| - }
|
| -}
|
| -
|
| -SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) {
|
| - SkBitmap result = source;
|
| -
|
| - if (result.width() != gfx::kFaviconSize ||
|
| - result.height() != gfx::kFaviconSize) {
|
| - result = skia::ImageOperations::Resize(
|
| - result, skia::ImageOperations::RESIZE_LANCZOS3,
|
| - gfx::kFaviconSize, gfx::kFaviconSize);
|
| - }
|
| -
|
| + gfx::Image modified_image = image;
|
| if (monochrome_) {
|
| color_utils::HSL shift = {-1, 0, 0.6};
|
| - result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift);
|
| + modified_image = gfx::Image(gfx::ImageSkiaOperations::CreateHSLShiftedImage(
|
| + image.AsImageSkia(), shift));
|
| }
|
| + icons_[extension_id] = modified_image;
|
| +}
|
|
|
| - if (!padding_.IsEmpty())
|
| - result = ApplyPadding(result, padding_);
|
| -
|
| - return result;
|
| +void ExtensionIconManager::EnsureDefaultIcon() {
|
| + if (default_icon_.IsEmpty()) {
|
| + default_icon_ = gfx::Image(gfx::CreateVectorIcon(
|
| + gfx::VectorIconId::EXTENSION, gfx::kFaviconSize, gfx::kChromeIconGrey));
|
| + }
|
| }
|
|
|