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 #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 Loading... | |
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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 enable = menuState_->IsCommandEnabled(tag) ? | 797 enable = menuState_->IsCommandEnabled(tag) ? |
796 [self keyWindowIsNotModal] : NO; | 798 [self keyWindowIsNotModal] : NO; |
797 } | 799 } |
798 } | 800 } |
799 } else if (action == @selector(terminate:)) { | 801 } else if (action == @selector(terminate:)) { |
800 enable = YES; | 802 enable = YES; |
801 } else if (action == @selector(showPreferences:)) { | 803 } else if (action == @selector(showPreferences:)) { |
802 enable = YES; | 804 enable = YES; |
803 } else if (action == @selector(orderFrontStandardAboutPanel:)) { | 805 } else if (action == @selector(orderFrontStandardAboutPanel:)) { |
804 enable = YES; | 806 enable = YES; |
805 } else if (action == @selector(newWindowFromDock:)) { | 807 } else if (action == @selector(commandFromDock:)) { |
806 enable = YES; | 808 enable = YES; |
807 } | 809 } |
808 return enable; | 810 return enable; |
809 } | 811 } |
810 | 812 |
811 // Called when the user picks a menu item when there are no key windows, or when | 813 // Called when the user picks a menu item when there are no key windows, or when |
812 // there is no foreground browser window. Calls through to the browser object to | 814 // there is no foreground browser window. Calls through to the browser object to |
813 // execute the command. This assumes that the command is supported and doesn't | 815 // execute the command. This assumes that the command is supported and doesn't |
814 // check, otherwise it should have been disabled in the UI in | 816 // check, otherwise it should have been disabled in the UI in |
815 // |-validateUserInterfaceItem:|. | 817 // |-validateUserInterfaceItem:|. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Background Applications use dynamic values that must be less than the | |
945 // smallest value among the predefined IDC_* labels. | |
946 if ([sender tag] < IDC_MinimumLabelValue) | |
947 [self executeApplication:sender]; | |
948 break; | |
941 } | 949 } |
942 } | 950 } |
943 | 951 |
952 // Run a (background) application in a new tab. | |
953 - (void)executeApplication:(id)sender { | |
954 NSInteger tag = [sender tag]; | |
955 Profile* profile = [self defaultProfile]; | |
956 DCHECK(profile); | |
957 BackgroundApplicationListModel applications(profile); | |
958 DCHECK(tag >= 0 && | |
959 tag < static_cast<int>(applications.size())); | |
960 Browser* browser = BrowserList::GetLastActive(); | |
961 if (!browser) { | |
962 Browser::OpenEmptyWindow(profile); | |
963 browser = BrowserList::GetLastActive(); | |
964 } | |
965 const Extension* extension = applications.GetExtension(tag); | |
966 browser->OpenApplicationTab(profile, extension, NULL); | |
967 } | |
968 | |
944 // Same as |-commandDispatch:|, but executes commands using a disposition | 969 // Same as |-commandDispatch:|, but executes commands using a disposition |
945 // determined by the key flags. This will get called in the case where the | 970 // 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 | 971 // frontmost window is not a browser window, and the user has command-clicked |
947 // a button in a background browser window whose action is | 972 // a button in a background browser window whose action is |
948 // |-commandDispatchUsingKeyModifiers:| | 973 // |-commandDispatchUsingKeyModifiers:| |
949 - (void)commandDispatchUsingKeyModifiers:(id)sender { | 974 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
950 DCHECK(sender); | 975 DCHECK(sender); |
951 if ([sender respondsToSelector:@selector(window)]) { | 976 if ([sender respondsToSelector:@selector(window)]) { |
952 id delegate = [[sender window] windowController]; | 977 id delegate = [[sender window] windowController]; |
953 if ([delegate isKindOfClass:[BrowserWindowController class]]) { | 978 if ([delegate isKindOfClass:[BrowserWindowController class]]) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1165 addObserver:self | 1190 addObserver:self |
1166 selector:@selector(aboutWindowClosed:) | 1191 selector:@selector(aboutWindowClosed:) |
1167 name:NSWindowWillCloseNotification | 1192 name:NSWindowWillCloseNotification |
1168 object:[aboutController_ window]]; | 1193 object:[aboutController_ window]]; |
1169 } | 1194 } |
1170 | 1195 |
1171 [aboutController_ showWindow:self]; | 1196 [aboutController_ showWindow:self]; |
1172 } | 1197 } |
1173 | 1198 |
1174 // Explicitly bring to the foreground when creating new windows from the dock. | 1199 // Explicitly bring to the foreground when creating new windows from the dock. |
1175 - (void)newWindowFromDock:(id)sender { | 1200 - (void)commandFromDock:(id)sender { |
1176 [NSApp activateIgnoringOtherApps:YES]; | 1201 [NSApp activateIgnoringOtherApps:YES]; |
1177 [self commandDispatch:sender]; | 1202 [self commandDispatch:sender]; |
1178 } | 1203 } |
1179 | 1204 |
1180 - (NSMenu*)applicationDockMenu:(NSApplication*)sender { | 1205 - (NSMenu*)applicationDockMenu:(NSApplication*)sender { |
1181 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease]; | 1206 NSMenu* dockMenu = [[[NSMenu alloc] initWithTitle: @""] autorelease]; |
1207 Profile* profile = [self defaultProfile]; | |
1208 DCHECK(profile); | |
1209 int position = 0; | |
1210 BackgroundApplicationListModel applications(profile); | |
1211 for (ExtensionList::const_iterator cursor = applications.begin(); | |
1212 cursor != applications.end(); | |
1213 ++cursor, ++position) { | |
1214 DCHECK(position == applications.GetPosition(*cursor)); | |
1215 scoped_nsobject<NSMenuItem> appItem([[NSMenuItem alloc] | |
1216 initWithTitle:base::SysUTF16ToNSString(UTF8ToUTF16((*cursor)->name())) | |
1217 action:@selector(commandFromDock:) | |
1218 keyEquivalent:@""]); | |
1219 [appItem setTarget:self]; | |
1220 [appItem setTag:position]; | |
1221 [dockMenu addItem:appItem]; | |
1222 } | |
1223 if (applications.begin() != applications.end()) { | |
1224 NSMenuItem* sepItem = [[NSMenuItem separatorItem] init]; | |
1225 [dockMenu addItem:sepItem]; | |
1226 } | |
1227 | |
1182 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); | 1228 NSString* titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_WINDOW_MAC); |
The wrong rickcam account
2010/12/16 19:21:40
Fix the indentation of the statement below.
| |
1183 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] | 1229 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] initWithTitle:titleStr |
1184 initWithTitle:titleStr | 1230 action:@selector(commandFromDock:) |
1185 action:@selector(newWindowFromDock:) | 1231 keyEquivalent:@""]); |
1186 keyEquivalent:@""]); | |
1187 [item setTarget:self]; | 1232 [item setTarget:self]; |
1188 [item setTag:IDC_NEW_WINDOW]; | 1233 [item setTag:IDC_NEW_WINDOW]; |
1189 [dockMenu addItem:item]; | 1234 [dockMenu addItem:item]; |
1190 | 1235 |
1191 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); | 1236 titleStr = l10n_util::GetNSStringWithFixup(IDS_NEW_INCOGNITO_WINDOW_MAC); |
1192 item.reset([[NSMenuItem alloc] initWithTitle:titleStr | 1237 item.reset([[NSMenuItem alloc] initWithTitle:titleStr |
1193 action:@selector(newWindowFromDock:) | 1238 action:@selector(commandFromDock:) |
1194 keyEquivalent:@""]); | 1239 keyEquivalent:@""]); |
1195 [item setTarget:self]; | 1240 [item setTarget:self]; |
1196 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; | 1241 [item setTag:IDC_NEW_INCOGNITO_WINDOW]; |
1197 [dockMenu addItem:item]; | 1242 [dockMenu addItem:item]; |
1198 | 1243 |
1199 return dockMenu; | 1244 return dockMenu; |
1200 } | 1245 } |
1201 | 1246 |
1202 - (const std::vector<GURL>&)startupUrls { | 1247 - (const std::vector<GURL>&)startupUrls { |
1203 return startupUrls_; | 1248 return startupUrls_; |
(...skipping 15 matching lines...) Expand all Loading... | |
1219 [appController showPreferencesWindow:nil page:page profile:profile]; | 1264 [appController showPreferencesWindow:nil page:page profile:profile]; |
1220 } | 1265 } |
1221 | 1266 |
1222 namespace app_controller_mac { | 1267 namespace app_controller_mac { |
1223 | 1268 |
1224 bool IsOpeningNewWindow() { | 1269 bool IsOpeningNewWindow() { |
1225 return g_is_opening_new_window; | 1270 return g_is_opening_new_window; |
1226 } | 1271 } |
1227 | 1272 |
1228 } // namespace app_controller_mac | 1273 } // namespace app_controller_mac |
OLD | NEW |