Index: chrome/common/extensions/extension_action.cc |
diff --git a/chrome/common/extensions/extension_action.cc b/chrome/common/extensions/extension_action.cc |
index ef8759dfb6d31949deed0a20ca9f2e2c5bf0db5b..a2a817da0a4bdbaba400c5b63f2c1df754b05aa5 100644 |
--- a/chrome/common/extensions/extension_action.cc |
+++ b/chrome/common/extensions/extension_action.cc |
@@ -59,6 +59,23 @@ const int kMaxTextWidth = 23; |
// The minimum width for center-aligning the badge. |
const int kCenterAlignThreshold = 20; |
+void CopyExtensionIconSet(const ExtensionIconSet* from, ExtensionIconSet* to) { |
+ for (ExtensionIconSet::IconMap::const_iterator iter = from->map().begin(); |
+ iter != from->map().end(); |
+ ++iter) { |
+ to->Add(iter->first, iter->second); |
+ } |
+} |
+ |
+gfx::ImageSkia GetIconFromIconSet(const ExtensionIconSet* icon_set, |
+ ExtensionAction::IconFactory* icon_factory, |
+ ExtensionAction::Type type) { |
+ if (!icon_set || !icon_factory) |
+ return gfx::ImageSkia(); |
+ |
+ return icon_factory->GetIcon(icon_set, type); |
+} |
+ |
class GetAttentionImageSource : public gfx::ImageSkiaSource { |
public: |
explicit GetAttentionImageSource(const gfx::ImageSkia& icon) |
@@ -269,12 +286,31 @@ scoped_ptr<ExtensionAction> ExtensionAction::CopyForTest() const { |
copy->badge_text_color_ = badge_text_color_; |
copy->appearance_ = appearance_; |
copy->icon_animation_ = icon_animation_; |
- copy->default_icon_path_ = default_icon_path_; |
copy->id_ = id_; |
- copy->icon_paths_ = icon_paths_; |
+ |
+ if (default_icon_.get()) { |
+ scoped_ptr<ExtensionIconSet> default_icon(new ExtensionIconSet()); |
+ CopyExtensionIconSet(default_icon_.get(), default_icon.get()); |
+ copy->default_icon_ = default_icon.Pass(); |
+ } |
+ |
+ for (size_t i = 0; i < page_action_icons_.size(); i++) { |
+ scoped_ptr<ExtensionIconSet> page_action_icon(new ExtensionIconSet()); |
+ CopyExtensionIconSet(page_action_icons_[i], page_action_icon.get()); |
+ copy->AddPageActionIcon(page_action_icon.release()); |
+ } |
+ |
return copy.Pass(); |
} |
+void ExtensionAction::AddPageActionIcon(const ExtensionIconSet* icon_set) { |
+ page_action_icons_.push_back(icon_set); |
+} |
+ |
+bool ExtensionAction::IsValidIconIndex(int index) const { |
+ return index >= 0 && (static_cast<size_t>(index) < page_action_icons_.size()); |
+} |
+ |
void ExtensionAction::SetPopupUrl(int tab_id, const GURL& url) { |
// We store |url| even if it is empty, rather than removing a URL from the |
// map. If an extension has a default popup, and removes it for a tab via |
@@ -292,36 +328,28 @@ GURL ExtensionAction::GetPopupUrl(int tab_id) const { |
return GetValue(&popup_url_, tab_id); |
} |
-void ExtensionAction::CacheIcon(const std::string& path, |
- const gfx::Image& icon) { |
- if (!icon.IsEmpty()) |
- path_to_icon_cache_.insert(std::make_pair(path, *icon.ToImageSkia())); |
-} |
- |
void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) { |
SetValue(&icon_, tab_id, image.AsImageSkia()); |
} |
-gfx::Image ExtensionAction::GetIcon(int tab_id) const { |
+gfx::Image ExtensionAction::GetIcon(int tab_id, |
+ IconFactory* icon_factory) const { |
// Check if a specific icon is set for this tab. |
gfx::ImageSkia icon = GetValue(&icon_, tab_id); |
if (icon.isNull()) { |
- // Need to find an icon from a path. |
- const std::string* path = NULL; |
// Check if one of the elements of icon_path() was selected. |
int icon_index = GetIconIndex(tab_id); |
+ const ExtensionIconSet* icon_set = NULL; |
if (icon_index >= 0) { |
- path = &icon_paths()->at(icon_index); |
+ icon_set = page_action_icons_[icon_index]; |
} else { |
- // Otherwise, use the default icon. |
- path = &default_icon_path(); |
+ icon_set = default_icon_.get(); |
} |
- std::map<std::string, gfx::ImageSkia>::const_iterator cached_icon = |
- path_to_icon_cache_.find(*path); |
- if (cached_icon != path_to_icon_cache_.end()) { |
- icon = cached_icon->second; |
- } else { |
+ icon = GetIconFromIconSet(icon_set, icon_factory, action_type()); |
+ |
+ // Extension favicon is our last resort. |
+ if (icon.isNull()) { |
icon = *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
IDR_EXTENSIONS_FAVICON); |
} |
@@ -334,7 +362,7 @@ gfx::Image ExtensionAction::GetIcon(int tab_id) const { |
} |
void ExtensionAction::SetIconIndex(int tab_id, int index) { |
- if (static_cast<size_t>(index) >= icon_paths_.size()) { |
+ if (static_cast<size_t>(index) >= page_action_icons_.size()) { |
NOTREACHED(); |
return; |
} |