| 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 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 if (SessionRestore::IsRestoring(lastProfile) && | 992 if (SessionRestore::IsRestoring(lastProfile) && |
| 993 base::MessageLoop::current()->IsNested()) | 993 base::MessageLoop::current()->IsNested()) |
| 994 return; | 994 return; |
| 995 | 995 |
| 996 NSInteger tag = [sender tag]; | 996 NSInteger tag = [sender tag]; |
| 997 | 997 |
| 998 // If there are no browser windows, and we are trying to open a browser | 998 // If there are no browser windows, and we are trying to open a browser |
| 999 // for a locked profile, we have to show the User Manager instead as the | 999 // for a locked profile, we have to show the User Manager instead as the |
| 1000 // locked profile needs authentication. | 1000 // locked profile needs authentication. |
| 1001 if (IsProfileSignedOut(lastProfile)) { | 1001 if (IsProfileSignedOut(lastProfile)) { |
| 1002 UserManager::Show(lastProfile->GetPath(), | 1002 UserManager::Show(base::FilePath(), |
| 1003 profiles::USER_MANAGER_NO_TUTORIAL, | 1003 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1004 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1004 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 1005 return; | 1005 return; |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 switch (tag) { | 1008 switch (tag) { |
| 1009 case IDC_NEW_TAB: | 1009 case IDC_NEW_TAB: |
| 1010 // Create a new tab in an existing browser window (which we activate) if | 1010 // Create a new tab in an existing browser window (which we activate) if |
| 1011 // possible. | 1011 // possible. |
| 1012 if (Browser* browser = ActivateBrowser(lastProfile)) { | 1012 if (Browser* browser = ActivateBrowser(lastProfile)) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 chrome::OpenHelpWindow(lastProfile, chrome::HELP_SOURCE_MENU); | 1087 chrome::OpenHelpWindow(lastProfile, chrome::HELP_SOURCE_MENU); |
| 1088 break; | 1088 break; |
| 1089 case IDC_SHOW_SYNC_SETUP: | 1089 case IDC_SHOW_SYNC_SETUP: |
| 1090 if (Browser* browser = ActivateBrowser(lastProfile)) { | 1090 if (Browser* browser = ActivateBrowser(lastProfile)) { |
| 1091 chrome::ShowBrowserSignin(browser, signin::SOURCE_MENU); | 1091 chrome::ShowBrowserSignin(browser, signin::SOURCE_MENU); |
| 1092 } else { | 1092 } else { |
| 1093 chrome::OpenSyncSetupWindow(lastProfile, signin::SOURCE_MENU); | 1093 chrome::OpenSyncSetupWindow(lastProfile, signin::SOURCE_MENU); |
| 1094 } | 1094 } |
| 1095 break; | 1095 break; |
| 1096 case IDC_TASK_MANAGER: | 1096 case IDC_TASK_MANAGER: |
| 1097 content::RecordAction(UserMetricsAction("TaskManager")); | 1097 chrome::OpenTaskManager(NULL); |
| 1098 TaskManagerMac::Show(); | |
| 1099 break; | 1098 break; |
| 1100 case IDC_OPTIONS: | 1099 case IDC_OPTIONS: |
| 1101 [self showPreferences:sender]; | 1100 [self showPreferences:sender]; |
| 1102 break; | 1101 break; |
| 1103 } | 1102 } |
| 1104 } | 1103 } |
| 1105 | 1104 |
| 1106 // Run a (background) application in a new tab. | 1105 // Run a (background) application in a new tab. |
| 1107 - (void)executeApplication:(id)sender { | 1106 - (void)executeApplication:(id)sender { |
| 1108 NSInteger tag = [sender tag]; | 1107 NSInteger tag = [sender tag]; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 } | 1195 } |
| 1197 } | 1196 } |
| 1198 | 1197 |
| 1199 // Otherwise open a new window. | 1198 // Otherwise open a new window. |
| 1200 // If the last profile was locked, we have to open the User Manager, as the | 1199 // If the last profile was locked, we have to open the User Manager, as the |
| 1201 // profile requires authentication. Similarly, because guest mode is | 1200 // profile requires authentication. Similarly, because guest mode is |
| 1202 // implemented as forced incognito, we can't open a new guest browser either, | 1201 // implemented as forced incognito, we can't open a new guest browser either, |
| 1203 // so we have to show the User Manager as well. | 1202 // so we have to show the User Manager as well. |
| 1204 Profile* lastProfile = [self lastProfile]; | 1203 Profile* lastProfile = [self lastProfile]; |
| 1205 if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile)) { | 1204 if (lastProfile->IsGuestSession() || IsProfileSignedOut(lastProfile)) { |
| 1206 UserManager::Show(lastProfile->GetPath(), | 1205 UserManager::Show(base::FilePath(), |
| 1207 profiles::USER_MANAGER_NO_TUTORIAL, | 1206 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1208 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1207 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 1209 } else { | 1208 } else { |
| 1210 CreateBrowser(lastProfile); | 1209 CreateBrowser(lastProfile); |
| 1211 } | 1210 } |
| 1212 | 1211 |
| 1213 // We've handled the reopen event, so return NO to tell AppKit not | 1212 // We've handled the reopen event, so return NO to tell AppKit not |
| 1214 // to do anything. | 1213 // to do anything. |
| 1215 return NO; | 1214 return NO; |
| 1216 } | 1215 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 - (Profile*)safeLastProfileForNewWindows { | 1303 - (Profile*)safeLastProfileForNewWindows { |
| 1305 Profile* profile = [self lastProfile]; | 1304 Profile* profile = [self lastProfile]; |
| 1306 | 1305 |
| 1307 // Guest sessions must always be OffTheRecord. Use that when opening windows. | 1306 // Guest sessions must always be OffTheRecord. Use that when opening windows. |
| 1308 if (profile->IsGuestSession()) | 1307 if (profile->IsGuestSession()) |
| 1309 return profile->GetOffTheRecordProfile(); | 1308 return profile->GetOffTheRecordProfile(); |
| 1310 | 1309 |
| 1311 return profile; | 1310 return profile; |
| 1312 } | 1311 } |
| 1313 | 1312 |
| 1313 // Returns true if a browser window may be opened for the last active profile. |
| 1314 - (bool)canOpenNewBrowser { |
| 1315 Profile* profile = [self safeLastProfileForNewWindows]; |
| 1316 |
| 1317 const PrefService* prefs = g_browser_process->local_state(); |
| 1318 return !profile->IsGuestSession() || |
| 1319 prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); |
| 1320 } |
| 1321 |
| 1314 // Various methods to open URLs that we get in a native fashion. We use | 1322 // Various methods to open URLs that we get in a native fashion. We use |
| 1315 // StartupBrowserCreator here because on the other platforms, URLs to open come | 1323 // StartupBrowserCreator here because on the other platforms, URLs to open come |
| 1316 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best | 1324 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best |
| 1317 // to bottleneck the openings through that for uniform handling. | 1325 // to bottleneck the openings through that for uniform handling. |
| 1318 | 1326 |
| 1319 - (void)openUrls:(const std::vector<GURL>&)urls { | 1327 - (void)openUrls:(const std::vector<GURL>&)urls { |
| 1320 // If the browser hasn't started yet, just queue up the URLs. | 1328 // If the browser hasn't started yet, just queue up the URLs. |
| 1321 if (!startupComplete_) { | 1329 if (!startupComplete_) { |
| 1322 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); | 1330 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
| 1323 return; | 1331 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 | 1373 |
| 1366 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; | 1374 [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; |
| 1367 } | 1375 } |
| 1368 | 1376 |
| 1369 // Show the preferences window, or bring it to the front if it's already | 1377 // Show the preferences window, or bring it to the front if it's already |
| 1370 // visible. | 1378 // visible. |
| 1371 - (IBAction)showPreferences:(id)sender { | 1379 - (IBAction)showPreferences:(id)sender { |
| 1372 if (Browser* browser = ActivateBrowser([self lastProfile])) { | 1380 if (Browser* browser = ActivateBrowser([self lastProfile])) { |
| 1373 // Show options tab in the active browser window. | 1381 // Show options tab in the active browser window. |
| 1374 chrome::ShowSettings(browser); | 1382 chrome::ShowSettings(browser); |
| 1375 } else { | 1383 } else if ([self canOpenNewBrowser]) { |
| 1376 // No browser window, so create one for the options tab. | 1384 // No browser window, so create one for the options tab. |
| 1377 chrome::OpenOptionsWindow([self safeLastProfileForNewWindows]); | 1385 chrome::OpenOptionsWindow([self safeLastProfileForNewWindows]); |
| 1386 } else { |
| 1387 // No way to create a browser, default to the User Manager. |
| 1388 UserManager::Show(base::FilePath(), |
| 1389 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1390 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_SETTINGS); |
| 1378 } | 1391 } |
| 1379 } | 1392 } |
| 1380 | 1393 |
| 1381 - (IBAction)orderFrontStandardAboutPanel:(id)sender { | 1394 - (IBAction)orderFrontStandardAboutPanel:(id)sender { |
| 1382 if (Browser* browser = ActivateBrowser([self lastProfile])) { | 1395 if (Browser* browser = ActivateBrowser([self lastProfile])) { |
| 1383 chrome::ShowAboutChrome(browser); | 1396 chrome::ShowAboutChrome(browser); |
| 1397 } else if ([self canOpenNewBrowser]) { |
| 1398 // No browser window, so create one for the options tab. |
| 1399 chrome::OpenAboutWindow([self safeLastProfileForNewWindows]); |
| 1384 } else { | 1400 } else { |
| 1385 // No browser window, so create one for the about tab. | 1401 // No way to create a browser, default to the User Manager. |
| 1386 chrome::OpenAboutWindow([self safeLastProfileForNewWindows]); | 1402 UserManager::Show(base::FilePath(), |
| 1403 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1404 profiles::USER_MANAGER_SELECT_PROFILE_ABOUT_CHROME); |
| 1387 } | 1405 } |
| 1388 } | 1406 } |
| 1389 | 1407 |
| 1390 - (IBAction)toggleConfirmToQuit:(id)sender { | 1408 - (IBAction)toggleConfirmToQuit:(id)sender { |
| 1391 PrefService* prefService = g_browser_process->local_state(); | 1409 PrefService* prefService = g_browser_process->local_state(); |
| 1392 bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); | 1410 bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); |
| 1393 prefService->SetBoolean(prefs::kConfirmToQuitEnabled, !enabled); | 1411 prefService->SetBoolean(prefs::kConfirmToQuitEnabled, !enabled); |
| 1394 } | 1412 } |
| 1395 | 1413 |
| 1396 - (IBAction)toggleDisplayMessageCenter:(id)sender { | 1414 - (IBAction)toggleDisplayMessageCenter:(id)sender { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 | 1590 |
| 1573 //--------------------------------------------------------------------------- | 1591 //--------------------------------------------------------------------------- |
| 1574 | 1592 |
| 1575 namespace app_controller_mac { | 1593 namespace app_controller_mac { |
| 1576 | 1594 |
| 1577 bool IsOpeningNewWindow() { | 1595 bool IsOpeningNewWindow() { |
| 1578 return g_is_opening_new_window; | 1596 return g_is_opening_new_window; |
| 1579 } | 1597 } |
| 1580 | 1598 |
| 1581 } // namespace app_controller_mac | 1599 } // namespace app_controller_mac |
| OLD | NEW |