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