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

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: Fixed copyright Created 9 years, 4 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
« no previous file with comments | « build/all.gyp ('k') | chrome/browser/printing/cloud_print/virtual_driver_install_helper.h » ('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) 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 "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #include "chrome/browser/background/background_application_list_model.h" 17 #include "chrome/browser/background/background_application_list_model.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_shutdown.h" 19 #include "chrome/browser/browser_shutdown.h"
20 #include "chrome/browser/command_updater.h" 20 #include "chrome/browser/command_updater.h"
21 #include "chrome/browser/download/download_manager.h" 21 #include "chrome/browser/download/download_manager.h"
22 #include "chrome/browser/instant/instant_confirm_dialog.h" 22 #include "chrome/browser/instant/instant_confirm_dialog.h"
23 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/printing/cloud_print/virtual_driver_install_helper.h"
25 #include "chrome/browser/printing/print_dialog_cloud.h"
24 #include "chrome/browser/printing/print_job_manager.h" 26 #include "chrome/browser/printing/print_job_manager.h"
25 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
28 #include "chrome/browser/service/service_process_control.h"
26 #include "chrome/browser/sessions/session_service.h" 29 #include "chrome/browser/sessions/session_service.h"
27 #include "chrome/browser/sessions/session_service_factory.h" 30 #include "chrome/browser/sessions/session_service_factory.h"
28 #include "chrome/browser/sessions/tab_restore_service.h" 31 #include "chrome/browser/sessions/tab_restore_service.h"
29 #include "chrome/browser/sessions/tab_restore_service_factory.h" 32 #include "chrome/browser/sessions/tab_restore_service_factory.h"
30 #include "chrome/browser/sync/profile_sync_service.h" 33 #include "chrome/browser/sync/profile_sync_service.h"
31 #include "chrome/browser/sync/sync_ui_util.h" 34 #include "chrome/browser/sync/sync_ui_util.h"
32 #include "chrome/browser/sync/sync_ui_util_mac.h" 35 #include "chrome/browser/sync/sync_ui_util_mac.h"
33 #include "chrome/browser/ui/browser.h" 36 #include "chrome/browser/ui/browser.h"
34 #include "chrome/browser/ui/browser_init.h" 37 #include "chrome/browser/ui/browser_init.h"
35 #include "chrome/browser/ui/browser_list.h" 38 #include "chrome/browser/ui/browser_list.h"
36 #include "chrome/browser/ui/browser_window.h" 39 #include "chrome/browser/ui/browser_window.h"
37 #import "chrome/browser/ui/cocoa/about_window_controller.h" 40 #import "chrome/browser/ui/cocoa/about_window_controller.h"
38 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" 41 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h"
39 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" 42 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
40 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 43 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
41 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h" 44 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
42 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" 45 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h"
43 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h" 46 #import "chrome/browser/ui/cocoa/encoding_menu_controller_delegate_mac.h"
44 #import "chrome/browser/ui/cocoa/history_menu_bridge.h" 47 #import "chrome/browser/ui/cocoa/history_menu_bridge.h"
45 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" 48 #import "chrome/browser/ui/cocoa/profile_menu_controller.h"
46 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 49 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
47 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" 50 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
48 #include "chrome/browser/ui/cocoa/task_manager_mac.h" 51 #include "chrome/browser/ui/cocoa/task_manager_mac.h"
49 #include "chrome/common/chrome_notification_types.h" 52 #include "chrome/common/chrome_notification_types.h"
50 #include "chrome/common/app_mode_common_mac.h" 53 #include "chrome/common/app_mode_common_mac.h"
51 #include "chrome/common/chrome_paths_internal.h" 54 #include "chrome/common/chrome_paths_internal.h"
52 #include "chrome/common/chrome_switches.h" 55 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/pref_names.h" 56 #include "chrome/common/pref_names.h"
57 #include "chrome/common/service_messages.h"
54 #include "chrome/common/url_constants.h" 58 #include "chrome/common/url_constants.h"
55 #include "content/browser/browser_thread.h" 59 #include "content/browser/browser_thread.h"
56 #include "content/browser/tab_contents/tab_contents.h" 60 #include "content/browser/tab_contents/tab_contents.h"
57 #include "content/browser/user_metrics.h" 61 #include "content/browser/user_metrics.h"
62 #include "content/common/cloud_print_class_mac.h"
58 #include "content/common/content_notification_types.h" 63 #include "content/common/content_notification_types.h"
59 #include "content/common/notification_service.h" 64 #include "content/common/notification_service.h"
60 #include "grit/chromium_strings.h" 65 #include "grit/chromium_strings.h"
61 #include "grit/generated_resources.h" 66 #include "grit/generated_resources.h"
62 #include "net/base/net_util.h" 67 #include "net/base/net_util.h"
63 #include "ui/base/l10n/l10n_util.h" 68 #include "ui/base/l10n/l10n_util.h"
64 #include "ui/base/l10n/l10n_util_mac.h" 69 #include "ui/base/l10n/l10n_util_mac.h"
65 #include "ui/base/models/accelerator_cocoa.h" 70 #include "ui/base/models/accelerator_cocoa.h"
66 71
67 // 10.6 adds a public API for the Spotlight-backed search menu item in the Help 72 // 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
147 base::SysUTF8ToCFStringRef(appBundlePath.value()), 152 base::SysUTF8ToCFStringRef(appBundlePath.value()),
148 BaseBundleID_CFString()); 153 BaseBundleID_CFString());
149 154
150 // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty. 155 // Sync after a delay avoid I/O contention on startup; 1500 ms is plenty.
151 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, 156 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
152 new PrefsSyncTask(), 1500); 157 new PrefsSyncTask(), 1500);
153 } 158 }
154 159
155 } // anonymous namespace 160 } // anonymous namespace
156 161
162 const AEEventClass kAECloudPrintInstallClass = 'GCPi';
163 const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
164
157 @interface AppController (Private) 165 @interface AppController (Private)
158 - (void)initMenuState; 166 - (void)initMenuState;
159 - (void)initProfileMenu; 167 - (void)initProfileMenu;
160 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; 168 - (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item;
161 - (void)registerServicesMenuTypesTo:(NSApplication*)app; 169 - (void)registerServicesMenuTypesTo:(NSApplication*)app;
162 - (void)openUrls:(const std::vector<GURL>&)urls; 170 - (void)openUrls:(const std::vector<GURL>&)urls;
163 - (void)getUrl:(NSAppleEventDescriptor*)event 171 - (void)getUrl:(NSAppleEventDescriptor*)event
164 withReply:(NSAppleEventDescriptor*)reply; 172 withReply:(NSAppleEventDescriptor*)reply;
173 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event;
174 - (void)installCloudPrint:(NSAppleEventDescriptor*)event;
175 - (void)uninstallCloudPrint:(NSAppleEventDescriptor*)event;
165 - (void)windowLayeringDidChange:(NSNotification*)inNotification; 176 - (void)windowLayeringDidChange:(NSNotification*)inNotification;
166 - (void)windowChangedToProfile:(Profile*)profile; 177 - (void)windowChangedToProfile:(Profile*)profile;
167 - (void)checkForAnyKeyWindows; 178 - (void)checkForAnyKeyWindows;
168 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; 179 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount;
169 - (BOOL)shouldQuitWithInProgressDownloads; 180 - (BOOL)shouldQuitWithInProgressDownloads;
170 - (void)executeApplication:(id)sender; 181 - (void)executeApplication:(id)sender;
171 @end 182 @end
172 183
173 @implementation AppController 184 @implementation AppController
174 185
175 @synthesize startupComplete = startupComplete_; 186 @synthesize startupComplete = startupComplete_;
176 187
177 // This method is called very early in application startup (ie, before 188 // This method is called very early in application startup (ie, before
178 // 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
179 // user-data initialization until -applicationDidFinishLaunching:. 190 // user-data initialization until -applicationDidFinishLaunching:.
180 - (void)awakeFromNib { 191 - (void)awakeFromNib {
181 // 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.
182 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; 193 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
183 [em setEventHandler:self 194 [em setEventHandler:self
184 andSelector:@selector(getUrl:withReply:) 195 andSelector:@selector(getUrl:withReply:)
185 forEventClass:kInternetEventClass 196 forEventClass:kInternetEventClass
186 andEventID:kAEGetURL]; 197 andEventID:kAEGetURL];
187 [em setEventHandler:self 198 [em setEventHandler:self
199 andSelector:@selector(submitCloudPrintJob:)
200 forEventClass:content::kAECloudPrintClass
201 andEventID:content::kAECloudPrintClass];
202 // Install and uninstall handlers for virtual drivers.
203 [em setEventHandler:self
204 andSelector:@selector(installCloudPrint:)
205 forEventClass:kAECloudPrintInstallClass
206 andEventID:kAECloudPrintInstallClass];
207 [em setEventHandler:self
208 andSelector:@selector(uninstallCloudPrint:)
209 forEventClass:kAECloudPrintUninstallClass
210 andEventID:kAECloudPrintUninstallClass];
211 [em setEventHandler:self
188 andSelector:@selector(getUrl:withReply:) 212 andSelector:@selector(getUrl:withReply:)
189 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates 213 forEventClass:'WWW!' // A particularly ancient AppleEvent that dates
190 andEventID:'OURL']; // back to the Spyglass days. 214 andEventID:'OURL']; // back to the Spyglass days.
191 215
192 // Register for various window layering changes. We use these to update 216 // Register for various window layering changes. We use these to update
193 // various UI elements (command-key equivalents, etc) when the frontmost 217 // various UI elements (command-key equivalents, etc) when the frontmost
194 // window changes. 218 // window changes.
195 NSNotificationCenter* notificationCenter = 219 NSNotificationCenter* notificationCenter =
196 [NSNotificationCenter defaultCenter]; 220 [NSNotificationCenter defaultCenter];
197 [notificationCenter 221 [notificationCenter
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject] 1088 NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
1065 stringValue]; 1089 stringValue];
1066 1090
1067 GURL gurl(base::SysNSStringToUTF8(urlStr)); 1091 GURL gurl(base::SysNSStringToUTF8(urlStr));
1068 std::vector<GURL> gurlVector; 1092 std::vector<GURL> gurlVector;
1069 gurlVector.push_back(gurl); 1093 gurlVector.push_back(gurl);
1070 1094
1071 [self openUrls:gurlVector]; 1095 [self openUrls:gurlVector];
1072 } 1096 }
1073 1097
1098 // Apple Event handler that receives print event from service
1099 // process, gets the required data and launches Print dialog.
1100 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event {
1101 // Pull parameter list out of Apple Event.
1102 NSAppleEventDescriptor *paramList =
1103 [event paramDescriptorForKeyword:content::kAECloudPrintClass];
1104
1105 if (paramList != nil) {
1106 // Pull required fields out of parameter list.
1107 NSString* mime = [[paramList descriptorAtIndex:1] stringValue];
1108 NSString* inputPath = [[paramList descriptorAtIndex:2] stringValue];
1109 NSString* printTitle = [[paramList descriptorAtIndex:3] stringValue];
1110 // Convert the title to UTF 16 as required.
1111 string16 title16 = base::SysNSStringToUTF16(printTitle);
1112 print_dialog_cloud::CreatePrintDialogForFile(
1113 FilePath([inputPath UTF8String]), title16,
1114 [mime UTF8String], /*modal=*/false);
1115 }
1116 }
1117
1118 // Calls the helper class to install the virtual driver to the
1119 // service process.
1120 - (void)installCloudPrint:(NSAppleEventDescriptor*)event {
1121 cloud_print::VirtualDriverInstallHelper::SetUpInstall();
1122 }
1123
1124 // Calls the helper class to uninstall the virtual driver to the
1125 // service process.
1126 - (void)uninstallCloudPrint:(NSAppleEventDescriptor*)event {
1127 cloud_print::VirtualDriverInstallHelper::SetUpUninstall();
1128 }
1129
1074 - (void)application:(NSApplication*)sender 1130 - (void)application:(NSApplication*)sender
1075 openFiles:(NSArray*)filenames { 1131 openFiles:(NSArray*)filenames {
1076 std::vector<GURL> gurlVector; 1132 std::vector<GURL> gurlVector;
1077 for (NSString* file in filenames) { 1133 for (NSString* file in filenames) {
1078 GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file))); 1134 GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file)));
1079 gurlVector.push_back(gurl); 1135 gurlVector.push_back(gurl);
1080 } 1136 }
1081 if (!gurlVector.empty()) 1137 if (!gurlVector.empty())
1082 [self openUrls:gurlVector]; 1138 [self openUrls:gurlVector];
1083 else 1139 else
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 1285
1230 } // namespace browser 1286 } // namespace browser
1231 1287
1232 namespace app_controller_mac { 1288 namespace app_controller_mac {
1233 1289
1234 bool IsOpeningNewWindow() { 1290 bool IsOpeningNewWindow() {
1235 return g_is_opening_new_window; 1291 return g_is_opening_new_window;
1236 } 1292 }
1237 1293
1238 } // namespace app_controller_mac 1294 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « build/all.gyp ('k') | chrome/browser/printing/cloud_print/virtual_driver_install_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698