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

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: Update GYP file to show warnings. 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 <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 // Create the AppleEvent parameters.
46 NSAppleEventDescriptor* printPath = [NSAppleEventDescriptor
47 descriptorWithString:[NSString stringWithUTF8String:outputPath.c_str()]];
48 NSAppleEventDescriptor* title = [NSAppleEventDescriptor
49 descriptorWithString:[NSString stringWithUTF8String:jobTitle.c_str()]];
50 NSAppleEventDescriptor* mime = [NSAppleEventDescriptor
51 descriptorWithString:@"application/pdf"];
52
53 // Create and populate the list of parameters.
54 // Note that the array starts at index 1.
55 NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor listDescriptor];
Scott Byer 2011/08/02 23:52:52 The order of construction here is funny; I would n
abeera 2011/08/03 20:34:47 Done.
56 [parameters insertDescriptor:mime atIndex:1];
57 [parameters insertDescriptor:printPath atIndex:2];
58 [parameters insertDescriptor:title atIndex:3];
59 NSAppleEventDescriptor* event =
60 [NSAppleEventDescriptor appleEventWithEventClass:cloudPrintClass
61 eventID:cloudPrintClass
62 targetDescriptor:nil
63 returnID:kAutoGenerateReturnID
64 transactionID:kAnyTransactionID];
65
66 if(event == nil) {
67 LOG(ERROR) << "Unable to Create Event";
68 exit(CUPS_BACKEND_CANCEL);
69 }
70 // Set the application launch parameters.
71 // We are just using launch services to deliver our Apple Event.
72 LSApplicationParameters params = {0, kLSLaunchDefaults , &ref, NULL, NULL,
Scott Byer 2011/08/02 23:52:52 ...I would move this down to just above where the
abeera 2011/08/03 20:34:47 Done.
73 NULL, NULL};
74 // Create the actual Apple Event.
75 [event setParamDescriptor:parameters forKeyword:cloudPrintClass];
Scott Byer 2011/08/02 23:52:52 ...and I would move this up to as soon as paramete
abeera 2011/08/03 20:34:47 Done.
76 params.initialEvent =(AppleEvent*) [event aeDesc];
Scott Byer 2011/08/02 23:52:52 nit: space after =, prefer static_cast<>()
abeera 2011/08/03 20:34:47 Done.
77 // Deliver the Apple Event using launch services.
78 status = LSOpenApplication(&params, NULL);
79 if (status != noErr) {
80 LOG(ERROR) <<"Unable to launch";
Scott Byer 2011/08/02 23:52:52 nit: space after operator
abeera 2011/08/03 20:34:47 Done.
81 LOG(ERROR) << GetMacOSStatusErrorString(status);
82 LOG(ERROR) << GetMacOSStatusCommentString(status);
83 exit(CUPS_BACKEND_CANCEL);
84 }
85
86 [pool release];
87 return;
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698