Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_action_icon_factory.cc
blob0e40e65fc420458d39bdd0c7a7f81b43c02be41c
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/extension_action_icon_factory.h"
7 #include "chrome/browser/extensions/extension_action.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/extensions/extension_icon_set.h"
10 #include "extensions/common/extension.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/image/image_skia.h"
15 using extensions::Extension;
16 using extensions::IconImage;
18 namespace {
20 gfx::ImageSkia GetDefaultIcon() {
21 return *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
22 IDR_EXTENSIONS_FAVICON).ToImageSkia();
25 } // namespace
27 ExtensionActionIconFactory::ExtensionActionIconFactory(
28 Profile* profile,
29 const Extension* extension,
30 const ExtensionAction* action,
31 Observer* observer)
32 : extension_(extension),
33 action_(action),
34 observer_(observer) {
35 if (action_->default_icon()) {
36 default_icon_.reset(new IconImage(
37 profile,
38 extension_,
39 *action_->default_icon(),
40 ExtensionAction::GetIconSizeForType(action_->action_type()),
41 GetDefaultIcon(),
42 this));
46 ExtensionActionIconFactory::~ExtensionActionIconFactory() {}
48 // extensions::IconImage::Observer overrides.
49 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) {
50 if (observer_)
51 observer_->OnIconUpdated();
54 gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) {
55 gfx::ImageSkia base_icon = GetBaseIconFromAction(tab_id);
56 return action_->ApplyAttentionAndAnimation(base_icon, tab_id);
59 gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction(int tab_id) {
60 gfx::ImageSkia icon = action_->GetExplicitlySetIcon(tab_id);
61 if (!icon.isNull())
62 return icon;
64 if (default_icon_)
65 return default_icon_->image_skia();
67 return GetDefaultIcon();