| 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" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
| 14 #include "chrome/browser/extensions/extension_action_manager.h" | 14 #include "chrome/browser/extensions/extension_action_manager.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/browser/extensions/extension_toolbar_model.h" | 17 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/sessions/session_tab_helper.h" | 19 #include "chrome/browser/sessions/session_tab_helper.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 23 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
| 23 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 24 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
| 24 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 25 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
| 25 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 26 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 26 #import "chrome/browser/ui/cocoa/menu_button.h" | 27 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/common/extensions/api/extension_action/action_info.h" | 29 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 30 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 - (void)actionButtonDragFinished:(NSNotification*)notification; | 133 - (void)actionButtonDragFinished:(NSNotification*)notification; |
| 133 | 134 |
| 134 // 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 |
| 135 // specified index. | 136 // specified index. |
| 136 - (void)moveButton:(BrowserActionButton*)button | 137 - (void)moveButton:(BrowserActionButton*)button |
| 137 toIndex:(NSUInteger)index | 138 toIndex:(NSUInteger)index |
| 138 animate:(BOOL)animate; | 139 animate:(BOOL)animate; |
| 139 | 140 |
| 140 // Handles when the given BrowserActionButton object is clicked. | 141 // Handles when the given BrowserActionButton object is clicked. |
| 141 - (void)browserActionClicked:(BrowserActionButton*)button; | 142 - (void)browserActionClicked:(BrowserActionButton*)button; |
| 143 - (void)browserActionClicked:(BrowserActionButton*)button |
| 144 andGrant:(BOOL)shouldGrant; |
| 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 void 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 || |
| 248 BrowserList::GetInstance(chrome::GetActiveDesktop())->GetLastActive() != |
| 249 browser_) { |
| 250 return; |
| 251 } |
| 252 |
| 253 BrowserActionButton* button = [owner_ buttonForExtension:extension]; |
| 254 if (button) { |
| 255 [owner_ browserActionClicked:button |
| 256 andGrant:false]; |
| 257 } |
| 258 } |
| 259 |
| 241 private: | 260 private: |
| 242 // The object we need to inform when we get a notification. Weak. Owns us. | 261 // The object we need to inform when we get a notification. Weak. Owns us. |
| 243 BrowserActionsController* owner_; | 262 BrowserActionsController* owner_; |
| 244 | 263 |
| 245 // The browser we listen for events from. Weak. | 264 // The browser we listen for events from. Weak. |
| 246 Browser* browser_; | 265 Browser* browser_; |
| 247 | 266 |
| 248 // Used for registering to receive notifications and automatic clean up. | 267 // Used for registering to receive notifications and automatic clean up. |
| 249 content::NotificationRegistrar registrar_; | 268 content::NotificationRegistrar registrar_; |
| 250 | 269 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 [button setAlphaValue:1.0]; | 751 [button setAlphaValue:1.0]; |
| 733 [hiddenButtons_ removeObjectIdenticalTo:button]; | 752 [hiddenButtons_ removeObjectIdenticalTo:button]; |
| 734 } | 753 } |
| 735 } else if (![hiddenButtons_ containsObject:button]) { | 754 } else if (![hiddenButtons_ containsObject:button]) { |
| 736 [hiddenButtons_ addObject:button]; | 755 [hiddenButtons_ addObject:button]; |
| 737 [button removeFromSuperview]; | 756 [button removeFromSuperview]; |
| 738 [button setAlphaValue:0.0]; | 757 [button setAlphaValue:0.0]; |
| 739 } | 758 } |
| 740 } | 759 } |
| 741 | 760 |
| 742 - (void)browserActionClicked:(BrowserActionButton*)button { | 761 - (void)browserActionClicked:(BrowserActionButton*)button |
| 762 andGrant:(BOOL)shouldGrant { |
| 743 const Extension* extension = [button extension]; | 763 const Extension* extension = [button extension]; |
| 744 GURL popupUrl; | 764 GURL popupUrl; |
| 745 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl)) { | 765 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl, |
| 766 shouldGrant)) { |
| 746 case ExtensionToolbarModel::ACTION_NONE: | 767 case ExtensionToolbarModel::ACTION_NONE: |
| 747 break; | 768 break; |
| 748 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { | 769 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { |
| 749 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; | 770 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; |
| 750 [ExtensionPopupController showURL:popupUrl | 771 [ExtensionPopupController showURL:popupUrl |
| 751 inBrowser:browser_ | 772 inBrowser:browser_ |
| 752 anchoredAt:arrowPoint | 773 anchoredAt:arrowPoint |
| 753 arrowLocation:info_bubble::kTopRight | 774 arrowLocation:info_bubble::kTopRight |
| 754 devMode:NO]; | 775 devMode:NO]; |
| 755 break; | 776 break; |
| 756 } | 777 } |
| 757 } | 778 } |
| 758 } | 779 } |
| 759 | 780 |
| 781 - (void)browserActionClicked:(BrowserActionButton*)button { |
| 782 [self browserActionClicked:button |
| 783 andGrant:true]; |
| 784 } |
| 785 |
| 760 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { | 786 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { |
| 761 // Only display incognito-enabled extensions while in incognito mode. | 787 // Only display incognito-enabled extensions while in incognito mode. |
| 762 return | 788 return |
| 763 (!profile_->IsOffTheRecord() || | 789 (!profile_->IsOffTheRecord() || |
| 764 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 790 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 765 IsIncognitoEnabled(extension->id())); | 791 IsIncognitoEnabled(extension->id())); |
| 766 } | 792 } |
| 767 | 793 |
| 768 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { | 794 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { |
| 769 [self setChevronHidden:([self buttonCount] == [self visibleButtonCount]) | 795 [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 = | 889 const extensions::ExtensionList& toolbar_items = |
| 864 toolbarModel_->toolbar_items(); | 890 toolbarModel_->toolbar_items(); |
| 865 if (index < toolbar_items.size()) { | 891 if (index < toolbar_items.size()) { |
| 866 const Extension* extension = toolbar_items[index].get(); | 892 const Extension* extension = toolbar_items[index].get(); |
| 867 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 893 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 868 } | 894 } |
| 869 return nil; | 895 return nil; |
| 870 } | 896 } |
| 871 | 897 |
| 872 @end | 898 @end |
| OLD | NEW |