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/extension_app_shim_handler_mac.h" | 7 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 // Reset the "trying to quit" state, so that closing all browser windows | 375 // Reset the "trying to quit" state, so that closing all browser windows |
376 // will no longer lead to termination. | 376 // will no longer lead to termination. |
377 browser_shutdown::SetTryingToQuit(false); | 377 browser_shutdown::SetTryingToQuit(false); |
378 | 378 |
379 // TODO(viettrungluu): Were we to remove Apple Event handlers above, we | 379 // TODO(viettrungluu): Were we to remove Apple Event handlers above, we |
380 // would have to reinstall them here. http://crbug.com/40861 | 380 // would have to reinstall them here. http://crbug.com/40861 |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app { | 384 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app { |
385 using apps::ShellWindowRegistry; | |
386 | |
387 // If there are no windows, quit immediately. | 385 // If there are no windows, quit immediately. |
388 if (chrome::BrowserIterator().done() && | 386 if (chrome::BrowserIterator().done() && |
389 !ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile(0)) { | 387 !apps::ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile(0)) { |
390 return NSTerminateNow; | 388 return NSTerminateNow; |
391 } | 389 } |
392 | 390 |
393 // Check if this is a keyboard initiated quit on an app window. If so, quit | |
394 // the app. This could cause the app to trigger another terminate, but that | |
395 // will be caught by the no windows condition above. | |
396 if ([[app currentEvent] type] == NSKeyDown) { | |
397 apps::ShellWindow* shellWindow = | |
398 ShellWindowRegistry::GetShellWindowForNativeWindowAnyProfile( | |
399 [app keyWindow]); | |
400 if (shellWindow) { | |
401 apps::ExtensionAppShimHandler::QuitAppForWindow(shellWindow); | |
402 return NSTerminateCancel; | |
403 } | |
404 } | |
405 | |
406 // Check if the preference is turned on. | 391 // Check if the preference is turned on. |
407 const PrefService* prefs = g_browser_process->local_state(); | 392 const PrefService* prefs = g_browser_process->local_state(); |
408 if (!prefs->GetBoolean(prefs::kConfirmToQuitEnabled)) { | 393 if (!prefs->GetBoolean(prefs::kConfirmToQuitEnabled)) { |
409 confirm_quit::RecordHistogram(confirm_quit::kNoConfirm); | 394 confirm_quit::RecordHistogram(confirm_quit::kNoConfirm); |
410 return NSTerminateNow; | 395 return NSTerminateNow; |
411 } | 396 } |
412 | 397 |
413 // If the application is going to terminate as the result of a Cmd+Q | 398 // If the application is going to terminate as the result of a Cmd+Q |
414 // invocation, use the special sauce to prevent accidental quitting. | 399 // invocation, use the special sauce to prevent accidental quitting. |
415 // http://dev.chromium.org/developers/design-documents/confirm-to-quit-experim
ent | 400 // http://dev.chromium.org/developers/design-documents/confirm-to-quit-experim
ent |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 | 1416 |
1432 //--------------------------------------------------------------------------- | 1417 //--------------------------------------------------------------------------- |
1433 | 1418 |
1434 namespace app_controller_mac { | 1419 namespace app_controller_mac { |
1435 | 1420 |
1436 bool IsOpeningNewWindow() { | 1421 bool IsOpeningNewWindow() { |
1437 return g_is_opening_new_window; | 1422 return g_is_opening_new_window; |
1438 } | 1423 } |
1439 | 1424 |
1440 } // namespace app_controller_mac | 1425 } // namespace app_controller_mac |
OLD | NEW |