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/printer_driver_util_posix.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/logging.h" |
| 13 #include "base/mac/foundation_util.h" |
| 14 |
| 15 #include <cups/backend.h> |
| 16 |
| 17 #include <stdlib.h> |
| 18 #include <string> |
| 19 |
| 20 // Duplicated is content/common/cloud_print_class_mac.h |
| 21 const AEEventClass cloudPrintClass = 'GCPp'; |
| 22 |
| 23 void LaunchPrintDialog(std::string outputPath, |
| 24 std::string jobTitle, |
| 25 std::string user) { |
| 26 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
| 27 OSStatus status = noErr; |
| 28 FSRef ref; |
| 29 // Generate the bundle ID for the Service process. |
| 30 std::string bundleID = base::mac::BaseBundleID(); |
| 31 bundleID = bundleID + ".helper"; |
| 32 CFStringRef bundleIDCF = CFStringCreateWithCString( |
| 33 NULL, |
| 34 bundleID.c_str(), |
| 35 kCFStringEncodingUTF8); |
| 36 CFURLRef* kDontWantURL = NULL; |
| 37 // Locate the service process with the help of the bundle ID. |
| 38 status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, |
| 39 NULL, &ref, kDontWantURL); |
| 40 |
| 41 if (status != noErr) { |
| 42 LOG(ERROR) <<"Couldn't find the service process"; |
| 43 exit(CUPS_BACKEND_CANCEL); |
| 44 } |
| 45 |
| 46 // Create the actual Apple Event. |
| 47 NSAppleEventDescriptor* event = |
| 48 [NSAppleEventDescriptor appleEventWithEventClass:cloudPrintClass |
| 49 eventID:cloudPrintClass |
| 50 targetDescriptor:nil |
| 51 returnID:kAutoGenerateReturnID |
| 52 transactionID:kAnyTransactionID]; |
| 53 |
| 54 if(event == nil) { |
| 55 LOG(ERROR) << "Unable to Create Event"; |
| 56 exit(CUPS_BACKEND_CANCEL); |
| 57 } |
| 58 |
| 59 // Create the AppleEvent parameters. |
| 60 NSAppleEventDescriptor* printPath = |
| 61 [NSAppleEventDescriptor descriptorWithString: |
| 62 [NSString stringWithUTF8String:outputPath.c_str()]]; |
| 63 NSAppleEventDescriptor* title = |
| 64 [NSAppleEventDescriptor descriptorWithString: |
| 65 [NSString stringWithUTF8String:jobTitle.c_str()]]; |
| 66 NSAppleEventDescriptor* mime = [NSAppleEventDescriptor |
| 67 descriptorWithString:@"application/pdf"]; |
| 68 |
| 69 // Create and populate the list of parameters. |
| 70 // Note that the array starts at index 1. |
| 71 NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor listDescriptor]; |
| 72 |
| 73 if(parameters == nil) { |
| 74 LOG(ERROR) << "Unable to Create Paramters"; |
| 75 exit(CUPS_BACKEND_CANCEL); |
| 76 } |
| 77 |
| 78 [parameters insertDescriptor:mime atIndex:1]; |
| 79 [parameters insertDescriptor:printPath atIndex:2]; |
| 80 [parameters insertDescriptor:title atIndex:3]; |
| 81 [event setParamDescriptor:parameters forKeyword:cloudPrintClass]; |
| 82 |
| 83 // Set the application launch parameters. |
| 84 // We are just using launch services to deliver our Apple Event. |
| 85 LSApplicationParameters params = { |
| 86 0, kLSLaunchDefaults , &ref, NULL, NULL, NULL, NULL }; |
| 87 |
| 88 AEDesc* initialEvent = const_cast<AEDesc*> ([event aeDesc]); |
| 89 params.initialEvent = static_cast<AppleEvent*> (initialEvent); |
| 90 // Deliver the Apple Event using launch services. |
| 91 status = LSOpenApplication(¶ms, NULL); |
| 92 if (status != noErr) { |
| 93 LOG(ERROR) << "Unable to launch"; |
| 94 LOG(ERROR) << GetMacOSStatusErrorString(status); |
| 95 LOG(ERROR) << GetMacOSStatusCommentString(status); |
| 96 exit(CUPS_BACKEND_CANCEL); |
| 97 } |
| 98 |
| 99 [pool release]; |
| 100 return; |
| 101 } |
OLD | NEW |