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

Unified 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: Style fixes Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
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..a3e25f17d48139d319427737e7c8f002064ee44c
--- /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
Nico 2011/08/01 21:31:12 why not include that header then?
abeera 2011/08/02 01:21:02 Currently, the driver does not depend on content/c
+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 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];
+ [parameters insertDescriptor:mime atIndex:1];
+ [parameters insertDescriptor:printPath atIndex:2];
+ [parameters insertDescriptor:title atIndex:3];
+ 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);
+ }
+ // 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:cloudPrintClass];
+ params.initialEvent =(AppleEvent *) [event aeDesc];
+ // Deliver the Apple Event using launch services.
+ status = LSOpenApplication(&params, NULL);
+ if (status != noErr) {
+ LOG(ERROR) <<"Unable to launch";
+ LOG(ERROR) << GetMacOSStatusErrorString(status);
+ LOG(ERROR) << GetMacOSStatusCommentString(status);
+ exit(CUPS_BACKEND_CANCEL);
+ }
+
+ [pool release];
+ return;
+}

Powered by Google App Engine
This is Rietveld 408576698