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

Side by Side Diff: chrome/service/chrome_service_application_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) 2010 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 #import "chrome/service/chrome_service_application_mac.h"
6
7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h"
9 #import "content/common/cloud_print_class_mac.h"
10 #include "chrome/common/chrome_switches.h"
11
12 @interface ServiceCrApplication ()
13 - (void)setCloudPrintHandler;
14 - (void)submitPrint:(NSAppleEventDescriptor*)event;
15 @end
16
17 @implementation ServiceCrApplication
18
19 -(void)setCloudPrintHandler {
20 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
21 [em setEventHandler:self
22 andSelector:@selector(submitPrint:)
23 forEventClass:cloudPrintClass
24 andEventID:cloudPrintClass];
25 }
26
27 // Event handler for Cloud Print Event. Forwards print job received to Chrome,
28 // launching Chrome if necessary. Used to beat CUPS sandboxing.
29 - (void)submitPrint:(NSAppleEventDescriptor*)event {
30 std::string silent = std::string("--") + switches::kNoStartupWindow;
31 // Set up flag so that it can be passed along with the Apple Event.
32 CFStringRef silentLaunchFlag =
33 CFStringCreateWithCString(NULL, silent.c_str(), kCFStringEncodingUTF8);
34 CFStringRef flags[] = { silentLaunchFlag };
35 // Argv array that will be passed.
36 CFArrayRef passArgv =
37 CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks);
38 FSRef ref;
39 OSStatus status = noErr;
40 CFURLRef* kDontWantURL = NULL;
41 // Get Chrome's bundle ID.
42 std::string bundleID = base::mac::BaseBundleID();
43 CFStringRef bundleIDCF =
44 CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8);
45 // Use Launch Services to locate Chrome using its bundleID.
46 status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
47 NULL, &ref, kDontWantURL);
48
49 if (status != noErr) {
50 LOG(ERROR) << "Failed to make path ref";
51 LOG(ERROR) << GetMacOSStatusErrorString(status);
52 LOG(ERROR) << GetMacOSStatusCommentString(status);
Scott Byer 2011/08/02 23:52:52 Is it reasonable to continue from here or should y
abeera 2011/08/03 20:34:47 Done.
53 }
54 // Actually create the Apple Event.
55 NSAppleEventDescriptor* sendEvent =
56 [NSAppleEventDescriptor appleEventWithEventClass:cloudPrintClass
57 eventID:cloudPrintClass
58 targetDescriptor:nil
59 returnID:kAutoGenerateReturnID
60 transactionID:kAnyTransactionID];
61 // Pull the parameters out of AppleEvent sent to us and attach them
62 // to our Apple Event.
63 NSAppleEventDescriptor* parameters =
64 [event paramDescriptorForKeyword:cloudPrintClass];
65 [sendEvent setParamDescriptor:parameters forKeyword:cloudPrintClass];
66 LSApplicationParameters params = { 0,
67 kLSLaunchDefaults,
68 &ref,
69 NULL,
70 NULL,
71 passArgv,
72 NULL };
73 params.initialEvent = (AppleEvent*) [sendEvent aeDesc];
Scott Byer 2011/08/02 23:52:52 prefer static_cast<>()
abeera 2011/08/03 20:34:47 Done.
74 // Send the Apple Event Using launch services, launching Chrome if necessary.
75 status = LSOpenApplication(&params, NULL);
76 if (status != noErr) {
77 LOG(ERROR) << "Unable to launch";
78 LOG(ERROR) << GetMacOSStatusErrorString(status);
79 LOG(ERROR) << GetMacOSStatusCommentString(status);
80 }
81 }
82
83
84 @end
85
86
87 namespace chrome_service_application_mac {
88
89 void RegisterServiceCrApp() {
90 ServiceCrApplication* var =
91 (ServiceCrApplication*) [ServiceCrApplication sharedApplication];
Scott Byer 2011/08/02 23:52:52 prefer static_cast<>()
abeera 2011/08/03 20:34:47 Done.
92 [var setCloudPrintHandler];
93 }
94
95 } // namespace chrome_service_application_mac
96
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698