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

Side by Side Diff: chrome/browser/gtk/browser_actions_toolbar_gtk.cc

Issue 1075006: Eliminate all UI thread decoding of extension images.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h" 5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/extensions/extension_browser_event_router.h" 10 #include "chrome/browser/extensions/extension_browser_event_router.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } // namespace 62 } // namespace
63 63
64 class BrowserActionButton : public NotificationObserver, 64 class BrowserActionButton : public NotificationObserver,
65 public ImageLoadingTracker::Observer, 65 public ImageLoadingTracker::Observer,
66 public ExtensionContextMenuModel::PopupDelegate { 66 public ExtensionContextMenuModel::PopupDelegate {
67 public: 67 public:
68 BrowserActionButton(BrowserActionsToolbarGtk* toolbar, 68 BrowserActionButton(BrowserActionsToolbarGtk* toolbar,
69 Extension* extension) 69 Extension* extension)
70 : toolbar_(toolbar), 70 : toolbar_(toolbar),
71 extension_(extension), 71 extension_(extension),
72 tracker_(NULL), 72 tracker_(this),
73 tab_specific_icon_(NULL), 73 tab_specific_icon_(NULL),
74 default_icon_(NULL) { 74 default_icon_(NULL) {
75 button_.Own( 75 button_.Own(
76 GtkThemeProvider::GetFrom(toolbar->profile_)->BuildChromeButton()); 76 GtkThemeProvider::GetFrom(toolbar->profile_)->BuildChromeButton());
77 77
78 DCHECK(extension_->browser_action()); 78 DCHECK(extension_->browser_action());
79 79
80 gtk_widget_set_size_request(button_.get(), kButtonSize, kButtonSize); 80 gtk_widget_set_size_request(button_.get(), kButtonSize, kButtonSize);
81 81
82 UpdateState(); 82 UpdateState();
83 83
84 // The Browser Action API does not allow the default icon path to be 84 // The Browser Action API does not allow the default icon path to be
85 // changed at runtime, so we can load this now and cache it. 85 // changed at runtime, so we can load this now and cache it.
86 std::string path = extension_->browser_action()->default_icon_path(); 86 std::string path = extension_->browser_action()->default_icon_path();
87 if (!path.empty()) { 87 if (!path.empty()) {
88 tracker_ = new ImageLoadingTracker(this, 1); 88 tracker_.LoadImage(extension_->GetResource(path),
89 tracker_->PostLoadImageTask(extension_->GetResource(path),
90 gfx::Size(Extension::kBrowserActionIconMaxSize, 89 gfx::Size(Extension::kBrowserActionIconMaxSize,
91 Extension::kBrowserActionIconMaxSize)); 90 Extension::kBrowserActionIconMaxSize));
92 } 91 }
93 92
94 g_signal_connect(button_.get(), "button-press-event", 93 g_signal_connect(button_.get(), "button-press-event",
95 G_CALLBACK(OnButtonPress), this); 94 G_CALLBACK(OnButtonPress), this);
96 g_signal_connect(button_.get(), "clicked", 95 g_signal_connect(button_.get(), "clicked",
97 G_CALLBACK(OnClicked), this); 96 G_CALLBACK(OnClicked), this);
98 g_signal_connect_after(button_.get(), "expose-event", 97 g_signal_connect_after(button_.get(), "expose-event",
99 G_CALLBACK(OnExposeEvent), this); 98 G_CALLBACK(OnExposeEvent), this);
100 g_signal_connect(button_.get(), "drag-begin", 99 g_signal_connect(button_.get(), "drag-begin",
101 G_CALLBACK(&OnDragBegin), this); 100 G_CALLBACK(&OnDragBegin), this);
102 101
103 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 102 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
104 Source<ExtensionAction>(extension->browser_action())); 103 Source<ExtensionAction>(extension->browser_action()));
105 } 104 }
106 105
107 ~BrowserActionButton() { 106 ~BrowserActionButton() {
108 if (tab_specific_icon_) 107 if (tab_specific_icon_)
109 g_object_unref(tab_specific_icon_); 108 g_object_unref(tab_specific_icon_);
110 109
111 if (default_icon_) 110 if (default_icon_)
112 g_object_unref(default_icon_); 111 g_object_unref(default_icon_);
113 112
114 button_.Destroy(); 113 button_.Destroy();
115
116 if (tracker_)
117 tracker_->StopTrackingImageLoad();
118 } 114 }
119 115
120 GtkWidget* widget() { return button_.get(); } 116 GtkWidget* widget() { return button_.get(); }
121 117
122 Extension* extension() { return extension_; } 118 Extension* extension() { return extension_; }
123 119
124 // NotificationObserver implementation. 120 // NotificationObserver implementation.
125 void Observe(NotificationType type, 121 void Observe(NotificationType type,
126 const NotificationSource& source, 122 const NotificationSource& source,
127 const NotificationDetails& details) { 123 const NotificationDetails& details) {
128 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) 124 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED)
129 UpdateState(); 125 UpdateState();
130 else 126 else
131 NOTREACHED(); 127 NOTREACHED();
132 } 128 }
133 129
134 // ImageLoadingTracker::Observer implementation. 130 // ImageLoadingTracker::Observer implementation.
135 void OnImageLoaded(SkBitmap* image, size_t index) { 131 void OnImageLoaded(SkBitmap* image, ExtensionResource resource, int index) {
136 if (image) { 132 if (image) {
137 default_skbitmap_ = *image; 133 default_skbitmap_ = *image;
138 default_icon_ = gfx::GdkPixbufFromSkBitmap(image); 134 default_icon_ = gfx::GdkPixbufFromSkBitmap(image);
139 } 135 }
140 tracker_ = NULL; // The tracker object will delete itself when we return.
141 UpdateState(); 136 UpdateState();
142 } 137 }
143 138
144 // Updates the button based on the latest state from the associated 139 // Updates the button based on the latest state from the associated
145 // browser action. 140 // browser action.
146 void UpdateState() { 141 void UpdateState() {
147 int tab_id = toolbar_->GetCurrentTabId(); 142 int tab_id = toolbar_->GetCurrentTabId();
148 if (tab_id < 0) 143 if (tab_id < 0)
149 return; 144 return;
150 145
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // The toolbar containing this button. 262 // The toolbar containing this button.
268 BrowserActionsToolbarGtk* toolbar_; 263 BrowserActionsToolbarGtk* toolbar_;
269 264
270 // The extension that contains this browser action. 265 // The extension that contains this browser action.
271 Extension* extension_; 266 Extension* extension_;
272 267
273 // The gtk widget for this browser action. 268 // The gtk widget for this browser action.
274 OwnedWidgetGtk button_; 269 OwnedWidgetGtk button_;
275 270
276 // Loads the button's icons for us on the file thread. 271 // Loads the button's icons for us on the file thread.
277 ImageLoadingTracker* tracker_; 272 ImageLoadingTracker tracker_;
278 273
279 // If we are displaying a tab-specific icon, it will be here. 274 // If we are displaying a tab-specific icon, it will be here.
280 GdkPixbuf* tab_specific_icon_; 275 GdkPixbuf* tab_specific_icon_;
281 276
282 // If the browser action has a default icon, it will be here. 277 // If the browser action has a default icon, it will be here.
283 GdkPixbuf* default_icon_; 278 GdkPixbuf* default_icon_;
284 279
285 // Same as |default_icon_|, but stored as SkBitmap. 280 // Same as |default_icon_|, but stored as SkBitmap.
286 SkBitmap default_skbitmap_; 281 SkBitmap default_skbitmap_;
287 282
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 gboolean BrowserActionsToolbarGtk::OnDragFailed(GtkWidget* widget, 632 gboolean BrowserActionsToolbarGtk::OnDragFailed(GtkWidget* widget,
638 GdkDragContext* drag_context, 633 GdkDragContext* drag_context,
639 GtkDragResult result) { 634 GtkDragResult result) {
640 // We connect to this signal and return TRUE so that the default failure 635 // We connect to this signal and return TRUE so that the default failure
641 // animation (wherein the drag widget floats back to the start of the drag) 636 // animation (wherein the drag widget floats back to the start of the drag)
642 // does not show, and the drag-end signal is emitted immediately instead of 637 // does not show, and the drag-end signal is emitted immediately instead of
643 // several seconds later. 638 // several seconds later.
644 return TRUE; 639 return TRUE;
645 } 640 }
646 641
647 void BrowserActionsToolbarGtk::OnHierarchyChanged(GtkWidget* widget, 642 void BrowserActionsToolbarGtk::OnHierarchyChanged(
648 GtkWidget* previous_toplevel) { 643 GtkWidget* widget, GtkWidget* previous_toplevel) {
649 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); 644 GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
650 if (!GTK_WIDGET_TOPLEVEL(toplevel)) 645 if (!GTK_WIDGET_TOPLEVEL(toplevel))
651 return; 646 return;
652 647
653 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this); 648 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this);
654 } 649 }
655 650
656 void BrowserActionsToolbarGtk::OnSetFocus(GtkWidget* widget, 651 void BrowserActionsToolbarGtk::OnSetFocus(GtkWidget* widget,
657 GtkWidget* focus_widget) { 652 GtkWidget* focus_widget) {
658 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); 653 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 752
758 // TODO(estade): set the menu item's tooltip. 753 // TODO(estade): set the menu item's tooltip.
759 } 754 }
760 755
761 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow), 756 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow),
762 GTK_STATE_ACTIVE); 757 GTK_STATE_ACTIVE);
763 overflow_menu_->PopupAsFromKeyEvent(overflow); 758 overflow_menu_->PopupAsFromKeyEvent(overflow);
764 759
765 return FALSE; 760 return FALSE;
766 } 761 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/image_loading_tracker.cc ('k') | chrome/browser/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698