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/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 } | 948 } |
949 return enable; | 949 return enable; |
950 } | 950 } |
951 | 951 |
952 // Called when the user picks a menu item when there are no key windows, or when | 952 // Called when the user picks a menu item when there are no key windows, or when |
953 // there is no foreground browser window. Calls through to the browser object to | 953 // there is no foreground browser window. Calls through to the browser object to |
954 // execute the command. This assumes that the command is supported and doesn't | 954 // execute the command. This assumes that the command is supported and doesn't |
955 // check, otherwise it should have been disabled in the UI in | 955 // check, otherwise it should have been disabled in the UI in |
956 // |-validateUserInterfaceItem:|. | 956 // |-validateUserInterfaceItem:|. |
957 - (void)commandDispatch:(id)sender { | 957 - (void)commandDispatch:(id)sender { |
958 Profile* lastProfile = [self lastProfile]; | 958 Profile* lastProfile = [self safeLastProfileForNewWindows]; |
959 | 959 |
960 // Handle the case where we're dispatching a command from a sender that's in a | 960 // Handle the case where we're dispatching a command from a sender that's in a |
961 // browser window. This means that the command came from a background window | 961 // browser window. This means that the command came from a background window |
962 // and is getting here because the foreground window is not a browser window. | 962 // and is getting here because the foreground window is not a browser window. |
963 if ([sender respondsToSelector:@selector(window)]) { | 963 if ([sender respondsToSelector:@selector(window)]) { |
964 id delegate = [[sender window] windowController]; | 964 id delegate = [[sender window] windowController]; |
965 if ([delegate isKindOfClass:[BrowserWindowController class]]) { | 965 if ([delegate isKindOfClass:[BrowserWindowController class]]) { |
966 [delegate commandDispatch:sender]; | 966 [delegate commandDispatch:sender]; |
967 return; | 967 return; |
968 } | 968 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 // the initial profile. | 1283 // the initial profile. |
1284 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1284 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
1285 if (!profile_manager) | 1285 if (!profile_manager) |
1286 return NULL; | 1286 return NULL; |
1287 | 1287 |
1288 return profile_manager->GetProfile(GetStartupProfilePath( | 1288 return profile_manager->GetProfile(GetStartupProfilePath( |
1289 profile_manager->user_data_dir(), | 1289 profile_manager->user_data_dir(), |
1290 *CommandLine::ForCurrentProcess())); | 1290 *CommandLine::ForCurrentProcess())); |
1291 } | 1291 } |
1292 | 1292 |
| 1293 - (Profile*)safeLastProfileForNewWindows { |
| 1294 Profile* profile = [self lastProfile]; |
| 1295 |
| 1296 // Guest sessions must always be OffTheRecord. Use that when opening windows. |
| 1297 if (profile->IsGuestSession()) |
| 1298 return profile->GetOffTheRecordProfile(); |
| 1299 |
| 1300 return profile; |
| 1301 } |
| 1302 |
1293 // Various methods to open URLs that we get in a native fashion. We use | 1303 // Various methods to open URLs that we get in a native fashion. We use |
1294 // StartupBrowserCreator here because on the other platforms, URLs to open come | 1304 // StartupBrowserCreator here because on the other platforms, URLs to open come |
1295 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best | 1305 // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best |
1296 // to bottleneck the openings through that for uniform handling. | 1306 // to bottleneck the openings through that for uniform handling. |
1297 | 1307 |
1298 - (void)openUrls:(const std::vector<GURL>&)urls { | 1308 - (void)openUrls:(const std::vector<GURL>&)urls { |
1299 // If the browser hasn't started yet, just queue up the URLs. | 1309 // If the browser hasn't started yet, just queue up the URLs. |
1300 if (!startupComplete_) { | 1310 if (!startupComplete_) { |
1301 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); | 1311 startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
1302 return; | 1312 return; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 } | 1356 } |
1347 | 1357 |
1348 // Show the preferences window, or bring it to the front if it's already | 1358 // Show the preferences window, or bring it to the front if it's already |
1349 // visible. | 1359 // visible. |
1350 - (IBAction)showPreferences:(id)sender { | 1360 - (IBAction)showPreferences:(id)sender { |
1351 if (Browser* browser = ActivateBrowser([self lastProfile])) { | 1361 if (Browser* browser = ActivateBrowser([self lastProfile])) { |
1352 // Show options tab in the active browser window. | 1362 // Show options tab in the active browser window. |
1353 chrome::ShowSettings(browser); | 1363 chrome::ShowSettings(browser); |
1354 } else { | 1364 } else { |
1355 // No browser window, so create one for the options tab. | 1365 // No browser window, so create one for the options tab. |
1356 chrome::OpenOptionsWindow([self lastProfile]); | 1366 chrome::OpenOptionsWindow([self safeLastProfileForNewWindows]); |
1357 } | 1367 } |
1358 } | 1368 } |
1359 | 1369 |
1360 - (IBAction)orderFrontStandardAboutPanel:(id)sender { | 1370 - (IBAction)orderFrontStandardAboutPanel:(id)sender { |
1361 if (Browser* browser = ActivateBrowser([self lastProfile])) { | 1371 if (Browser* browser = ActivateBrowser([self lastProfile])) { |
1362 chrome::ShowAboutChrome(browser); | 1372 chrome::ShowAboutChrome(browser); |
1363 } else { | 1373 } else { |
1364 // No browser window, so create one for the about tab. | 1374 // No browser window, so create one for the about tab. |
1365 chrome::OpenAboutWindow([self lastProfile]); | 1375 chrome::OpenAboutWindow([self safeLastProfileForNewWindows]); |
1366 } | 1376 } |
1367 } | 1377 } |
1368 | 1378 |
1369 - (IBAction)toggleConfirmToQuit:(id)sender { | 1379 - (IBAction)toggleConfirmToQuit:(id)sender { |
1370 PrefService* prefService = g_browser_process->local_state(); | 1380 PrefService* prefService = g_browser_process->local_state(); |
1371 bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); | 1381 bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled); |
1372 prefService->SetBoolean(prefs::kConfirmToQuitEnabled, !enabled); | 1382 prefService->SetBoolean(prefs::kConfirmToQuitEnabled, !enabled); |
1373 } | 1383 } |
1374 | 1384 |
1375 // Explicitly bring to the foreground when creating new windows from the dock. | 1385 // Explicitly bring to the foreground when creating new windows from the dock. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 | 1495 |
1486 //--------------------------------------------------------------------------- | 1496 //--------------------------------------------------------------------------- |
1487 | 1497 |
1488 namespace app_controller_mac { | 1498 namespace app_controller_mac { |
1489 | 1499 |
1490 bool IsOpeningNewWindow() { | 1500 bool IsOpeningNewWindow() { |
1491 return g_is_opening_new_window; | 1501 return g_is_opening_new_window; |
1492 } | 1502 } |
1493 | 1503 |
1494 } // namespace app_controller_mac | 1504 } // namespace app_controller_mac |
OLD | NEW |