OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cloud_print/virtual_driver/posix/installer_util_mac.h" | |
6 | |
7 #import <ApplicationServices/ApplicationServices.h> | |
8 #import <Foundation/NSAutoreleasePool.h> | |
9 #import <Foundation/NSAppleEventDescriptor.h> | |
10 #import <CoreServices/CoreServices.h> | |
11 | |
12 #include "base/mac/foundation_util.h" | |
13 | |
14 #include <stdlib.h> | |
15 #include <string> | |
16 #include <iostream> | |
17 | |
18 namespace cloud_print { | |
19 // Sends an event of a class Type sendClass to the Chromium | |
20 // service process. Used to install and uninstall the Cloud | |
21 // Print driver on Mac. | |
22 void sendServiceProcessEvent(const AEEventClass sendClass) { | |
23 FSRef ref; | |
24 OSStatus status = noErr; | |
25 CFURLRef* kDontWantURL = NULL; | |
26 | |
27 std::string bundleID = base::mac::BaseBundleID(); | |
28 CFStringRef bundleIDCF = CFStringCreateWithCString(NULL, bundleID.c_str(), | |
29 kCFStringEncodingUTF8); | |
30 | |
31 status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, NULL, | |
32 &ref, kDontWantURL); | |
33 | |
34 if (status != noErr) { | |
35 std::cerr << "Failed to make path ref"; | |
Scott Byer
2011/08/02 23:52:52
Add a comment explaining the iostream use.
abeera
2011/08/03 20:34:47
Done.
| |
36 std::cerr << GetMacOSStatusErrorString(status); | |
37 std::cerr << GetMacOSStatusCommentString(status); | |
38 exit(-1); | |
39 } | |
40 | |
41 NSAppleEventDescriptor* sendEvent = | |
Scott Byer
2011/08/02 23:52:52
Be consistent with error checking - check for nil.
abeera
2011/08/03 20:34:47
Done.
| |
42 [NSAppleEventDescriptor appleEventWithEventClass:sendClass | |
43 eventID:sendClass | |
44 targetDescriptor:nil | |
45 returnID:kAutoGenerateReturnID | |
46 transactionID:kAnyTransactionID]; | |
47 LSApplicationParameters params = { 0, kLSLaunchDefaults , &ref, NULL, NULL, | |
Scott Byer
2011/08/02 23:52:52
nit: no space before comma
abeera
2011/08/03 20:34:47
Done.
| |
48 NULL, NULL }; | |
49 params.initialEvent = (AppleEvent*) [sendEvent aeDesc]; | |
Scott Byer
2011/08/02 23:52:52
prefer static_cast<>()
abeera
2011/08/03 20:34:47
Done.
| |
50 status = LSOpenApplication(¶ms, NULL); | |
51 | |
52 if (status != noErr) { | |
53 std::cerr << "Unable to launch Chrome to install"; | |
54 std::cerr << GetMacOSStatusErrorString(status); | |
55 std::cerr << GetMacOSStatusCommentString(status); | |
56 exit(-1); | |
57 } | |
58 } | |
59 | |
60 } // namespace cloud_print | |
OLD | NEW |