Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 5908003: Added Background Application entries to Dock menu (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added TODO for mocking BackgroundApplicationListModel Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/app/chrome_command_ids.h ('k') | chrome/browser/app_controller_mac_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/l10n_util_mac.h" 8 #include "app/l10n_util_mac.h"
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/mac_util.h" 12 #include "base/mac_util.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/background_application_list_model.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/browser_shutdown.h" 19 #include "chrome/browser/browser_shutdown.h"
19 #include "chrome/browser/browser_thread.h" 20 #include "chrome/browser/browser_thread.h"
20 #include "chrome/browser/command_updater.h" 21 #include "chrome/browser/command_updater.h"
21 #include "chrome/browser/download/download_manager.h" 22 #include "chrome/browser/download/download_manager.h"
22 #include "chrome/browser/metrics/user_metrics.h" 23 #include "chrome/browser/metrics/user_metrics.h"
23 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/printing/print_job_manager.h" 25 #include "chrome/browser/printing/print_job_manager.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/sessions/tab_restore_service.h" 27 #include "chrome/browser/sessions/tab_restore_service.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 - (void)openUrls:(const std::vector<GURL>&)urls; 148 - (void)openUrls:(const std::vector<GURL>&)urls;
148 - (void)getUrl:(NSAppleEventDescriptor*)event 149 - (void)getUrl:(NSAppleEventDescriptor*)event
149 withReply:(NSAppleEventDescriptor*)reply; 150 withReply:(NSAppleEventDescriptor*)reply;
150 - (void)windowLayeringDidChange:(NSNotification*)inNotification; 151 - (void)windowLayeringDidChange:(NSNotification*)inNotification;
151 - (void)checkForAnyKeyWindows; 152 - (void)checkForAnyKeyWindows;
152 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; 153 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
153 - (BOOL)shouldQuitWithInProgressDownloads; 154 - (BOOL)shouldQuitWithInProgressDownloads;
154 - (void)showPreferencesWindow:(id)sender 155 - (void)showPreferencesWindow:(id)sender
155 page:(OptionsPage)page 156 page:(OptionsPage)page
156 profile:(Profile*)profile; 157 profile:(Profile*)profile;
158 - (void)executeApplication:(id)sender;
157 @end 159 @end
158 160
159 @implementation AppController 161 @implementation AppController
160 162
161 @synthesize startupComplete = startupComplete_; 163 @synthesize startupComplete = startupComplete_;
162 164
163 // This method is called very early in application startup (ie, before 165 // This method is called very early in application startup (ie, before
164 // the profile is loaded or any preferences have been registered). Defer any 166 // the profile is loaded or any preferences have been registered). Defer any
165 // user-data initialization until -applicationDidFinishLaunching:. 167 // user-data initialization until -applicationDidFinishLaunching:.
166 - (void)awakeFromNib { 168 - (void)awakeFromNib {
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 enable = menuState_->IsCommandEnabled(tag) ? 787 enable = menuState_->IsCommandEnabled(tag) ?
786 [self keyWindowIsNotModal] : NO; 788 [self keyWindowIsNotModal] : NO;
787 } 789 }
788 } 790 }
789 } else if (action == @selector(terminate:)) { 791 } else if (action == @selector(terminate:)) {
790 enable = YES; 792 enable = YES;
791 } else if (action == @selector(showPreferences:)) { 793 } else if (action == @selector(showPreferences:)) {
792 enable = YES; 794 enable = YES;
793 } else if (action == @selector(orderFrontStandardAboutPanel:)) { 795 } else if (action == @selector(orderFrontStandardAboutPanel:)) {
794 enable = YES; 796 enable = YES;
795 } else if (action == @selector(newWindowFromDock:)) { 797 } else if (action == @selector(commandFromDock:)) {
796 enable = YES; 798 enable = YES;
797 } 799 }
798 return enable; 800 return enable;
799 } 801 }
800 802
801 // Called when the user picks a menu item when there are no key windows, or when 803 // Called when the user picks a menu item when there are no key windows, or when
802 // there is no foreground browser window. Calls through to the browser object to 804 // there is no foreground browser window. Calls through to the browser object to
803 // execute the command. This assumes that the command is supported and doesn't 805 // execute the command. This assumes that the command is supported and doesn't
804 // check, otherwise it should have been disabled in the UI in 806 // check, otherwise it should have been disabled in the UI in
805 // |-validateUserInterfaceItem:|. 807 // |-validateUserInterfaceItem:|.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 defaultProfile, ProfileSyncService::START_FROM_WRENCH); 923 defaultProfile, ProfileSyncService::START_FROM_WRENCH);
922 break; 924 break;
923 case IDC_TASK_MANAGER: 925 case IDC_TASK_MANAGER:
924 UserMetrics::RecordAction(UserMetricsAction("TaskManager"), 926 UserMetrics::RecordAction(UserMetricsAction("TaskManager"),
925 defaultProfile); 927 defaultProfile);
926 TaskManagerMac::Show(); 928 TaskManagerMac::Show();
927 break; 929 break;
928 case IDC_OPTIONS: 930 case IDC_OPTIONS:
929 [self showPreferences:sender]; 931 [self showPreferences:sender];
930 break; 932 break;
933 default:
934 // Background Applications use dynamic values that must be less than the
935 // smallest value among the predefined IDC_* labels.
936 if ([sender tag] < IDC_MinimumLabelValue)
937 [self executeApplication:sender];
938 break;
931 } 939 }
932 } 940 }
933 941
942 // Run a (background) application in a new tab.
943 - (void)executeApplication:(id)sender {
944 NSInteger tag = [sender tag];
945 Profile* profile = [self defaultProfile];
946 DCHECK(profile);
947 BackgroundApplicationListModel applications(profile);
948 DCHECK(tag >= 0 &&
949 tag < static_cast<int>(applications.size()));
950 Browser* browser = BrowserList::GetLastActive();
951 if (!browser) {
952 Browser::OpenEmptyWindow(profile);
953 browser = BrowserList::GetLastActive();
954 }
955 const Extension* extension = applications.GetExtension(tag);
956 browser->OpenApplicationTab(profile, extension, NULL);
957 }
958
934 // Same as |-commandDispatch:|, but executes commands using a disposition 959 // Same as |-commandDispatch:|, but executes commands using a disposition
935 // determined by the key flags. This will get called in the case where the 960 // determined by the key flags. This will get called in the case where the
936 // frontmost window is not a browser window, and the user has command-clicked 961 // frontmost window is not a browser window, and the user has command-clicked
937 // a button in a background browser window whose action is 962 // a button in a background browser window whose action is
938 // |-commandDispatchUsingKeyModifiers:| 963 // |-commandDispatchUsingKeyModifiers:|
939 - (void)commandDispatchUsingKeyModifiers:(id)sender { 964 - (void)commandDispatchUsingKeyModifiers:(id)sender {
940 DCHECK(sender); 965 DCHECK(sender);
941 if ([sender respondsToSelector:@selector(window)]) { 966 if ([sender respondsToSelector:@selector(window)]) {
942 id delegate = [[sender window] windowController]; 967 id delegate = [[sender window] windowController];
943 if ([delegate isKindOfClass:[BrowserWindowController class]]) { 968 if ([delegate isKindOfClass:[BrowserWindowController class]]) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 addObserver:self 1180 addObserver:self
1156 selector:@selector(aboutWindowClosed:) 1181 selector:@selector(aboutWindowClosed:)
1157 name:NSWindowWillCloseNotification 1182 name:NSWindowWillCloseNotification
1158 object:[aboutController_ window]]; 1183 object:[aboutController_ window]];
1159 } 1184 }
1160 1185
1161 [aboutController_ showWindow:self]; 1186 [aboutController_ showWindow:self];
1162 } 1187 }
1163 1188
1164 // Explicitly bring to the foreground when creating new windows from the dock. 1189 // Explicitly bring to the foreground when creating new windows from the dock.
1165 - (void)newWindowFromDock:(id)sender { 1190 - (void)commandFromDock:(id)sender {
1166 [NSApp activateIgnoringOtherApps:YES]; 1191 [NSApp activateIgnoringOtherApps:YES];
1167 [self commandDispatch:sender]; 1192 [self commandDispatch:sender];
1168 } 1193 }
1169 1194
1170 - (NSMenu*)applicationDockMenu:(NSApplication*)sender { 1195 - (NSMenu*)applicationDockMenu:(NSApplication*)sender {
1171 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease]; 1196 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease];
1197 Profile* profile = [self defaultProfile];
1198
1199 // TODO(rickcam): Mock out BackgroundApplicationListModel, then add unit
1200 // tests which use the mock in place of the profile-initialized model.
1201
1202 // Avoid breaking unit tests which have no profile.
1203 if (profile) {
1204 int position = 0;
1205 BackgroundApplicationListModel applications(profile);
1206 for (ExtensionList::const_iterator cursor = applications.begin();
1207 cursor != applications.end();
1208 ++cursor, ++position) {
1209 DCHECK(position == applications.GetPosition(*cursor));
1210 scoped_nsobject<NSMenuItem> appItem([[NSMenuItem alloc]
1211 initWithTitle:base::SysUTF16ToNSString(UTF8ToUTF16((*cursor)->name()))
1212 action:@selector(commandFromDock:)
1213 keyEquivalent:@""]);
1214 [appItem setTarget:self];
1215 [appItem setTag:position];
1216 [dockMenu addItem:appItem];
1217 }
1218 if (applications.begin() != applications.end()) {
1219 NSMenuItem* sepItem = [[NSMenuItem separatorItem] init];
1220 [dockMenu addItem:sepItem];
1221 }
1222 }
1223
1172 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); 1224 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC);
1173 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] 1225 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc]
1174 initWithTitle:titleStr 1226 initWithTitle:titleStr
1175 action:@selector(newWindowFromDock:) 1227 action:@selector(commandFromDock:)
1176 keyEquivalent:@""]); 1228 keyEquivalent:@""]);
1177 [item setTarget:self]; 1229 [item setTarget:self];
1178 [item setTag:IDC_NEW_WINDOW]; 1230 [item setTag:IDC_NEW_WINDOW];
1179 [dockMenu addItem:item]; 1231 [dockMenu addItem:item];
1180 1232
1181 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); 1233 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC);
1182 item.reset([[NSMenuItem alloc] initWithTitle:titleStr 1234 item.reset([[NSMenuItem alloc] initWithTitle:titleStr
1183 action:@selector(newWindowFromDock:) 1235 action:@selector(commandFromDock:)
1184 keyEquivalent:@""]); 1236 keyEquivalent:@""]);
1185 [item setTarget:self]; 1237 [item setTarget:self];
1186 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; 1238 [item setTag:IDC_NEW_INCOGNITO_WINDOW];
1187 [dockMenu addItem:item]; 1239 [dockMenu addItem:item];
1188 1240
1189 return dockMenu; 1241 return dockMenu;
1190 } 1242 }
1191 1243
1192 - (const std::vector<GURL>&)startupUrls { 1244 - (const std::vector<GURL>&)startupUrls {
1193 return startupUrls_; 1245 return startupUrls_;
(...skipping 15 matching lines...) Expand all
1209 [appController showPreferencesWindow:nil page:page profile:profile]; 1261 [appController showPreferencesWindow:nil page:page profile:profile];
1210 } 1262 }
1211 1263
1212 namespace app_controller_mac { 1264 namespace app_controller_mac {
1213 1265
1214 bool IsOpeningNewWindow() { 1266 bool IsOpeningNewWindow() {
1215 return g_is_opening_new_window; 1267 return g_is_opening_new_window;
1216 } 1268 }
1217 1269
1218 } // namespace app_controller_mac 1270 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « chrome/app/chrome_command_ids.h ('k') | chrome/browser/app_controller_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698