Index: content/common/chrome_application_mac.mm |
diff --git a/content/common/chrome_application_mac.mm b/content/common/chrome_application_mac.mm |
index f21852fb78ffeacd5bcd123492d7568bb047ce99..b430f0101100979f4d78f13e4cc9ba7f729a18e5 100644 |
--- a/content/common/chrome_application_mac.mm |
+++ b/content/common/chrome_application_mac.mm |
@@ -3,11 +3,15 @@ |
// found in the LICENSE file. |
#import "content/common/chrome_application_mac.h" |
+#import "content/common/cloud_print_class_mac.h" |
#include "base/logging.h" |
+#include "base/mac/foundation_util.h" |
@interface CrApplication () |
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; |
+- (void)setCloudPrintHandler; |
+- (void)submitPrint:(NSAppleEventDescriptor*)event; |
@end |
@implementation CrApplication |
@@ -31,6 +35,75 @@ |
return self; |
} |
+// Sets the Cloud Print Handler. Used only by service process. |
+- (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, |
+// launching Chrome if necessary. Used to beat CUPS sandboxing. |
+- (void)submitPrint:(NSAppleEventDescriptor*)event { |
+ // TODO: Resolve dependency on flag. |
+ const char silent[] = "--no-startup-window"; |
+ // Set up flag so that it can be passed along with Apple Event. |
+ CFStringRef silentLaunchFlag = CFStringCreateWithCString( |
Nico
2011/07/22 16:53:55
break after =
|
+ NULL,silent,kCFStringEncodingUTF8); |
+ CFStringRef flags[] = {silentLaunchFlag}; |
Nico
2011/07/22 16:53:55
spaces inside {}
|
+ // 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); |
Nico
2011/07/22 16:53:55
wrong indent
|
+ |
+ if (status != noErr) { |
+ LOG(ERROR) <<"Failed to make path ref"; |
Nico
2011/07/22 16:53:55
space after <<
|
+ LOG(ERROR) << GetMacOSStatusErrorString(status); |
+ LOG(ERROR) << GetMacOSStatusCommentString(status); |
+ } |
+ // Actually create the Apple Event. |
+ NSAppleEventDescriptor *sendEvent = [NSAppleEventDescriptor |
+ 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(¶ms, NULL); |
+ |
+ if (status != noErr) { |
+ LOG(ERROR) <<"Unable to launch"; |
+ LOG(ERROR) << GetMacOSStatusErrorString(status); |
+ LOG(ERROR) << GetMacOSStatusCommentString(status); |
+ } |
+} |
+ |
+ |
- (BOOL)isHandlingSendEvent { |
return handlingSendEvent_; |
} |
@@ -62,6 +135,7 @@ |
@end |
namespace chrome_application_mac { |
+ CrApplication* var; |
ScopedSendingEvent::ScopedSendingEvent() |
: app_(static_cast<CrApplication*>([CrApplication sharedApplication])), |
@@ -74,7 +148,13 @@ ScopedSendingEvent::~ScopedSendingEvent() { |
} |
void RegisterCrApp() { |
- [CrApplication sharedApplication]; |
+ var = (CrApplication*)[CrApplication sharedApplication]; |
+} |
+ |
+void SetHandler() { |
+ [var setCloudPrintHandler]; |
} |
+ |
} // namespace chrome_application_mac |
+ |