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

Side by Side Diff: cloud_print/virtual_driver/posix/printer_driver_util_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
OLDNEW
(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/printer_driver_util_posix.h"
6
7 #import <ApplicationServices/ApplicationServices.h>
8 #import <CoreServices/CoreServices.h>
9 #import <Foundation/NSAutoreleasePool.h>
10 #import <Foundation/NSAppleEventDescriptor.h>
11 #import <ScriptingBridge/SBApplication.h>
12
13 #include "base/logging.h"
14 #include "base/mac/foundation_util.h"
15
16 #include <cups/backend.h>
17
18 #include <stdlib.h>
19 #include <string>
20
21 // Duplicated is content/common/cloud_print_class_mac.h
22 const AEEventClass kAECloudPrintClass = 'GCPp';
23
24 namespace cloud_print {
25 // Checks to see whether the browser process, whose bundle ID
26 // is specified by bundle ID, is running.
27 bool IsBrowserRunning(std::string bundleID) {
28 SBApplication* app = [SBApplication applicationWithBundleIdentifier:
29 [NSString stringWithUTF8String:bundleID.c_str()]];
30 if ([app isRunning]) {
31 return true;
32 }
33 return false;
34 }
35 } // namespace cloud_print
36
37 void LaunchPrintDialog(const std::string& outputPath,
38 const std::string& jobTitle,
39 const std::string& user) {
40 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
41 OSStatus status = noErr;
42 FSRef ref;
43 // Get the bundleID of the browser.
44 std::string bundleID = base::mac::BaseBundleID();
45 // If the browser is running, send the event to it.
46 // Otherwise, send the event to the service process.
47 if (!cloud_print::IsBrowserRunning(bundleID)) {
48 // Generate the bundle ID for the Service process.
49 bundleID = bundleID + ".helper";
50 }
51 CFStringRef bundleIDCF = CFStringCreateWithCString(
52 NULL,
53 bundleID.c_str(),
54 kCFStringEncodingUTF8);
55 CFURLRef* kDontWantURL = NULL;
56 // Locate the service process with the help of the bundle ID.
57 status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
58 NULL, &ref, kDontWantURL);
59
60 if (status != noErr) {
61 LOG(ERROR) << "Couldn't locate the process to send Apple Event";
62 exit(CUPS_BACKEND_CANCEL);
63 }
64
65 // Create the actual Apple Event.
66 NSAppleEventDescriptor* event =
67 [NSAppleEventDescriptor appleEventWithEventClass:kAECloudPrintClass
68 eventID:kAECloudPrintClass
69 targetDescriptor:nil
70 returnID:kAutoGenerateReturnID
71 transactionID:kAnyTransactionID];
72
73 if(event == nil) {
74 LOG(ERROR) << "Unable to Create Event";
75 exit(CUPS_BACKEND_CANCEL);
76 }
77
78 // Create the AppleEvent parameters.
79 NSAppleEventDescriptor* printPath =
80 [NSAppleEventDescriptor descriptorWithString:
81 [NSString stringWithUTF8String:outputPath.c_str()]];
82 NSAppleEventDescriptor* title =
83 [NSAppleEventDescriptor descriptorWithString:
84 [NSString stringWithUTF8String:jobTitle.c_str()]];
85 NSAppleEventDescriptor* mime = [NSAppleEventDescriptor
86 descriptorWithString:@"application/pdf"];
87
88 // Create and populate the list of parameters.
89 // Note that the array starts at index 1.
90 NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor listDescriptor];
91
92 if(parameters == nil) {
93 LOG(ERROR) << "Unable to Create Paramters";
94 exit(CUPS_BACKEND_CANCEL);
95 }
96
97 [parameters insertDescriptor:mime atIndex:1];
98 [parameters insertDescriptor:printPath atIndex:2];
99 [parameters insertDescriptor:title atIndex:3];
100 [event setParamDescriptor:parameters forKeyword:kAECloudPrintClass];
101
102 // Set the application launch parameters.
103 // We are just using launch services to deliver our Apple Event.
104 LSApplicationParameters params = {
105 0, kLSLaunchDefaults , &ref, NULL, NULL, NULL, NULL };
106
107 AEDesc* initialEvent = const_cast<AEDesc*> ([event aeDesc]);
108 params.initialEvent = static_cast<AppleEvent*> (initialEvent);
109 // Deliver the Apple Event using launch services.
110 status = LSOpenApplication(&params, NULL);
111 if (status != noErr) {
112 LOG(ERROR) << "Unable to launch";
113 LOG(ERROR) << GetMacOSStatusErrorString(status);
114 LOG(ERROR) << GetMacOSStatusCommentString(status);
115 exit(CUPS_BACKEND_CANCEL);
116 }
117
118 [pool release];
119 return;
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698