Index: chrome/browser/ui/views/location_bar/page_action_image_view.cc |
diff --git a/chrome/browser/ui/views/location_bar/page_action_image_view.cc b/chrome/browser/ui/views/location_bar/page_action_image_view.cc |
index f584096d66bbcb959c044bc551643b35f7728f28..92612620683cef9338fe9c4426758d85398d6cdc 100644 |
--- a/chrome/browser/ui/views/location_bar/page_action_image_view.cc |
+++ b/chrome/browser/ui/views/location_bar/page_action_image_view.cc |
@@ -7,6 +7,7 @@ |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/extensions/api/commands/command_service.h" |
#include "chrome/browser/extensions/api/commands/command_service_factory.h" |
+#include "chrome/browser/extensions/extension_action_icon_factory.h" |
#include "chrome/browser/extensions/extension_context_menu_model.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/extension_tab_util.h" |
@@ -43,7 +44,6 @@ PageActionImageView::PageActionImageView(LocationBarView* owner, |
: owner_(owner), |
page_action_(page_action), |
browser_(browser), |
- ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
current_tab_id_(-1), |
preview_enabled_(false), |
popup_(NULL), |
@@ -55,19 +55,7 @@ PageActionImageView::PageActionImageView(LocationBarView* owner, |
GetExtensionById(page_action->extension_id(), false); |
DCHECK(extension); |
- // Load all the icons declared in the manifest. This is the contents of the |
- // icons array, plus the default_icon property, if any. |
- std::vector<std::string> icon_paths(*page_action->icon_paths()); |
- if (!page_action_->default_icon_path().empty()) |
- icon_paths.push_back(page_action_->default_icon_path()); |
- |
- for (std::vector<std::string>::iterator i(icon_paths.begin()); |
- i != icon_paths.end(); ++i) { |
- tracker_.LoadImage(extension, extension->GetResource(*i), |
- gfx::Size(Extension::kPageActionIconMaxSize, |
- Extension::kPageActionIconMaxSize), |
- ImageLoadingTracker::DONT_CACHE); |
- } |
+ icon_factory_.reset(new ExtensionActionIconFactory(extension, this)); |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
content::Source<Profile>( |
@@ -196,29 +184,6 @@ bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) { |
return false; |
} |
-void PageActionImageView::OnImageLoaded(const gfx::Image& image, |
- const std::string& extension_id, |
- int index) { |
- // We loaded icons()->size() icons, plus one extra if the page action had |
- // a default icon. |
- int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
- if (!page_action_->default_icon_path().empty()) |
- total_icons++; |
- DCHECK(index < total_icons); |
- |
- // Map the index of the loaded image back to its name. If we ever get an |
- // index greater than the number of icons, it must be the default icon. |
- if (index < static_cast<int>(page_action_->icon_paths()->size())) |
- page_action_->CacheIcon(page_action_->icon_paths()->at(index), image); |
- else |
- page_action_->CacheIcon(page_action_->default_icon_path(), image); |
- |
- // During object construction owner_ will be NULL. |
- TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; |
- if (tab_contents) |
- UpdateVisibility(tab_contents->web_contents(), current_url_); |
-} |
- |
void PageActionImageView::ShowContextMenuForView(View* source, |
const gfx::Point& point) { |
const Extension* extension = owner_->profile()->GetExtensionService()-> |
@@ -270,7 +235,7 @@ void PageActionImageView::UpdateVisibility(WebContents* contents, |
SetTooltipText(UTF8ToUTF16(tooltip_)); |
// Set the image. |
- gfx::Image icon = page_action_->GetIcon(current_tab_id_); |
+ gfx::Image icon = page_action_->GetIcon(current_tab_id_, icon_factory_.get()); |
if (!icon.IsEmpty()) |
SetImage(*icon.ToImageSkia()); |
@@ -289,16 +254,20 @@ void PageActionImageView::Observe(int type, |
DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); |
const Extension* unloaded_extension = |
content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
- if (page_action_ == unloaded_extension ->page_action()) |
+ if (page_action_ == unloaded_extension->page_action()) |
owner_->UpdatePageActions(); |
} |
-void PageActionImageView::OnIconChanged() { |
+void PageActionImageView::OnIconUpdated() { |
TabContents* tab_contents = owner_->GetTabContents(); |
if (tab_contents) |
UpdateVisibility(tab_contents->web_contents(), current_url_); |
} |
+void PageActionImageView::OnIconChanged() { |
+ OnIconUpdated(); |
+} |
+ |
void PageActionImageView::ShowPopupWithURL(const GURL& popup_url) { |
bool popup_showing = popup_ != NULL; |