| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 5 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_action.h" | 7 #include "chrome/browser/extensions/extension_action.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "extensions/common/extension.h" | 9 #include "ui/gfx/image/image.h" |
| 10 #include "extensions/common/extension_icon_set.h" | |
| 11 #include "grit/theme_resources.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/gfx/image/image_skia.h" | 10 #include "ui/gfx/image/image_skia.h" |
| 14 | 11 |
| 15 using extensions::Extension; | 12 using extensions::Extension; |
| 16 using extensions::IconImage; | 13 using extensions::IconImage; |
| 17 | 14 |
| 18 namespace { | |
| 19 | |
| 20 gfx::ImageSkia GetDefaultIcon() { | |
| 21 return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 22 IDR_EXTENSIONS_FAVICON).ToImageSkia(); | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 ExtensionActionIconFactory::ExtensionActionIconFactory( | 15 ExtensionActionIconFactory::ExtensionActionIconFactory( |
| 28 Profile* profile, | 16 Profile* profile, |
| 29 const Extension* extension, | 17 const Extension* extension, |
| 30 const ExtensionAction* action, | 18 ExtensionAction* action, |
| 31 Observer* observer) | 19 Observer* observer) |
| 32 : extension_(extension), | 20 : extension_(extension), |
| 33 action_(action), | 21 action_(action), |
| 34 observer_(observer) { | 22 observer_(observer), |
| 35 if (action_->default_icon()) { | 23 icon_image_observer_(this) { |
| 36 default_icon_.reset(new IconImage( | 24 extensions::IconImage* default_icon_image = |
| 37 profile, | 25 action->LoadDefaultIconImage(*extension, profile); |
| 38 extension_, | 26 if (default_icon_image) |
| 39 *action_->default_icon(), | 27 icon_image_observer_.Add(default_icon_image); |
| 40 ExtensionAction::GetIconSizeForType(action_->action_type()), | |
| 41 GetDefaultIcon(), | |
| 42 this)); | |
| 43 } | |
| 44 } | 28 } |
| 45 | 29 |
| 46 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} | 30 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} |
| 47 | 31 |
| 48 // extensions::IconImage::Observer overrides. | 32 // extensions::IconImage::Observer overrides. |
| 49 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { | 33 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { |
| 50 if (observer_) | 34 if (observer_) |
| 51 observer_->OnIconUpdated(); | 35 observer_->OnIconUpdated(); |
| 52 } | 36 } |
| 53 | 37 |
| 38 void ExtensionActionIconFactory::OnExtensionIconImageDestroyed( |
| 39 IconImage* image) { |
| 40 icon_image_observer_.RemoveAll(); |
| 41 } |
| 42 |
| 54 gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) { | 43 gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) { |
| 55 gfx::ImageSkia base_icon = GetBaseIconFromAction(tab_id); | 44 return gfx::Image(GetBaseIconFromAction(tab_id)); |
| 56 return gfx::Image(base_icon); | |
| 57 } | 45 } |
| 58 | 46 |
| 59 gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction(int tab_id) { | 47 gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction(int tab_id) { |
| 60 gfx::ImageSkia icon = action_->GetExplicitlySetIcon(tab_id); | 48 gfx::ImageSkia icon = action_->GetExplicitlySetIcon(tab_id); |
| 61 if (!icon.isNull()) | 49 if (!icon.isNull()) |
| 62 return icon; | 50 return icon; |
| 63 | 51 |
| 64 icon = action_->GetDeclarativeIcon(tab_id); | 52 icon = action_->GetDeclarativeIcon(tab_id); |
| 65 if (!icon.isNull()) | 53 if (!icon.isNull()) |
| 66 return icon; | 54 return icon; |
| 67 | 55 |
| 68 if (default_icon_) | 56 return action_->GetDefaultIconImage(); |
| 69 return default_icon_->image_skia(); | |
| 70 | |
| 71 return GetDefaultIcon(); | |
| 72 } | 57 } |
| OLD | NEW |