OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 6 |
| 7 #include "chrome/common/extensions/extension.h" |
| 8 #include "chrome/common/extensions/extension_action.h" |
| 9 #include "chrome/common/extensions/extension_icon_set.h" |
| 10 #include "grit/theme_resources.h" |
| 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/image/image_skia.h" |
| 13 |
| 14 using extensions::Extension; |
| 15 using extensions::IconImage; |
| 16 |
| 17 namespace { |
| 18 |
| 19 gfx::ImageSkia GetDefaultIcon() { |
| 20 return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 21 IDR_EXTENSIONS_FAVICON).ToImageSkia(); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 ExtensionActionIconFactory::ExtensionActionIconFactory( |
| 27 const Extension* extension, |
| 28 const ExtensionAction* action, |
| 29 Observer* observer) |
| 30 : extension_(extension), |
| 31 action_(action), |
| 32 observer_(observer) { |
| 33 if (action_->default_icon()) { |
| 34 default_icon_.reset(new IconImage( |
| 35 extension_, |
| 36 *action_->default_icon(), |
| 37 ExtensionAction::GetIconSizeForType(action_->action_type()), |
| 38 GetDefaultIcon(), |
| 39 this)); |
| 40 } |
| 41 } |
| 42 |
| 43 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} |
| 44 |
| 45 // extensions::IconImage::Observer overrides. |
| 46 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { |
| 47 if (observer_) |
| 48 observer_->OnIconUpdated(); |
| 49 } |
| 50 |
| 51 gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) { |
| 52 gfx::ImageSkia base_icon = GetBaseIconFromAction(tab_id); |
| 53 return action_->ApplyAttentionAndAnimation(base_icon, tab_id); |
| 54 } |
| 55 |
| 56 gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction(int tab_id) { |
| 57 gfx::ImageSkia icon = action_->GetExplicitlySetIcon(tab_id); |
| 58 if (!icon.isNull()) |
| 59 return icon; |
| 60 |
| 61 if (default_icon_.get()) |
| 62 return default_icon_->image_skia(); |
| 63 |
| 64 return GetDefaultIcon(); |
| 65 } |
| 66 |
OLD | NEW |