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 d2f056b3e20de48ca80a281cb1e4983e5efaf2ea..7f6049e6856610bf8bf9eef30c55e1f6e1cc3f3c 100644 |
--- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
+++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc |
@@ -7,6 +7,7 @@ |
#include <gtk/gtk.h> |
#include <algorithm> |
+#include <utility> |
#include <vector> |
#include "base/bind.h" |
@@ -253,21 +254,25 @@ 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. Showing the |
+ // popup will grant tab permissions if |should_grant| is true. Popup's shown |
+ // via an API should not grant permissions. |
+ bool Activate(GtkWidget* widget, bool should_grant) { |
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, should_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. |
@@ -324,7 +329,7 @@ class BrowserActionButton : public content::NotificationObserver, |
static void OnClicked(GtkWidget* widget, BrowserActionButton* button) { |
if (button->enabled_) |
- button->Activate(widget); |
+ button->Activate(widget, true); |
} |
static gboolean OnExposeEvent(GtkWidget* widget, |
@@ -365,7 +370,7 @@ class BrowserActionButton : public content::NotificationObserver, |
// The anchor might be in the overflow menu. Then we point to the chevron. |
if (!gtk_widget_get_visible(anchor)) |
anchor = button->toolbar_->chevron(); |
- button->Activate(anchor); |
+ button->Activate(anchor, true); |
return TRUE; |
} |
@@ -670,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( |
@@ -770,6 +778,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(); |
} |
@@ -809,7 +835,8 @@ void BrowserActionsToolbarGtk::ExecuteCommand(int command_id, int event_flags) { |
const Extension* extension = model_->toolbar_items()[command_id].get(); |
GURL popup_url; |
- switch (model_->ExecuteBrowserAction(extension, browser(), &popup_url)) { |
+ switch (model_->ExecuteBrowserAction( |
+ extension, browser(), &popup_url, true)) { |
case ExtensionToolbarModel::ACTION_NONE: |
break; |
case ExtensionToolbarModel::ACTION_SHOW_POPUP: |
@@ -1079,13 +1106,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; |