Chromium Code Reviews| 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 // close the popover so map it to "Close Window". | 548 // close the popover so map it to "Close Window". |
| 552 // Otherwise, map Cmd-W to "Close Tab" if it's a browser window. | 549 // Otherwise, map Cmd-W to "Close Tab" if it's a browser window. |
| 553 if ([target isKindOfClass:[NSWindow class]]) { | 550 if ([target isKindOfClass:[NSWindow class]]) { |
| 554 NSWindow* window = target; | 551 NSWindow* window = target; |
| 555 NSWindow* mainWindow = [NSApp mainWindow]; | 552 NSWindow* mainWindow = [NSApp mainWindow]; |
| 556 if (!window || ([window parentWindow] == mainWindow)) { | 553 if (!window || ([window parentWindow] == mainWindow)) { |
| 557 // If the target window is a child of the main window (e.g. a bubble), the | 554 // 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. | 555 // main window should be the one that handles the close menu item action. |
| 559 window = mainWindow; | 556 window = mainWindow; |
| 560 } | 557 } |
| 561 enableCloseTabShortcut = | 558 Browser* browser = chrome::FindBrowserWithWindow(window); |
| 562 [[window windowController] isKindOfClass:[TabWindowController class]]; | 559 enableCloseTabShortcut = browser && browser->is_type_tabbed(); |
| 563 } | 560 } |
| 564 | 561 |
| 565 [self adjustCloseWindowMenuItemKeyEquivalent:enableCloseTabShortcut]; | 562 [self adjustCloseWindowMenuItemKeyEquivalent:enableCloseTabShortcut]; |
| 566 [self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut]; | 563 [self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut]; |
| 567 } | 564 } |
| 568 | 565 |
| 569 - (void)windowDidResignKey:(NSNotification*)notify { | 566 - (void)windowDidResignKey:(NSNotification*)notify { |
| 570 // If a window is closed, this notification is fired but |[NSApp keyWindow]| | 567 // If a window is closed, this notification is fired but |[NSApp keyWindow]| |
| 571 // returns nil regardless of whether any suitable candidates for the key | 568 // 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 | 569 // 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 | 570 // until after this notification is fired, so a check is performed after the |
| 574 // run loop is allowed to spin. | 571 // run loop is allowed to spin. |
| 575 [self performSelector:@selector(checkForAnyKeyWindows) | 572 [self performSelector:@selector(checkForAnyKeyWindows) |
| 576 withObject:nil | 573 withObject:nil |
| 577 afterDelay:0.0]; | 574 afterDelay:0.0]; |
| 578 } | 575 } |
| 579 | 576 |
| 580 - (void)windowDidBecomeMain:(NSNotification*)notify { | 577 - (void)windowDidBecomeMain:(NSNotification*)notify { |
| 581 // If the window changed to a new BrowserWindowController, update the profile. | 578 Browser* browser = chrome::FindBrowserWithWindow([notify object]); |
| 582 id windowController = [[notify object] windowController]; | 579 if (browser) |
| 583 if (![windowController isKindOfClass:[BrowserWindowController class]]) | 580 [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 } | 581 } |
| 590 | 582 |
| 591 - (void)windowDidResignMain:(NSNotification*)notify { | 583 - (void)windowDidResignMain:(NSNotification*)notify { |
| 592 if (chrome::GetTotalBrowserCount() == 0) { | 584 if (chrome::GetTotalBrowserCount() == 0) { |
| 593 [self windowChangedToProfile: | 585 [self windowChangedToProfile: |
| 594 g_browser_process->profile_manager()->GetLastUsedProfile()]; | 586 g_browser_process->profile_manager()->GetLastUsedProfile()]; |
| 595 } | 587 } |
| 596 } | 588 } |
| 597 | 589 |
| 598 - (void)activeSpaceDidChange:(NSNotification*)notify { | 590 - (void)activeSpaceDidChange:(NSNotification*)notify { |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 // NULL. | 937 // NULL. |
| 946 if (!lastProfile) { | 938 if (!lastProfile) { |
| 947 LOG(WARNING) | 939 LOG(WARNING) |
| 948 << "NULL lastProfile detected -- not doing anything"; | 940 << "NULL lastProfile detected -- not doing anything"; |
| 949 break; | 941 break; |
| 950 } | 942 } |
| 951 SigninManager* signin = SigninManagerFactory::GetForProfile( | 943 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 952 lastProfile->GetOriginalProfile()); | 944 lastProfile->GetOriginalProfile()); |
| 953 enable = signin->IsSigninAllowed() && | 945 enable = signin->IsSigninAllowed() && |
| 954 ![self keyWindowIsModal]; | 946 ![self keyWindowIsModal]; |
| 955 [BrowserWindowController updateSigninItem:item | 947 base::string16 label = |
|
Robert Sesek
2015/03/31 22:46:35
Could you move this method to AppController instea
Andre
2015/03/31 23:09:44
Done.
| |
| 956 shouldShow:enable | 948 signin_ui_util::GetSigninMenuLabel(lastProfile); |
| 957 currentProfile:lastProfile]; | 949 NSMenuItem* menuItem = static_cast<NSMenuItem*>(item); |
| 950 [menuItem setTitle:l10n_util::FixUpWindowsStyleLabel(label)]; | |
| 951 [menuItem setHidden:!enable]; | |
| 958 break; | 952 break; |
| 959 } | 953 } |
| 960 #if defined(GOOGLE_CHROME_BUILD) | 954 #if defined(GOOGLE_CHROME_BUILD) |
| 961 case IDC_FEEDBACK: | 955 case IDC_FEEDBACK: |
| 962 enable = NO; | 956 enable = NO; |
| 963 break; | 957 break; |
| 964 #endif | 958 #endif |
| 965 default: | 959 default: |
| 966 enable = menuState_->IsCommandEnabled(tag) ? | 960 enable = menuState_->IsCommandEnabled(tag) ? |
| 967 ![self keyWindowIsModal] : NO; | 961 ![self keyWindowIsModal] : NO; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 994 // check, otherwise it should have been disabled in the UI in | 988 // check, otherwise it should have been disabled in the UI in |
| 995 // |-validateUserInterfaceItem:|. | 989 // |-validateUserInterfaceItem:|. |
| 996 - (void)commandDispatch:(id)sender { | 990 - (void)commandDispatch:(id)sender { |
| 997 Profile* lastProfile = [self safeLastProfileForNewWindows]; | 991 Profile* lastProfile = [self safeLastProfileForNewWindows]; |
| 998 | 992 |
| 999 // Handle the case where we're dispatching a command from a sender that's in a | 993 // 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 | 994 // 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. | 995 // and is getting here because the foreground window is not a browser window. |
| 1002 if ([sender respondsToSelector:@selector(window)]) { | 996 if ([sender respondsToSelector:@selector(window)]) { |
| 1003 id delegate = [[sender window] windowController]; | 997 id delegate = [[sender window] windowController]; |
| 1004 if ([delegate isKindOfClass:[BrowserWindowController class]]) { | 998 if ([delegate respondsToSelector:@selector(commandDispatch:)]) { |
| 1005 [delegate commandDispatch:sender]; | 999 [delegate commandDispatch:sender]; |
| 1006 return; | 1000 return; |
| 1007 } | 1001 } |
| 1008 } | 1002 } |
| 1009 | 1003 |
| 1010 // Ignore commands during session restore's browser creation. It uses a | 1004 // Ignore commands during session restore's browser creation. It uses a |
| 1011 // nested message loop and commands dispatched during this operation cause | 1005 // nested message loop and commands dispatched during this operation cause |
| 1012 // havoc. | 1006 // havoc. |
| 1013 if (SessionRestore::IsRestoring(lastProfile) && | 1007 if (SessionRestore::IsRestoring(lastProfile) && |
| 1014 base::MessageLoop::current()->IsNested()) | 1008 base::MessageLoop::current()->IsNested()) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 | 1132 |
| 1139 // Same as |-commandDispatch:|, but executes commands using a disposition | 1133 // Same as |-commandDispatch:|, but executes commands using a disposition |
| 1140 // determined by the key flags. This will get called in the case where the | 1134 // 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 | 1135 // frontmost window is not a browser window, and the user has command-clicked |
| 1142 // a button in a background browser window whose action is | 1136 // a button in a background browser window whose action is |
| 1143 // |-commandDispatchUsingKeyModifiers:| | 1137 // |-commandDispatchUsingKeyModifiers:| |
| 1144 - (void)commandDispatchUsingKeyModifiers:(id)sender { | 1138 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
| 1145 DCHECK(sender); | 1139 DCHECK(sender); |
| 1146 if ([sender respondsToSelector:@selector(window)]) { | 1140 if ([sender respondsToSelector:@selector(window)]) { |
| 1147 id delegate = [[sender window] windowController]; | 1141 id delegate = [[sender window] windowController]; |
| 1148 if ([delegate isKindOfClass:[BrowserWindowController class]]) { | 1142 if ([delegate respondsToSelector: |
| 1143 @selector(commandDispatchUsingKeyModifiers:)]) { | |
|
Robert Sesek
2015/03/31 22:46:35
nit: indent +4
Andre
2015/03/31 23:09:44
Done.
| |
| 1149 [delegate commandDispatchUsingKeyModifiers:sender]; | 1144 [delegate commandDispatchUsingKeyModifiers:sender]; |
| 1150 } | 1145 } |
| 1151 } | 1146 } |
| 1152 } | 1147 } |
| 1153 | 1148 |
| 1154 // NSApplication delegate method called when someone clicks on the dock icon. | 1149 // 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 | 1150 // To match standard mac behavior, we should open a new window if there are no |
| 1156 // browser windows. | 1151 // browser windows. |
| 1157 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication | 1152 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication |
| 1158 hasVisibleWindows:(BOOL)hasVisibleWindows { | 1153 hasVisibleWindows:(BOOL)hasVisibleWindows { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1311 } | 1306 } |
| 1312 | 1307 |
| 1313 - (void)registerServicesMenuTypesTo:(NSApplication*)app { | 1308 - (void)registerServicesMenuTypesTo:(NSApplication*)app { |
| 1314 // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which | 1309 // Note that RenderWidgetHostViewCocoa implements NSServicesRequests which |
| 1315 // handles requests from services. | 1310 // handles requests from services. |
| 1316 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; | 1311 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; |
| 1317 [app registerServicesMenuSendTypes:types returnTypes:types]; | 1312 [app registerServicesMenuSendTypes:types returnTypes:types]; |
| 1318 } | 1313 } |
| 1319 | 1314 |
| 1320 - (Profile*)lastProfile { | 1315 - (Profile*)lastProfile { |
| 1321 // Return the profile of the last-used BrowserWindowController, if available. | 1316 // Return the profile of the last-used Browser, if available. |
| 1322 if (lastProfile_) | 1317 if (lastProfile_) |
| 1323 return lastProfile_; | 1318 return lastProfile_; |
| 1324 | 1319 |
| 1325 // On first launch, use the logic that ChromeBrowserMain uses to determine | 1320 // On first launch, use the logic that ChromeBrowserMain uses to determine |
| 1326 // the initial profile. | 1321 // the initial profile. |
| 1327 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1322 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1328 if (!profile_manager) | 1323 if (!profile_manager) |
| 1329 return NULL; | 1324 return NULL; |
| 1330 | 1325 |
| 1331 return profile_manager->GetProfile( | 1326 return profile_manager->GetProfile( |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1684 | 1679 |
| 1685 //--------------------------------------------------------------------------- | 1680 //--------------------------------------------------------------------------- |
| 1686 | 1681 |
| 1687 namespace app_controller_mac { | 1682 namespace app_controller_mac { |
| 1688 | 1683 |
| 1689 bool IsOpeningNewWindow() { | 1684 bool IsOpeningNewWindow() { |
| 1690 return g_is_opening_new_window; | 1685 return g_is_opening_new_window; |
| 1691 } | 1686 } |
| 1692 | 1687 |
| 1693 } // namespace app_controller_mac | 1688 } // namespace app_controller_mac |
| OLD | NEW |