Chromium Code Reviews| Index: chrome/browser/extensions/extension_action_icon_factory.cc |
| diff --git a/chrome/browser/extensions/extension_action_icon_factory.cc b/chrome/browser/extensions/extension_action_icon_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d8195e9ead05553f0a249ac3efcdf652b43f41a4 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_action_icon_factory.cc |
| @@ -0,0 +1,62 @@ |
| +// 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/extensions/extension_action_icon_factory.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "chrome/browser/extensions/extension_icon_image.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "chrome/common/extensions/extension_icon_set.h" |
| +#include "grit/theme_resources.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/image/image_skia.h" |
| + |
| +using extensions::Extension; |
| +using extensions::IconImage; |
| + |
| +namespace { |
| + |
| +gfx::ImageSkia GetDefaultIcon() { |
| + return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| + IDR_EXTENSIONS_FAVICON).ToImageSkia(); |
| +} |
| + |
| +} // namespace |
| + |
| +// extension::IconImage wrapper for extension action icons. We need this |
| +// because ExtensionAction class cannot use extensions::IconImage directly. |
| +ExtensionActionIconFactory::ExtensionActionIconFactory( |
| + const Extension* extension, Observer* observer) |
| + : extension_(extension), |
| + observer_(observer), |
| + last_icon_set_(NULL), |
| + last_size_(0) { |
| +} |
| + |
| +ExtensionActionIconFactory::~ExtensionActionIconFactory() {} |
| + |
| +// extensions::IconImage::Observer overrides. |
| +void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { |
| + observer_->OnIconUpdated(); |
| +} |
| + |
| +gfx::ImageSkia ExtensionActionIconFactory::GetIcon( |
| + const ExtensionIconSet* icon_set, |
| + int desired_size) { |
| + // If icon set hasn't changed, return the present icon. |
| + if (icon_.get() && last_icon_set_ == icon_set) { |
| + DCHECK_EQ(last_size_, desired_size); |
|
Jeffrey Yasskin
2012/09/13 00:23:36
I don't see a reason to DCHECK that the sizes matc
tbarzic
2012/09/13 02:01:01
Done.
|
| + return icon_->image_skia(); |
| + } |
| + |
| + // TODO(tbarzic): Cache old icon, so we don't have to reload it if gets |
| + // requested again. |
| + icon_.reset( |
| + new IconImage(extension_, *icon_set, desired_size, GetDefaultIcon(), |
| + this)); |
| + last_icon_set_ = icon_set; |
| + last_size_ = desired_size; |
| + |
| + return icon_->image_skia(); |
| +} |