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 26 matching lines...) Expand all Loading... | |
37 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 37 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
38 #include "chrome/browser/profiles/profile_manager.h" | 38 #include "chrome/browser/profiles/profile_manager.h" |
39 #include "chrome/browser/profiles/profiles_state.h" | 39 #include "chrome/browser/profiles/profiles_state.h" |
40 #include "chrome/browser/sessions/session_restore.h" | 40 #include "chrome/browser/sessions/session_restore.h" |
41 #include "chrome/browser/sessions/session_service.h" | 41 #include "chrome/browser/sessions/session_service.h" |
42 #include "chrome/browser/sessions/session_service_factory.h" | 42 #include "chrome/browser/sessions/session_service_factory.h" |
43 #include "chrome/browser/sessions/tab_restore_service.h" | 43 #include "chrome/browser/sessions/tab_restore_service.h" |
44 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 44 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
45 #include "chrome/browser/signin/signin_manager_factory.h" | 45 #include "chrome/browser/signin/signin_manager_factory.h" |
46 #include "chrome/browser/signin/signin_promo.h" | 46 #include "chrome/browser/signin/signin_promo.h" |
47 #include "chrome/browser/signin/signin_ui_util.h" | |
47 #include "chrome/browser/sync/profile_sync_service.h" | 48 #include "chrome/browser/sync/profile_sync_service.h" |
48 #include "chrome/browser/sync/sync_ui_util.h" | 49 #include "chrome/browser/sync/sync_ui_util.h" |
49 #include "chrome/browser/ui/browser.h" | 50 #include "chrome/browser/ui/browser.h" |
50 #include "chrome/browser/ui/browser_command_controller.h" | 51 #include "chrome/browser/ui/browser_command_controller.h" |
51 #include "chrome/browser/ui/browser_commands.h" | 52 #include "chrome/browser/ui/browser_commands.h" |
52 #include "chrome/browser/ui/browser_dialogs.h" | 53 #include "chrome/browser/ui/browser_dialogs.h" |
53 #include "chrome/browser/ui/browser_finder.h" | 54 #include "chrome/browser/ui/browser_finder.h" |
54 #include "chrome/browser/ui/browser_iterator.h" | 55 #include "chrome/browser/ui/browser_iterator.h" |
55 #include "chrome/browser/ui/browser_mac.h" | 56 #include "chrome/browser/ui/browser_mac.h" |
56 #include "chrome/browser/ui/browser_window.h" | 57 #include "chrome/browser/ui/browser_window.h" |
57 #include "chrome/browser/ui/chrome_pages.h" | 58 #include "chrome/browser/ui/chrome_pages.h" |
58 #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" |
59 #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" |
60 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 61 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
61 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | |
62 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | |
63 #import "chrome/browser/ui/cocoa/confirm_quit.h" | 62 #import "chrome/browser/ui/cocoa/confirm_quit.h" |
64 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" | 63 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
65 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" | 64 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
66 #include "chrome/browser/ui/cocoa/handoff_active_url_observer_bridge.h" | 65 #include "chrome/browser/ui/cocoa/handoff_active_url_observer_bridge.h" |
67 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" | 66 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" |
68 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | 67 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
69 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" | 68 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" |
70 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | |
71 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | |
72 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | |
73 #include "chrome/browser/ui/extensions/application_launch.h" | 69 #include "chrome/browser/ui/extensions/application_launch.h" |
74 #include "chrome/browser/ui/host_desktop.h" | 70 #include "chrome/browser/ui/host_desktop.h" |
75 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 71 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
76 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 72 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
73 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
77 #include "chrome/browser/ui/user_manager.h" | 74 #include "chrome/browser/ui/user_manager.h" |
78 #include "chrome/browser/web_applications/web_app_mac.h" | 75 #include "chrome/browser/web_applications/web_app_mac.h" |
79 #include "chrome/common/chrome_paths_internal.h" | 76 #include "chrome/common/chrome_paths_internal.h" |
80 #include "chrome/common/chrome_switches.h" | 77 #include "chrome/common/chrome_switches.h" |
81 #include "chrome/common/cloud_print/cloud_print_class_mac.h" | 78 #include "chrome/common/cloud_print/cloud_print_class_mac.h" |
82 #include "chrome/common/extensions/extension_constants.h" | 79 #include "chrome/common/extensions/extension_constants.h" |
83 #include "chrome/common/mac/app_mode_common.h" | 80 #include "chrome/common/mac/app_mode_common.h" |
84 #include "chrome/common/pref_names.h" | 81 #include "chrome/common/pref_names.h" |
85 #include "chrome/common/url_constants.h" | 82 #include "chrome/common/url_constants.h" |
86 #include "chrome/grit/chromium_strings.h" | 83 #include "chrome/grit/chromium_strings.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 | 296 |
300 AppController* app_controller_; // Weak; owns us. | 297 AppController* app_controller_; // Weak; owns us. |
301 | 298 |
302 DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver); | 299 DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver); |
303 }; | 300 }; |
304 | 301 |
305 @implementation AppController | 302 @implementation AppController |
306 | 303 |
307 @synthesize startupComplete = startupComplete_; | 304 @synthesize startupComplete = startupComplete_; |
308 | 305 |
306 + (void)updateSigninItem:(id)signinItem | |
307 shouldShow:(BOOL)showSigninMenuItem | |
308 currentProfile:(Profile*)profile { | |
309 DCHECK([signinItem isKindOfClass:[NSMenuItem class]]); | |
310 NSMenuItem* signinMenuItem = static_cast<NSMenuItem*>(signinItem); | |
Robert Sesek
2015/04/01 15:17:45
nit: can use base::mac::ObjCCastStrict<>.
| |
311 | |
312 // Look for a separator immediately after the menu item so it can be hidden | |
313 // or shown appropriately along with the signin menu item. | |
314 NSMenuItem* followingSeparator = nil; | |
315 NSMenu* menu = [signinItem menu]; | |
316 if (menu) { | |
317 NSInteger signinItemIndex = [menu indexOfItem:signinMenuItem]; | |
318 DCHECK_NE(signinItemIndex, -1); | |
319 if ((signinItemIndex + 1) < [menu numberOfItems]) { | |
320 NSMenuItem* menuItem = [menu itemAtIndex:(signinItemIndex + 1)]; | |
321 if ([menuItem isSeparatorItem]) { | |
322 followingSeparator = menuItem; | |
323 } | |
324 } | |
325 } | |
326 | |
327 base::string16 label = signin_ui_util::GetSigninMenuLabel(profile); | |
328 [signinMenuItem setTitle:l10n_util::FixUpWindowsStyleLabel(label)]; | |
329 [signinMenuItem setHidden:!showSigninMenuItem]; | |
330 [followingSeparator setHidden:!showSigninMenuItem]; | |
331 } | |
332 | |
309 - (void)dealloc { | 333 - (void)dealloc { |
310 [[closeTabMenuItem_ menu] setDelegate:nil]; | 334 [[closeTabMenuItem_ menu] setDelegate:nil]; |
311 [super dealloc]; | 335 [super dealloc]; |
312 } | 336 } |
313 | 337 |
314 // This method is called very early in application startup (ie, before | 338 // This method is called very early in application startup (ie, before |
315 // the profile is loaded or any preferences have been registered). Defer any | 339 // the profile is loaded or any preferences have been registered). Defer any |
316 // user-data initialization until -applicationDidFinishLaunching:. | 340 // user-data initialization until -applicationDidFinishLaunching:. |
317 - (void)awakeFromNib { | 341 - (void)awakeFromNib { |
318 MacStartupProfiler::GetInstance()->Profile( | 342 MacStartupProfiler::GetInstance()->Profile( |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 // close the popover so map it to "Close Window". | 575 // close the popover so map it to "Close Window". |
552 // Otherwise, map Cmd-W to "Close Tab" if it's a browser window. | 576 // Otherwise, map Cmd-W to "Close Tab" if it's a browser window. |
553 if ([target isKindOfClass:[NSWindow class]]) { | 577 if ([target isKindOfClass:[NSWindow class]]) { |
554 NSWindow* window = target; | 578 NSWindow* window = target; |
555 NSWindow* mainWindow = [NSApp mainWindow]; | 579 NSWindow* mainWindow = [NSApp mainWindow]; |
556 if (!window || ([window parentWindow] == mainWindow)) { | 580 if (!window || ([window parentWindow] == mainWindow)) { |
557 // If the target window is a child of the main window (e.g. a bubble), the | 581 // If the target window is a child of the main window (e.g. a bubble), the |
558 // main window should be the one that handles the close menu item action. | 582 // main window should be the one that handles the close menu item action. |
559 window = mainWindow; | 583 window = mainWindow; |
560 } | 584 } |
561 enableCloseTabShortcut = | 585 Browser* browser = chrome::FindBrowserWithWindow(window); |
562 [[window windowController] isKindOfClass:[TabWindowController class]]; | 586 enableCloseTabShortcut = browser && browser->is_type_tabbed(); |
563 } | 587 } |
564 | 588 |
565 [self adjustCloseWindowMenuItemKeyEquivalent:enableCloseTabShortcut]; | 589 [self adjustCloseWindowMenuItemKeyEquivalent:enableCloseTabShortcut]; |
566 [self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut]; | 590 [self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut]; |
567 } | 591 } |
568 | 592 |
569 - (void)windowDidResignKey:(NSNotification*)notify { | 593 - (void)windowDidResignKey:(NSNotification*)notify { |
570 // If a window is closed, this notification is fired but |[NSApp keyWindow]| | 594 // If a window is closed, this notification is fired but |[NSApp keyWindow]| |
571 // returns nil regardless of whether any suitable candidates for the key | 595 // returns nil regardless of whether any suitable candidates for the key |
572 // window remain. It seems that the new key window for the app is not set | 596 // window remain. It seems that the new key window for the app is not set |
573 // until after this notification is fired, so a check is performed after the | 597 // until after this notification is fired, so a check is performed after the |
574 // run loop is allowed to spin. | 598 // run loop is allowed to spin. |
575 [self performSelector:@selector(checkForAnyKeyWindows) | 599 [self performSelector:@selector(checkForAnyKeyWindows) |
576 withObject:nil | 600 withObject:nil |
577 afterDelay:0.0]; | 601 afterDelay:0.0]; |
578 } | 602 } |
579 | 603 |
580 - (void)windowDidBecomeMain:(NSNotification*)notify { | 604 - (void)windowDidBecomeMain:(NSNotification*)notify { |
581 // If the window changed to a new BrowserWindowController, update the profile. | 605 Browser* browser = chrome::FindBrowserWithWindow([notify object]); |
582 id windowController = [[notify object] windowController]; | 606 if (browser) |
583 if (![windowController isKindOfClass:[BrowserWindowController class]]) | 607 [self windowChangedToProfile:browser->profile()->GetOriginalProfile()]; |
584 return; | |
585 | |
586 // If the profile is incognito, use the original profile. | |
587 Profile* newProfile = [windowController profile]->GetOriginalProfile(); | |
588 [self windowChangedToProfile:newProfile]; | |
589 } | 608 } |
590 | 609 |
591 - (void)windowDidResignMain:(NSNotification*)notify { | 610 - (void)windowDidResignMain:(NSNotification*)notify { |
592 if (chrome::GetTotalBrowserCount() == 0) { | 611 if (chrome::GetTotalBrowserCount() == 0) { |
593 [self windowChangedToProfile: | 612 [self windowChangedToProfile: |
594 g_browser_process->profile_manager()->GetLastUsedProfile()]; | 613 g_browser_process->profile_manager()->GetLastUsedProfile()]; |
595 } | 614 } |
596 } | 615 } |
597 | 616 |
598 - (void)activeSpaceDidChange:(NSNotification*)notify { | 617 - (void)activeSpaceDidChange:(NSNotification*)notify { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 // TODO(akalin,viettrungluu): Figure out whether this method | 962 // TODO(akalin,viettrungluu): Figure out whether this method |
944 // can be prevented from being called if lastProfile is | 963 // can be prevented from being called if lastProfile is |
945 // NULL. | 964 // NULL. |
946 if (!lastProfile) { | 965 if (!lastProfile) { |
947 LOG(WARNING) | 966 LOG(WARNING) |
948 << "NULL lastProfile detected -- not doing anything"; | 967 << "NULL lastProfile detected -- not doing anything"; |
949 break; | 968 break; |
950 } | 969 } |
951 SigninManager* signin = SigninManagerFactory::GetForProfile( | 970 SigninManager* signin = SigninManagerFactory::GetForProfile( |
952 lastProfile->GetOriginalProfile()); | 971 lastProfile->GetOriginalProfile()); |
953 enable = signin->IsSigninAllowed() && | 972 enable = signin->IsSigninAllowed() && ![self keyWindowIsModal]; |
954 ![self keyWindowIsModal]; | 973 [AppController updateSigninItem:item |
955 [BrowserWindowController updateSigninItem:item | 974 shouldShow:enable |
956 shouldShow:enable | 975 currentProfile:lastProfile]; |
957 currentProfile:lastProfile]; | |
958 break; | 976 break; |
959 } | 977 } |
960 #if defined(GOOGLE_CHROME_BUILD) | 978 #if defined(GOOGLE_CHROME_BUILD) |
961 case IDC_FEEDBACK: | 979 case IDC_FEEDBACK: |
962 enable = NO; | 980 enable = NO; |
963 break; | 981 break; |
964 #endif | 982 #endif |
965 default: | 983 default: |
966 enable = menuState_->IsCommandEnabled(tag) ? | 984 enable = menuState_->IsCommandEnabled(tag) ? |
967 ![self keyWindowIsModal] : NO; | 985 ![self keyWindowIsModal] : NO; |
(...skipping 26 matching lines...) Expand all Loading... | |
994 // check, otherwise it should have been disabled in the UI in | 1012 // check, otherwise it should have been disabled in the UI in |
995 // |-validateUserInterfaceItem:|. | 1013 // |-validateUserInterfaceItem:|. |
996 - (void)commandDispatch:(id)sender { | 1014 - (void)commandDispatch:(id)sender { |
997 Profile* lastProfile = [self safeLastProfileForNewWindows]; | 1015 Profile* lastProfile = [self safeLastProfileForNewWindows]; |
998 | 1016 |
999 // Handle the case where we're dispatching a command from a sender that's in a | 1017 // Handle the case where we're dispatching a command from a sender that's in a |
1000 // browser window. This means that the command came from a background window | 1018 // browser window. This means that the command came from a background window |
1001 // and is getting here because the foreground window is not a browser window. | 1019 // and is getting here because the foreground window is not a browser window. |
1002 if ([sender respondsToSelector:@selector(window)]) { | 1020 if ([sender respondsToSelector:@selector(window)]) { |
1003 id delegate = [[sender window] windowController]; | 1021 id delegate = [[sender window] windowController]; |
1004 if ([delegate isKindOfClass:[BrowserWindowController class]]) { | 1022 if ([delegate respondsToSelector:@selector(commandDispatch:)]) { |
1005 [delegate commandDispatch:sender]; | 1023 [delegate commandDispatch:sender]; |
1006 return; | 1024 return; |
1007 } | 1025 } |
1008 } | 1026 } |
1009 | 1027 |
1010 // Ignore commands during session restore's browser creation. It uses a | 1028 // Ignore commands during session restore's browser creation. It uses a |
1011 // nested message loop and commands dispatched during this operation cause | 1029 // nested message loop and commands dispatched during this operation cause |
1012 // havoc. | 1030 // havoc. |
1013 if (SessionRestore::IsRestoring(lastProfile) && | 1031 if (SessionRestore::IsRestoring(lastProfile) && |
1014 base::MessageLoop::current()->IsNested()) | 1032 base::MessageLoop::current()->IsNested()) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 | 1156 |
1139 // Same as |-commandDispatch:|, but executes commands using a disposition | 1157 // Same as |-commandDispatch:|, but executes commands using a disposition |
1140 // determined by the key flags. This will get called in the case where the | 1158 // determined by the key flags. This will get called in the case where the |
1141 // frontmost window is not a browser window, and the user has command-clicked | 1159 // frontmost window is not a browser window, and the user has command-clicked |
1142 // a button in a background browser window whose action is | 1160 // a button in a background browser window whose action is |
1143 // |-commandDispatchUsingKeyModifiers:| | 1161 // |-commandDispatchUsingKeyModifiers:| |
1144 - (void)commandDispatchUsingKeyModifiers:(id)sender { | 1162 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
1145 DCHECK(sender); | 1163 DCHECK(sender); |
1146 if ([sender respondsToSelector:@selector(window)]) { | 1164 if ([sender respondsToSelector:@selector(window)]) { |
1147 id delegate = [[sender window] windowController]; | 1165 id delegate = [[sender window] windowController]; |
1148 if ([delegate isKindOfClass:[BrowserWindowController class]]) { | 1166 if ([delegate respondsToSelector: |
1167 @selector(commandDispatchUsingKeyModifiers:)]) { | |
1149 [delegate commandDispatchUsingKeyModifiers:sender]; | 1168 [delegate commandDispatchUsingKeyModifiers:sender]; |
1150 } | 1169 } |
1151 } | 1170 } |
1152 } | 1171 } |
1153 | 1172 |
1154 // NSApplication delegate method called when someone clicks on the dock icon. | 1173 // NSApplication delegate method called when someone clicks on the dock icon. |
1155 // To match standard mac behavior, we should open a new window if there are no | 1174 // To match standard mac behavior, we should open a new window if there are no |
1156 // browser windows. | 1175 // browser windows. |
1157 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication | 1176 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication |
1158 hasVisibleWindows:(BOOL)hasVisibleWindows { | 1177 hasVisibleWindows:(BOOL)hasVisibleWindows { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1311 } | 1330 } |
1312 | 1331 |
1313 - (void)registerServicesMenuTypesTo:(NSApplication*)app { | 1332 - (void)registerServicesMenuTypesTo:(NSApplication*)app { |
1314 // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which | 1333 // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which |
1315 // handles requests from services. | 1334 // handles requests from services. |
1316 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; | 1335 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; |
1317 [app registerServicesMenuSendTypes:types returnTypes:types]; | 1336 [app registerServicesMenuSendTypes:types returnTypes:types]; |
1318 } | 1337 } |
1319 | 1338 |
1320 - (Profile*)lastProfile { | 1339 - (Profile*)lastProfile { |
1321 // Return the profile of the last-used BrowserWindowController, if available. | 1340 // Return the profile of the last-used Browser, if available. |
1322 if (lastProfile_) | 1341 if (lastProfile_) |
1323 return lastProfile_; | 1342 return lastProfile_; |
1324 | 1343 |
1325 // On first launch, use the logic that ChromeBrowserMain uses to determine | 1344 // On first launch, use the logic that ChromeBrowserMain uses to determine |
1326 // the initial profile. | 1345 // the initial profile. |
1327 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1346 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1328 if (!profile_manager) | 1347 if (!profile_manager) |
1329 return NULL; | 1348 return NULL; |
1330 | 1349 |
1331 return profile_manager->GetProfile( | 1350 return profile_manager->GetProfile( |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1684 | 1703 |
1685 //--------------------------------------------------------------------------- | 1704 //--------------------------------------------------------------------------- |
1686 | 1705 |
1687 namespace app_controller_mac { | 1706 namespace app_controller_mac { |
1688 | 1707 |
1689 bool IsOpeningNewWindow() { | 1708 bool IsOpeningNewWindow() { |
1690 return g_is_opening_new_window; | 1709 return g_is_opening_new_window; |
1691 } | 1710 } |
1692 | 1711 |
1693 } // namespace app_controller_mac | 1712 } // namespace app_controller_mac |
OLD | NEW |