Index: chrome/browser/ui/gtk/browser_toolbar_gtk.cc |
diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc |
index 11e1b2b34b78916bd15475979e0b4f690ec2013a..fc57a73abf1a4dd91c03480fb7304f59cc4542c6 100644 |
--- a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc |
+++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc |
@@ -124,6 +124,11 @@ BrowserToolbarGtk::~BrowserToolbarGtk() { |
offscreen_entry_.Destroy(); |
wrench_menu_.reset(); |
+ |
+ HostZoomMap::GetForBrowserContext( |
+ browser()->profile())->AddZoomLevelChangedCallback( |
+ base::Bind(&BrowserToolbarGtk::OnZoomLevelChanged, |
+ base::Unretained(this))); |
} |
void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { |
@@ -241,9 +246,10 @@ void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { |
// The bookmark menu model needs to be able to force the wrench menu to close. |
wrench_menu_model_->bookmark_sub_menu_model()->SetMenuGtk(wrench_menu_.get()); |
- registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
- content::Source<HostZoomMap>( |
- HostZoomMap::GetForBrowserContext(profile))); |
+ HostZoomMap::GetForBrowserContext( |
+ browser()->profile())->AddZoomLevelChangedCallback( |
+ base::Bind(&BrowserToolbarGtk::OnZoomLevelChanged, |
+ base::Unretained(this))); |
if (ShouldOnlyShowLocation()) { |
gtk_widget_show(event_box_); |
@@ -372,6 +378,21 @@ bool BrowserToolbarGtk::GetAcceleratorForCommandId( |
return true; |
} |
+// content::HostZoomMapObserver ------------------------------------------------ |
+ |
+void BrowserToolbarGtk::OnZoomLevelChanged(const std::string& host) { |
+ // Since BrowserToolbarGtk create a new |wrench_menu_model_| in |
+ // RebuildWrenchMenu(), the ordering of the observers of HostZoomMap |
+ // can change, and result in subtle bugs like http://crbug.com/118823. |
+ // Rather than depending on the ordering of the observers, always update |
+ // the WrenchMenuModel before updating the WrenchMenu. |
+ wrench_menu_model_->UpdateZoomControls(); |
+ |
+ // If our zoom level changed, we need to tell the menu to update its state, |
+ // since the menu could still be open. |
+ wrench_menu_->UpdateMenu(); |
+} |
+ |
// content::NotificationObserver ----------------------------------------------- |
void BrowserToolbarGtk::Observe(int type, |
@@ -416,18 +437,6 @@ void BrowserToolbarGtk::Observe(int type, |
} else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { |
is_wrench_menu_model_valid_ = false; |
gtk_widget_queue_draw(wrench_menu_button_->widget()); |
- } else if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { |
- // Since BrowserToolbarGtk create a new |wrench_menu_model_| in |
- // RebuildWrenchMenu(), the ordering of the observers of |
- // NOTIFICATION_ZOOM_LEVEL_CHANGED can change, and result in subtle bugs |
- // like http://crbug.com/118823. Rather than depending on the ordering |
- // of the notification observers, always update the WrenchMenuModel before |
- // updating the WrenchMenu. |
- wrench_menu_model_->UpdateZoomControls(); |
- |
- // If our zoom level changed, we need to tell the menu to update its state, |
- // since the menu could still be open. |
- wrench_menu_->UpdateMenu(); |
} else { |
NOTREACHED(); |
} |