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

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),
Aaron Boodman 2010/03/23 19:10:55 allow_this_in_initalizer ?
Finnur 2010/03/23 21:19:48 The ALLOW_THIS macro is for working around a VC co
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_.PostLoadImageTask(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, 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // The toolbar containing this button. 252 // The toolbar containing this button.
258 BrowserActionsToolbarGtk* toolbar_; 253 BrowserActionsToolbarGtk* toolbar_;
259 254
260 // The extension that contains this browser action. 255 // The extension that contains this browser action.
261 Extension* extension_; 256 Extension* extension_;
262 257
263 // The gtk widget for this browser action. 258 // The gtk widget for this browser action.
264 OwnedWidgetGtk button_; 259 OwnedWidgetGtk button_;
265 260
266 // Loads the button's icons for us on the file thread. 261 // Loads the button's icons for us on the file thread.
267 ImageLoadingTracker* tracker_; 262 ImageLoadingTracker tracker_;
268 263
269 // If we are displaying a tab-specific icon, it will be here. 264 // If we are displaying a tab-specific icon, it will be here.
270 GdkPixbuf* tab_specific_icon_; 265 GdkPixbuf* tab_specific_icon_;
271 266
272 // If the browser action has a default icon, it will be here. 267 // If the browser action has a default icon, it will be here.
273 GdkPixbuf* default_icon_; 268 GdkPixbuf* default_icon_;
274 269
275 // Same as |default_icon_|, but stored as SkBitmap. 270 // Same as |default_icon_|, but stored as SkBitmap.
276 SkBitmap default_skbitmap_; 271 SkBitmap default_skbitmap_;
277 272
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 gboolean BrowserActionsToolbarGtk::OnDragFailed(GtkWidget* widget, 621 gboolean BrowserActionsToolbarGtk::OnDragFailed(GtkWidget* widget,
627 GdkDragContext* drag_context, 622 GdkDragContext* drag_context,
628 GtkDragResult result) { 623 GtkDragResult result) {
629 // We connect to this signal and return TRUE so that the default failure 624 // We connect to this signal and return TRUE so that the default failure
630 // animation (wherein the drag widget floats back to the start of the drag) 625 // animation (wherein the drag widget floats back to the start of the drag)
631 // does not show, and the drag-end signal is emitted immediately instead of 626 // does not show, and the drag-end signal is emitted immediately instead of
632 // several seconds later. 627 // several seconds later.
633 return TRUE; 628 return TRUE;
634 } 629 }
635 630
636 void BrowserActionsToolbarGtk::OnHierarchyChanged(GtkWidget* widget, 631 void BrowserActionsToolbarGtk::OnHierarchyChanged(
637 GtkWidget* previous_toplevel) { 632 GtkWidget* widget, GtkWidget* previous_toplevel) {
638 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); 633 GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
639 if (!GTK_WIDGET_TOPLEVEL(toplevel)) 634 if (!GTK_WIDGET_TOPLEVEL(toplevel))
640 return; 635 return;
641 636
642 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this); 637 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this);
643 } 638 }
644 639
645 void BrowserActionsToolbarGtk::OnSetFocus(GtkWidget* widget, 640 void BrowserActionsToolbarGtk::OnSetFocus(GtkWidget* widget,
646 GtkWidget* focus_widget) { 641 GtkWidget* focus_widget) {
647 // The focus of the parent window has changed. Close the popup. Delay the hide 642 // The focus of the parent window has changed. Close the popup. Delay the hide
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 740
746 // TODO(estade): set the menu item's tooltip. 741 // TODO(estade): set the menu item's tooltip.
747 } 742 }
748 743
749 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow), 744 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(overflow),
750 GTK_STATE_ACTIVE); 745 GTK_STATE_ACTIVE);
751 overflow_menu_->PopupAsFromKeyEvent(overflow); 746 overflow_menu_->PopupAsFromKeyEvent(overflow);
752 747
753 return FALSE; 748 return FALSE;
754 } 749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698