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

Unified Diff: chrome/common/extensions/extension_action.h

Issue 10806058: Move icon fallbacks into ExtensionAction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move the icon cache inside ExtensionAction. Created 8 years, 5 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/common/extensions/extension_action.h
diff --git a/chrome/common/extensions/extension_action.h b/chrome/common/extensions/extension_action.h
index 4de8e1f400d2032c060ff70f9f34c7314b302fc8..00b0e603f89fc40a1232802d9bc083833b0b3533 100644
--- a/chrome/common/extensions/extension_action.h
+++ b/chrome/common/extensions/extension_action.h
@@ -23,6 +23,7 @@ class SkDevice;
namespace gfx {
class Canvas;
+class Image;
class Rect;
}
@@ -119,6 +120,7 @@ class ExtensionAction {
// static icon paths from manifest -- only used with legacy page actions API.
std::vector<std::string>* icon_paths() { return &icon_paths_; }
+ const std::vector<std::string>* icon_paths() const { return &icon_paths_; }
// Set the url which the popup will load when the user clicks this action's
// icon. Setting an empty URL will disable the popup for a given tab.
@@ -142,15 +144,24 @@ class ExtensionAction {
// Icons are a bit different because the default value can be set to either a
// bitmap or a path. However, conceptually, there is only one default icon.
// Setting the default icon using a path clears the bitmap and vice-versa.
+
+ // Since ExtensionAction, living in common/, can't interact with the browser
+ // to load images, the UI code needs to load the images for each path. For
+ // each path in default_icon_path() and icon_paths(), load the image there
+ // using an ImageLoadingTracker and call CacheIcon(path, image) with the
+ // result.
//
- // To get the default icon, first check for the bitmap. If it is null, check
- // for the path.
+ // If an image is cached redundantly, the first load will be used.
+ void CacheIcon(const std::string& path, const gfx::Image& icon);
// Set this action's icon bitmap on a specific tab.
void SetIcon(int tab_id, const SkBitmap& bitmap);
- // Get the icon for a tab, or the default if no icon was set.
- SkBitmap GetIcon(int tab_id) const;
+ // Get the icon for a tab, or the default if no icon was set for this tab,
+ // retrieving icons that have been specified by path from the previous
+ // arguments to CacheIcon(). If the default icon isn't found in the cache,
+ // returns the puzzle piece icon.
+ gfx::Image GetIcon(int tab_id) const;
// Set this action's icon index for a specific tab. For use with
// icon_paths(), only used in page actions.
@@ -167,7 +178,7 @@ class ExtensionAction {
void set_default_icon_path(const std::string& path) {
default_icon_path_ = path;
}
- std::string default_icon_path() const {
+ const std::string& default_icon_path() const {
return default_icon_path_;
}
@@ -224,6 +235,10 @@ class ExtensionAction {
void RunIconAnimation(int tab_id);
private:
+ // If the icon animation is running on tab |tab_id|, applies it to
+ // |orig| and returns the result. Otherwise, just returns |orig|.
+ gfx::Image ApplyIconAnimation(int tab_id, const gfx::Image& orig) const;
+
template <class T>
struct ValueTraits {
static T CreateEmpty() {
@@ -257,7 +272,7 @@ class ExtensionAction {
// kDefaultTabId), or tab-specific state (stored with the tab_id as the key).
std::map<int, GURL> popup_url_;
std::map<int, std::string> title_;
- std::map<int, SkBitmap> icon_;
+ std::map<int, gfx::Image> icon_;
std::map<int, int> icon_index_; // index into icon_paths_
std::map<int, std::string> badge_text_;
std::map<int, SkColor> badge_background_color_;
@@ -277,6 +292,9 @@ class ExtensionAction {
// the legacy setIcon({iconIndex:...} method of the page actions API.
std::vector<std::string> icon_paths_;
+ // Saves the arguments from CacheIcon() calls.
+ std::map<std::string, gfx::Image> path_to_icon_cache_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionAction);
};

Powered by Google App Engine
This is Rietveld 408576698