OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/background_application_list_model.h" | 16 #include "chrome/browser/background_application_list_model.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/browser_shutdown.h" | 18 #include "chrome/browser/browser_shutdown.h" |
19 #include "chrome/browser/command_updater.h" | 19 #include "chrome/browser/command_updater.h" |
20 #include "chrome/browser/download/download_manager.h" | 20 #include "chrome/browser/download/download_manager.h" |
21 #include "chrome/browser/instant/instant_confirm_dialog.h" | 21 #include "chrome/browser/instant/instant_confirm_dialog.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/printing/print_job_manager.h" | 23 #include "chrome/browser/printing/print_job_manager.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/browser/sessions/session_service.h" | 25 #include "chrome/browser/sessions/session_service.h" |
| 26 #include "chrome/browser/sessions/session_service_factory.h" |
26 #include "chrome/browser/sessions/tab_restore_service.h" | 27 #include "chrome/browser/sessions/tab_restore_service.h" |
| 28 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
27 #include "chrome/browser/sync/profile_sync_service.h" | 29 #include "chrome/browser/sync/profile_sync_service.h" |
28 #include "chrome/browser/sync/sync_ui_util.h" | 30 #include "chrome/browser/sync/sync_ui_util.h" |
29 #include "chrome/browser/sync/sync_ui_util_mac.h" | 31 #include "chrome/browser/sync/sync_ui_util_mac.h" |
30 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
31 #include "chrome/browser/ui/browser_init.h" | 33 #include "chrome/browser/ui/browser_init.h" |
32 #include "chrome/browser/ui/browser_list.h" | 34 #include "chrome/browser/ui/browser_list.h" |
33 #include "chrome/browser/ui/browser_window.h" | 35 #include "chrome/browser/ui/browser_window.h" |
34 #import "chrome/browser/ui/cocoa/about_window_controller.h" | 36 #import "chrome/browser/ui/cocoa/about_window_controller.h" |
35 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 37 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
36 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 38 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 324 } |
323 | 325 |
324 - (void)didEndMainMessageLoop { | 326 - (void)didEndMainMessageLoop { |
325 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile])); | 327 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile])); |
326 if (!BrowserList::HasBrowserWithProfile([self defaultProfile])) { | 328 if (!BrowserList::HasBrowserWithProfile([self defaultProfile])) { |
327 // As we're shutting down, we need to nuke the TabRestoreService, which | 329 // As we're shutting down, we need to nuke the TabRestoreService, which |
328 // will start the shutdown of the NavigationControllers and allow for | 330 // will start the shutdown of the NavigationControllers and allow for |
329 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, | 331 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, |
330 // and may end up crashing when some thread tries to use the IO thread (or | 332 // and may end up crashing when some thread tries to use the IO thread (or |
331 // another thread) that is no longer valid. | 333 // another thread) that is no longer valid. |
332 [self defaultProfile]->ResetTabRestoreService(); | 334 TabRestoreServiceFactory::ResetForProfile([self defaultProfile]); |
333 } | 335 } |
334 } | 336 } |
335 | 337 |
336 // Helper routine to get the window controller if the key window is a tabbed | 338 // Helper routine to get the window controller if the key window is a tabbed |
337 // window, or nil if not. Examples of non-tabbed windows are "about" or | 339 // window, or nil if not. Examples of non-tabbed windows are "about" or |
338 // "preferences". | 340 // "preferences". |
339 - (TabWindowController*)keyWindowTabController { | 341 - (TabWindowController*)keyWindowTabController { |
340 NSWindowController* keyWindowController = | 342 NSWindowController* keyWindowController = |
341 [[NSApp keyWindow] windowController]; | 343 [[NSApp keyWindow] windowController]; |
342 if ([keyWindowController isKindOfClass:[TabWindowController class]]) | 344 if ([keyWindowController isKindOfClass:[TabWindowController class]]) |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } | 631 } |
630 | 632 |
631 // No profiles or active downloads found, okay to exit. | 633 // No profiles or active downloads found, okay to exit. |
632 return YES; | 634 return YES; |
633 } | 635 } |
634 | 636 |
635 // Called to determine if we should enable the "restore tab" menu item. | 637 // Called to determine if we should enable the "restore tab" menu item. |
636 // Checks with the TabRestoreService to see if there's anything there to | 638 // Checks with the TabRestoreService to see if there's anything there to |
637 // restore and returns YES if so. | 639 // restore and returns YES if so. |
638 - (BOOL)canRestoreTab { | 640 - (BOOL)canRestoreTab { |
639 TabRestoreService* service = [self defaultProfile]->GetTabRestoreService(); | 641 TabRestoreService* service = |
| 642 TabRestoreServiceFactory::GetForProfile([self defaultProfile]); |
640 return service && !service->entries().empty(); | 643 return service && !service->entries().empty(); |
641 } | 644 } |
642 | 645 |
643 // Returns true if there is not a modal window (either window- or application- | 646 // Returns true if there is not a modal window (either window- or application- |
644 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth | 647 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth |
645 // sheets) will not count as blocking the browser. But things like open/save | 648 // sheets) will not count as blocking the browser. But things like open/save |
646 // dialogs that are window modal will block the browser. | 649 // dialogs that are window modal will block the browser. |
647 - (BOOL)keyWindowIsNotModal { | 650 - (BOOL)keyWindowIsNotModal { |
648 Browser* browser = BrowserList::GetLastActive(); | 651 Browser* browser = BrowserList::GetLastActive(); |
649 return [NSApp modalWindow] == nil && (!browser || | 652 return [NSApp modalWindow] == nil && (!browser || |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 // If launched as a hidden login item (due to installation of a persistent app | 921 // If launched as a hidden login item (due to installation of a persistent app |
919 // or by the user, for example in System Preferenecs->Accounts->Login Items), | 922 // or by the user, for example in System Preferenecs->Accounts->Login Items), |
920 // allow session to be restored first time the user clicks on a Dock icon. | 923 // allow session to be restored first time the user clicks on a Dock icon. |
921 // Normally, it'd just open a new empty page. | 924 // Normally, it'd just open a new empty page. |
922 { | 925 { |
923 static BOOL doneOnce = NO; | 926 static BOOL doneOnce = NO; |
924 if (!doneOnce) { | 927 if (!doneOnce) { |
925 doneOnce = YES; | 928 doneOnce = YES; |
926 if (base::mac::WasLaunchedAsHiddenLoginItem()) { | 929 if (base::mac::WasLaunchedAsHiddenLoginItem()) { |
927 SessionService* sessionService = | 930 SessionService* sessionService = |
928 [self defaultProfile]->GetSessionService(); | 931 SessionServiceFactory::GetForProfile([self defaultProfile]); |
929 if (sessionService && | 932 if (sessionService && |
930 sessionService->RestoreIfNecessary(std::vector<GURL>())) | 933 sessionService->RestoreIfNecessary(std::vector<GURL>())) |
931 return NO; | 934 return NO; |
932 } | 935 } |
933 } | 936 } |
934 } | 937 } |
935 // Otherwise open a new window. | 938 // Otherwise open a new window. |
936 { | 939 { |
937 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true); | 940 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true); |
938 Browser::OpenEmptyWindow([self defaultProfile]); | 941 Browser::OpenEmptyWindow([self defaultProfile]); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 | 1186 |
1184 } // namespace browser | 1187 } // namespace browser |
1185 | 1188 |
1186 namespace app_controller_mac { | 1189 namespace app_controller_mac { |
1187 | 1190 |
1188 bool IsOpeningNewWindow() { | 1191 bool IsOpeningNewWindow() { |
1189 return g_is_opening_new_window; | 1192 return g_is_opening_new_window; |
1190 } | 1193 } |
1191 | 1194 |
1192 } // namespace app_controller_mac | 1195 } // namespace app_controller_mac |
OLD | NEW |