Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1278)

Unified Diff: chrome/browser/extensions/extension_action_icon_factory.cc

Issue 10905005: Change browser/page action default icon defined in manifest to support hidpi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forgot to update tests Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a96891cfc8017555ad8585984b596f5d43e099d8
--- /dev/null
+++ b/chrome/browser/extensions/extension_action_icon_factory.cc
@@ -0,0 +1,68 @@
+// 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 {
+
+gfx::ImageSkia GetDefaultIcon() {
+ return *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ IDR_EXTENSIONS_FAVICON).ToImageSkia();
+}
+
+} // namespace
+
+ExtensionActionIconFactory::ExtensionActionIconFactory(
+ const Extension* extension,
+ const ExtensionAction* action,
+ Observer* observer)
+ : extension_(extension),
+ action_(action),
+ observer_(observer) {
+}
+
+ExtensionActionIconFactory::~ExtensionActionIconFactory() {}
+
+// extensions::IconImage::Observer overrides.
+void ExtensionActionIconFactory::OnExtensionIconImageChanged(IconImage* image) {
+ if (observer_)
+ observer_->OnIconUpdated();
+}
+
+gfx::Image ExtensionActionIconFactory::GetIcon(int tab_id) {
+ gfx::ImageSkia base_icon = GetBaseIconFromAction(tab_id);
+ return action_->ApplyAttentionAndAnimation(base_icon, tab_id);
+}
+
+gfx::ImageSkia ExtensionActionIconFactory::GetBaseIconFromAction(int tab_id) {
+ gfx::ImageSkia icon = action_->GetExplicitlySetIcon(tab_id);
+ if (!icon.isNull())
+ return icon;
+ if (action_->default_icon()) {
+ // If the icon image has already been created, return its image skia.
+ if (icon_.get())
+ return icon_->image_skia();
+
+ 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.
+ extension_,
+ *action_->default_icon(),
+ ExtensionAction::GetIconSizeForType(action_->action_type()),
+ GetDefaultIcon(),
+ this));
+ return icon_->image_skia();
+ }
+
+ return GetDefaultIcon();
+}
+

Powered by Google App Engine
This is Rietveld 408576698