| 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..e60e5f46368f2ce018552be0657ba5fbe995f2a8
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/extension_action_icon_factory.cc
|
| @@ -0,0 +1,60 @@
|
| +// 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) {
|
| +}
|
| +
|
| +ExtensionActionIconFactory::~ExtensionActionIconFactory() {}
|
| +
|
| +// extensions::IconImage::Observer overrides.
|
| +void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) {
|
| + observer_->OnIconUpdated();
|
| +}
|
| +
|
| +gfx::ImageSkia ExtensionActionIconFactory::GetIcon(
|
| + const ExtensionIconSet* icon_set,
|
| + const gfx::Size& desired_size) {
|
| + // If icon set hasn't changed, return the present icon.
|
| + if (icon_.get() && last_icon_set_ == icon_set && last_size_ == desired_size) {
|
| + 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.width(),
|
| + GetDefaultIcon(), this));
|
| + last_icon_set_ = icon_set;
|
| + last_size_ = desired_size;
|
| +
|
| + return icon_->image_skia();
|
| +}
|
|
|