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 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 enable = YES; | 800 enable = YES; |
801 } else if (action == @selector(showPreferences:)) { | 801 } else if (action == @selector(showPreferences:)) { |
802 enable = YES; | 802 enable = YES; |
803 } else if (action == @selector(orderFrontStandardAboutPanel:)) { | 803 } else if (action == @selector(orderFrontStandardAboutPanel:)) { |
804 enable = YES; | 804 enable = YES; |
805 } else if (action == @selector(commandFromDock:)) { | 805 } else if (action == @selector(commandFromDock:)) { |
806 enable = YES; | 806 enable = YES; |
807 } else if (action == @selector(toggleConfirmToQuit:)) { | 807 } else if (action == @selector(toggleConfirmToQuit:)) { |
808 [self updateConfirmToQuitPrefMenuItem:static_cast<NSMenuItem*>(item)]; | 808 [self updateConfirmToQuitPrefMenuItem:static_cast<NSMenuItem*>(item)]; |
809 enable = YES; | 809 enable = YES; |
| 810 } else if (action == @selector(executeApplication:)) { |
| 811 enable = YES; |
810 } | 812 } |
811 return enable; | 813 return enable; |
812 } | 814 } |
813 | 815 |
814 // Called when the user picks a menu item when there are no key windows, or when | 816 // Called when the user picks a menu item when there are no key windows, or when |
815 // there is no foreground browser window. Calls through to the browser object to | 817 // there is no foreground browser window. Calls through to the browser object to |
816 // execute the command. This assumes that the command is supported and doesn't | 818 // execute the command. This assumes that the command is supported and doesn't |
817 // check, otherwise it should have been disabled in the UI in | 819 // check, otherwise it should have been disabled in the UI in |
818 // |-validateUserInterfaceItem:|. | 820 // |-validateUserInterfaceItem:|. |
819 - (void)commandDispatch:(id)sender { | 821 - (void)commandDispatch:(id)sender { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 else | 927 else |
926 chrome::OpenSyncSetupWindow(lastProfile, SyncPromoUI::SOURCE_MENU); | 928 chrome::OpenSyncSetupWindow(lastProfile, SyncPromoUI::SOURCE_MENU); |
927 break; | 929 break; |
928 case IDC_TASK_MANAGER: | 930 case IDC_TASK_MANAGER: |
929 content::RecordAction(UserMetricsAction("TaskManager")); | 931 content::RecordAction(UserMetricsAction("TaskManager")); |
930 TaskManagerMac::Show(false); | 932 TaskManagerMac::Show(false); |
931 break; | 933 break; |
932 case IDC_OPTIONS: | 934 case IDC_OPTIONS: |
933 [self showPreferences:sender]; | 935 [self showPreferences:sender]; |
934 break; | 936 break; |
935 default: | |
936 // Background Applications use dynamic values that must be less than the | |
937 // smallest value among the predefined IDC_* labels. | |
938 if ([sender tag] < IDC_MinimumLabelValue) | |
939 [self executeApplication:sender]; | |
940 break; | |
941 } | 937 } |
942 } | 938 } |
943 | 939 |
944 // Run a (background) application in a new tab. | 940 // Run a (background) application in a new tab. |
945 - (void)executeApplication:(id)sender { | 941 - (void)executeApplication:(id)sender { |
946 NSInteger tag = [sender tag]; | 942 NSInteger tag = [sender tag]; |
947 Profile* profile = [self lastProfile]; | 943 Profile* profile = [self lastProfile]; |
948 DCHECK(profile); | 944 DCHECK(profile); |
949 BackgroundApplicationListModel applications(profile); | 945 BackgroundApplicationListModel applications(profile); |
950 DCHECK(tag >= 0 && | 946 DCHECK(tag >= 0 && |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 | 1277 |
1282 // Avoid breaking unit tests which have no profile. | 1278 // Avoid breaking unit tests which have no profile. |
1283 if (profile) { | 1279 if (profile) { |
1284 BackgroundApplicationListModel applications(profile); | 1280 BackgroundApplicationListModel applications(profile); |
1285 if (applications.size()) { | 1281 if (applications.size()) { |
1286 int position = 0; | 1282 int position = 0; |
1287 NSString* menuStr = | 1283 NSString* menuStr = |
1288 l10n_util::GetNSStringWithFixup(IDS_BACKGROUND_APPS_MAC); | 1284 l10n_util::GetNSStringWithFixup(IDS_BACKGROUND_APPS_MAC); |
1289 scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:menuStr]); | 1285 scoped_nsobject<NSMenu> appMenu([[NSMenu alloc] initWithTitle:menuStr]); |
1290 for (extensions::ExtensionList::const_iterator cursor = | 1286 for (extensions::ExtensionList::const_iterator cursor = |
1291 applications.begin(); | 1287 applications.begin(); |
1292 cursor != applications.end(); | 1288 cursor != applications.end(); |
1293 ++cursor, ++position) { | 1289 ++cursor, ++position) { |
1294 DCHECK_EQ(applications.GetPosition(*cursor), position); | 1290 DCHECK_EQ(applications.GetPosition(*cursor), position); |
1295 NSString* itemStr = | 1291 NSString* itemStr = |
1296 base::SysUTF16ToNSString(UTF8ToUTF16((*cursor)->name())); | 1292 base::SysUTF16ToNSString(UTF8ToUTF16((*cursor)->name())); |
1297 scoped_nsobject<NSMenuItem> appItem([[NSMenuItem alloc] | 1293 scoped_nsobject<NSMenuItem> appItem([[NSMenuItem alloc] |
1298 initWithTitle:itemStr | 1294 initWithTitle:itemStr |
1299 action:@selector(commandFromDock:) | 1295 action:@selector(executeApplication:) |
1300 keyEquivalent:@""]); | 1296 keyEquivalent:@""]); |
1301 [appItem setTarget:self]; | 1297 [appItem setTarget:self]; |
1302 [appItem setTag:position]; | 1298 [appItem setTag:position]; |
1303 [appMenu addItem:appItem]; | 1299 [appMenu addItem:appItem]; |
1304 } | 1300 } |
| 1301 |
1305 scoped_nsobject<NSMenuItem> appMenuItem([[NSMenuItem alloc] | 1302 scoped_nsobject<NSMenuItem> appMenuItem([[NSMenuItem alloc] |
1306 initWithTitle:menuStr | 1303 initWithTitle:menuStr |
1307 action:@selector(commandFromDock:) | 1304 action:@selector(executeApplication:) |
1308 keyEquivalent:@""]); | 1305 keyEquivalent:@""]); |
1309 [appMenuItem setTarget:self]; | 1306 [appMenuItem setTarget:self]; |
1310 [appMenuItem setTag:position]; | 1307 [appMenuItem setTag:IDC_VIEW_BACKGROUND_PAGES]; |
1311 [appMenuItem setSubmenu:appMenu]; | 1308 [appMenuItem setSubmenu:appMenu]; |
1312 [dockMenu addItem:appMenuItem]; | 1309 [dockMenu addItem:appMenuItem]; |
1313 } | 1310 } |
1314 } | 1311 } |
1315 | 1312 |
1316 return dockMenu; | 1313 return dockMenu; |
1317 } | 1314 } |
1318 | 1315 |
1319 - (const std::vector<GURL>&)startupUrls { | 1316 - (const std::vector<GURL>&)startupUrls { |
1320 return startupUrls_; | 1317 return startupUrls_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 | 1349 |
1353 //--------------------------------------------------------------------------- | 1350 //--------------------------------------------------------------------------- |
1354 | 1351 |
1355 namespace app_controller_mac { | 1352 namespace app_controller_mac { |
1356 | 1353 |
1357 bool IsOpeningNewWindow() { | 1354 bool IsOpeningNewWindow() { |
1358 return g_is_opening_new_window; | 1355 return g_is_opening_new_window; |
1359 } | 1356 } |
1360 | 1357 |
1361 } // namespace app_controller_mac | 1358 } // namespace app_controller_mac |
OLD | NEW |