| 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..85f2629c73d16e973f115be9b37fe373070acc50
|
| --- /dev/null
|
| +++ b/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm
|
| @@ -0,0 +1,89 @@
|
| +// 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 cloud_print_class = 'GCPp';
|
| +
|
| +void LaunchPrintDialog(std::string output_path,
|
| + std::string job_title,
|
| + std::string user) {
|
| + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
| + OSStatus status = noErr;
|
| + FSRef ref;
|
| +
|
| + 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 AppleEvent parameters.
|
| + NSAppleEventDescriptor *print_path = [NSAppleEventDescriptor
|
| + descriptorWithString:[NSString stringWithUTF8String:output_path.c_str()]];
|
| + NSAppleEventDescriptor *title = [NSAppleEventDescriptor
|
| + descriptorWithString:[NSString stringWithUTF8String:job_title.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];
|
| + [parameters insertDescriptor:mime atIndex:1];
|
| + [parameters insertDescriptor:print_path atIndex:2];
|
| + [parameters insertDescriptor:title atIndex:3];
|
| + NSAppleEventDescriptor *event = [NSAppleEventDescriptor
|
| + appleEventWithEventClass:
|
| + cloud_print_class
|
| + eventID:cloud_print_class
|
| + targetDescriptor:nil
|
| + returnID:kAutoGenerateReturnID
|
| + transactionID:kAnyTransactionID];
|
| +
|
| + if(event == nil) {
|
| + LOG(ERROR) << "Unable to Create Event";
|
| + exit(CUPS_BACKEND_CANCEL);
|
| + }
|
| + // 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};
|
| + // Create the actual Apple Event.
|
| + [event setParamDescriptor:parameters forKeyword:cloud_print_class];
|
| + params.initialEvent =(AppleEvent *) [event aeDesc];
|
| + // 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;
|
| +}
|
|
|