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

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

Issue 7485011: Virtual Cloud Print Driver for Mac. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Style fixes. Created 9 years, 5 months 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
OLDNEW
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"
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
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
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)submitPrint:(NSAppleEventDescriptor*)event;
174 - (void)installCloudPrint:(NSAppleEventDescriptor*)event;
164 - (void)windowLayeringDidChange:(NSNotification*)inNotification; 175 - (void)windowLayeringDidChange:(NSNotification*)inNotification;
165 - (void)windowChangedToProfile:(Profile*)profile; 176 - (void)windowChangedToProfile:(Profile*)profile;
166 - (void)checkForAnyKeyWindows; 177 - (void)checkForAnyKeyWindows;
167 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; 178 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
168 - (BOOL)shouldQuitWithInProgressDownloads; 179 - (BOOL)shouldQuitWithInProgressDownloads;
169 - (void)executeApplication:(id)sender; 180 - (void)executeApplication:(id)sender;
170 @end 181 @end
171 182
172 @implementation AppController 183 @implementation AppController
173 184
174 @synthesize startupComplete = startupComplete_; 185 @synthesize startupComplete = startupComplete_;
175 186
187 // Apple Event handler that receives print event from service
188 // process, gets the required data and launches Print dialog.
189 - (void)submitPrint:(NSAppleEventDescriptor*)event {
190 // Pull parameter list out of Apple Event.
191 NSAppleEventDescriptor *paramList =
192 [event paramDescriptorForKeyword:cloudPrintClass];
193
194 if (paramList != NULL) {
195 // Pull required fields out of parameter list.
196 NSString* mime = [[paramList descriptorAtIndex:1] stringValue];
197 NSString* inputPath = [[paramList descriptorAtIndex:2] stringValue];
198 NSString* printTitle = [[paramList descriptorAtIndex:3] stringValue];
199 // Convert the title to UTF 16 as required.
200 string16 title16 = base::SysNSStringToUTF16(printTitle);
201 print_dialog_cloud::CreatePrintDialogForFile(
202 FilePath([inputPath UTF8String]),title16, [mime UTF8String], false);
203 }
204 }
205
206 // Calls the helper class to install the virtual driver to the
207 // service process.
208 - (void)installCloudPrint:(NSAppleEventDescriptor*)event {
209 cloud_print::VirtualDriverInstallHelper::SetUpInstall();
210 }
211
212 // Calls the helper class to uninstall the virtual driver to the
213 // service process.
214 - (void)uninstallCloudPrint:(NSAppleEventDescriptor*)event {
215 cloud_print::VirtualDriverInstallHelper::SetUpUninstall();
216 }
217
176 // This method is called very early in application startup (ie, before 218 // This method is called very early in application startup (ie, before
177 // the profile is loaded or any preferences have been registered). Defer any 219 // the profile is loaded or any preferences have been registered). Defer any
178 // user-data initialization until -applicationDidFinishLaunching:. 220 // user-data initialization until -applicationDidFinishLaunching:.
179 - (void)awakeFromNib { 221 - (void)awakeFromNib {
180 // We need to register the handlers early to catch events fired on launch. 222 // We need to register the handlers early to catch events fired on launch.
181 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; 223 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
182 [em setEventHandler:self 224 [em setEventHandler:self
183 andSelector:@selector(getUrl:withReply:) 225 andSelector:@selector(getUrl:withReply:)
184 forEventClass:kInternetEventClass 226 forEventClass:kInternetEventClass
185 andEventID:kAEGetURL]; 227 andEventID:kAEGetURL];
186 [em setEventHandler:self 228 [em setEventHandler:self
229 andSelector:@selector(submitPrint:)
230 forEventClass:cloudPrintClass
231 andEventID:cloudPrintClass]; // Event handler for cloud print.
232 // Install and uninstall handlers for virtual drivers.
233 [em setEventHandler:self
234 andSelector:@selector(installCloudPrint:)
235 forEventClass:cloudPrintInstallClass
236 andEventID:cloudPrintInstallClass];
237 [em setEventHandler:self
238 andSelector:@selector(uninstallCloudPrint:)
239 forEventClass:cloudPrintUninstallClass
240 andEventID:cloudPrintUninstallClass];
241 [em setEventHandler:self
187 andSelector:@selector(getUrl:withReply:) 242 andSelector:@selector(getUrl:withReply:)
188 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates 243 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates
189 andEventID:'OURL']; // back to the Spyglass days. 244 andEventID:'OURL']; // back to the Spyglass days.
190 245
191 // Register for various window layering changes. We use these to update 246 // Register for various window layering changes. We use these to update
192 // various UI elements (command-key equivalents, etc) when the frontmost 247 // various UI elements (command-key equivalents, etc) when the frontmost
193 // window changes. 248 // window changes.
194 NSNotificationCenter* notificationCenter = 249 NSNotificationCenter* notificationCenter =
195 [NSNotificationCenter defaultCenter]; 250 [NSNotificationCenter defaultCenter];
196 [notificationCenter 251 [notificationCenter
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 1273
1219 } // namespace browser 1274 } // namespace browser
1220 1275
1221 namespace app_controller_mac { 1276 namespace app_controller_mac {
1222 1277
1223 bool IsOpeningNewWindow() { 1278 bool IsOpeningNewWindow() {
1224 return g_is_opening_new_window; 1279 return g_is_opening_new_window;
1225 } 1280 }
1226 1281
1227 } // namespace app_controller_mac 1282 } // namespace app_controller_mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698