Index: chrome/browser/extensions/extension_action_icon_factory.cc |
diff --git a/chrome/browser/extensions/extension_action_icon_factory.cc b/chrome/browser/extensions/extension_action_icon_factory.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f571c07ff68a860f73d00f27439ff1afb90f289a |
--- /dev/null |
+++ b/chrome/browser/extensions/extension_action_icon_factory.cc |
@@ -0,0 +1,82 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/extensions/extension_action_icon_factory.h" |
+ |
+#include "chrome/common/extensions/extension.h" |
+#include "chrome/common/extensions/extension_action.h" |
+#include "chrome/common/extensions/extension_icon_set.h" |
+#include "grit/theme_resources.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/image/image_skia.h" |
+ |
+using extensions::Extension; |
+using extensions::IconImage; |
+ |
+namespace { |
+ |
+int GetIconSizeForType(ExtensionAction::Type type) { |
+ switch (type) { |
+ case ExtensionAction::TYPE_BROWSER: |
+ case ExtensionAction::TYPE_PAGE: |
+ return extension_misc::EXTENSION_ICON_ACTION; |
+ case ExtensionAction::TYPE_SCRIPT_BADGE: |
+ return extension_misc::EXTENSION_ICON_BITTY; |
+ default: |
+ NOTREACHED(); |
+ return 0; |
+ } |
+} |
+ |
+gfx::ImageSkia GetDefaultIcon() { |
+ return *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_EXTENSIONS_FAVICON).ToImageSkia(); |
+} |
+ |
+} // namespace |
+ |
+ExtensionActionIconFactory::ExtensionActionIconFactory( |
+ const Extension* extension, Observer* observer) |
+ : extension_(extension), |
+ observer_(observer) { |
+} |
+ |
+ExtensionActionIconFactory::~ExtensionActionIconFactory() {} |
+ |
+// extensions::IconImage::Observer overrides. |
+void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) { |
+ if (observer_) |
+ observer_->OnIconUpdated(); |
+} |
+ |
+gfx::Image ExtensionActionIconFactory::GetIcon( |
+ const ExtensionAction* action, |
+ int tab_id) { |
+ gfx::ImageSkia base_icon = GetBaseIconFromAction(action, tab_id); |
+ return action->ApplyAttentionAndAnimation(base_icon, tab_id); |
+} |
+ |
+gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction( |
+ const ExtensionAction* action, |
+ int tab_id) { |
+ gfx::ImageSkia icon = action->GetExplicitlySetIcon(tab_id); |
+ if (!icon.isNull()) |
+ return icon; |
+ if (action->default_icon()) { |
+ // If icon set hasn't changed, return the present icon. |
Jeffrey Yasskin
2012/09/14 23:47:12
If GetIcon() is called with two different Extensio
tbarzic
2012/09/15 00:29:10
Done.
|
+ if (icon_.get()) { |
+ return icon_->image_skia(); |
+ } |
+ |
+ icon_.reset(new IconImage(extension_, |
Jeffrey Yasskin
2012/09/14 23:47:12
I see a path from the observer callback through Br
tbarzic
2012/09/15 00:29:10
if I get your comment correctly, you're afraid tha
|
+ *action->default_icon(), |
+ GetIconSizeForType(action->action_type()), |
+ GetDefaultIcon(), |
+ this)); |
+ return icon_->image_skia(); |
+ } |
+ |
+ return GetDefaultIcon(); |
+} |
+ |