Index: chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
index 9a8d17e272a140956a6f2760b177c33e96cf39c8..badfeb6e69eb9102446ca6e0a9ad0128fd6fa043 100644 |
--- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
+++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
@@ -15,9 +15,9 @@ |
#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/image_loading_tracker.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/sessions/session_tab_helper.h" |
#include "chrome/browser/ui/browser.h" |
@@ -91,7 +91,7 @@ gint WidthForIconCount(gint icon_count) { |
using ui::SimpleMenuModel; |
class BrowserActionButton : public content::NotificationObserver, |
- public ImageLoadingTracker::Observer, |
+ public ExtensionActionIconFactory::Observer, |
public ExtensionContextMenuModel::PopupDelegate, |
public MenuGtk::Delegate { |
public: |
@@ -101,9 +101,7 @@ class BrowserActionButton : public content::NotificationObserver, |
: toolbar_(toolbar), |
extension_(extension), |
image_(NULL), |
- tracker_(this), |
- tab_specific_icon_(NULL), |
- default_icon_(NULL), |
+ icon_factory_(extension, extension->browser_action(), this), |
accel_group_(NULL) { |
button_.reset(new CustomDrawButton( |
theme_provider, |
@@ -119,16 +117,6 @@ class BrowserActionButton : public content::NotificationObserver, |
DCHECK(extension_->browser_action()); |
- // The Browser Action API does not allow the default icon path to be |
- // changed at runtime, so we can load this now and cache it. |
- std::string path = extension_->browser_action()->default_icon_path(); |
- if (!path.empty()) { |
- tracker_.LoadImage(extension_, extension_->GetResource(path), |
- gfx::Size(Extension::kBrowserActionIconMaxSize, |
- Extension::kBrowserActionIconMaxSize), |
- ImageLoadingTracker::DONT_CACHE); |
- } |
- |
UpdateState(); |
signals_.Connect(button(), "button-press-event", |
@@ -170,12 +158,6 @@ class BrowserActionButton : public content::NotificationObserver, |
~BrowserActionButton() { |
DisconnectBrowserActionPopupAccelerator(); |
- if (tab_specific_icon_) |
- g_object_unref(tab_specific_icon_); |
- |
- if (default_icon_) |
- g_object_unref(default_icon_); |
- |
alignment_.Destroy(); |
} |
@@ -218,11 +200,8 @@ class BrowserActionButton : public content::NotificationObserver, |
} |
} |
- // ImageLoadingTracker::Observer implementation. |
- void OnImageLoaded(const gfx::Image& image, |
- const std::string& extension_id, |
- int index) OVERRIDE { |
- extension_->browser_action()->CacheIcon(image); |
+ // ExtensionActionIconFactory::Observer implementation. |
+ void OnIconUpdated() OVERRIDE { |
UpdateState(); |
} |
@@ -239,7 +218,7 @@ class BrowserActionButton : public content::NotificationObserver, |
else |
gtk_widget_set_tooltip_text(button(), tooltip.c_str()); |
- gfx::Image image = extension_->browser_action()->GetIcon(tab_id); |
+ gfx::Image image = icon_factory_.GetIcon(tab_id); |
if (!image.IsEmpty()) |
SetImage(image.ToGdkPixbuf()); |
bool enabled = extension_->browser_action()->GetIsVisible(tab_id); |
@@ -249,8 +228,7 @@ class BrowserActionButton : public content::NotificationObserver, |
} |
gfx::Image GetIcon() { |
- return extension_->browser_action()->GetIcon( |
- toolbar_->GetCurrentTabId()); |
+ return icon_factory_.GetIcon(toolbar_->GetCurrentTabId()); |
} |
MenuGtk* GetContextMenu() { |
@@ -461,14 +439,11 @@ class BrowserActionButton : public content::NotificationObserver, |
// extensions change browser action icon in a loop. |
GtkWidget* image_; |
- // Loads the button's icons for us on the file thread. |
- ImageLoadingTracker tracker_; |
- |
- // If we are displaying a tab-specific icon, it will be here. |
- GdkPixbuf* tab_specific_icon_; |
- |
- // If the browser action has a default icon, it will be here. |
- GdkPixbuf* default_icon_; |
+ // The object that will be used to get the browser action icon for us. |
+ // It may load the icon asynchronously (in which case the initial icon |
+ // returned by the factory will be transparent), so we have to observe it for |
+ // updates to the icon. |
+ ExtensionActionIconFactory icon_factory_; |
Jeffrey Yasskin
2012/09/17 20:18:39
Remove the second space between ExtensionActionIco
tbarzic
2012/09/17 22:06:10
Done.
|
// Same as |default_icon_|, but stored as SkBitmap. |
SkBitmap default_skbitmap_; |