OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 // Avoid breaking unit tests which have no profile. | |
Andrew T Wilson (Slow)
2010/12/21 17:49:09
Ultimately we should have a test of some sort once
The wrong rickcam account
2010/12/21 19:20:09
Done.
| |
1199 if (profile) { | |
1200 int position = 0; | |
1201 BackgroundApplicationListModel applications(profile); | |
1202 for (ExtensionList::const_iterator cursor = applications.begin(); | |
1203 cursor != applications.end(); | |
1204 ++cursor, ++position) { | |
1205 DCHECK(position == applications.GetPosition(*cursor)); | |
1206 scoped_nsobject<NSMenuItem> appItem([[NSMenuItem alloc] | |
1207 initWithTitle:base::SysUTF16ToNSString(UTF8ToUTF16((*cursor)->name())) | |
1208 action:@selector(commandFromDock:) | |
1209 keyEquivalent:@""]); | |
1210 [appItem setTarget:self]; | |
1211 [appItem setTag:position]; | |
1212 [dockMenu addItem:appItem]; | |
1213 } | |
1214 if (applications.begin() != applications.end()) { | |
1215 NSMenuItem* sepItem = [[NSMenuItem separatorItem] init]; | |
1216 [dockMenu addItem:sepItem]; | |
1217 } | |
1218 } | |
1219 | |
1172 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); | 1220 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); |
1173 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] | 1221 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] |
1174 initWithTitle:titleStr | 1222 initWithTitle:titleStr |
1175 action:@selector(newWindowFromDock:) | 1223 action:@selector(commandFromDock:) |
1176 keyEquivalent:@""]); | 1224 keyEquivalent:@""]); |
1177 [item setTarget:self]; | 1225 [item setTarget:self]; |
1178 [item setTag:IDC_NEW_WINDOW]; | 1226 [item setTag:IDC_NEW_WINDOW]; |
1179 [dockMenu addItem:item]; | 1227 [dockMenu addItem:item]; |
1180 | 1228 |
1181 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); | 1229 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); |
1182 item.reset([[NSMenuItem alloc] initWithTitle:titleStr | 1230 item.reset([[NSMenuItem alloc] initWithTitle:titleStr |
1183 action:@selector(newWindowFromDock:) | 1231 action:@selector(commandFromDock:) |
1184 keyEquivalent:@""]); | 1232 keyEquivalent:@""]); |
1185 [item setTarget:self]; | 1233 [item setTarget:self]; |
1186 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; | 1234 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; |
1187 [dockMenu addItem:item]; | 1235 [dockMenu addItem:item]; |
1188 | 1236 |
1189 return dockMenu; | 1237 return dockMenu; |
1190 } | 1238 } |
1191 | 1239 |
1192 - (const std::vector<GURL>&)startupUrls { | 1240 - (const std::vector<GURL>&)startupUrls { |
1193 return startupUrls_; | 1241 return startupUrls_; |
(...skipping 15 matching lines...) Expand all Loading... | |
1209 [appController showPreferencesWindow:nil page:page profile:profile]; | 1257 [appController showPreferencesWindow:nil page:page profile:profile]; |
1210 } | 1258 } |
1211 | 1259 |
1212 namespace app_controller_mac { | 1260 namespace app_controller_mac { |
1213 | 1261 |
1214 bool IsOpeningNewWindow() { | 1262 bool IsOpeningNewWindow() { |
1215 return g_is_opening_new_window; | 1263 return g_is_opening_new_window; |
1216 } | 1264 } |
1217 | 1265 |
1218 } // namespace app_controller_mac | 1266 } // namespace app_controller_mac |
OLD | NEW |