Chromium Code Reviews| 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..f575e4211ab6b97bd51e5af775fab441913b5871 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), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(icon_factory_(extension, this)), |
|
Evan Stade
2012/09/14 09:36:21
you only need ALLOW_THIS... for windows
|
| 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,8 @@ 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 = |
| + extension_->browser_action()->GetIcon(tab_id, &icon_factory_); |
| if (!image.IsEmpty()) |
| SetImage(image.ToGdkPixbuf()); |
| bool enabled = extension_->browser_action()->GetIsVisible(tab_id); |
| @@ -250,7 +230,7 @@ class BrowserActionButton : public content::NotificationObserver, |
| gfx::Image GetIcon() { |
| return extension_->browser_action()->GetIcon( |
| - toolbar_->GetCurrentTabId()); |
| + toolbar_->GetCurrentTabId(), &icon_factory_); |
| } |
| MenuGtk* GetContextMenu() { |
| @@ -461,14 +441,10 @@ 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 browser action will use to create icon for us. |
|
Evan Stade
2012/09/14 09:36:21
singular "icon" needs an article ("the"/"a")
|
| + // It may load icon asynchronously (in which case initial icon returned by |
| + // the action will be blank), so we have to observe it for icon's updates. |
|
Evan Stade
2012/09/14 09:36:21
"for updates to the icon"
|
| + ExtensionActionIconFactory icon_factory_; |
| // Same as |default_icon_|, but stored as SkBitmap. |
| SkBitmap default_skbitmap_; |