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 "apps/app_shim/app_shim_mac.h" | 7 #include "apps/app_shim/app_shim_mac.h" |
8 #include "apps/app_shim/extension_app_shim_handler_mac.h" | 8 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
9 #include "apps/shell_window_registry.h" | 9 #include "apps/shell_window_registry.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "chrome/browser/sessions/tab_restore_service.h" | 42 #include "chrome/browser/sessions/tab_restore_service.h" |
43 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 43 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
44 #include "chrome/browser/signin/signin_manager.h" | 44 #include "chrome/browser/signin/signin_manager.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/sync/profile_sync_service.h" | 47 #include "chrome/browser/sync/profile_sync_service.h" |
48 #include "chrome/browser/sync/sync_ui_util.h" | 48 #include "chrome/browser/sync/sync_ui_util.h" |
49 #include "chrome/browser/ui/browser.h" | 49 #include "chrome/browser/ui/browser.h" |
50 #include "chrome/browser/ui/browser_command_controller.h" | 50 #include "chrome/browser/ui/browser_command_controller.h" |
51 #include "chrome/browser/ui/browser_commands.h" | 51 #include "chrome/browser/ui/browser_commands.h" |
| 52 #include "chrome/browser/ui/browser_dialogs.h" |
52 #include "chrome/browser/ui/browser_finder.h" | 53 #include "chrome/browser/ui/browser_finder.h" |
53 #include "chrome/browser/ui/browser_iterator.h" | 54 #include "chrome/browser/ui/browser_iterator.h" |
54 #include "chrome/browser/ui/browser_mac.h" | 55 #include "chrome/browser/ui/browser_mac.h" |
55 #include "chrome/browser/ui/browser_window.h" | 56 #include "chrome/browser/ui/browser_window.h" |
56 #include "chrome/browser/ui/chrome_pages.h" | 57 #include "chrome/browser/ui/chrome_pages.h" |
57 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" | 58 #import "chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac.h" |
58 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 59 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
59 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 60 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
60 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 61 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
61 #import "chrome/browser/ui/cocoa/confirm_quit.h" | 62 #import "chrome/browser/ui/cocoa/confirm_quit.h" |
62 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" | 63 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
63 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" | 64 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
64 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" | 65 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" |
65 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | 66 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
66 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" | 67 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" |
67 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 68 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
68 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 69 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
69 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 70 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
70 #include "chrome/browser/ui/extensions/application_launch.h" | 71 #include "chrome/browser/ui/extensions/application_launch.h" |
71 #include "chrome/browser/ui/host_desktop.h" | 72 #include "chrome/browser/ui/host_desktop.h" |
72 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 73 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
73 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 74 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
74 #include "chrome/common/chrome_paths_internal.h" | 75 #include "chrome/common/chrome_paths_internal.h" |
75 #include "chrome/common/chrome_switches.h" | 76 #include "chrome/common/chrome_switches.h" |
76 #include "chrome/common/cloud_print/cloud_print_class_mac.h" | 77 #include "chrome/common/cloud_print/cloud_print_class_mac.h" |
77 #include "chrome/common/extensions/extension_constants.h" | 78 #include "chrome/common/extensions/extension_constants.h" |
78 #include "chrome/common/mac/app_mode_common.h" | 79 #include "chrome/common/mac/app_mode_common.h" |
79 #include "chrome/common/pref_names.h" | 80 #include "chrome/common/pref_names.h" |
| 81 #include "chrome/common/profile_management_switches.h" |
80 #include "chrome/common/service_messages.h" | 82 #include "chrome/common/service_messages.h" |
81 #include "chrome/common/url_constants.h" | 83 #include "chrome/common/url_constants.h" |
82 #include "content/public/browser/browser_thread.h" | 84 #include "content/public/browser/browser_thread.h" |
83 #include "content/public/browser/download_manager.h" | 85 #include "content/public/browser/download_manager.h" |
84 #include "content/public/browser/notification_service.h" | 86 #include "content/public/browser/notification_service.h" |
85 #include "content/public/browser/notification_types.h" | 87 #include "content/public/browser/notification_types.h" |
86 #include "content/public/browser/plugin_service.h" | 88 #include "content/public/browser/plugin_service.h" |
87 #include "content/public/browser/user_metrics.h" | 89 #include "content/public/browser/user_metrics.h" |
88 #include "grit/chromium_strings.h" | 90 #include "grit/chromium_strings.h" |
89 #include "grit/generated_resources.h" | 91 #include "grit/generated_resources.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 base::mac::NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), | 184 base::mac::NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), |
183 app_bundle_path_cfstring, BaseBundleID_CFString()); | 185 app_bundle_path_cfstring, BaseBundleID_CFString()); |
184 | 186 |
185 // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty. | 187 // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty. |
186 BrowserThread::PostDelayedTask( | 188 BrowserThread::PostDelayedTask( |
187 BrowserThread::FILE, FROM_HERE, | 189 BrowserThread::FILE, FROM_HERE, |
188 base::Bind(&PrefsSyncCallback), | 190 base::Bind(&PrefsSyncCallback), |
189 base::TimeDelta::FromMilliseconds(1500)); | 191 base::TimeDelta::FromMilliseconds(1500)); |
190 } | 192 } |
191 | 193 |
| 194 bool IsProfileSignedOut(Profile* profile) { |
| 195 // The signed out status only makes sense at the moment in the context of the |
| 196 // --new-profile-management flag. |
| 197 if (!switches::IsNewProfileManagement()) |
| 198 return false; |
| 199 ProfileInfoCache& cache = |
| 200 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 201 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 202 if (profile_index == std::string::npos) |
| 203 return false; |
| 204 return cache.ProfileIsSigninRequiredAtIndex(profile_index); |
| 205 } |
| 206 |
192 } // anonymous namespace | 207 } // anonymous namespace |
193 | 208 |
194 @interface AppController (Private) | 209 @interface AppController (Private) |
195 - (void)initMenuState; | 210 - (void)initMenuState; |
196 - (void)initProfileMenu; | 211 - (void)initProfileMenu; |
197 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; | 212 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
198 - (void)registerServicesMenuTypesTo:(NSApplication*)app; | 213 - (void)registerServicesMenuTypesTo:(NSApplication*)app; |
199 - (void)openUrls:(const std::vector<GURL>&)urls; | 214 - (void)openUrls:(const std::vector<GURL>&)urls; |
200 - (void)getUrl:(NSAppleEventDescriptor*)event | 215 - (void)getUrl:(NSAppleEventDescriptor*)event |
201 withReply:(NSAppleEventDescriptor*)reply; | 216 withReply:(NSAppleEventDescriptor*)reply; |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 } | 980 } |
966 | 981 |
967 // Ignore commands during session restore's browser creation. It uses a | 982 // Ignore commands during session restore's browser creation. It uses a |
968 // nested message loop and commands dispatched during this operation cause | 983 // nested message loop and commands dispatched during this operation cause |
969 // havoc. | 984 // havoc. |
970 if (SessionRestore::IsRestoring(lastProfile) && | 985 if (SessionRestore::IsRestoring(lastProfile) && |
971 base::MessageLoop::current()->IsNested()) | 986 base::MessageLoop::current()->IsNested()) |
972 return; | 987 return; |
973 | 988 |
974 NSInteger tag = [sender tag]; | 989 NSInteger tag = [sender tag]; |
| 990 |
| 991 // If there are no browser windows, and we are trying to open a browser |
| 992 // for a locked profile, we have to show the User Manager instead as the |
| 993 // locked profile needs authentication. |
| 994 if (IsProfileSignedOut(lastProfile)) { |
| 995 chrome::ShowUserManager(lastProfile->GetPath()); |
| 996 return; |
| 997 } |
| 998 |
975 switch (tag) { | 999 switch (tag) { |
976 case IDC_NEW_TAB: | 1000 case IDC_NEW_TAB: |
977 // Create a new tab in an existing browser window (which we activate) if | 1001 // Create a new tab in an existing browser window (which we activate) if |
978 // possible. | 1002 // possible. |
979 if (Browser* browser = ActivateBrowser(lastProfile)) { | 1003 if (Browser* browser = ActivateBrowser(lastProfile)) { |
980 chrome::ExecuteCommand(browser, IDC_NEW_TAB); | 1004 chrome::ExecuteCommand(browser, IDC_NEW_TAB); |
981 break; | 1005 break; |
982 } | 1006 } |
983 // Else fall through to create new window. | 1007 // Else fall through to create new window. |
984 case IDC_NEW_WINDOW: | 1008 case IDC_NEW_WINDOW: |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 StartupBrowserCreator browser_creator; | 1201 StartupBrowserCreator browser_creator; |
1178 browser_creator.LaunchBrowser( | 1202 browser_creator.LaunchBrowser( |
1179 command_line, [self lastProfile], base::FilePath(), | 1203 command_line, [self lastProfile], base::FilePath(), |
1180 chrome::startup::IS_NOT_PROCESS_STARTUP, | 1204 chrome::startup::IS_NOT_PROCESS_STARTUP, |
1181 chrome::startup::IS_NOT_FIRST_RUN, &return_code); | 1205 chrome::startup::IS_NOT_FIRST_RUN, &return_code); |
1182 } | 1206 } |
1183 return NO; | 1207 return NO; |
1184 } | 1208 } |
1185 | 1209 |
1186 // Otherwise open a new window. | 1210 // Otherwise open a new window. |
1187 CreateBrowser([self lastProfile]); | 1211 // If the last profile was locked, we have to open the User Manager, as the |
| 1212 // profile requires authentication. Similarly, because guest mode is |
| 1213 // implemented as forced incognito, we can't open a new guest browser either, |
| 1214 // so we have to show the User Manager as well. |
| 1215 Profile* lastProfile = [self lastProfile]; |
| 1216 if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile)) |
| 1217 chrome::ShowUserManager(lastProfile->GetPath()); |
| 1218 else |
| 1219 CreateBrowser(lastProfile); |
1188 | 1220 |
1189 // We've handled the reopen event, so return NO to tell AppKit not | 1221 // We've handled the reopen event, so return NO to tell AppKit not |
1190 // to do anything. | 1222 // to do anything. |
1191 return NO; | 1223 return NO; |
1192 } | 1224 } |
1193 | 1225 |
1194 - (void)initMenuState { | 1226 - (void)initMenuState { |
1195 menuState_.reset(new CommandUpdater(NULL)); | 1227 menuState_.reset(new CommandUpdater(NULL)); |
1196 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true); | 1228 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true); |
1197 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); | 1229 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 | 1515 |
1484 //--------------------------------------------------------------------------- | 1516 //--------------------------------------------------------------------------- |
1485 | 1517 |
1486 namespace app_controller_mac { | 1518 namespace app_controller_mac { |
1487 | 1519 |
1488 bool IsOpeningNewWindow() { | 1520 bool IsOpeningNewWindow() { |
1489 return g_is_opening_new_window; | 1521 return g_is_opening_new_window; |
1490 } | 1522 } |
1491 | 1523 |
1492 } // namespace app_controller_mac | 1524 } // namespace app_controller_mac |
OLD | NEW |