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/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" | 59 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" |
60 #include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h" | 60 #include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h" |
61 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 61 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
62 #import "chrome/browser/ui/cocoa/confirm_quit.h" | 62 #import "chrome/browser/ui/cocoa/confirm_quit.h" |
63 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" | 63 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
64 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" | 64 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
65 #include "chrome/browser/ui/cocoa/handoff_active_url_observer_bridge.h" | 65 #include "chrome/browser/ui/cocoa/handoff_active_url_observer_bridge.h" |
66 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" | 66 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" |
67 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | 67 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
68 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" | 68 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" |
| 69 #import "chrome/browser/ui/cocoa/share_menu/share_menu_controller.h" |
69 #include "chrome/browser/ui/extensions/application_launch.h" | 70 #include "chrome/browser/ui/extensions/application_launch.h" |
70 #include "chrome/browser/ui/host_desktop.h" | 71 #include "chrome/browser/ui/host_desktop.h" |
71 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 72 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
72 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 73 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
73 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 74 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
74 #include "chrome/browser/ui/user_manager.h" | 75 #include "chrome/browser/ui/user_manager.h" |
75 #include "chrome/browser/web_applications/web_app_mac.h" | 76 #include "chrome/browser/web_applications/web_app_mac.h" |
76 #include "chrome/common/chrome_paths_internal.h" | 77 #include "chrome/common/chrome_paths_internal.h" |
77 #include "chrome/common/chrome_switches.h" | 78 #include "chrome/common/chrome_switches.h" |
78 #include "chrome/common/cloud_print/cloud_print_class_mac.h" | 79 #include "chrome/common/cloud_print/cloud_print_class_mac.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return false; | 205 return false; |
205 return cache.ProfileIsSigninRequiredAtIndex(profile_index); | 206 return cache.ProfileIsSigninRequiredAtIndex(profile_index); |
206 } | 207 } |
207 | 208 |
208 } // namespace | 209 } // namespace |
209 | 210 |
210 @interface AppController () <HandoffActiveURLObserverBridgeDelegate> | 211 @interface AppController () <HandoffActiveURLObserverBridgeDelegate> |
211 | 212 |
212 - (void)initMenuState; | 213 - (void)initMenuState; |
213 - (void)initProfileMenu; | 214 - (void)initProfileMenu; |
| 215 - (void)initShareMenu; |
214 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; | 216 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
215 - (void)updateDisplayMessageCenterPrefMenuItem:(NSMenuItem*)item; | 217 - (void)updateDisplayMessageCenterPrefMenuItem:(NSMenuItem*)item; |
216 - (void)registerServicesMenuTypesTo:(NSApplication*)app; | 218 - (void)registerServicesMenuTypesTo:(NSApplication*)app; |
217 - (void)getUrl:(NSAppleEventDescriptor*)event | 219 - (void)getUrl:(NSAppleEventDescriptor*)event |
218 withReply:(NSAppleEventDescriptor*)reply; | 220 withReply:(NSAppleEventDescriptor*)reply; |
219 - (void)activeSpaceDidChange:(NSNotification*)inNotification; | 221 - (void)activeSpaceDidChange:(NSNotification*)inNotification; |
220 - (void)checkForAnyKeyWindows; | 222 - (void)checkForAnyKeyWindows; |
221 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 223 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
222 - (BOOL)shouldQuitWithInProgressDownloads; | 224 - (BOOL)shouldQuitWithInProgressDownloads; |
223 - (void)executeApplication:(id)sender; | 225 - (void)executeApplication:(id)sender; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 addObserver:self | 383 addObserver:self |
382 selector:@selector(willPowerOff:) | 384 selector:@selector(willPowerOff:) |
383 name:NSWorkspaceWillPowerOffNotification | 385 name:NSWorkspaceWillPowerOffNotification |
384 object:nil]; | 386 object:nil]; |
385 | 387 |
386 // Set up the command updater for when there are no windows open | 388 // Set up the command updater for when there are no windows open |
387 [self initMenuState]; | 389 [self initMenuState]; |
388 | 390 |
389 // Initialize the Profile menu. | 391 // Initialize the Profile menu. |
390 [self initProfileMenu]; | 392 [self initProfileMenu]; |
| 393 |
| 394 // Initialize the Share menu. Call this method only for OSX versions >= 10.9. |
| 395 if (base::mac::IsOSMavericksOrLater()) |
| 396 [self initShareMenu]; |
391 } | 397 } |
392 | 398 |
393 - (void)unregisterEventHandlers { | 399 - (void)unregisterEventHandlers { |
394 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 400 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
395 [em removeEventHandlerForEventClass:kInternetEventClass | 401 [em removeEventHandlerForEventClass:kInternetEventClass |
396 andEventID:kAEGetURL]; | 402 andEventID:kAEGetURL]; |
397 [em removeEventHandlerForEventClass:cloud_print::kAECloudPrintClass | 403 [em removeEventHandlerForEventClass:cloud_print::kAECloudPrintClass |
398 andEventID:cloud_print::kAECloudPrintClass]; | 404 andEventID:cloud_print::kAECloudPrintClass]; |
399 [em removeEventHandlerForEventClass:'WWW!' | 405 [em removeEventHandlerForEventClass:'WWW!' |
400 andEventID:'OURL']; | 406 andEventID:'OURL']; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 // Build up the encoding menu, the order of the items differs based on the | 749 // Build up the encoding menu, the order of the items differs based on the |
744 // current locale (see http://crbug.com/7647 for details). | 750 // current locale (see http://crbug.com/7647 for details). |
745 // We need a valid g_browser_process to get the profile which is why we can't | 751 // We need a valid g_browser_process to get the profile which is why we can't |
746 // call this from awakeFromNib. | 752 // call this from awakeFromNib. |
747 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; | 753 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; |
748 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; | 754 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; |
749 NSMenu* encodingMenu = [encodingMenuItem submenu]; | 755 NSMenu* encodingMenu = [encodingMenuItem submenu]; |
750 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], | 756 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], |
751 encodingMenu); | 757 encodingMenu); |
752 | 758 |
| 759 // Implement delegate methods to rebuild share menu when the cursor hovers |
| 760 // over the Share Menu Item. |
| 761 NSMenu* fileMenu = [[[NSApp mainMenu] itemWithTag:IDC_FILE_MENU] submenu]; |
| 762 [fileMenu setDelegate:self]; |
| 763 |
753 // Instantiate the ProfileInfoCache observer so that we can get | 764 // Instantiate the ProfileInfoCache observer so that we can get |
754 // notified when a profile is deleted. | 765 // notified when a profile is deleted. |
755 profileInfoCacheObserver_.reset(new AppControllerProfileObserver( | 766 profileInfoCacheObserver_.reset(new AppControllerProfileObserver( |
756 g_browser_process->profile_manager(), self)); | 767 g_browser_process->profile_manager(), self)); |
757 | 768 |
758 // Since Chrome is localized to more languages than the OS, tell Cocoa which | 769 // Since Chrome is localized to more languages than the OS, tell Cocoa which |
759 // menu is the Help so it can add the search item to it. | 770 // menu is the Help so it can add the search item to it. |
760 [NSApp setHelpMenu:helpMenu_]; | 771 [NSApp setHelpMenu:helpMenu_]; |
761 | 772 |
762 // Record the path to the (browser) app bundle; this is used by the app mode | 773 // Record the path to the (browser) app bundle; this is used by the app mode |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 return; | 1307 return; |
1297 } | 1308 } |
1298 | 1309 |
1299 // The controller will unhide the menu if necessary. | 1310 // The controller will unhide the menu if necessary. |
1300 [profileMenu setHidden:YES]; | 1311 [profileMenu setHidden:YES]; |
1301 | 1312 |
1302 profileMenuController_.reset( | 1313 profileMenuController_.reset( |
1303 [[ProfileMenuController alloc] initWithMainMenuItem:profileMenu]); | 1314 [[ProfileMenuController alloc] initWithMainMenuItem:profileMenu]); |
1304 } | 1315 } |
1305 | 1316 |
| 1317 - (void)initShareMenu { |
| 1318 NSMenu* mainMenu = [NSApp mainMenu]; |
| 1319 |
| 1320 shareMenuController_.reset( |
| 1321 [[ShareMenuController alloc] initWithMainMenu:mainMenu]); |
| 1322 } |
| 1323 |
| 1324 // Rebuild the share menu when the cursor hovers over Share Menu Item. |
| 1325 // This is to ensure Share menu has updated list of items since it has been |
| 1326 // changed in System Pref panel. |
| 1327 - (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item { |
| 1328 if ([item tag] == IDC_SHARE_MENU) { |
| 1329 NSLog(@"menu item highlighted %@ %s", item, __FUNCTION__); |
| 1330 [shareMenuController_.get() rebuildShareMenu]; |
| 1331 } |
| 1332 } |
| 1333 |
1306 // The Confirm to Quit preference is atypical in that the preference lives in | 1334 // The Confirm to Quit preference is atypical in that the preference lives in |
1307 // the app menu right above the Quit menu item. This method will refresh the | 1335 // the app menu right above the Quit menu item. This method will refresh the |
1308 // display of that item depending on the preference state. | 1336 // display of that item depending on the preference state. |
1309 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item { | 1337 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item { |
1310 // Format the string so that the correct key equivalent is displayed. | 1338 // Format the string so that the correct key equivalent is displayed. |
1311 NSString* acceleratorString = [ConfirmQuitPanelController keyCommandString]; | 1339 NSString* acceleratorString = [ConfirmQuitPanelController keyCommandString]; |
1312 NSString* title = l10n_util::GetNSStringF(IDS_CONFIRM_TO_QUIT_OPTION, | 1340 NSString* title = l10n_util::GetNSStringF(IDS_CONFIRM_TO_QUIT_OPTION, |
1313 base::SysNSStringToUTF16(acceleratorString)); | 1341 base::SysNSStringToUTF16(acceleratorString)); |
1314 [item setTitle:title]; | 1342 [item setTitle:title]; |
1315 | 1343 |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 | 1732 |
1705 //--------------------------------------------------------------------------- | 1733 //--------------------------------------------------------------------------- |
1706 | 1734 |
1707 namespace app_controller_mac { | 1735 namespace app_controller_mac { |
1708 | 1736 |
1709 bool IsOpeningNewWindow() { | 1737 bool IsOpeningNewWindow() { |
1710 return g_is_opening_new_window; | 1738 return g_is_opening_new_window; |
1711 } | 1739 } |
1712 | 1740 |
1713 } // namespace app_controller_mac | 1741 } // namespace app_controller_mac |
OLD | NEW |