| 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..2fcbe7e0b19853fe0c179beac130845fa913d696 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,74 @@
|
| return self;
|
| }
|
|
|
| +// Sets the Cloud Print Handler. Used only by service process.
|
| +- (void)setCloudPrintHandler {
|
| + NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
|
| + LOG(ERROR) << "Setting handler";
|
| + [em setEventHandler:self
|
| + andSelector:@selector(submitPrint:)
|
| + forEventClass:cloud_print_class
|
| + andEventID:cloud_print_class];
|
| + LOG(ERROR) << "Successfully Set handler";
|
| +}
|
| +
|
| +// 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 {
|
| + LOG(ERROR) << "In submit print";
|
| + //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 silent_launch_flag = CFStringCreateWithCString(
|
| + NULL,silent,kCFStringEncodingUTF8);
|
| + CFStringRef flags[] = {silent_launch_flag};
|
| + //Argv array that will be passed
|
| + CFArrayRef pass_argv = CFArrayCreate(NULL, (const void**) flags, 1,
|
| + &kCFTypeArrayCallBacks);
|
| + FSRef ref;
|
| + OSStatus status = noErr;
|
| + CFURLRef* kDontWantURL = NULL;
|
| + //Get the bundle ID of Chrome
|
| + 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 *send_event = [NSAppleEventDescriptor
|
| + appleEventWithEventClass:
|
| + cloud_print_class
|
| + eventID:cloud_print_class
|
| + 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:
|
| + cloud_print_class];
|
| + [send_event setParamDescriptor:parameters forKeyword:cloud_print_class];
|
| + LSApplicationParameters params = {0, kLSLaunchDefaults , &ref, NULL,
|
| + NULL, pass_argv, NULL};
|
| + params.initialEvent =(AppleEvent *) [send_event 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 +134,7 @@
|
| @end
|
|
|
| namespace chrome_application_mac {
|
| + CrApplication* var;
|
|
|
| ScopedSendingEvent::ScopedSendingEvent()
|
| : app_(static_cast<CrApplication*>([CrApplication sharedApplication])),
|
| @@ -74,7 +147,12 @@ ScopedSendingEvent::~ScopedSendingEvent() {
|
| }
|
|
|
| void RegisterCrApp() {
|
| - [CrApplication sharedApplication];
|
| + var = (CrApplication*)[CrApplication sharedApplication];
|
| }
|
|
|
| +void setHandler() {
|
| + [var setCloudPrintHandler];
|
| +}
|
| +
|
| +
|
| } // namespace chrome_application_mac
|
|
|