Chromium Code Reviews| 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 } | |
| 34 | |
| 35 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} | |
| 36 | |
| 37 // extensions::IconImage::Observer overrides. | |
| 38 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { | |
| 39 if (observer_) | |
| 40 observer_->OnIconUpdated(); | |
| 41 } | |
| 42 | |
| 43 gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) { | |
| 44 gfx::ImageSkia base_icon = GetBaseIconFromAction(tab_id); | |
| 45 return action_->ApplyAttentionAndAnimation(base_icon, tab_id); | |
| 46 } | |
| 47 | |
| 48 gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction(int tab_id) { | |
| 49 gfx::ImageSkia icon = action_->GetExplicitlySetIcon(tab_id); | |
| 50 if (!icon.isNull()) | |
| 51 return icon; | |
| 52 if (action_->default_icon()) { | |
| 53 // If the icon image has already been created, return its image skia. | |
| 54 if (icon_.get()) | |
| 55 return icon_->image_skia(); | |
| 56 | |
| 57 icon_.reset(new IconImage( | |
|
Jeffrey Yasskin
2012/09/17 20:18:39
Now that action_ is set in the constructor, please
tbarzic
2012/09/17 22:06:10
Done.
| |
| 58 extension_, | |
| 59 *action_->default_icon(), | |
| 60 ExtensionAction::GetIconSizeForType(action_->action_type()), | |
| 61 GetDefaultIcon(), | |
| 62 this)); | |
| 63 return icon_->image_skia(); | |
| 64 } | |
| 65 | |
| 66 return GetDefaultIcon(); | |
| 67 } | |
| 68 | |
| OLD | NEW |