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"; | |
36 std::cerr << GetMacOSStatusErrorString(status); | |
37 std::cerr << GetMacOSStatusCommentString(status); | |
38 exit(-1); | |
39 } | |
40 | |
41 NSAppleEventDescriptor* sendEvent = | |
42 [NSAppleEventDescriptor appleEventWithEventClass:sendClass | |
43 eventID:sendClass | |
44 targetDescriptor:nil | |
45 returnID:kAutoGenerateReturnID | |
46 transactionID:kAnyTransactionID]; | |
47 if(sendEvent == nil) { | |
Scott Byer
2011/08/04 20:43:54
nit: space after if
| |
48 // Write to system error log using cerr. | |
49 std::cerr << "Unable to create Apple Event"; | |
50 } | |
51 LSApplicationParameters params = { 0, kLSLaunchDefaults, &ref, NULL, NULL, | |
52 NULL, NULL }; | |
53 AEDesc* initialEvent = const_cast<AEDesc*> ([sendEvent aeDesc]); | |
54 params.initialEvent = static_cast<AppleEvent*> (initialEvent); | |
55 status = LSOpenApplication(¶ms, NULL); | |
56 | |
57 if (status != noErr) { | |
58 std::cerr << "Unable to launch Chrome to install"; | |
59 std::cerr << GetMacOSStatusErrorString(status); | |
60 std::cerr << GetMacOSStatusCommentString(status); | |
61 exit(-1); | |
62 } | |
63 } | |
64 | |
65 } // namespace cloud_print | |
OLD | NEW |