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 "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/extensions/extension_icon_image.h" |
| 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/common/extensions/extension_action.h" |
| 11 #include "chrome/common/extensions/extension_icon_set.h" |
| 12 #include "grit/theme_resources.h" |
| 13 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/image/image_skia.h" |
| 15 |
| 16 using extensions::Extension; |
| 17 using extensions::IconImage; |
| 18 |
| 19 namespace { |
| 20 |
| 21 int GetIconSizeForType(ExtensionAction::Type type) { |
| 22 switch (type) { |
| 23 case ExtensionAction::TYPE_BROWSER: |
| 24 case ExtensionAction::TYPE_PAGE: |
| 25 return extension_misc::EXTENSION_ICON_ACTION; |
| 26 case ExtensionAction::TYPE_SCRIPT_BADGE: |
| 27 return extension_misc::EXTENSION_ICON_BITTY; |
| 28 default: |
| 29 NOTREACHED(); |
| 30 return 0; |
| 31 } |
| 32 } |
| 33 |
| 34 gfx::ImageSkia GetDefaultIcon() { |
| 35 return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 36 IDR_EXTENSIONS_FAVICON).ToImageSkia(); |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 41 ExtensionActionIconFactory::ExtensionActionIconFactory( |
| 42 const Extension* extension, Observer* observer) |
| 43 : extension_(extension), |
| 44 observer_(observer) { |
| 45 } |
| 46 |
| 47 ExtensionActionIconFactory::~ExtensionActionIconFactory() {} |
| 48 |
| 49 // extensions::IconImage::Observer overrides. |
| 50 void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { |
| 51 observer_->OnIconUpdated(); |
| 52 } |
| 53 |
| 54 gfx::Image ExtensionActionIconFactory::GetIcon( |
| 55 const ExtensionAction* action, |
| 56 int tab_id) { |
| 57 gfx::ImageSkia base_icon = GetBaseIconFromAction(action, tab_id); |
| 58 return action->ApplyAttentionAndAnimation(base_icon, tab_id); |
| 59 } |
| 60 |
| 61 gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction( |
| 62 const ExtensionAction* action, |
| 63 int tab_id) { |
| 64 gfx::ImageSkia icon = action->GetExplicitlySetIcon(tab_id); |
| 65 if (!icon.isNull()) |
| 66 return icon; |
| 67 if (action->default_icon()) { |
| 68 // If icon set hasn't changed, return the present icon. |
| 69 if (icon_.get()) { |
| 70 return icon_->image_skia(); |
| 71 } |
| 72 |
| 73 icon_.reset(new IconImage(extension_, |
| 74 *action->default_icon(), |
| 75 GetIconSizeForType(action->action_type()), |
| 76 GetDefaultIcon(), |
| 77 this)); |
| 78 return icon_->image_skia(); |
| 79 } |
| 80 |
| 81 return GetDefaultIcon(); |
| 82 } |
| 83 |
OLD | NEW |