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..728e5cc402deca824b98cc2958ae51361120aa78 |
--- /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" |
+ |
+#import "content/common/cloud_print_class_mac.h" |
+ |
Nico
2011/08/01 17:13:39
remove this newline, sort the 3 include/import sta
abeera
2011/08/01 20:45:10
Done.
|
+#include "base/logging.h" |
+#include "base/mac/foundation_util.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 recieved to Chrome, |
Nico
2011/08/01 17:13:39
received
abeera
2011/08/01 20:45:10
Done.
|
+// launching Chrome if necessary. Used to beat CUPS sandboxing. |
+- (void)submitPrint:(NSAppleEventDescriptor*)event { |
+ // TODO: Resolve dependency on flag. |
+ const char silent[] = "--no-startup-window"; |
Nico
2011/08/01 17:13:39
i think there's a global constant for this already
abeera
2011/08/01 20:45:10
Done. Earlier, this lived in content/common, which
|
+ // Set up flag so that it can be passed along with Apple Event. |
+ CFStringRef silentLaunchFlag = |
+ CFStringCreateWithCString(NULL, silent, 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 17:13:39
Break before [, align colons
abeera
2011/08/01 20:45:10
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]; |
Nico
2011/08/01 17:13:39
no space before *
abeera
2011/08/01 20:45:10
Done.
|
+ // Send the Apple Event Using launch services, launching Chrome if necessary. |
+ status = LSOpenApplication(¶ms, 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]; |
+ |
+} |
+ |
+} // namespace chrome_service_application_mac |
+ |