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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" 5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <string> 8 #include <string>
9 9
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // sync visually. 131 // sync visually.
132 - (void)actionButtonDragFinished:(NSNotification*)notification; 132 - (void)actionButtonDragFinished:(NSNotification*)notification;
133 133
134 // Moves the given button both visually and within the toolbar model to the 134 // Moves the given button both visually and within the toolbar model to the
135 // specified index. 135 // specified index.
136 - (void)moveButton:(BrowserActionButton*)button 136 - (void)moveButton:(BrowserActionButton*)button
137 toIndex:(NSUInteger)index 137 toIndex:(NSUInteger)index
138 animate:(BOOL)animate; 138 animate:(BOOL)animate;
139 139
140 // Handles when the given BrowserActionButton object is clicked. 140 // Handles when the given BrowserActionButton object is clicked.
141 - (void)browserActionClicked:(BrowserActionButton*)button; 141 - (bool)browserActionClicked:(BrowserActionButton*)button;
142 - (bool)browserActionClicked:(BrowserActionButton*)button
Alexei Svitkine (slow) 2013/10/17 20:39:55 Can you add a comment here and explain |shouldGran
justinlin 2013/10/17 20:49:47 Done.
Finnur 2013/10/18 10:31:01 I think these should be consolidated into one func
justinlin 2013/10/19 06:01:48 Yea, so the problem is this function is used with
143 andGrant:(BOOL)shouldGrant;
142 144
143 // Returns whether the given extension should be displayed. Only displays 145 // Returns whether the given extension should be displayed. Only displays
144 // incognito-enabled extensions in incognito mode. Otherwise returns YES. 146 // incognito-enabled extensions in incognito mode. Otherwise returns YES.
145 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension; 147 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension;
146 148
147 // The reason |frame| is specified in these chevron functions is because the 149 // The reason |frame| is specified in these chevron functions is because the
148 // container may be animating and the end frame of the animation should be 150 // container may be animating and the end frame of the animation should be
149 // passed instead of the current frame (which may be off and cause the chevron 151 // passed instead of the current frame (which may be off and cause the chevron
150 // to jump at the end of its animation). 152 // to jump at the end of its animation).
151 153
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 int index) OVERRIDE { 233 int index) OVERRIDE {
232 [owner_ createActionButtonForExtension:extension withIndex:index]; 234 [owner_ createActionButtonForExtension:extension withIndex:index];
233 [owner_ resizeContainerAndAnimate:NO]; 235 [owner_ resizeContainerAndAnimate:NO];
234 } 236 }
235 237
236 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE { 238 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE {
237 [owner_ removeActionButtonForExtension:extension]; 239 [owner_ removeActionButtonForExtension:extension];
238 [owner_ resizeContainerAndAnimate:NO]; 240 [owner_ resizeContainerAndAnimate:NO];
239 } 241 }
240 242
243 virtual bool BrowserActionShowPopup(const Extension* extension) OVERRIDE {
244 // Do not override other popups and only show in active window.
245 ExtensionPopupController* popup = [ExtensionPopupController popup];
246 if (popup || !browser_->window()->IsActive())
247 return false;
248
249 BrowserActionButton* button = [owner_ buttonForExtension:extension];
250 return button && [owner_ browserActionClicked:button
251 andGrant:false];
252 }
253
241 private: 254 private:
242 // The object we need to inform when we get a notification. Weak. Owns us. 255 // The object we need to inform when we get a notification. Weak. Owns us.
243 BrowserActionsController* owner_; 256 BrowserActionsController* owner_;
244 257
245 // The browser we listen for events from. Weak. 258 // The browser we listen for events from. Weak.
246 Browser* browser_; 259 Browser* browser_;
247 260
248 // Used for registering to receive notifications and automatic clean up. 261 // Used for registering to receive notifications and automatic clean up.
249 content::NotificationRegistrar registrar_; 262 content::NotificationRegistrar registrar_;
250 263
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 [button setAlphaValue:1.0]; 745 [button setAlphaValue:1.0];
733 [hiddenButtons_ removeObjectIdenticalTo:button]; 746 [hiddenButtons_ removeObjectIdenticalTo:button];
734 } 747 }
735 } else if (![hiddenButtons_ containsObject:button]) { 748 } else if (![hiddenButtons_ containsObject:button]) {
736 [hiddenButtons_ addObject:button]; 749 [hiddenButtons_ addObject:button];
737 [button removeFromSuperview]; 750 [button removeFromSuperview];
738 [button setAlphaValue:0.0]; 751 [button setAlphaValue:0.0];
739 } 752 }
740 } 753 }
741 754
742 - (void)browserActionClicked:(BrowserActionButton*)button { 755 - (bool)browserActionClicked:(BrowserActionButton*)button
756 andGrant:(BOOL)shouldGrant {
743 const Extension* extension = [button extension]; 757 const Extension* extension = [button extension];
744 GURL popupUrl; 758 GURL popupUrl;
745 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl)) { 759 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl,
760 shouldGrant)) {
746 case ExtensionToolbarModel::ACTION_NONE: 761 case ExtensionToolbarModel::ACTION_NONE:
747 break; 762 break;
748 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { 763 case ExtensionToolbarModel::ACTION_SHOW_POPUP: {
749 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; 764 NSPoint arrowPoint = [self popupPointForBrowserAction:extension];
750 [ExtensionPopupController showURL:popupUrl 765 [ExtensionPopupController showURL:popupUrl
751 inBrowser:browser_ 766 inBrowser:browser_
752 anchoredAt:arrowPoint 767 anchoredAt:arrowPoint
753 arrowLocation:info_bubble::kTopRight 768 arrowLocation:info_bubble::kTopRight
754 devMode:NO]; 769 devMode:NO];
755 break; 770 return true;
756 } 771 }
757 } 772 }
773 return false;
774 }
775
776 - (bool)browserActionClicked:(BrowserActionButton*)button {
777 return [self browserActionClicked:button
778 andGrant:true];
758 } 779 }
759 780
760 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { 781 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension {
761 // Only display incognito-enabled extensions while in incognito mode. 782 // Only display incognito-enabled extensions while in incognito mode.
762 return 783 return
763 (!profile_->IsOffTheRecord() || 784 (!profile_->IsOffTheRecord() ||
764 extensions::ExtensionSystem::Get(profile_)->extension_service()-> 785 extensions::ExtensionSystem::Get(profile_)->extension_service()->
765 IsIncognitoEnabled(extension->id())); 786 IsIncognitoEnabled(extension->id()));
766 } 787 }
767 788
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 const extensions::ExtensionList& toolbar_items = 884 const extensions::ExtensionList& toolbar_items =
864 toolbarModel_->toolbar_items(); 885 toolbarModel_->toolbar_items();
865 if (index < toolbar_items.size()) { 886 if (index < toolbar_items.size()) {
866 const Extension* extension = toolbar_items[index].get(); 887 const Extension* extension = toolbar_items[index].get();
867 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; 888 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())];
868 } 889 }
869 return nil; 890 return nil;
870 } 891 }
871 892
872 @end 893 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698