OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #import "chrome/service/chrome_service_application_mac.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/mac/foundation_util.h" | |
9 #import "content/common/cloud_print_class_mac.h" | |
10 #include "chrome/common/chrome_switches.h" | |
11 | |
12 @interface ServiceCrApplication () | |
13 - (void)setCloudPrintHandler; | |
14 - (void)submitPrint:(NSAppleEventDescriptor*)event; | |
15 @end | |
16 | |
17 @implementation ServiceCrApplication | |
18 | |
19 -(void)setCloudPrintHandler { | |
20 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | |
21 [em setEventHandler:self | |
22 andSelector:@selector(submitPrint:) | |
23 forEventClass:cloudPrintClass | |
24 andEventID:cloudPrintClass]; | |
25 } | |
26 | |
27 // Event handler for Cloud Print Event. Forwards print job received to Chrome, | |
28 // launching Chrome if necessary. Used to beat CUPS sandboxing. | |
29 - (void)submitPrint:(NSAppleEventDescriptor*)event { | |
30 std::string silent = "--"; | |
Nico
2011/08/01 21:31:12
"--" + switches::kNoStartupWindow
abeera
2011/08/02 01:21:02
Done.
| |
31 silent.append(switches::kNoStartupWindow); | |
32 // Set up flag so that it can be passed along with Apple Event. | |
Nico
2011/08/01 21:31:12
with the Apple Event
abeera
2011/08/02 01:21:02
Done.
| |
33 CFStringRef silentLaunchFlag = | |
34 CFStringCreateWithCString(NULL, silent.c_str(), kCFStringEncodingUTF8); | |
35 CFStringRef flags[] = { silentLaunchFlag }; | |
36 // Argv array that will be passed. | |
37 CFArrayRef passArgv = | |
38 CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks); | |
39 FSRef ref; | |
40 OSStatus status = noErr; | |
41 CFURLRef* kDontWantURL = NULL; | |
42 // Get Chrome's bundle ID. | |
43 std::string bundleID = base::mac::BaseBundleID(); | |
44 CFStringRef bundleIDCF = | |
45 CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8); | |
46 // Use Launch Services to locate Chrome using its bundleID. | |
47 status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, | |
48 NULL, &ref, kDontWantURL); | |
49 | |
50 if (status != noErr) { | |
51 LOG(ERROR) << "Failed to make path ref"; | |
52 LOG(ERROR) << GetMacOSStatusErrorString(status); | |
53 LOG(ERROR) << GetMacOSStatusCommentString(status); | |
54 } | |
55 // Actually create the Apple Event. | |
56 NSAppleEventDescriptor* sendEvent = | |
57 [NSAppleEventDescriptor | |
Nico
2011/08/01 21:31:12
nit: i'd get rid of this linebreak
abeera
2011/08/02 01:21:02
Done.
| |
58 appleEventWithEventClass:cloudPrintClass | |
59 eventID:cloudPrintClass | |
60 targetDescriptor:nil | |
61 returnID:kAutoGenerateReturnID | |
62 transactionID:kAnyTransactionID]; | |
63 // Pull the parameters out of AppleEvent sent to us and attach them | |
64 // to our Apple Event. | |
65 NSAppleEventDescriptor* parameters = | |
66 [event paramDescriptorForKeyword:cloudPrintClass]; | |
67 [sendEvent setParamDescriptor:parameters forKeyword:cloudPrintClass]; | |
68 LSApplicationParameters params = { 0, | |
69 kLSLaunchDefaults, | |
70 &ref, | |
71 NULL, | |
72 NULL, | |
73 passArgv, | |
74 NULL }; | |
75 params.initialEvent = (AppleEvent*) [sendEvent aeDesc]; | |
76 // Send the Apple Event Using launch services, launching Chrome if necessary. | |
77 status = LSOpenApplication(¶ms, NULL); | |
78 if (status != noErr) { | |
79 LOG(ERROR) << "Unable to launch"; | |
80 LOG(ERROR) << GetMacOSStatusErrorString(status); | |
81 LOG(ERROR) << GetMacOSStatusCommentString(status); | |
82 } | |
83 } | |
84 | |
85 | |
86 @end | |
87 | |
88 | |
89 namespace chrome_service_application_mac { | |
90 | |
91 void RegisterServiceCrApp() { | |
92 ServiceCrApplication* var = | |
93 (ServiceCrApplication*) [ServiceCrApplication sharedApplication]; | |
94 [var setCloudPrintHandler]; | |
95 | |
Nico
2011/08/01 21:31:12
no newline
abeera
2011/08/02 01:21:02
Done.
| |
96 } | |
97 | |
98 } // namespace chrome_service_application_mac | |
99 | |
OLD | NEW |