| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 - (void)browserActionClicked:(BrowserActionButton*)button; |
| 142 - (void)browserActionClicked:(BrowserActionButton*)button |
| 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 Loading... |
| 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 void 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; |
| 248 |
| 249 BrowserActionButton* button = [owner_ buttonForExtension:extension]; |
| 250 if (button) { |
| 251 [owner_ browserActionClicked:button |
| 252 andGrant:false]; |
| 253 } |
| 254 } |
| 255 |
| 241 private: | 256 private: |
| 242 // 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. |
| 243 BrowserActionsController* owner_; | 258 BrowserActionsController* owner_; |
| 244 | 259 |
| 245 // The browser we listen for events from. Weak. | 260 // The browser we listen for events from. Weak. |
| 246 Browser* browser_; | 261 Browser* browser_; |
| 247 | 262 |
| 248 // Used for registering to receive notifications and automatic clean up. | 263 // Used for registering to receive notifications and automatic clean up. |
| 249 content::NotificationRegistrar registrar_; | 264 content::NotificationRegistrar registrar_; |
| 250 | 265 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 [button setAlphaValue:1.0]; | 747 [button setAlphaValue:1.0]; |
| 733 [hiddenButtons_ removeObjectIdenticalTo:button]; | 748 [hiddenButtons_ removeObjectIdenticalTo:button]; |
| 734 } | 749 } |
| 735 } else if (![hiddenButtons_ containsObject:button]) { | 750 } else if (![hiddenButtons_ containsObject:button]) { |
| 736 [hiddenButtons_ addObject:button]; | 751 [hiddenButtons_ addObject:button]; |
| 737 [button removeFromSuperview]; | 752 [button removeFromSuperview]; |
| 738 [button setAlphaValue:0.0]; | 753 [button setAlphaValue:0.0]; |
| 739 } | 754 } |
| 740 } | 755 } |
| 741 | 756 |
| 742 - (void)browserActionClicked:(BrowserActionButton*)button { | 757 - (void)browserActionClicked:(BrowserActionButton*)button |
| 758 andGrant:(BOOL)shouldGrant { |
| 743 const Extension* extension = [button extension]; | 759 const Extension* extension = [button extension]; |
| 744 GURL popupUrl; | 760 GURL popupUrl; |
| 745 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl)) { | 761 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl, |
| 762 shouldGrant)) { |
| 746 case ExtensionToolbarModel::ACTION_NONE: | 763 case ExtensionToolbarModel::ACTION_NONE: |
| 747 break; | 764 break; |
| 748 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { | 765 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { |
| 749 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; | 766 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; |
| 750 [ExtensionPopupController showURL:popupUrl | 767 [ExtensionPopupController showURL:popupUrl |
| 751 inBrowser:browser_ | 768 inBrowser:browser_ |
| 752 anchoredAt:arrowPoint | 769 anchoredAt:arrowPoint |
| 753 arrowLocation:info_bubble::kTopRight | 770 arrowLocation:info_bubble::kTopRight |
| 754 devMode:NO]; | 771 devMode:NO]; |
| 755 break; | 772 break; |
| 756 } | 773 } |
| 757 } | 774 } |
| 758 } | 775 } |
| 759 | 776 |
| 777 - (void)browserActionClicked:(BrowserActionButton*)button { |
| 778 [self browserActionClicked:button |
| 779 andGrant:true]; |
| 780 } |
| 781 |
| 760 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { | 782 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { |
| 761 // Only display incognito-enabled extensions while in incognito mode. | 783 // Only display incognito-enabled extensions while in incognito mode. |
| 762 return | 784 return |
| 763 (!profile_->IsOffTheRecord() || | 785 (!profile_->IsOffTheRecord() || |
| 764 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 786 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 765 IsIncognitoEnabled(extension->id())); | 787 IsIncognitoEnabled(extension->id())); |
| 766 } | 788 } |
| 767 | 789 |
| 768 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { | 790 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { |
| 769 [self setChevronHidden:([self buttonCount] == [self visibleButtonCount]) | 791 [self setChevronHidden:([self buttonCount] == [self visibleButtonCount]) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 const extensions::ExtensionList& toolbar_items = | 885 const extensions::ExtensionList& toolbar_items = |
| 864 toolbarModel_->toolbar_items(); | 886 toolbarModel_->toolbar_items(); |
| 865 if (index < toolbar_items.size()) { | 887 if (index < toolbar_items.size()) { |
| 866 const Extension* extension = toolbar_items[index].get(); | 888 const Extension* extension = toolbar_items[index].get(); |
| 867 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 889 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 868 } | 890 } |
| 869 return nil; | 891 return nil; |
| 870 } | 892 } |
| 871 | 893 |
| 872 @end | 894 @end |
| OLD | NEW |