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

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: Fixed indentation 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 | « no previous file | chrome/browser/background_application_list_model.cc » ('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 #import "base/worker_pool_mac.h" 16 #import "base/worker_pool_mac.h"
17 #include "chrome/app/chrome_command_ids.h" 17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/background_application_list_model.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_shutdown.h" 20 #include "chrome/browser/browser_shutdown.h"
20 #include "chrome/browser/browser_thread.h" 21 #include "chrome/browser/browser_thread.h"
21 #include "chrome/browser/command_updater.h" 22 #include "chrome/browser/command_updater.h"
22 #include "chrome/browser/download/download_manager.h" 23 #include "chrome/browser/download/download_manager.h"
23 #include "chrome/browser/metrics/user_metrics.h" 24 #include "chrome/browser/metrics/user_metrics.h"
24 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/printing/print_job_manager.h" 26 #include "chrome/browser/printing/print_job_manager.h"
26 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/sessions/tab_restore_service.h" 28 #include "chrome/browser/sessions/tab_restore_service.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 - (void)openUrls:(const std::vector<GURL>&)urls; 149 - (void)openUrls:(const std::vector<GURL>&)urls;
149 - (void)getUrl:(NSAppleEventDescriptor*)event 150 - (void)getUrl:(NSAppleEventDescriptor*)event
150 withReply:(NSAppleEventDescriptor*)reply; 151 withReply:(NSAppleEventDescriptor*)reply;
151 - (void)windowLayeringDidChange:(NSNotification*)inNotification; 152 - (void)windowLayeringDidChange:(NSNotification*)inNotification;
152 - (void)checkForAnyKeyWindows; 153 - (void)checkForAnyKeyWindows;
153 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; 154 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
154 - (BOOL)shouldQuitWithInProgressDownloads; 155 - (BOOL)shouldQuitWithInProgressDownloads;
155 - (void)showPreferencesWindow:(id)sender 156 - (void)showPreferencesWindow:(id)sender
156 page:(OptionsPage)page 157 page:(OptionsPage)page
157 profile:(Profile*)profile; 158 profile:(Profile*)profile;
159 - (void)executeApplication:(id)sender;
158 @end 160 @end
159 161
160 @implementation AppController 162 @implementation AppController
161 163
162 @synthesize startupComplete = startupComplete_; 164 @synthesize startupComplete = startupComplete_;
163 165
164 // This method is called very early in application startup (ie, before 166 // This method is called very early in application startup (ie, before
165 // the profile is loaded or any preferences have been registered). Defer any 167 // the profile is loaded or any preferences have been registered). Defer any
166 // user-data initialization until -applicationDidFinishLaunching:. 168 // user-data initialization until -applicationDidFinishLaunching:.
167 - (void)awakeFromNib { 169 - (void)awakeFromNib {
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 defaultProfile, ProfileSyncService::START_FROM_WRENCH); 933 defaultProfile, ProfileSyncService::START_FROM_WRENCH);
932 break; 934 break;
933 case IDC_TASK_MANAGER: 935 case IDC_TASK_MANAGER:
934 UserMetrics::RecordAction(UserMetricsAction("TaskManager"), 936 UserMetrics::RecordAction(UserMetricsAction("TaskManager"),
935 defaultProfile); 937 defaultProfile);
936 TaskManagerMac::Show(); 938 TaskManagerMac::Show();
937 break; 939 break;
938 case IDC_OPTIONS: 940 case IDC_OPTIONS:
939 [self showPreferences:sender]; 941 [self showPreferences:sender];
940 break; 942 break;
943 default:
944 [self executeApplication:sender];
Andrew T Wilson (Slow) 2010/12/16 02:18:25 Is there any assert we could have here to make sur
The wrong rickcam account 2010/12/16 18:50:58 Done . . . provided that you like the approach tha
941 } 945 }
942 } 946 }
943 947
948 // Run a (background) application in a new tab.
949 - (void)executeApplication:(id)sender {
950 NSInteger tag = [sender tag];
951 Profile* profile = [self defaultProfile];
952 DCHECK(profile);
953 BackgroundApplicationListModel applications(profile);
954 DCHECK(tag >= 0 &&
955 tag < static_cast<int>(applications.size()));
956 Browser* browser = BrowserList::GetLastActive();
957 if (!browser) {
958 Browser::OpenEmptyWindow(profile);
959 browser = BrowserList::GetLastActive();
960 }
961 const Extension* extension = applications.GetExtension(tag);
962 browser->OpenApplicationTab(profile, extension, NULL);
963 }
964
944 // Same as |-commandDispatch:|, but executes commands using a disposition 965 // Same as |-commandDispatch:|, but executes commands using a disposition
945 // determined by the key flags. This will get called in the case where the 966 // determined by the key flags. This will get called in the case where the
946 // frontmost window is not a browser window, and the user has command-clicked 967 // frontmost window is not a browser window, and the user has command-clicked
947 // a button in a background browser window whose action is 968 // a button in a background browser window whose action is
948 // |-commandDispatchUsingKeyModifiers:| 969 // |-commandDispatchUsingKeyModifiers:|
949 - (void)commandDispatchUsingKeyModifiers:(id)sender { 970 - (void)commandDispatchUsingKeyModifiers:(id)sender {
950 DCHECK(sender); 971 DCHECK(sender);
951 if ([sender respondsToSelector:@selector(window)]) { 972 if ([sender respondsToSelector:@selector(window)]) {
952 id delegate = [[sender window] windowController]; 973 id delegate = [[sender window] windowController];
953 if ([delegate isKindOfClass:[BrowserWindowController class]]) { 974 if ([delegate isKindOfClass:[BrowserWindowController class]]) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 } 1193 }
1173 1194
1174 // Explicitly bring to the foreground when creating new windows from the dock. 1195 // Explicitly bring to the foreground when creating new windows from the dock.
1175 - (void)newWindowFromDock:(id)sender { 1196 - (void)newWindowFromDock:(id)sender {
1176 [NSApp activateIgnoringOtherApps:YES]; 1197 [NSApp activateIgnoringOtherApps:YES];
1177 [self commandDispatch:sender]; 1198 [self commandDispatch:sender];
1178 } 1199 }
1179 1200
1180 - (NSMenu*)applicationDockMenu:(NSApplication*)sender { 1201 - (NSMenu*)applicationDockMenu:(NSApplication*)sender {
1181 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease]; 1202 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease];
1182 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); 1203 NSString* titleStr = NULL;
Andrew T Wilson (Slow) 2010/12/16 02:18:25 Should we use nil instead of NULL here? Not sure a
The wrong rickcam account 2010/12/16 18:50:58 Yes. Well, as best as I can tell anyway. I didn'
1183 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] 1204 scoped_nsobject<NSMenuItem> item(NULL);
1184 initWithTitle:titleStr 1205
Andrew T Wilson (Slow) 2010/12/16 02:18:25 I was confused by us using titleStr/item up here a
The wrong rickcam account 2010/12/16 18:50:58 Done.
1185 action:@selector(newWindowFromDock:) 1206 Profile* profile = [self defaultProfile];
1186 keyEquivalent:@""]); 1207 DCHECK(profile);
1208 int position = 0;
1209 BackgroundApplicationListModel applications(profile);
1210 if (applications.begin() != applications.end()) {
Andrew T Wilson (Slow) 2010/12/16 02:18:25 I wonder if it's cleaner to move the for loop outs
The wrong rickcam account 2010/12/16 18:50:58 Done. I saw the purpose as "avoiding the whole bl
1211 for (ExtensionList::const_iterator cursor = applications.begin();
The wrong rickcam account 2010/12/16 01:22:26 Need to indent the following two lines a bit more.
1212 cursor != applications.end();
1213 ++cursor, ++position) {
1214 int sort_position = applications.GetPosition(*cursor);
1215 DCHECK(sort_position == position);
Andrew T Wilson (Slow) 2010/12/16 02:18:25 I dimly recall talking about this before - why can
The wrong rickcam account 2010/12/16 18:50:58 Done. In fact, I think I missed that bit of clean
1216 const std::string& name = (*cursor)->name();
1217 string16 label = ASCIIToUTF16(name);
Andrew T Wilson (Slow) 2010/12/16 02:18:25 This seems weird to me. Should this be UTF8ToUTF16
The wrong rickcam account 2010/12/16 18:50:58 Done.
1218 titleStr = l10n_util::FixUpWindowsStyleLabel(label);
Andrew T Wilson (Slow) 2010/12/16 02:18:25 I'm not sure that we should call this - I think th
The wrong rickcam account 2010/12/16 18:50:58 Done. Swtiched to base::SysUTF16ToNSString which
1219 item.reset([[NSMenuItem alloc] initWithTitle:titleStr
1220 action:@selector(newWindowFromDock:)
Andrew T Wilson (Slow) 2010/12/16 02:18:25 BTW, I'm wondering if newWindowFromDock should be
The wrong rickcam account 2010/12/16 18:50:58 Done.
1221 keyEquivalent:@""]);
1222 [item setTarget:self];
1223 [item setTag:position];
1224 [dockMenu addItem:item];
1225 }
1226 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC);
Andrew T Wilson (Slow) 2010/12/16 02:18:25 Remove this superfluous set of titleStr.
The wrong rickcam account 2010/12/16 18:50:58 Done.
1227 NSMenuItem* sepItem = [[NSMenuItem separatorItem] init];
1228 [dockMenu addItem:sepItem];
1229 }
1230 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC);
1231 item.reset([[NSMenuItem alloc] initWithTitle:titleStr
1232 action:@selector(newWindowFromDock:)
1233 keyEquivalent:@""]);
1187 [item setTarget:self]; 1234 [item setTarget:self];
1188 [item setTag:IDC_NEW_WINDOW]; 1235 [item setTag:IDC_NEW_WINDOW];
1189 [dockMenu addItem:item]; 1236 [dockMenu addItem:item];
1190 1237
1191 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); 1238 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC);
1192 item.reset([[NSMenuItem alloc] initWithTitle:titleStr 1239 item.reset([[NSMenuItem alloc] initWithTitle:titleStr
1193 action:@selector(newWindowFromDock:) 1240 action:@selector(newWindowFromDock:)
1194 keyEquivalent:@""]); 1241 keyEquivalent:@""]);
1195 [item setTarget:self]; 1242 [item setTarget:self];
1196 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; 1243 [item setTag:IDC_NEW_INCOGNITO_WINDOW];
(...skipping 22 matching lines...) Expand all
1219 [appController showPreferencesWindow:nil page:page profile:profile]; 1266 [appController showPreferencesWindow:nil page:page profile:profile];
1220 } 1267 }
1221 1268
1222 namespace app_controller_mac { 1269 namespace app_controller_mac {
1223 1270
1224 bool IsOpeningNewWindow() { 1271 bool IsOpeningNewWindow() {
1225 return g_is_opening_new_window; 1272 return g_is_opening_new_window;
1226 } 1273 }
1227 1274
1228 } // namespace app_controller_mac 1275 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/background_application_list_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698