OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/background/background_application_list_model.h" | 16 #include "chrome/browser/background/background_application_list_model.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/browser_shutdown.h" | 18 #include "chrome/browser/browser_shutdown.h" |
19 #include "chrome/browser/command_updater.h" | 19 #include "chrome/browser/command_updater.h" |
20 #include "chrome/browser/download/download_manager.h" | 20 #include "chrome/browser/download/download_manager.h" |
21 #include "chrome/browser/instant/instant_confirm_dialog.h" | 21 #include "chrome/browser/instant/instant_confirm_dialog.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/printing/print_dialog_cloud.h" | |
23 #include "chrome/browser/printing/print_job_manager.h" | 24 #include "chrome/browser/printing/print_job_manager.h" |
25 #include "chrome/browser/printing/cloud_print/virtual_driver_install_helper.h" | |
Scott Byer
2011/08/02 23:52:52
alphabetize include order
abeera
2011/08/03 20:34:47
Done.
| |
24 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/browser/service/service_process_control.h" | |
25 #include "chrome/browser/sessions/session_service.h" | 28 #include "chrome/browser/sessions/session_service.h" |
26 #include "chrome/browser/sessions/session_service_factory.h" | 29 #include "chrome/browser/sessions/session_service_factory.h" |
27 #include "chrome/browser/sessions/tab_restore_service.h" | 30 #include "chrome/browser/sessions/tab_restore_service.h" |
28 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 31 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
29 #include "chrome/browser/sync/profile_sync_service.h" | 32 #include "chrome/browser/sync/profile_sync_service.h" |
30 #include "chrome/browser/sync/sync_ui_util.h" | 33 #include "chrome/browser/sync/sync_ui_util.h" |
31 #include "chrome/browser/sync/sync_ui_util_mac.h" | 34 #include "chrome/browser/sync/sync_ui_util_mac.h" |
32 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_init.h" | 36 #include "chrome/browser/ui/browser_init.h" |
34 #include "chrome/browser/ui/browser_list.h" | 37 #include "chrome/browser/ui/browser_list.h" |
35 #include "chrome/browser/ui/browser_window.h" | 38 #include "chrome/browser/ui/browser_window.h" |
36 #import "chrome/browser/ui/cocoa/about_window_controller.h" | 39 #import "chrome/browser/ui/cocoa/about_window_controller.h" |
37 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" | 40 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" |
38 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 41 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
39 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 42 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
40 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h" | 43 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h" |
41 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" | 44 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" |
42 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" | 45 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" |
43 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" | 46 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" |
44 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" | 47 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" |
45 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 48 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
46 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 49 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
47 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 50 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
48 #include "chrome/common/chrome_notification_types.h" | 51 #include "chrome/common/chrome_notification_types.h" |
49 #include "chrome/common/app_mode_common_mac.h" | 52 #include "chrome/common/app_mode_common_mac.h" |
50 #include "chrome/common/chrome_paths_internal.h" | 53 #include "chrome/common/chrome_paths_internal.h" |
51 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
52 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
56 #include "chrome/common/service_messages.h" | |
53 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
54 #include "content/browser/browser_thread.h" | 58 #include "content/browser/browser_thread.h" |
55 #include "content/browser/tab_contents/tab_contents.h" | 59 #include "content/browser/tab_contents/tab_contents.h" |
56 #include "content/browser/user_metrics.h" | 60 #include "content/browser/user_metrics.h" |
61 #include "content/common/cloud_print_class_mac.h" | |
57 #include "content/common/content_notification_types.h" | 62 #include "content/common/content_notification_types.h" |
58 #include "content/common/notification_service.h" | 63 #include "content/common/notification_service.h" |
59 #include "grit/chromium_strings.h" | 64 #include "grit/chromium_strings.h" |
60 #include "grit/generated_resources.h" | 65 #include "grit/generated_resources.h" |
61 #include "net/base/net_util.h" | 66 #include "net/base/net_util.h" |
62 #include "ui/base/l10n/l10n_util.h" | 67 #include "ui/base/l10n/l10n_util.h" |
63 #include "ui/base/l10n/l10n_util_mac.h" | 68 #include "ui/base/l10n/l10n_util_mac.h" |
64 #include "ui/base/models/accelerator_cocoa.h" | 69 #include "ui/base/models/accelerator_cocoa.h" |
65 | 70 |
66 // 10.6 adds a public API for the Spotlight-backed search menu item in the Help | 71 // 10.6 adds a public API for the Spotlight-backed search menu item in the Help |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 base::SysUTF8ToCFStringRef(appBundlePath.value()), | 151 base::SysUTF8ToCFStringRef(appBundlePath.value()), |
147 BaseBundleID_CFString()); | 152 BaseBundleID_CFString()); |
148 | 153 |
149 // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty. | 154 // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty. |
150 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, | 155 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, |
151 new PrefsSyncTask(), 1500); | 156 new PrefsSyncTask(), 1500); |
152 } | 157 } |
153 | 158 |
154 } // anonymous namespace | 159 } // anonymous namespace |
155 | 160 |
161 const AEEventClass cloudPrintInstallClass = 'GCPi'; | |
162 const AEEventClass cloudPrintUninstallClass = 'GCPu'; | |
163 | |
Scott Byer
2011/08/02 23:52:52
nit: extra blank line
abeera
2011/08/03 20:34:47
Done.
| |
164 | |
156 @interface AppController (Private) | 165 @interface AppController (Private) |
157 - (void)initMenuState; | 166 - (void)initMenuState; |
158 - (void)initProfileMenu; | 167 - (void)initProfileMenu; |
159 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; | 168 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
160 - (void)registerServicesMenuTypesTo:(NSApplication*)app; | 169 - (void)registerServicesMenuTypesTo:(NSApplication*)app; |
161 - (void)openUrls:(const std::vector<GURL>&)urls; | 170 - (void)openUrls:(const std::vector<GURL>&)urls; |
162 - (void)getUrl:(NSAppleEventDescriptor*)event | 171 - (void)getUrl:(NSAppleEventDescriptor*)event |
163 withReply:(NSAppleEventDescriptor*)reply; | 172 withReply:(NSAppleEventDescriptor*)reply; |
173 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; | |
174 - (void)installCloudPrint:(NSAppleEventDescriptor*)event; | |
175 - (void)uninstallCloudPrint:(NSAppleEventDescriptor*)event; | |
164 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 176 - (void)windowLayeringDidChange:(NSNotification*)inNotification; |
165 - (void)windowChangedToProfile:(Profile*)profile; | 177 - (void)windowChangedToProfile:(Profile*)profile; |
166 - (void)checkForAnyKeyWindows; | 178 - (void)checkForAnyKeyWindows; |
167 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 179 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
168 - (BOOL)shouldQuitWithInProgressDownloads; | 180 - (BOOL)shouldQuitWithInProgressDownloads; |
169 - (void)executeApplication:(id)sender; | 181 - (void)executeApplication:(id)sender; |
170 @end | 182 @end |
171 | 183 |
172 @implementation AppController | 184 @implementation AppController |
173 | 185 |
174 @synthesize startupComplete = startupComplete_; | 186 @synthesize startupComplete = startupComplete_; |
175 | 187 |
176 // This method is called very early in application startup (ie, before | 188 // This method is called very early in application startup (ie, before |
177 // the profile is loaded or any preferences have been registered). Defer any | 189 // the profile is loaded or any preferences have been registered). Defer any |
178 // user-data initialization until -applicationDidFinishLaunching:. | 190 // user-data initialization until -applicationDidFinishLaunching:. |
179 - (void)awakeFromNib { | 191 - (void)awakeFromNib { |
180 // We need to register the handlers early to catch events fired on launch. | 192 // We need to register the handlers early to catch events fired on launch. |
181 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 193 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
182 [em setEventHandler:self | 194 [em setEventHandler:self |
183 andSelector:@selector(getUrl:withReply:) | 195 andSelector:@selector(getUrl:withReply:) |
184 forEventClass:kInternetEventClass | 196 forEventClass:kInternetEventClass |
185 andEventID:kAEGetURL]; | 197 andEventID:kAEGetURL]; |
186 [em setEventHandler:self | 198 [em setEventHandler:self |
199 andSelector:@selector(submitCloudPrintJob:) | |
200 forEventClass:cloudPrintClass | |
201 andEventID:cloudPrintClass]; | |
202 // Install and uninstall handlers for virtual drivers. | |
203 [em setEventHandler:self | |
204 andSelector:@selector(installCloudPrint:) | |
205 forEventClass:cloudPrintInstallClass | |
206 andEventID:cloudPrintInstallClass]; | |
207 [em setEventHandler:self | |
208 andSelector:@selector(uninstallCloudPrint:) | |
209 forEventClass:cloudPrintUninstallClass | |
210 andEventID:cloudPrintUninstallClass]; | |
211 [em setEventHandler:self | |
187 andSelector:@selector(getUrl:withReply:) | 212 andSelector:@selector(getUrl:withReply:) |
188 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates | 213 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates |
189 andEventID:'OURL']; // back to the Spyglass days. | 214 andEventID:'OURL']; // back to the Spyglass days. |
190 | 215 |
191 // Register for various window layering changes. We use these to update | 216 // Register for various window layering changes. We use these to update |
192 // various UI elements (command-key equivalents, etc) when the frontmost | 217 // various UI elements (command-key equivalents, etc) when the frontmost |
193 // window changes. | 218 // window changes. |
194 NSNotificationCenter* notificationCenter = | 219 NSNotificationCenter* notificationCenter = |
195 [NSNotificationCenter defaultCenter]; | 220 [NSNotificationCenter defaultCenter]; |
196 [notificationCenter | 221 [notificationCenter |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] | 1078 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] |
1054 stringValue]; | 1079 stringValue]; |
1055 | 1080 |
1056 GURL gurl(base::SysNSStringToUTF8(urlStr)); | 1081 GURL gurl(base::SysNSStringToUTF8(urlStr)); |
1057 std::vector<GURL> gurlVector; | 1082 std::vector<GURL> gurlVector; |
1058 gurlVector.push_back(gurl); | 1083 gurlVector.push_back(gurl); |
1059 | 1084 |
1060 [self openUrls:gurlVector]; | 1085 [self openUrls:gurlVector]; |
1061 } | 1086 } |
1062 | 1087 |
1088 // Apple Event handler that receives print event from service | |
1089 // process, gets the required data and launches Print dialog. | |
1090 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event { | |
1091 // Pull parameter list out of Apple Event. | |
1092 NSAppleEventDescriptor *paramList = | |
1093 [event paramDescriptorForKeyword:cloudPrintClass]; | |
1094 | |
1095 if (paramList != NULL) { | |
Scott Byer
2011/08/02 23:52:52
Check against nil for ObjC objects
abeera
2011/08/03 20:34:47
Done.
| |
1096 // Pull required fields out of parameter list. | |
1097 NSString* mime = [[paramList descriptorAtIndex:1] stringValue]; | |
1098 NSString* inputPath = [[paramList descriptorAtIndex:2] stringValue]; | |
1099 NSString* printTitle = [[paramList descriptorAtIndex:3] stringValue]; | |
1100 // Convert the title to UTF 16 as required. | |
1101 string16 title16 = base::SysNSStringToUTF16(printTitle); | |
1102 print_dialog_cloud::CreatePrintDialogForFile( | |
1103 FilePath([inputPath UTF8String]), title16, | |
1104 [mime UTF8String], /*modal=*/false); | |
1105 } | |
1106 } | |
1107 | |
1108 // Calls the helper class to install the virtual driver to the | |
1109 // service process. | |
1110 - (void)installCloudPrint:(NSAppleEventDescriptor*)event { | |
1111 cloud_print::VirtualDriverInstallHelper::SetUpInstall(); | |
1112 } | |
1113 | |
1114 // Calls the helper class to uninstall the virtual driver to the | |
1115 // service process. | |
1116 - (void)uninstallCloudPrint:(NSAppleEventDescriptor*)event { | |
1117 cloud_print::VirtualDriverInstallHelper::SetUpUninstall(); | |
1118 } | |
1119 | |
1063 - (void)application:(NSApplication*)sender | 1120 - (void)application:(NSApplication*)sender |
1064 openFiles:(NSArray*)filenames { | 1121 openFiles:(NSArray*)filenames { |
1065 std::vector<GURL> gurlVector; | 1122 std::vector<GURL> gurlVector; |
1066 for (NSString* file in filenames) { | 1123 for (NSString* file in filenames) { |
1067 GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file))); | 1124 GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file))); |
1068 gurlVector.push_back(gurl); | 1125 gurlVector.push_back(gurl); |
1069 } | 1126 } |
1070 if (!gurlVector.empty()) | 1127 if (!gurlVector.empty()) |
1071 [self openUrls:gurlVector]; | 1128 [self openUrls:gurlVector]; |
1072 else | 1129 else |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1218 | 1275 |
1219 } // namespace browser | 1276 } // namespace browser |
1220 | 1277 |
1221 namespace app_controller_mac { | 1278 namespace app_controller_mac { |
1222 | 1279 |
1223 bool IsOpeningNewWindow() { | 1280 bool IsOpeningNewWindow() { |
1224 return g_is_opening_new_window; | 1281 return g_is_opening_new_window; |
1225 } | 1282 } |
1226 | 1283 |
1227 } // namespace app_controller_mac | 1284 } // namespace app_controller_mac |
OLD | NEW |