OLD | NEW |
---|---|
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 // when _any_ Browser Action button is done dragging to keep all open windows in | 130 // when _any_ Browser Action button is done dragging to keep all open windows in |
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 and whether it |
141 - (void)browserActionClicked:(BrowserActionButton*)button; | 141 // it should grant tab permissions. API-simulated clicks should not grant. |
Alexei Svitkine (slow)
2013/10/17 20:56:40
Nit: Remove extra 'it'
justinlin
2013/10/17 21:33:59
Done.
| |
142 - (bool)browserActionClicked:(BrowserActionButton*)button | |
143 shouldGrant:(BOOL)shouldGrant; | |
144 - (bool)browserActionClicked:(BrowserActionButton*)button; | |
142 | 145 |
143 // Returns whether the given extension should be displayed. Only displays | 146 // Returns whether the given extension should be displayed. Only displays |
144 // incognito-enabled extensions in incognito mode. Otherwise returns YES. | 147 // incognito-enabled extensions in incognito mode. Otherwise returns YES. |
145 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension; | 148 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension; |
146 | 149 |
147 // The reason |frame| is specified in these chevron functions is because the | 150 // 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 | 151 // 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 | 152 // passed instead of the current frame (which may be off and cause the chevron |
150 // to jump at the end of its animation). | 153 // to jump at the end of its animation). |
151 | 154 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 int index) OVERRIDE { | 234 int index) OVERRIDE { |
232 [owner_ createActionButtonForExtension:extension withIndex:index]; | 235 [owner_ createActionButtonForExtension:extension withIndex:index]; |
233 [owner_ resizeContainerAndAnimate:NO]; | 236 [owner_ resizeContainerAndAnimate:NO]; |
234 } | 237 } |
235 | 238 |
236 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE { | 239 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE { |
237 [owner_ removeActionButtonForExtension:extension]; | 240 [owner_ removeActionButtonForExtension:extension]; |
238 [owner_ resizeContainerAndAnimate:NO]; | 241 [owner_ resizeContainerAndAnimate:NO]; |
239 } | 242 } |
240 | 243 |
244 virtual bool BrowserActionShowPopup(const Extension* extension) OVERRIDE { | |
245 // Do not override other popups and only show in active window. | |
246 ExtensionPopupController* popup = [ExtensionPopupController popup]; | |
247 if (popup || !browser_->window()->IsActive()) | |
248 return false; | |
249 | |
250 BrowserActionButton* button = [owner_ buttonForExtension:extension]; | |
251 return button && [owner_ browserActionClicked:button | |
252 shouldGrant:false]; | |
Alexei Svitkine (slow)
2013/10/17 20:56:40
Nit: This is an Obj-C call, so change false -> NO
justinlin
2013/10/17 21:33:59
Done.
| |
253 } | |
254 | |
241 private: | 255 private: |
242 // The object we need to inform when we get a notification. Weak. Owns us. | 256 // The object we need to inform when we get a notification. Weak. Owns us. |
243 BrowserActionsController* owner_; | 257 BrowserActionsController* owner_; |
244 | 258 |
245 // The browser we listen for events from. Weak. | 259 // The browser we listen for events from. Weak. |
246 Browser* browser_; | 260 Browser* browser_; |
247 | 261 |
248 // Used for registering to receive notifications and automatic clean up. | 262 // Used for registering to receive notifications and automatic clean up. |
249 content::NotificationRegistrar registrar_; | 263 content::NotificationRegistrar registrar_; |
250 | 264 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 [button setAlphaValue:1.0]; | 746 [button setAlphaValue:1.0]; |
733 [hiddenButtons_ removeObjectIdenticalTo:button]; | 747 [hiddenButtons_ removeObjectIdenticalTo:button]; |
734 } | 748 } |
735 } else if (![hiddenButtons_ containsObject:button]) { | 749 } else if (![hiddenButtons_ containsObject:button]) { |
736 [hiddenButtons_ addObject:button]; | 750 [hiddenButtons_ addObject:button]; |
737 [button removeFromSuperview]; | 751 [button removeFromSuperview]; |
738 [button setAlphaValue:0.0]; | 752 [button setAlphaValue:0.0]; |
739 } | 753 } |
740 } | 754 } |
741 | 755 |
742 - (void)browserActionClicked:(BrowserActionButton*)button { | 756 - (bool)browserActionClicked:(BrowserActionButton*)button |
Alexei Svitkine (slow)
2013/10/17 20:56:40
Nit: Change return value to BOOL and return YES/NO
justinlin
2013/10/17 21:33:59
Done.
| |
757 shouldGrant:(BOOL)shouldGrant { | |
743 const Extension* extension = [button extension]; | 758 const Extension* extension = [button extension]; |
744 GURL popupUrl; | 759 GURL popupUrl; |
745 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl)) { | 760 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl, |
761 shouldGrant)) { | |
746 case ExtensionToolbarModel::ACTION_NONE: | 762 case ExtensionToolbarModel::ACTION_NONE: |
747 break; | 763 break; |
748 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { | 764 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { |
749 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; | 765 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; |
750 [ExtensionPopupController showURL:popupUrl | 766 [ExtensionPopupController showURL:popupUrl |
751 inBrowser:browser_ | 767 inBrowser:browser_ |
752 anchoredAt:arrowPoint | 768 anchoredAt:arrowPoint |
753 arrowLocation:info_bubble::kTopRight | 769 arrowLocation:info_bubble::kTopRight |
754 devMode:NO]; | 770 devMode:NO]; |
755 break; | 771 return true; |
756 } | 772 } |
757 } | 773 } |
774 return false; | |
775 } | |
776 | |
777 - (bool)browserActionClicked:(BrowserActionButton*)button { | |
778 return [self browserActionClicked:button]; | |
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 Loading... | |
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 |
OLD | NEW |