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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // when _any_ Browser Action button is done dragging to keep all open windows in | 131 // when _any_ Browser Action button is done dragging to keep all open windows in |
132 // sync visually. | 132 // sync visually. |
133 - (void)actionButtonDragFinished:(NSNotification*)notification; | 133 - (void)actionButtonDragFinished:(NSNotification*)notification; |
134 | 134 |
135 // Moves the given button both visually and within the toolbar model to the | 135 // Moves the given button both visually and within the toolbar model to the |
136 // specified index. | 136 // specified index. |
137 - (void)moveButton:(BrowserActionButton*)button | 137 - (void)moveButton:(BrowserActionButton*)button |
138 toIndex:(NSUInteger)index | 138 toIndex:(NSUInteger)index |
139 animate:(BOOL)animate; | 139 animate:(BOOL)animate; |
140 | 140 |
141 // Handles when the given BrowserActionButton object is clicked. | 141 // Handles when the given BrowserActionButton object is clicked and whether |
142 - (void)browserActionClicked:(BrowserActionButton*)button; | 142 // it should grant tab permissions. API-simulated clicks should not grant. |
| 143 - (BOOL)browserActionClicked:(BrowserActionButton*)button |
| 144 shouldGrant:(BOOL)shouldGrant; |
| 145 - (BOOL)browserActionClicked:(BrowserActionButton*)button; |
143 | 146 |
144 // Returns whether the given extension should be displayed. Only displays | 147 // Returns whether the given extension should be displayed. Only displays |
145 // incognito-enabled extensions in incognito mode. Otherwise returns YES. | 148 // incognito-enabled extensions in incognito mode. Otherwise returns YES. |
146 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension; | 149 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension; |
147 | 150 |
148 // The reason |frame| is specified in these chevron functions is because the | 151 // The reason |frame| is specified in these chevron functions is because the |
149 // container may be animating and the end frame of the animation should be | 152 // container may be animating and the end frame of the animation should be |
150 // passed instead of the current frame (which may be off and cause the chevron | 153 // passed instead of the current frame (which may be off and cause the chevron |
151 // to jump at the end of its animation). | 154 // to jump at the end of its animation). |
152 | 155 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 int index) OVERRIDE { | 235 int index) OVERRIDE { |
233 [owner_ createActionButtonForExtension:extension withIndex:index]; | 236 [owner_ createActionButtonForExtension:extension withIndex:index]; |
234 [owner_ resizeContainerAndAnimate:NO]; | 237 [owner_ resizeContainerAndAnimate:NO]; |
235 } | 238 } |
236 | 239 |
237 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE { | 240 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE { |
238 [owner_ removeActionButtonForExtension:extension]; | 241 [owner_ removeActionButtonForExtension:extension]; |
239 [owner_ resizeContainerAndAnimate:NO]; | 242 [owner_ resizeContainerAndAnimate:NO]; |
240 } | 243 } |
241 | 244 |
| 245 virtual bool BrowserActionShowPopup(const Extension* extension) OVERRIDE { |
| 246 // Do not override other popups and only show in active window. |
| 247 ExtensionPopupController* popup = [ExtensionPopupController popup]; |
| 248 if (popup || !browser_->window()->IsActive()) |
| 249 return false; |
| 250 |
| 251 BrowserActionButton* button = [owner_ buttonForExtension:extension]; |
| 252 return button && [owner_ browserActionClicked:button |
| 253 shouldGrant:NO]; |
| 254 } |
| 255 |
242 private: | 256 private: |
243 // The object we need to inform when we get a notification. Weak. Owns us. | 257 // The object we need to inform when we get a notification. Weak. Owns us. |
244 BrowserActionsController* owner_; | 258 BrowserActionsController* owner_; |
245 | 259 |
246 // The browser we listen for events from. Weak. | 260 // The browser we listen for events from. Weak. |
247 Browser* browser_; | 261 Browser* browser_; |
248 | 262 |
249 // Used for registering to receive notifications and automatic clean up. | 263 // Used for registering to receive notifications and automatic clean up. |
250 content::NotificationRegistrar registrar_; | 264 content::NotificationRegistrar registrar_; |
251 | 265 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 [button setAlphaValue:1.0]; | 747 [button setAlphaValue:1.0]; |
734 [hiddenButtons_ removeObjectIdenticalTo:button]; | 748 [hiddenButtons_ removeObjectIdenticalTo:button]; |
735 } | 749 } |
736 } else if (![hiddenButtons_ containsObject:button]) { | 750 } else if (![hiddenButtons_ containsObject:button]) { |
737 [hiddenButtons_ addObject:button]; | 751 [hiddenButtons_ addObject:button]; |
738 [button removeFromSuperview]; | 752 [button removeFromSuperview]; |
739 [button setAlphaValue:0.0]; | 753 [button setAlphaValue:0.0]; |
740 } | 754 } |
741 } | 755 } |
742 | 756 |
743 - (void)browserActionClicked:(BrowserActionButton*)button { | 757 - (BOOL)browserActionClicked:(BrowserActionButton*)button |
| 758 shouldGrant:(BOOL)shouldGrant { |
744 const Extension* extension = [button extension]; | 759 const Extension* extension = [button extension]; |
745 GURL popupUrl; | 760 GURL popupUrl; |
746 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl)) { | 761 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl, |
| 762 shouldGrant)) { |
747 case ExtensionToolbarModel::ACTION_NONE: | 763 case ExtensionToolbarModel::ACTION_NONE: |
748 break; | 764 break; |
749 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { | 765 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { |
750 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; | 766 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; |
751 [ExtensionPopupController showURL:popupUrl | 767 [ExtensionPopupController showURL:popupUrl |
752 inBrowser:browser_ | 768 inBrowser:browser_ |
753 anchoredAt:arrowPoint | 769 anchoredAt:arrowPoint |
754 arrowLocation:info_bubble::kTopRight | 770 arrowLocation:info_bubble::kTopRight |
755 devMode:NO]; | 771 devMode:NO]; |
756 break; | 772 return YES; |
757 } | 773 } |
758 } | 774 } |
| 775 return NO; |
| 776 } |
| 777 |
| 778 - (BOOL)browserActionClicked:(BrowserActionButton*)button { |
| 779 return [self browserActionClicked:button |
| 780 shouldGrant:YES]; |
759 } | 781 } |
760 | 782 |
761 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { | 783 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { |
762 // Only display incognito-enabled extensions while in incognito mode. | 784 // Only display incognito-enabled extensions while in incognito mode. |
763 return | 785 return |
764 (!profile_->IsOffTheRecord() || | 786 (!profile_->IsOffTheRecord() || |
765 extension_util::IsIncognitoEnabled( | 787 extension_util::IsIncognitoEnabled( |
766 extension->id(), | 788 extension->id(), |
767 extensions::ExtensionSystem::Get(profile_)->extension_service())); | 789 extensions::ExtensionSystem::Get(profile_)->extension_service())); |
768 } | 790 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 const extensions::ExtensionList& toolbar_items = | 887 const extensions::ExtensionList& toolbar_items = |
866 toolbarModel_->toolbar_items(); | 888 toolbarModel_->toolbar_items(); |
867 if (index < toolbar_items.size()) { | 889 if (index < toolbar_items.size()) { |
868 const Extension* extension = toolbar_items[index].get(); | 890 const Extension* extension = toolbar_items[index].get(); |
869 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 891 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
870 } | 892 } |
871 return nil; | 893 return nil; |
872 } | 894 } |
873 | 895 |
874 @end | 896 @end |
OLD | NEW |