| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 284 |
| 285 AppController* app_controller_; // Weak; owns us. | 285 AppController* app_controller_; // Weak; owns us. |
| 286 | 286 |
| 287 DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver); | 287 DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver); |
| 288 }; | 288 }; |
| 289 | 289 |
| 290 @implementation AppController | 290 @implementation AppController |
| 291 | 291 |
| 292 @synthesize startupComplete = startupComplete_; | 292 @synthesize startupComplete = startupComplete_; |
| 293 | 293 |
| 294 + (void)updateSigninItem:(id)signinItem | |
| 295 shouldShow:(BOOL)showSigninMenuItem | |
| 296 currentProfile:(Profile*)profile { | |
| 297 DCHECK([signinItem isKindOfClass:[NSMenuItem class]]); | |
| 298 NSMenuItem* signinMenuItem = static_cast<NSMenuItem*>(signinItem); | |
| 299 | |
| 300 // Look for a separator immediately after the menu item so it can be hidden | |
| 301 // or shown appropriately along with the signin menu item. | |
| 302 NSMenuItem* followingSeparator = nil; | |
| 303 NSMenu* menu = [signinItem menu]; | |
| 304 if (menu) { | |
| 305 NSInteger signinItemIndex = [menu indexOfItem:signinMenuItem]; | |
| 306 DCHECK_NE(signinItemIndex, -1); | |
| 307 if ((signinItemIndex + 1) < [menu numberOfItems]) { | |
| 308 NSMenuItem* menuItem = [menu itemAtIndex:(signinItemIndex + 1)]; | |
| 309 if ([menuItem isSeparatorItem]) { | |
| 310 followingSeparator = menuItem; | |
| 311 } | |
| 312 } | |
| 313 } | |
| 314 | |
| 315 base::string16 label = signin_ui_util::GetSigninMenuLabel(profile); | |
| 316 [signinMenuItem setTitle:l10n_util::FixUpWindowsStyleLabel(label)]; | |
| 317 [signinMenuItem setHidden:!showSigninMenuItem]; | |
| 318 [followingSeparator setHidden:!showSigninMenuItem]; | |
| 319 } | |
| 320 | |
| 321 - (void)dealloc { | 294 - (void)dealloc { |
| 322 [[closeTabMenuItem_ menu] setDelegate:nil]; | 295 [[closeTabMenuItem_ menu] setDelegate:nil]; |
| 323 [super dealloc]; | 296 [super dealloc]; |
| 324 } | 297 } |
| 325 | 298 |
| 326 // This method is called very early in application startup (ie, before | 299 // This method is called very early in application startup (ie, before |
| 327 // the profile is loaded or any preferences have been registered). Defer any | 300 // the profile is loaded or any preferences have been registered). Defer any |
| 328 // user-data initialization until -applicationDidFinishLaunching:. | 301 // user-data initialization until -applicationDidFinishLaunching:. |
| 329 - (void)awakeFromNib { | 302 - (void)awakeFromNib { |
| 330 MacStartupProfiler::GetInstance()->Profile( | 303 MacStartupProfiler::GetInstance()->Profile( |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 case IDC_SHOW_HISTORY: | 888 case IDC_SHOW_HISTORY: |
| 916 case IDC_SHOW_BOOKMARK_MANAGER: | 889 case IDC_SHOW_BOOKMARK_MANAGER: |
| 917 enable = ![self keyWindowIsModal]; | 890 enable = ![self keyWindowIsModal]; |
| 918 break; | 891 break; |
| 919 // Browser-level items that open in new windows. | 892 // Browser-level items that open in new windows. |
| 920 case IDC_TASK_MANAGER: | 893 case IDC_TASK_MANAGER: |
| 921 // Allow the user to open a new window if there's a window-modal | 894 // Allow the user to open a new window if there's a window-modal |
| 922 // dialog. | 895 // dialog. |
| 923 enable = ![self keyWindowIsModal]; | 896 enable = ![self keyWindowIsModal]; |
| 924 break; | 897 break; |
| 925 case IDC_SHOW_SYNC_SETUP: { | |
| 926 Profile* lastProfile = [self lastProfile]; | |
| 927 // The profile may be NULL during shutdown -- see | |
| 928 // http://code.google.com/p/chromium/issues/detail?id=43048 . | |
| 929 // | |
| 930 // TODO(akalin,viettrungluu): Figure out whether this method | |
| 931 // can be prevented from being called if lastProfile is | |
| 932 // NULL. | |
| 933 if (!lastProfile) { | |
| 934 LOG(WARNING) | |
| 935 << "NULL lastProfile detected -- not doing anything"; | |
| 936 break; | |
| 937 } | |
| 938 SigninManager* signin = SigninManagerFactory::GetForProfile( | |
| 939 lastProfile->GetOriginalProfile()); | |
| 940 enable = signin->IsSigninAllowed() && ![self keyWindowIsModal]; | |
| 941 [AppController updateSigninItem:item | |
| 942 shouldShow:enable | |
| 943 currentProfile:lastProfile]; | |
| 944 break; | |
| 945 } | |
| 946 default: | 898 default: |
| 947 enable = menuState_->IsCommandEnabled(tag) ? | 899 enable = menuState_->IsCommandEnabled(tag) ? |
| 948 ![self keyWindowIsModal] : NO; | 900 ![self keyWindowIsModal] : NO; |
| 949 } | 901 } |
| 950 } | 902 } |
| 951 | 903 |
| 952 // "Show as tab" should only appear when the current window is a popup. | 904 // "Show as tab" should only appear when the current window is a popup. |
| 953 // Since |validateUserInterfaceItem:| is called only when there are no | 905 // Since |validateUserInterfaceItem:| is called only when there are no |
| 954 // key windows, we should just hide this. | 906 // key windows, we should just hide this. |
| 955 // This is handled outside of the switch statement because we want to hide | 907 // This is handled outside of the switch statement because we want to hide |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 chrome::ShowExtensions(browser, std::string()); | 1033 chrome::ShowExtensions(browser, std::string()); |
| 1082 else | 1034 else |
| 1083 chrome::OpenExtensionsWindow(lastProfile); | 1035 chrome::OpenExtensionsWindow(lastProfile); |
| 1084 break; | 1036 break; |
| 1085 case IDC_HELP_PAGE_VIA_MENU: | 1037 case IDC_HELP_PAGE_VIA_MENU: |
| 1086 if (Browser* browser = ActivateBrowser(lastProfile)) | 1038 if (Browser* browser = ActivateBrowser(lastProfile)) |
| 1087 chrome::ShowHelp(browser, chrome::HELP_SOURCE_MENU); | 1039 chrome::ShowHelp(browser, chrome::HELP_SOURCE_MENU); |
| 1088 else | 1040 else |
| 1089 chrome::OpenHelpWindow(lastProfile, chrome::HELP_SOURCE_MENU); | 1041 chrome::OpenHelpWindow(lastProfile, chrome::HELP_SOURCE_MENU); |
| 1090 break; | 1042 break; |
| 1091 case IDC_SHOW_SYNC_SETUP: | |
| 1092 if (Browser* browser = ActivateBrowser(lastProfile)) { | |
| 1093 chrome::ShowBrowserSigninOrSettings( | |
| 1094 browser, signin_metrics::AccessPoint::ACCESS_POINT_MENU); | |
| 1095 } else { | |
| 1096 chrome::OpenSyncSetupWindow( | |
| 1097 lastProfile, signin_metrics::AccessPoint::ACCESS_POINT_MENU); | |
| 1098 } | |
| 1099 break; | |
| 1100 case IDC_TASK_MANAGER: | 1043 case IDC_TASK_MANAGER: |
| 1101 chrome::OpenTaskManager(NULL); | 1044 chrome::OpenTaskManager(NULL); |
| 1102 break; | 1045 break; |
| 1103 case IDC_OPTIONS: | 1046 case IDC_OPTIONS: |
| 1104 [self showPreferences:sender]; | 1047 [self showPreferences:sender]; |
| 1105 break; | 1048 break; |
| 1106 } | 1049 } |
| 1107 } | 1050 } |
| 1108 | 1051 |
| 1109 // Run a (background) application in a new tab. | 1052 // Run a (background) application in a new tab. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 menuState_->UpdateCommandEnabled(IDC_FOCUS_SEARCH, true); | 1185 menuState_->UpdateCommandEnabled(IDC_FOCUS_SEARCH, true); |
| 1243 menuState_->UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); | 1186 menuState_->UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); |
| 1244 menuState_->UpdateCommandEnabled(IDC_SHOW_HISTORY, true); | 1187 menuState_->UpdateCommandEnabled(IDC_SHOW_HISTORY, true); |
| 1245 menuState_->UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 1188 menuState_->UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 1246 menuState_->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); | 1189 menuState_->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, true); |
| 1247 menuState_->UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 1190 menuState_->UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
| 1248 menuState_->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); | 1191 menuState_->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); |
| 1249 #if defined(GOOGLE_CHROME_BUILD) | 1192 #if defined(GOOGLE_CHROME_BUILD) |
| 1250 menuState_->UpdateCommandEnabled(IDC_FEEDBACK, true); | 1193 menuState_->UpdateCommandEnabled(IDC_FEEDBACK, true); |
| 1251 #endif | 1194 #endif |
| 1252 menuState_->UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, true); | |
| 1253 menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true); | 1195 menuState_->UpdateCommandEnabled(IDC_TASK_MANAGER, true); |
| 1254 } | 1196 } |
| 1255 | 1197 |
| 1256 // Conditionally adds the Profile menu to the main menu bar. | 1198 // Conditionally adds the Profile menu to the main menu bar. |
| 1257 - (void)initProfileMenu { | 1199 - (void)initProfileMenu { |
| 1258 NSMenu* mainMenu = [NSApp mainMenu]; | 1200 NSMenu* mainMenu = [NSApp mainMenu]; |
| 1259 NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; | 1201 NSMenuItem* profileMenu = [mainMenu itemWithTag:IDC_PROFILE_MAIN_MENU]; |
| 1260 | 1202 |
| 1261 if (!profiles::IsMultipleProfilesEnabled()) { | 1203 if (!profiles::IsMultipleProfilesEnabled()) { |
| 1262 [mainMenu removeItem:profileMenu]; | 1204 [mainMenu removeItem:profileMenu]; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1665 | 1607 |
| 1666 //--------------------------------------------------------------------------- | 1608 //--------------------------------------------------------------------------- |
| 1667 | 1609 |
| 1668 namespace app_controller_mac { | 1610 namespace app_controller_mac { |
| 1669 | 1611 |
| 1670 bool IsOpeningNewWindow() { | 1612 bool IsOpeningNewWindow() { |
| 1671 return g_is_opening_new_window; | 1613 return g_is_opening_new_window; |
| 1672 } | 1614 } |
| 1673 | 1615 |
| 1674 } // namespace app_controller_mac | 1616 } // namespace app_controller_mac |
| OLD | NEW |