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

Unified Diff: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm

Issue 25305002: Implement initial chrome.browserAction.openPopup API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/cocoa/extensions/browser_actions_controller.mm
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
index a17f3d8cde36d18dbab3e47d97209012f9400896..cdc9840e3e99f1cbd433b45ce140e7d7500ae48b 100644
--- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
@@ -140,6 +140,10 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
// Handles when the given BrowserActionButton object is clicked.
- (void)browserActionClicked:(BrowserActionButton*)button;
+// Triggers opening the popup window for an extension without a user action.
+// Used by an extension API that opens an extension's popup.
+- (void)openPopup:(const Extension*)extension;
+
// Returns whether the given extension should be displayed. Only displays
// incognito-enabled extensions in incognito mode. Otherwise returns YES.
- (BOOL)shouldDisplayBrowserAction:(const Extension*)extension;
@@ -238,6 +242,14 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
[owner_ resizeContainerAndAnimate:NO];
}
+ virtual void BrowserActionShowPopup(const Extension* extension) OVERRIDE {
+ content::WebContents* active_tab =
+ browser_->tab_strip_model()->GetActiveWebContents();
+ if (!active_tab)
+ return;
+ [owner_ openPopup:extension];
+ }
+
private:
// The object we need to inform when we get a notification. Weak. Owns us.
BrowserActionsController* owner_;
@@ -739,6 +751,26 @@ class ExtensionServiceObserverBridge : public content::NotificationObserver,
}
}
+- (void)openPopup:(const Extension*)extension {
+ const GURL popupUrl = toolbarModel_->GetPopupUrl(extension, browser_);
+ if (!popupUrl.is_empty()) {
+ NSPoint arrowPoint = [self popupPointForBrowserAction:extension];
+ if (NSEqualPoints(arrowPoint, NSZeroPoint)) {
+ // The button is hidden if arrowPoint is zero.
+
+ // TODO(justinlin): This is not right.. position below hotdog menu.
+ arrowPoint = NSMakePoint(NSWidth([containerView_ frame]),
+ kBrowserActionOriginYOffset);
+ }
+
+ [ExtensionPopupController showURL:popupUrl
+ inBrowser:browser_
+ anchoredAt:arrowPoint
+ arrowLocation:info_bubble::kTopRight
+ devMode:NO];
+ }
+}
+
- (void)browserActionClicked:(BrowserActionButton*)button {
const Extension* extension = [button extension];
GURL popupUrl;

Powered by Google App Engine
This is Rietveld 408576698