summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_action_icon_factory.h
diff options
context:
space:
mode:
authortbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 05:53:45 +0000
committertbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-18 05:53:45 +0000
commit684cc6a02fb5e536a52cbccece01ef5c319252f1 (patch)
treea79b30a8b8d997a71e8e323fa10672c2497a3436 /chrome/browser/extensions/extension_action_icon_factory.h
parent910b34bb21c120b78aa84648d09330a415d538dc (diff)
downloadchromium_src-684cc6a02fb5e536a52cbccece01ef5c319252f1.zip
chromium_src-684cc6a02fb5e536a52cbccece01ef5c319252f1.tar.gz
chromium_src-684cc6a02fb5e536a52cbccece01ef5c319252f1.tar.bz2
Change browser/page action default icon defined in manifest to support hidpi.
To support hidpi for browser action default icons, ability to define dictionary of icon in manifest as default icons is added. Defining images of sizes 19 and 38 is allowed (other dictionary values will be ignored). The image to be painted will be determined based on screen density. Similary, for script badges, default icon is determined using 16 and 32 px icon defined in extension manifest. I have extracted actual icon loading code to extension_action_icon_factory.h/.cc, so it doesn't have to be implemented for all platform specific solutions. BUG=138025,135271 Review URL: https://chromiumcodereview.appspot.com/10905005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_action_icon_factory.h')
-rw-r--r--chrome/browser/extensions/extension_action_icon_factory.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_action_icon_factory.h b/chrome/browser/extensions/extension_action_icon_factory.h
new file mode 100644
index 0000000..a93c9a1
--- /dev/null
+++ b/chrome/browser/extensions/extension_action_icon_factory.h
@@ -0,0 +1,66 @@
+// 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.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/extensions/extension_icon_image.h"
+
+class ExtensionAction;
+class ExtensionIconSet;
+
+namespace extensions {
+class Extension;
+}
+
+// Used to get an icon to be used in the UI for an extension action.
+// If the extension action icon is the default icon defined in the extension's
+// manifest, it is loaded using extensions::IconImage. This icon can be loaded
+// asynchronously. The factory observes underlying IconImage and notifies its
+// own observer when the icon image changes.
+class ExtensionActionIconFactory : public extensions::IconImage::Observer {
+ public:
+ class Observer {
+ public:
+ virtual ~Observer() {}
+ // Called when the underlying icon image changes.
+ virtual void OnIconUpdated() = 0;
+ };
+
+ // Observer should outlive this.
+ ExtensionActionIconFactory(const extensions::Extension* extension,
+ const ExtensionAction* action,
+ Observer* observer);
+ virtual ~ExtensionActionIconFactory();
+
+ // extensions::IconImage override.
+ virtual void OnExtensionIconImageChanged(
+ extensions::IconImage* image) OVERRIDE;
+
+ // Gets the extension action icon for the tab.
+ // If there is an icon set using |SetIcon|, that icon is returned.
+ // Else, if there is a default icon set for the extension action, the icon is
+ // created using IconImage. Observer is triggered wheniever the icon gets
+ // updated.
+ // Else, extension favicon is returned.
+ // In all cases, action's attention and animation icon transformations are
+ // applied on the icon.
+ gfx::Image GetIcon(int tab_id);
+
+ private:
+ // Gets the icon that should be returned by |GetIcon| (without the attention
+ // and animation transformations).
+ gfx::ImageSkia GetBaseIconFromAction(int tab_id);
+
+ const extensions::Extension* extension_;
+ const ExtensionAction* action_;
+ Observer* observer_;
+ // Underlying icon image for the default icon.
+ scoped_ptr<extensions::IconImage> default_icon_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionActionIconFactory);
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_ICON_FACTORY_H_