Chromium Code Reviews| 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/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "chrome/browser/service/service_process_control.h" | 32 #include "chrome/browser/service/service_process_control.h" |
| 33 #include "chrome/browser/sessions/session_restore.h" | 33 #include "chrome/browser/sessions/session_restore.h" |
| 34 #include "chrome/browser/sessions/session_service.h" | 34 #include "chrome/browser/sessions/session_service.h" |
| 35 #include "chrome/browser/sessions/session_service_factory.h" | 35 #include "chrome/browser/sessions/session_service_factory.h" |
| 36 #include "chrome/browser/sessions/tab_restore_service.h" | 36 #include "chrome/browser/sessions/tab_restore_service.h" |
| 37 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 37 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 38 #include "chrome/browser/sync/profile_sync_service.h" | 38 #include "chrome/browser/sync/profile_sync_service.h" |
| 39 #include "chrome/browser/sync/sync_ui_util.h" | 39 #include "chrome/browser/sync/sync_ui_util.h" |
| 40 #include "chrome/browser/sync/sync_ui_util_mac.h" | 40 #include "chrome/browser/sync/sync_ui_util_mac.h" |
| 41 #include "chrome/browser/ui/browser.h" | 41 #include "chrome/browser/ui/browser.h" |
| 42 #include "chrome/browser/ui/browser_command_controller.h" | |
| 42 #include "chrome/browser/ui/browser_commands.h" | 43 #include "chrome/browser/ui/browser_commands.h" |
| 43 #include "chrome/browser/ui/browser_finder.h" | 44 #include "chrome/browser/ui/browser_finder.h" |
| 44 #include "chrome/browser/ui/browser_list.h" | 45 #include "chrome/browser/ui/browser_list.h" |
| 45 #include "chrome/browser/ui/browser_mac.h" | 46 #include "chrome/browser/ui/browser_mac.h" |
| 46 #include "chrome/browser/ui/browser_window.h" | 47 #include "chrome/browser/ui/browser_window.h" |
| 47 #include "chrome/browser/ui/chrome_pages.h" | 48 #include "chrome/browser/ui/chrome_pages.h" |
| 48 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 49 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
| 49 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 50 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 50 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 51 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 51 #import "chrome/browser/ui/cocoa/confirm_quit.h" | 52 #import "chrome/browser/ui/cocoa/confirm_quit.h" |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 | 516 |
| 516 // Rebuild the menus with the new profile. | 517 // Rebuild the menus with the new profile. |
| 517 lastProfile_ = profile; | 518 lastProfile_ = profile; |
| 518 | 519 |
| 519 bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_, | 520 bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_, |
| 520 [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu])); | 521 [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu])); |
| 521 // No need to |BuildMenu| here. It is done lazily upon menu access. | 522 // No need to |BuildMenu| here. It is done lazily upon menu access. |
| 522 | 523 |
| 523 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); | 524 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); |
| 524 historyMenuBridge_->BuildMenu(); | 525 historyMenuBridge_->BuildMenu(); |
| 526 | |
| 527 chrome::BrowserCommandController:: | |
| 528 UpdateSharedCommandsForIncognitoAvailability(menuState_.get(), lastProfile_); | |
|
Robert Sesek
2013/01/16 18:24:50
nit: indent 4
Avi (use Gerrit)
2013/01/16 19:04:37
Done.
| |
| 529 profilePrefRegistrar_.reset(new PrefChangeRegistrar()); | |
| 530 profilePrefRegistrar_->Init(lastProfile_->GetPrefs()); | |
| 531 profilePrefRegistrar_->Add( | |
| 532 prefs::kIncognitoModeAvailability, | |
| 533 base::Bind(&chrome::BrowserCommandController:: | |
| 534 UpdateSharedCommandsForIncognitoAvailability, | |
|
Robert Sesek
2013/01/16 18:24:50
nit: indent 4
Avi (use Gerrit)
2013/01/16 19:04:37
Done.
| |
| 535 menuState_.get(), | |
| 536 lastProfile_)); | |
| 525 } | 537 } |
| 526 | 538 |
| 527 - (void)checkForAnyKeyWindows { | 539 - (void)checkForAnyKeyWindows { |
| 528 if ([NSApp keyWindow]) | 540 if ([NSApp keyWindow]) |
| 529 return; | 541 return; |
| 530 | 542 |
| 531 content::NotificationService::current()->Notify( | 543 content::NotificationService::current()->Notify( |
| 532 chrome::NOTIFICATION_NO_KEY_WINDOW, | 544 chrome::NOTIFICATION_NO_KEY_WINDOW, |
| 533 content::NotificationService::AllSources(), | 545 content::NotificationService::AllSources(), |
| 534 content::NotificationService::NoDetails()); | 546 content::NotificationService::NoDetails()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 // (probably-empty) list of URLs from the command line. | 603 // (probably-empty) list of URLs from the command line. |
| 592 if (startupUrls_.size()) { | 604 if (startupUrls_.size()) { |
| 593 [self openUrls:startupUrls_]; | 605 [self openUrls:startupUrls_]; |
| 594 [self clearStartupUrls]; | 606 [self clearStartupUrls]; |
| 595 } | 607 } |
| 596 | 608 |
| 597 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 609 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 598 if (!parsed_command_line.HasSwitch(switches::kEnableExposeForTabs)) { | 610 if (!parsed_command_line.HasSwitch(switches::kEnableExposeForTabs)) { |
| 599 [tabposeMenuItem_ setHidden:YES]; | 611 [tabposeMenuItem_ setHidden:YES]; |
| 600 } | 612 } |
| 613 | |
| 614 PrefService* localState = g_browser_process->local_state(); | |
| 615 if (localState) { | |
| 616 localPrefRegistrar_.Init(localState); | |
| 617 localPrefRegistrar_.Add( | |
| 618 prefs::kAllowFileSelectionDialogs, | |
| 619 base::Bind(&chrome::BrowserCommandController::UpdateOpenFileState, | |
| 620 menuState_.get())); | |
| 621 } | |
| 601 } | 622 } |
| 602 | 623 |
| 603 // This is called after profiles have been loaded and preferences registered. | 624 // This is called after profiles have been loaded and preferences registered. |
| 604 // It is safe to access the default profile here. | 625 // It is safe to access the default profile here. |
| 605 - (void)applicationDidBecomeActive:(NSNotification*)notify { | 626 - (void)applicationDidBecomeActive:(NSNotification*)notify { |
| 606 content::PluginService::GetInstance()->AppActivated(); | 627 content::PluginService::GetInstance()->AppActivated(); |
| 607 } | 628 } |
| 608 | 629 |
| 609 // Helper function for populating and displaying the in progress downloads at | 630 // Helper function for populating and displaying the in progress downloads at |
| 610 // exit alert panel. | 631 // exit alert panel. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 | 706 |
| 686 // Called to determine if we should enable the "restore tab" menu item. | 707 // Called to determine if we should enable the "restore tab" menu item. |
| 687 // Checks with the TabRestoreService to see if there's anything there to | 708 // Checks with the TabRestoreService to see if there's anything there to |
| 688 // restore and returns YES if so. | 709 // restore and returns YES if so. |
| 689 - (BOOL)canRestoreTab { | 710 - (BOOL)canRestoreTab { |
| 690 TabRestoreService* service = | 711 TabRestoreService* service = |
| 691 TabRestoreServiceFactory::GetForProfile([self lastProfile]); | 712 TabRestoreServiceFactory::GetForProfile([self lastProfile]); |
| 692 return service && !service->entries().empty(); | 713 return service && !service->entries().empty(); |
| 693 } | 714 } |
| 694 | 715 |
| 695 // Returns true if there is not a modal window (either window- or application- | 716 // Returns true if there is a modal window (either window- or application- |
| 696 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth | 717 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth |
| 697 // sheets) will not count as blocking the browser. But things like open/save | 718 // sheets) will not count as blocking the browser. But things like open/save |
| 698 // dialogs that are window modal will block the browser. | 719 // dialogs that are window modal will block the browser. |
| 699 - (BOOL)keyWindowIsNotModal { | 720 - (BOOL)keyWindowIsModal { |
| 721 if ([NSApp modalWindow]) | |
| 722 return YES; | |
| 723 | |
| 700 Browser* browser = chrome::GetLastActiveBrowser(); | 724 Browser* browser = chrome::GetLastActiveBrowser(); |
| 701 return [NSApp modalWindow] == nil && (!browser || | 725 return browser && |
| 702 ![[browser->window()->GetNativeWindow() attachedSheet] | 726 [[browser->window()->GetNativeWindow() attachedSheet] |
| 703 isKindOfClass:[NSWindow class]]); | 727 isKindOfClass:[NSWindow class]]; |
| 704 } | 728 } |
| 705 | 729 |
| 706 // Called to validate menu items when there are no key windows. All the | 730 // Called to validate menu items when there are no key windows. All the |
| 707 // items we care about have been set with the |commandDispatch:| action and | 731 // items we care about have been set with the |commandDispatch:| action and |
| 708 // a target of FirstResponder in IB. If it's not one of those, let it | 732 // a target of FirstResponder in IB. If it's not one of those, let it |
| 709 // continue up the responder chain to be handled elsewhere. We pull out the | 733 // continue up the responder chain to be handled elsewhere. We pull out the |
| 710 // tag as the cross-platform constant to differentiate and dispatch the | 734 // tag as the cross-platform constant to differentiate and dispatch the |
| 711 // various commands. | 735 // various commands. |
| 712 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 736 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 713 SEL action = [item action]; | 737 SEL action = [item action]; |
| 714 BOOL enable = NO; | 738 BOOL enable = NO; |
| 715 if (action == @selector(commandDispatch:)) { | 739 if (action == @selector(commandDispatch:) || |
| 740 action == @selector(commandFromDock:)) { | |
| 716 NSInteger tag = [item tag]; | 741 NSInteger tag = [item tag]; |
| 717 if (menuState_->SupportsCommand(tag)) { | 742 if (menuState_ && // NULL in tests. |
| 743 menuState_->SupportsCommand(tag)) { | |
| 718 switch (tag) { | 744 switch (tag) { |
| 719 // The File Menu commands are not automatically disabled by Cocoa when a | 745 // The File Menu commands are not automatically disabled by Cocoa when a |
| 720 // dialog sheet obscures the browser window, so we disable several of | 746 // dialog sheet obscures the browser window, so we disable several of |
| 721 // them here. We don't need to include IDC_CLOSE_WINDOW, because | 747 // them here. We don't need to include IDC_CLOSE_WINDOW, because |
| 722 // app_controller is only activated when there are no key windows (see | 748 // app_controller is only activated when there are no key windows (see |
| 723 // function comment). | 749 // function comment). |
| 724 case IDC_RESTORE_TAB: | 750 case IDC_RESTORE_TAB: |
| 725 enable = [self keyWindowIsNotModal] && [self canRestoreTab]; | 751 enable = ![self keyWindowIsModal] && [self canRestoreTab]; |
| 726 break; | 752 break; |
| 727 // Browser-level items that open in new tabs should not open if there's | 753 // Browser-level items that open in new tabs should not open if there's |
| 728 // a window- or app-modal dialog. | 754 // a window- or app-modal dialog. |
| 729 case IDC_OPEN_FILE: | 755 case IDC_OPEN_FILE: |
| 730 case IDC_NEW_TAB: | 756 case IDC_NEW_TAB: |
| 731 case IDC_SHOW_HISTORY: | 757 case IDC_SHOW_HISTORY: |
| 732 case IDC_SHOW_BOOKMARK_MANAGER: | 758 case IDC_SHOW_BOOKMARK_MANAGER: |
| 733 enable = [self keyWindowIsNotModal]; | 759 enable = ![self keyWindowIsModal]; |
| 734 break; | 760 break; |
| 735 // Browser-level items that open in new windows. | 761 // Browser-level items that open in new windows. |
| 736 case IDC_NEW_WINDOW: | |
| 737 case IDC_TASK_MANAGER: | 762 case IDC_TASK_MANAGER: |
| 738 // Allow the user to open a new window if there's a window-modal | 763 // Allow the user to open a new window if there's a window-modal |
| 739 // dialog. | 764 // dialog. |
| 740 enable = [self keyWindowIsNotModal] || ([NSApp modalWindow] == nil); | 765 enable = ![self keyWindowIsModal]; |
| 741 break; | 766 break; |
| 742 case IDC_SHOW_SYNC_SETUP: { | 767 case IDC_SHOW_SYNC_SETUP: { |
| 743 Profile* lastProfile = [self lastProfile]; | 768 Profile* lastProfile = [self lastProfile]; |
| 744 // The profile may be NULL during shutdown -- see | 769 // The profile may be NULL during shutdown -- see |
| 745 // http://code.google.com/p/chromium/issues/detail?id=43048 . | 770 // http://code.google.com/p/chromium/issues/detail?id=43048 . |
| 746 // | 771 // |
| 747 // TODO(akalin,viettrungluu): Figure out whether this method | 772 // TODO(akalin,viettrungluu): Figure out whether this method |
| 748 // can be prevented from being called if lastProfile is | 773 // can be prevented from being called if lastProfile is |
| 749 // NULL. | 774 // NULL. |
| 750 if (!lastProfile) { | 775 if (!lastProfile) { |
| 751 LOG(WARNING) | 776 LOG(WARNING) |
| 752 << "NULL lastProfile detected -- not doing anything"; | 777 << "NULL lastProfile detected -- not doing anything"; |
| 753 break; | 778 break; |
| 754 } | 779 } |
| 755 enable = lastProfile->IsSyncAccessible() && | 780 enable = lastProfile->IsSyncAccessible() && ![self keyWindowIsModal]; |
| 756 [self keyWindowIsNotModal]; | |
| 757 sync_ui_util::UpdateSyncItem(item, enable, lastProfile); | 781 sync_ui_util::UpdateSyncItem(item, enable, lastProfile); |
| 758 break; | 782 break; |
| 759 } | 783 } |
| 760 case IDC_FEEDBACK: | 784 case IDC_FEEDBACK: |
| 761 enable = NO; | 785 enable = NO; |
| 762 break; | 786 break; |
| 763 default: | 787 default: |
| 764 enable = menuState_->IsCommandEnabled(tag) ? | 788 enable = menuState_->IsCommandEnabled(tag) ? |
| 765 [self keyWindowIsNotModal] : NO; | 789 ![self keyWindowIsModal] : NO; |
| 766 } | 790 } |
| 767 } | 791 } |
| 768 } else if (action == @selector(terminate:)) { | 792 } else if (action == @selector(terminate:)) { |
| 769 enable = YES; | 793 enable = YES; |
| 770 } else if (action == @selector(showPreferences:)) { | 794 } else if (action == @selector(showPreferences:)) { |
| 771 enable = YES; | 795 enable = YES; |
| 772 } else if (action == @selector(orderFrontStandardAboutPanel:)) { | 796 } else if (action == @selector(orderFrontStandardAboutPanel:)) { |
| 773 enable = YES; | 797 enable = YES; |
| 774 } else if (action == @selector(commandFromDock:)) { | 798 } else if (action == @selector(commandFromDock:)) { |
| 775 enable = YES; | 799 enable = YES; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 if (profilesAdded) | 1248 if (profilesAdded) |
| 1225 [dockMenu addItem:[NSMenuItem separatorItem]]; | 1249 [dockMenu addItem:[NSMenuItem separatorItem]]; |
| 1226 | 1250 |
| 1227 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); | 1251 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); |
| 1228 scoped_nsobject<NSMenuItem> item( | 1252 scoped_nsobject<NSMenuItem> item( |
| 1229 [[NSMenuItem alloc] initWithTitle:titleStr | 1253 [[NSMenuItem alloc] initWithTitle:titleStr |
| 1230 action:@selector(commandFromDock:) | 1254 action:@selector(commandFromDock:) |
| 1231 keyEquivalent:@""]); | 1255 keyEquivalent:@""]); |
| 1232 [item setTarget:self]; | 1256 [item setTarget:self]; |
| 1233 [item setTag:IDC_NEW_WINDOW]; | 1257 [item setTag:IDC_NEW_WINDOW]; |
| 1258 [item setEnabled:[self validateUserInterfaceItem:item]]; | |
| 1234 [dockMenu addItem:item]; | 1259 [dockMenu addItem:item]; |
| 1235 | 1260 |
| 1236 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); | 1261 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); |
| 1237 item.reset( | 1262 item.reset( |
| 1238 [[NSMenuItem alloc] initWithTitle:titleStr | 1263 [[NSMenuItem alloc] initWithTitle:titleStr |
| 1239 action:@selector(commandFromDock:) | 1264 action:@selector(commandFromDock:) |
| 1240 keyEquivalent:@""]); | 1265 keyEquivalent:@""]); |
| 1241 [item setTarget:self]; | 1266 [item setTarget:self]; |
| 1242 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; | 1267 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; |
| 1268 [item setEnabled:[self validateUserInterfaceItem:item]]; | |
| 1243 [dockMenu addItem:item]; | 1269 [dockMenu addItem:item]; |
| 1244 | 1270 |
| 1245 // TODO(rickcam): Mock out BackgroundApplicationListModel, then add unit | 1271 // TODO(rickcam): Mock out BackgroundApplicationListModel, then add unit |
| 1246 // tests which use the mock in place of the profile-initialized model. | 1272 // tests which use the mock in place of the profile-initialized model. |
| 1247 | 1273 |
| 1248 // Avoid breaking unit tests which have no profile. | 1274 // Avoid breaking unit tests which have no profile. |
| 1249 if (profile) { | 1275 if (profile) { |
| 1250 BackgroundApplicationListModel applications(profile); | 1276 BackgroundApplicationListModel applications(profile); |
| 1251 if (applications.size()) { | 1277 if (applications.size()) { |
| 1252 int position = 0; | 1278 int position = 0; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1318 | 1344 |
| 1319 //--------------------------------------------------------------------------- | 1345 //--------------------------------------------------------------------------- |
| 1320 | 1346 |
| 1321 namespace app_controller_mac { | 1347 namespace app_controller_mac { |
| 1322 | 1348 |
| 1323 bool IsOpeningNewWindow() { | 1349 bool IsOpeningNewWindow() { |
| 1324 return g_is_opening_new_window; | 1350 return g_is_opening_new_window; |
| 1325 } | 1351 } |
| 1326 | 1352 |
| 1327 } // namespace app_controller_mac | 1353 } // namespace app_controller_mac |
| OLD | NEW |