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 34f300ac07e04720260efa3d538186ec84698fb7..1d51aad8f11adae747f8057d9c645d13d74628d0 100644 |
| --- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
| +++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
| @@ -252,21 +252,27 @@ class BrowserActionButton : public content::NotificationObserver, |
| } |
| private: |
| - // Activate the browser action. |
| - void Activate(GtkWidget* widget) { |
| + // Activate the browser action. Returns true if a popup was shown. |
| + bool Activate(GtkWidget* widget) { |
| + return Activate(widget, true); |
| + } |
| + |
| + bool Activate(GtkWidget* widget, bool allow_grant) { |
|
Finnur
2013/10/17 14:58:34
Same here (avoid forking the function just to add
|
| ExtensionToolbarModel* model = toolbar_->model(); |
| const Extension* extension = extension_; |
| Browser* browser = toolbar_->browser(); |
| GURL popup_url; |
| - switch (model->ExecuteBrowserAction(extension, browser, &popup_url)) { |
| + switch (model->ExecuteBrowserAction( |
| + extension, browser, &popup_url, allow_grant)) { |
| case ExtensionToolbarModel::ACTION_NONE: |
| break; |
| case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
| ExtensionPopupGtk::Show(popup_url, browser, widget, |
| ExtensionPopupGtk::SHOW); |
| - break; |
| + return true; |
| } |
| + return false; |
| } |
| // MenuGtk::Delegate implementation. |
| @@ -669,14 +675,17 @@ void BrowserActionsToolbarGtk::CreateButtonForExtension( |
| UpdateVisibility(); |
| } |
| -GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( |
| +BrowserActionButton* BrowserActionsToolbarGtk::GetBrowserActionButton( |
| const Extension* extension) { |
| ExtensionButtonMap::iterator it = extension_button_map_.find( |
| extension->id()); |
| - if (it == extension_button_map_.end()) |
| - return NULL; |
| + return it == extension_button_map_.end() ? NULL : it->second.get(); |
| +} |
| - return it->second.get()->widget(); |
| +GtkWidget* BrowserActionsToolbarGtk::GetBrowserActionWidget( |
| + const Extension* extension) { |
| + BrowserActionButton* button = GetBrowserActionButton(extension); |
| + return button == NULL ? NULL : button->widget(); |
| } |
| void BrowserActionsToolbarGtk::RemoveButtonForExtension( |
| @@ -768,6 +777,24 @@ void BrowserActionsToolbarGtk::BrowserActionMoved(const Extension* extension, |
| gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), button_widget, index); |
| } |
| +bool BrowserActionsToolbarGtk::BrowserActionShowPopup( |
| + const Extension* extension) { |
| + // Do not override other popups and only show in active window. |
| + if (ExtensionPopupGtk::get_current_extension_popup() || |
| + !browser_->window()->IsActive()) { |
| + return false; |
| + } |
| + |
| + BrowserActionButton* button = GetBrowserActionButton(extension); |
| + if (button == NULL || button->widget() == NULL) |
| + return false; |
| + |
| + GtkWidget* anchor = button->widget(); |
| + if (!gtk_widget_get_visible(anchor)) |
| + anchor = button->toolbar_->chevron(); |
| + return button->Activate(anchor, false); |
| +} |
| + |
| void BrowserActionsToolbarGtk::ModelLoaded() { |
| SetContainerWidth(); |
| } |
| @@ -1077,13 +1104,13 @@ gboolean BrowserActionsToolbarGtk::OnOverflowMenuButtonPress( |
| item_index = model_->IncognitoIndexToOriginal(item_index); |
| const Extension* extension = model_->toolbar_items()[item_index].get(); |
| - ExtensionButtonMap::iterator it = extension_button_map_.find(extension->id()); |
| - if (it == extension_button_map_.end()) { |
| + BrowserActionButton* button = GetBrowserActionButton(extension); |
| + if (button == NULL) { |
| NOTREACHED(); |
| return FALSE; |
| } |
| - MenuGtk* menu = it->second.get()->GetContextMenu(); |
| + MenuGtk* menu = button->GetContextMenu(); |
| if (!menu) |
| return FALSE; |