Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 129333002: [Mac] Check if a profile is locked before allowing a new window to be opened. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed test! ^___^ Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 } 982 }
968 983
969 // Ignore commands during session restore's browser creation. It uses a 984 // Ignore commands during session restore's browser creation. It uses a
970 // nested message loop and commands dispatched during this operation cause 985 // nested message loop and commands dispatched during this operation cause
971 // havoc. 986 // havoc.
972 if (SessionRestore::IsRestoring(lastProfile) && 987 if (SessionRestore::IsRestoring(lastProfile) &&
973 base::MessageLoop::current()->IsNested()) 988 base::MessageLoop::current()->IsNested())
974 return; 989 return;
975 990
976 NSInteger tag = [sender tag]; 991 NSInteger tag = [sender tag];
992
993 // If there are no browser windows, and we are trying to open a browser
994 // for a locked profile, we have to show the User Manager instead as the
995 // locked profile needs authentication.
996 if (IsProfileSignedOut(lastProfile)) {
997 chrome::ShowUserManager(lastProfile->GetPath());
998 return;
999 }
1000
977 switch (tag) { 1001 switch (tag) {
978 case IDC_NEW_TAB: 1002 case IDC_NEW_TAB:
979 // Create a new tab in an existing browser window (which we activate) if 1003 // Create a new tab in an existing browser window (which we activate) if
980 // possible. 1004 // possible.
981 if (Browser* browser = ActivateBrowser(lastProfile)) { 1005 if (Browser* browser = ActivateBrowser(lastProfile)) {
982 chrome::ExecuteCommand(browser, IDC_NEW_TAB); 1006 chrome::ExecuteCommand(browser, IDC_NEW_TAB);
983 break; 1007 break;
984 } 1008 }
985 // Else fall through to create new window. 1009 // Else fall through to create new window.
986 case IDC_NEW_WINDOW: 1010 case IDC_NEW_WINDOW:
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 StartupBrowserCreator browser_creator; 1203 StartupBrowserCreator browser_creator;
1180 browser_creator.LaunchBrowser( 1204 browser_creator.LaunchBrowser(
1181 command_line, [self lastProfile], base::FilePath(), 1205 command_line, [self lastProfile], base::FilePath(),
1182 chrome::startup::IS_NOT_PROCESS_STARTUP, 1206 chrome::startup::IS_NOT_PROCESS_STARTUP,
1183 chrome::startup::IS_NOT_FIRST_RUN, &return_code); 1207 chrome::startup::IS_NOT_FIRST_RUN, &return_code);
1184 } 1208 }
1185 return NO; 1209 return NO;
1186 } 1210 }
1187 1211
1188 // Otherwise open a new window. 1212 // Otherwise open a new window.
1189 CreateBrowser([self lastProfile]); 1213 // If the last profile was locked, we have to open the User Manager, as the
1214 // profile requires authentication. Similarly, because guest mode is
1215 // implemented as forced incognito, we can't open a new guest browser either,
1216 // so we have to show the User Manager as well.
1217 Profile* lastProfile = [self lastProfile];
1218 if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile))
1219 chrome::ShowUserManager(lastProfile->GetPath());
1220 else
1221 CreateBrowser(lastProfile);
1190 1222
1191 // We've handled the reopen event, so return NO to tell AppKit not 1223 // We've handled the reopen event, so return NO to tell AppKit not
1192 // to do anything. 1224 // to do anything.
1193 return NO; 1225 return NO;
1194 } 1226 }
1195 1227
1196 - (void)initMenuState { 1228 - (void)initMenuState {
1197 menuState_.reset(new CommandUpdater(NULL)); 1229 menuState_.reset(new CommandUpdater(NULL));
1198 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true); 1230 menuState_->UpdateCommandEnabled(IDC_NEW_TAB, true);
1199 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true); 1231 menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 1521
1490 //--------------------------------------------------------------------------- 1522 //---------------------------------------------------------------------------
1491 1523
1492 namespace app_controller_mac { 1524 namespace app_controller_mac {
1493 1525
1494 bool IsOpeningNewWindow() { 1526 bool IsOpeningNewWindow() {
1495 return g_is_opening_new_window; 1527 return g_is_opening_new_window;
1496 } 1528 }
1497 1529
1498 } // namespace app_controller_mac 1530 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/app_controller_mac_browsertest.mm » ('j') | chrome/browser/app_controller_mac_browsertest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698