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

Unified 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: 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: chrome/service/chrome_service_application_mac.mm
diff --git a/chrome/service/chrome_service_application_mac.mm b/chrome/service/chrome_service_application_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..d25873e757d61b05629e63f5dd76517f74161bab
--- /dev/null
+++ b/chrome/service/chrome_service_application_mac.mm
@@ -0,0 +1,99 @@
+// Copyright (c) 2010 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.
+
+#import "chrome/service/chrome_service_application_mac.h"
+
+#include "base/logging.h"
+#include "base/mac/foundation_util.h"
+#import "content/common/cloud_print_class_mac.h"
+#include "chrome/common/chrome_switches.h"
+
+@interface ServiceCrApplication ()
+- (void)setCloudPrintHandler;
+- (void)submitPrint:(NSAppleEventDescriptor*)event;
+@end
+
+@implementation ServiceCrApplication
+
+-(void)setCloudPrintHandler {
+ NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
+ [em setEventHandler:self
+ andSelector:@selector(submitPrint:)
+ forEventClass:cloudPrintClass
+ andEventID:cloudPrintClass];
+}
+
+// Event handler for Cloud Print Event. Forwards print job received to Chrome,
+// launching Chrome if necessary. Used to beat CUPS sandboxing.
+- (void)submitPrint:(NSAppleEventDescriptor*)event {
+ std::string silent = "--";
Nico 2011/08/01 21:31:12 "--" + switches::kNoStartupWindow
abeera 2011/08/02 01:21:02 Done.
+ silent.append(switches::kNoStartupWindow);
+ // Set up flag so that it can be passed along with Apple Event.
Nico 2011/08/01 21:31:12 with the Apple Event
abeera 2011/08/02 01:21:02 Done.
+ CFStringRef silentLaunchFlag =
+ CFStringCreateWithCString(NULL, silent.c_str(), kCFStringEncodingUTF8);
+ CFStringRef flags[] = { silentLaunchFlag };
+ // Argv array that will be passed.
+ CFArrayRef passArgv =
+ CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks);
+ FSRef ref;
+ OSStatus status = noErr;
+ CFURLRef* kDontWantURL = NULL;
+ // Get Chrome's bundle ID.
+ std::string bundleID = base::mac::BaseBundleID();
+ CFStringRef bundleIDCF =
+ CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8);
+ // Use Launch Services to locate Chrome using its bundleID.
+ status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
+ NULL, &ref, kDontWantURL);
+
+ if (status != noErr) {
+ LOG(ERROR) << "Failed to make path ref";
+ LOG(ERROR) << GetMacOSStatusErrorString(status);
+ LOG(ERROR) << GetMacOSStatusCommentString(status);
+ }
+ // Actually create the Apple Event.
+ NSAppleEventDescriptor* sendEvent =
+ [NSAppleEventDescriptor
Nico 2011/08/01 21:31:12 nit: i'd get rid of this linebreak
abeera 2011/08/02 01:21:02 Done.
+ appleEventWithEventClass:cloudPrintClass
+ eventID:cloudPrintClass
+ targetDescriptor:nil
+ returnID:kAutoGenerateReturnID
+ transactionID:kAnyTransactionID];
+ // Pull the parameters out of AppleEvent sent to us and attach them
+ // to our Apple Event.
+ NSAppleEventDescriptor* parameters =
+ [event paramDescriptorForKeyword:cloudPrintClass];
+ [sendEvent setParamDescriptor:parameters forKeyword:cloudPrintClass];
+ LSApplicationParameters params = { 0,
+ kLSLaunchDefaults,
+ &ref,
+ NULL,
+ NULL,
+ passArgv,
+ NULL };
+ params.initialEvent = (AppleEvent*) [sendEvent aeDesc];
+ // Send the Apple Event Using launch services, launching Chrome if necessary.
+ status = LSOpenApplication(&params, NULL);
+ if (status != noErr) {
+ LOG(ERROR) << "Unable to launch";
+ LOG(ERROR) << GetMacOSStatusErrorString(status);
+ LOG(ERROR) << GetMacOSStatusCommentString(status);
+ }
+}
+
+
+@end
+
+
+namespace chrome_service_application_mac {
+
+void RegisterServiceCrApp() {
+ ServiceCrApplication* var =
+ (ServiceCrApplication*) [ServiceCrApplication sharedApplication];
+ [var setCloudPrintHandler];
+
Nico 2011/08/01 21:31:12 no newline
abeera 2011/08/02 01:21:02 Done.
+}
+
+} // namespace chrome_service_application_mac
+

Powered by Google App Engine
This is Rietveld 408576698