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 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/browser_shutdown.h" | 22 #include "chrome/browser/browser_shutdown.h" |
23 #include "chrome/browser/command_updater.h" | 23 #include "chrome/browser/command_updater.h" |
24 #include "chrome/browser/download/download_service.h" | 24 #include "chrome/browser/download/download_service.h" |
25 #include "chrome/browser/download/download_service_factory.h" | 25 #include "chrome/browser/download/download_service_factory.h" |
26 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
27 #include "chrome/browser/extensions/extension_system.h" | 27 #include "chrome/browser/extensions/extension_system.h" |
28 #include "chrome/browser/first_run/first_run.h" | 28 #include "chrome/browser/first_run/first_run.h" |
29 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" |
30 #include "chrome/browser/printing/print_dialog_cloud.h" | 30 #include "chrome/browser/printing/print_dialog_cloud.h" |
| 31 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
31 #include "chrome/browser/profiles/profile_manager.h" | 32 #include "chrome/browser/profiles/profile_manager.h" |
32 #include "chrome/browser/service/service_process_control.h" | 33 #include "chrome/browser/service/service_process_control.h" |
33 #include "chrome/browser/sessions/session_restore.h" | 34 #include "chrome/browser/sessions/session_restore.h" |
34 #include "chrome/browser/sessions/session_service.h" | 35 #include "chrome/browser/sessions/session_service.h" |
35 #include "chrome/browser/sessions/session_service_factory.h" | 36 #include "chrome/browser/sessions/session_service_factory.h" |
36 #include "chrome/browser/sessions/tab_restore_service.h" | 37 #include "chrome/browser/sessions/tab_restore_service.h" |
37 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 38 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
38 #include "chrome/browser/signin/signin_manager.h" | 39 #include "chrome/browser/signin/signin_manager.h" |
39 #include "chrome/browser/signin/signin_manager_factory.h" | 40 #include "chrome/browser/signin/signin_manager_factory.h" |
40 #include "chrome/browser/sync/profile_sync_service.h" | 41 #include "chrome/browser/sync/profile_sync_service.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 - (void)openUrls:(const std::vector<GURL>&)urls; | 184 - (void)openUrls:(const std::vector<GURL>&)urls; |
184 - (void)getUrl:(NSAppleEventDescriptor*)event | 185 - (void)getUrl:(NSAppleEventDescriptor*)event |
185 withReply:(NSAppleEventDescriptor*)reply; | 186 withReply:(NSAppleEventDescriptor*)reply; |
186 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; | 187 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; |
187 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 188 - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
188 - (void)windowChangedToProfile:(Profile*)profile; | 189 - (void)windowChangedToProfile:(Profile*)profile; |
189 - (void)checkForAnyKeyWindows; | 190 - (void)checkForAnyKeyWindows; |
190 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 191 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
191 - (BOOL)shouldQuitWithInProgressDownloads; | 192 - (BOOL)shouldQuitWithInProgressDownloads; |
192 - (void)executeApplication:(id)sender; | 193 - (void)executeApplication:(id)sender; |
| 194 - (void)profileWasRemoved:(const base::FilePath&)profilePath; |
193 @end | 195 @end |
194 | 196 |
| 197 class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
| 198 public: |
| 199 AppControllerProfileObserver( |
| 200 ProfileManager* profile_manager, AppController* app_controller) |
| 201 : profile_manager_(profile_manager), |
| 202 app_controller_(app_controller) { |
| 203 DCHECK(profile_manager_); |
| 204 DCHECK(app_controller_); |
| 205 profile_manager_->GetProfileInfoCache().AddObserver(this); |
| 206 } |
| 207 |
| 208 virtual ~AppControllerProfileObserver() { |
| 209 DCHECK(profile_manager_); |
| 210 profile_manager_->GetProfileInfoCache().RemoveObserver(this); |
| 211 } |
| 212 |
| 213 private: |
| 214 // ProfileInfoCacheObserver implementation: |
| 215 |
| 216 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE { |
| 217 } |
| 218 |
| 219 virtual void OnProfileWasRemoved(const base::FilePath& profile_path, |
| 220 const string16& profile_name) OVERRIDE { |
| 221 // When a profile is deleted we need to notify the AppController, |
| 222 // so it can correctly update its pointer to the last used profile. |
| 223 [app_controller_ profileWasRemoved:profile_path]; |
| 224 } |
| 225 |
| 226 virtual void OnProfileWillBeRemoved( |
| 227 const base::FilePath& profile_path) OVERRIDE { |
| 228 } |
| 229 |
| 230 virtual void OnProfileNameChanged(const base::FilePath& profile_path, |
| 231 const string16& old_profile_name) OVERRIDE { |
| 232 } |
| 233 |
| 234 virtual void OnProfileAvatarChanged( |
| 235 const base::FilePath& profile_path) OVERRIDE { |
| 236 } |
| 237 |
| 238 ProfileManager* profile_manager_; |
| 239 |
| 240 AppController* app_controller_; // Weak; owns us. |
| 241 |
| 242 DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver); |
| 243 }; |
| 244 |
195 @implementation AppController | 245 @implementation AppController |
196 | 246 |
197 @synthesize startupComplete = startupComplete_; | 247 @synthesize startupComplete = startupComplete_; |
198 | 248 |
199 // This method is called very early in application startup (ie, before | 249 // This method is called very early in application startup (ie, before |
200 // the profile is loaded or any preferences have been registered). Defer any | 250 // the profile is loaded or any preferences have been registered). Defer any |
201 // user-data initialization until -applicationDidFinishLaunching:. | 251 // user-data initialization until -applicationDidFinishLaunching:. |
202 - (void)awakeFromNib { | 252 - (void)awakeFromNib { |
203 // We need to register the handlers early to catch events fired on launch. | 253 // We need to register the handlers early to catch events fired on launch. |
204 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 254 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 // Build up the encoding menu, the order of the items differs based on the | 628 // Build up the encoding menu, the order of the items differs based on the |
579 // current locale (see http://crbug.com/7647 for details). | 629 // current locale (see http://crbug.com/7647 for details). |
580 // We need a valid g_browser_process to get the profile which is why we can't | 630 // We need a valid g_browser_process to get the profile which is why we can't |
581 // call this from awakeFromNib. | 631 // call this from awakeFromNib. |
582 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; | 632 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; |
583 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; | 633 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; |
584 NSMenu* encodingMenu = [encodingMenuItem submenu]; | 634 NSMenu* encodingMenu = [encodingMenuItem submenu]; |
585 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], | 635 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], |
586 encodingMenu); | 636 encodingMenu); |
587 | 637 |
| 638 // Instantiate the ProfileInfoCache observer so that we can get |
| 639 // notified when a profile is deleted. |
| 640 profileInfoCacheObserver_.reset(new AppControllerProfileObserver( |
| 641 g_browser_process->profile_manager(), self)); |
| 642 |
588 // Since Chrome is localized to more languages than the OS, tell Cocoa which | 643 // Since Chrome is localized to more languages than the OS, tell Cocoa which |
589 // menu is the Help so it can add the search item to it. | 644 // menu is the Help so it can add the search item to it. |
590 [NSApp setHelpMenu:helpMenu_]; | 645 [NSApp setHelpMenu:helpMenu_]; |
591 | 646 |
592 // Record the path to the (browser) app bundle; this is used by the app mode | 647 // Record the path to the (browser) app bundle; this is used by the app mode |
593 // shim. | 648 // shim. |
594 RecordLastRunAppBundlePath(); | 649 RecordLastRunAppBundlePath(); |
595 | 650 |
596 // Makes "Services" menu items available. | 651 // Makes "Services" menu items available. |
597 [self registerServicesMenuTypesTo:[notify object]]; | 652 [self registerServicesMenuTypesTo:[notify object]]; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 762 |
708 // Called to determine if we should enable the "restore tab" menu item. | 763 // Called to determine if we should enable the "restore tab" menu item. |
709 // Checks with the TabRestoreService to see if there's anything there to | 764 // Checks with the TabRestoreService to see if there's anything there to |
710 // restore and returns YES if so. | 765 // restore and returns YES if so. |
711 - (BOOL)canRestoreTab { | 766 - (BOOL)canRestoreTab { |
712 TabRestoreService* service = | 767 TabRestoreService* service = |
713 TabRestoreServiceFactory::GetForProfile([self lastProfile]); | 768 TabRestoreServiceFactory::GetForProfile([self lastProfile]); |
714 return service && !service->entries().empty(); | 769 return service && !service->entries().empty(); |
715 } | 770 } |
716 | 771 |
| 772 // Called from the AppControllerProfileObserver every time a profile is deleted. |
| 773 - (void)profileWasRemoved:(const base::FilePath&)profilePath { |
| 774 Profile* lastProfile = [self lastProfile]; |
| 775 |
| 776 // If the lastProfile has been deleted, the profile manager has |
| 777 // already loaded a new one, so the pointer needs to be updated; |
| 778 // otherwise we will try to start up a browser window with a pointer |
| 779 // to the old profile. |
| 780 if (profilePath == lastProfile->GetPath()) |
| 781 lastProfile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 782 } |
| 783 |
717 // Returns true if there is a modal window (either window- or application- | 784 // Returns true if there is a modal window (either window- or application- |
718 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth | 785 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth |
719 // sheets) will not count as blocking the browser. But things like open/save | 786 // sheets) will not count as blocking the browser. But things like open/save |
720 // dialogs that are window modal will block the browser. | 787 // dialogs that are window modal will block the browser. |
721 - (BOOL)keyWindowIsModal { | 788 - (BOOL)keyWindowIsModal { |
722 if ([NSApp modalWindow]) | 789 if ([NSApp modalWindow]) |
723 return YES; | 790 return YES; |
724 | 791 |
725 Browser* browser = chrome::GetLastActiveBrowser(); | 792 Browser* browser = chrome::GetLastActiveBrowser(); |
726 return browser && | 793 return browser && |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 | 1381 |
1315 //--------------------------------------------------------------------------- | 1382 //--------------------------------------------------------------------------- |
1316 | 1383 |
1317 namespace app_controller_mac { | 1384 namespace app_controller_mac { |
1318 | 1385 |
1319 bool IsOpeningNewWindow() { | 1386 bool IsOpeningNewWindow() { |
1320 return g_is_opening_new_window; | 1387 return g_is_opening_new_window; |
1321 } | 1388 } |
1322 | 1389 |
1323 } // namespace app_controller_mac | 1390 } // namespace app_controller_mac |
OLD | NEW |