| Index: cloud_print/virtual_driver/posix/printer_driver_util_mac.mm
|
| diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm b/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..89b59e985d0e0267989d02642c48e12028c19279
|
| --- /dev/null
|
| +++ b/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm
|
| @@ -0,0 +1,101 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h"
|
| +
|
| +#import <ApplicationServices/ApplicationServices.h>
|
| +#import <Foundation/NSAutoreleasePool.h>
|
| +#import <Foundation/NSAppleEventDescriptor.h>
|
| +#import <CoreServices/CoreServices.h>
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/mac/foundation_util.h"
|
| +
|
| +#include <cups/backend.h>
|
| +
|
| +#include <stdlib.h>
|
| +#include <string>
|
| +
|
| +// Duplicated is content/common/cloud_print_class_mac.h
|
| +const AEEventClass cloudPrintClass = 'GCPp';
|
| +
|
| +void LaunchPrintDialog(std::string outputPath,
|
| + std::string jobTitle,
|
| + std::string user) {
|
| + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
| + OSStatus status = noErr;
|
| + FSRef ref;
|
| + // Generate the bundle ID for the Service process.
|
| + std::string bundleID = base::mac::BaseBundleID();
|
| + bundleID = bundleID + ".helper";
|
| + CFStringRef bundleIDCF = CFStringCreateWithCString(
|
| + NULL,
|
| + bundleID.c_str(),
|
| + kCFStringEncodingUTF8);
|
| + CFURLRef* kDontWantURL = NULL;
|
| + // Locate the service process with the help of the bundle ID.
|
| + status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
|
| + NULL, &ref, kDontWantURL);
|
| +
|
| + if (status != noErr) {
|
| + LOG(ERROR) <<"Couldn't find the service process";
|
| + exit(CUPS_BACKEND_CANCEL);
|
| + }
|
| +
|
| + // Create the actual Apple Event.
|
| + NSAppleEventDescriptor* event =
|
| + [NSAppleEventDescriptor appleEventWithEventClass:cloudPrintClass
|
| + eventID:cloudPrintClass
|
| + targetDescriptor:nil
|
| + returnID:kAutoGenerateReturnID
|
| + transactionID:kAnyTransactionID];
|
| +
|
| + if(event == nil) {
|
| + LOG(ERROR) << "Unable to Create Event";
|
| + exit(CUPS_BACKEND_CANCEL);
|
| + }
|
| +
|
| + // Create the AppleEvent parameters.
|
| + NSAppleEventDescriptor* printPath =
|
| + [NSAppleEventDescriptor descriptorWithString:
|
| + [NSString stringWithUTF8String:outputPath.c_str()]];
|
| + NSAppleEventDescriptor* title =
|
| + [NSAppleEventDescriptor descriptorWithString:
|
| + [NSString stringWithUTF8String:jobTitle.c_str()]];
|
| + NSAppleEventDescriptor* mime = [NSAppleEventDescriptor
|
| + descriptorWithString:@"application/pdf"];
|
| +
|
| + // Create and populate the list of parameters.
|
| + // Note that the array starts at index 1.
|
| + NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor listDescriptor];
|
| +
|
| + if(parameters == nil) {
|
| + LOG(ERROR) << "Unable to Create Paramters";
|
| + exit(CUPS_BACKEND_CANCEL);
|
| + }
|
| +
|
| + [parameters insertDescriptor:mime atIndex:1];
|
| + [parameters insertDescriptor:printPath atIndex:2];
|
| + [parameters insertDescriptor:title atIndex:3];
|
| + [event setParamDescriptor:parameters forKeyword:cloudPrintClass];
|
| +
|
| + // Set the application launch parameters.
|
| + // We are just using launch services to deliver our Apple Event.
|
| + LSApplicationParameters params = {
|
| + 0, kLSLaunchDefaults , &ref, NULL, NULL, NULL, NULL };
|
| +
|
| + AEDesc* initialEvent = const_cast<AEDesc*> ([event aeDesc]);
|
| + params.initialEvent = static_cast<AppleEvent*> (initialEvent);
|
| + // Deliver the Apple Event using launch services.
|
| + status = LSOpenApplication(¶ms, NULL);
|
| + if (status != noErr) {
|
| + LOG(ERROR) << "Unable to launch";
|
| + LOG(ERROR) << GetMacOSStatusErrorString(status);
|
| + LOG(ERROR) << GetMacOSStatusCommentString(status);
|
| + exit(CUPS_BACKEND_CANCEL);
|
| + }
|
| +
|
| + [pool release];
|
| + return;
|
| +}
|
|
|