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