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 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 if (SessionRestore::IsRestoring(lastProfile) && | 1000 if (SessionRestore::IsRestoring(lastProfile) && |
1001 base::MessageLoop::current()->IsNested()) | 1001 base::MessageLoop::current()->IsNested()) |
1002 return; | 1002 return; |
1003 | 1003 |
1004 NSInteger tag = [sender tag]; | 1004 NSInteger tag = [sender tag]; |
1005 | 1005 |
1006 // If there are no browser windows, and we are trying to open a browser | 1006 // If there are no browser windows, and we are trying to open a browser |
1007 // for a locked profile, we have to show the User Manager instead as the | 1007 // for a locked profile, we have to show the User Manager instead as the |
1008 // locked profile needs authentication. | 1008 // locked profile needs authentication. |
1009 if (IsProfileSignedOut(lastProfile)) { | 1009 if (IsProfileSignedOut(lastProfile)) { |
1010 UserManager::Show(lastProfile->GetPath(), | 1010 UserManager::Show(base::FilePath(), |
1011 profiles::USER_MANAGER_NO_TUTORIAL, | 1011 profiles::USER_MANAGER_NO_TUTORIAL, |
1012 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1012 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
1013 return; | 1013 return; |
1014 } | 1014 } |
1015 | 1015 |
1016 switch (tag) { | 1016 switch (tag) { |
1017 case IDC_NEW_TAB: | 1017 case IDC_NEW_TAB: |
1018 // Create a new tab in an existing browser window (which we activate) if | 1018 // Create a new tab in an existing browser window (which we activate) if |
1019 // possible. | 1019 // possible. |
1020 if (Browser* browser = ActivateBrowser(lastProfile)) { | 1020 if (Browser* browser = ActivateBrowser(lastProfile)) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 chrome::OpenHelpWindow(lastProfile, chrome::HELP_SOURCE_MENU); | 1095 chrome::OpenHelpWindow(lastProfile, chrome::HELP_SOURCE_MENU); |
1096 break; | 1096 break; |
1097 case IDC_SHOW_SYNC_SETUP: | 1097 case IDC_SHOW_SYNC_SETUP: |
1098 if (Browser* browser = ActivateBrowser(lastProfile)) { | 1098 if (Browser* browser = ActivateBrowser(lastProfile)) { |
1099 chrome::ShowBrowserSignin(browser, signin::SOURCE_MENU); | 1099 chrome::ShowBrowserSignin(browser, signin::SOURCE_MENU); |
1100 } else { | 1100 } else { |
1101 chrome::OpenSyncSetupWindow(lastProfile, signin::SOURCE_MENU); | 1101 chrome::OpenSyncSetupWindow(lastProfile, signin::SOURCE_MENU); |
1102 } | 1102 } |
1103 break; | 1103 break; |
1104 case IDC_TASK_MANAGER: | 1104 case IDC_TASK_MANAGER: |
1105 content::RecordAction(UserMetricsAction("TaskManager")); | 1105 chrome::OpenTaskManager(NULL); |
1106 TaskManagerMac::Show(); | |
1107 break; | 1106 break; |
1108 case IDC_OPTIONS: | 1107 case IDC_OPTIONS: |
1109 [self showPreferences:sender]; | 1108 [self showPreferences:sender]; |
1110 break; | 1109 break; |
1111 } | 1110 } |
1112 } | 1111 } |
1113 | 1112 |
1114 // Run a (background) application in a new tab. | 1113 // Run a (background) application in a new tab. |
1115 - (void)executeApplication:(id)sender { | 1114 - (void)executeApplication:(id)sender { |
1116 NSInteger tag = [sender tag]; | 1115 NSInteger tag = [sender tag]; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 } | 1203 } |
1205 } | 1204 } |
1206 | 1205 |
1207 // Otherwise open a new window. | 1206 // Otherwise open a new window. |
1208 // If the last profile was locked, we have to open the User Manager, as the | 1207 // If the last profile was locked, we have to open the User Manager, as the |
1209 // profile requires authentication. Similarly, because guest mode is | 1208 // profile requires authentication. Similarly, because guest mode is |
1210 // implemented as forced incognito, we can't open a new guest browser either, | 1209 // implemented as forced incognito, we can't open a new guest browser either, |
1211 // so we have to show the User Manager as well. | 1210 // so we have to show the User Manager as well. |
1212 Profile* lastProfile = [self lastProfile]; | 1211 Profile* lastProfile = [self lastProfile]; |
1213 if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile)) { | 1212 if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile)) { |
1214 UserManager::Show(lastProfile->GetPath(), | 1213 UserManager::Show(base::FilePath(), |
1215 profiles::USER_MANAGER_NO_TUTORIAL, | 1214 profiles::USER_MANAGER_NO_TUTORIAL, |
1216 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1215 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
1217 } else { | 1216 } else { |
1218 CreateBrowser(lastProfile); | 1217 CreateBrowser(lastProfile); |
1219 } | 1218 } |
1220 | 1219 |
1221 // We've handled the reopen event, so return NO to tell AppKit not | 1220 // We've handled the reopen event, so return NO to tell AppKit not |
1222 // to do anything. | 1221 // to do anything. |
1223 return NO; | 1222 return NO; |
1224 } | 1223 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 - (Profile*)safeLastProfileForNewWindows { | 1311 - (Profile*)safeLastProfileForNewWindows { |
1313 Profile* profile = [self lastProfile]; | 1312 Profile* profile = [self lastProfile]; |
1314 | 1313 |
1315 // Guest sessions must always be OffTheRecord. Use that when opening windows. | 1314 // Guest sessions must always be OffTheRecord. Use that when opening windows. |
1316 if (profile->IsGuestSession()) | 1315 if (profile->IsGuestSession()) |
1317 return profile->GetOffTheRecordProfile(); | 1316 return profile->GetOffTheRecordProfile(); |
1318 | 1317 |
1319 return profile; | 1318 return profile; |
1320 } | 1319 } |
1321 | 1320 |
| 1321 // Returns true if a browser window may be opened for the last active profile. |
| 1322 - (bool)canOpenNewBrowser { |
| 1323 Profile* profile = [self safeLastProfileForNewWindows]; |
| 1324 |
| 1325 const PrefService* prefs = g_browser_process->local_state(); |
| 1326 return !profile->IsGuestSession() || |
| 1327 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); |
| 1328 } |
| 1329 |
1322 // Various methods to open URLs that we get in a native fashion. We use | 1330 // Various methods to open URLs that we get in a native fashion. We use |
1323 // StartupBrowserCreator here because on the other platforms, URLs to open come | 1331 // StartupBrowserCreator here because on the other platforms, URLs to open come |
1324 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best | 1332 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best |
1325 // to bottleneck the openings through that for uniform handling. | 1333 // to bottleneck the openings through that for uniform handling. |
1326 | 1334 |
1327 - (void)openUrls:(const std::vector<GURL>&)urls { | 1335 - (void)openUrls:(const std::vector<GURL>&)urls { |
1328 // If the browser hasn't started yet, just queue up the URLs. | 1336 // If the browser hasn't started yet, just queue up the URLs. |
1329 if (!startupComplete_) { | 1337 if (!startupComplete_) { |
1330 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); | 1338 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
1331 return; | 1339 return; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 | 1381 |
1374 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; | 1382 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; |
1375 } | 1383 } |
1376 | 1384 |
1377 // Show the preferences window, or bring it to the front if it's already | 1385 // Show the preferences window, or bring it to the front if it's already |
1378 // visible. | 1386 // visible. |
1379 - (IBAction)showPreferences:(id)sender { | 1387 - (IBAction)showPreferences:(id)sender { |
1380 if (Browser* browser = ActivateBrowser([self lastProfile])) { | 1388 if (Browser* browser = ActivateBrowser([self lastProfile])) { |
1381 // Show options tab in the active browser window. | 1389 // Show options tab in the active browser window. |
1382 chrome::ShowSettings(browser); | 1390 chrome::ShowSettings(browser); |
1383 } else { | 1391 } else if ([self canOpenNewBrowser]) { |
1384 // No browser window, so create one for the options tab. | 1392 // No browser window, so create one for the options tab. |
1385 chrome::OpenOptionsWindow([self safeLastProfileForNewWindows]); | 1393 chrome::OpenOptionsWindow([self safeLastProfileForNewWindows]); |
| 1394 } else { |
| 1395 // No way to create a browser, default to the User Manager. |
| 1396 UserManager::Show(base::FilePath(), |
| 1397 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1398 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS); |
1386 } | 1399 } |
1387 } | 1400 } |
1388 | 1401 |
1389 - (IBAction)orderFrontStandardAboutPanel:(id)sender { | 1402 - (IBAction)orderFrontStandardAboutPanel:(id)sender { |
1390 if (Browser* browser = ActivateBrowser([self lastProfile])) { | 1403 if (Browser* browser = ActivateBrowser([self lastProfile])) { |
1391 chrome::ShowAboutChrome(browser); | 1404 chrome::ShowAboutChrome(browser); |
| 1405 } else if ([self canOpenNewBrowser]) { |
| 1406 // No browser window, so create one for the options tab. |
| 1407 chrome::OpenAboutWindow([self safeLastProfileForNewWindows]); |
1392 } else { | 1408 } else { |
1393 // No browser window, so create one for the about tab. | 1409 // No way to create a browser, default to the User Manager. |
1394 chrome::OpenAboutWindow([self safeLastProfileForNewWindows]); | 1410 UserManager::Show(base::FilePath(), |
| 1411 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1412 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME); |
1395 } | 1413 } |
1396 } | 1414 } |
1397 | 1415 |
1398 - (IBAction)toggleConfirmToQuit:(id)sender { | 1416 - (IBAction)toggleConfirmToQuit:(id)sender { |
1399 PrefService* prefService = g_browser_process->local_state(); | 1417 PrefService* prefService = g_browser_process->local_state(); |
1400 bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); | 1418 bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); |
1401 prefService->SetBoolean(prefs::kConfirmToQuitEnabled, !enabled); | 1419 prefService->SetBoolean(prefs::kConfirmToQuitEnabled, !enabled); |
1402 } | 1420 } |
1403 | 1421 |
1404 - (IBAction)toggleDisplayMessageCenter:(id)sender { | 1422 - (IBAction)toggleDisplayMessageCenter:(id)sender { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 | 1598 |
1581 //--------------------------------------------------------------------------- | 1599 //--------------------------------------------------------------------------- |
1582 | 1600 |
1583 namespace app_controller_mac { | 1601 namespace app_controller_mac { |
1584 | 1602 |
1585 bool IsOpeningNewWindow() { | 1603 bool IsOpeningNewWindow() { |
1586 return g_is_opening_new_window; | 1604 return g_is_opening_new_window; |
1587 } | 1605 } |
1588 | 1606 |
1589 } // namespace app_controller_mac | 1607 } // namespace app_controller_mac |
OLD | NEW |