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

Unified Diff: chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc

Issue 25305002: Implement initial chrome.browserAction.openPopup API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: finnur@ comments Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
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..513db68cf2a854650dd5328d9f6022482969aa1b 100644
--- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc
@@ -252,21 +252,23 @@ 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, bool should_grant) {
Finnur 2013/10/18 10:31:01 I would copy the explanation of should_grant (in t
justinlin 2013/10/19 06:01:48 Hmm, this was already done, must be an older patch
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.
@@ -323,7 +325,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,
@@ -364,7 +366,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;
}
@@ -669,14 +671,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 +773,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();
}
@@ -807,7 +830,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:
@@ -1077,13 +1101,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;

Powered by Google App Engine
This is Rietveld 408576698