| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/service/chrome_service_application_mac.h" | 5 #import "chrome/service/chrome_service_application_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/mac/mac_logging.h" | 8 #include "base/mac/mac_logging.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "chrome/common/cloud_print/cloud_print_class_mac.h" | 10 #import "chrome/common/cloud_print/cloud_print_class_mac.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 | 12 |
| 13 @interface ServiceEventHandler : NSObject | 13 @interface ServiceEventHandler : NSObject |
| 14 + (void)submitPrint:(NSAppleEventDescriptor*)event; | 14 + (void)submitPrint:(NSAppleEventDescriptor*)event; |
| 15 @end | 15 @end |
| 16 | 16 |
| 17 @implementation ServiceEventHandler | 17 @implementation ServiceEventHandler |
| 18 | 18 |
| 19 // Event handler for Cloud Print Event. Forwards print job received to Chrome, | 19 // Event handler for Cloud Print Event. Forwards print job received to Chrome, |
| 20 // launching Chrome if necessary. Used to beat CUPS sandboxing. | 20 // launching Chrome if necessary. Used to beat CUPS sandboxing. |
| 21 + (void)submitPrint:(NSAppleEventDescriptor*)event { | 21 + (void)submitPrint:(NSAppleEventDescriptor*)event { |
| 22 std::string silent = std::string("--") + switches::kNoStartupWindow; | 22 std::string silent = std::string("--") + switches::kNoStartupWindow; |
| 23 // Set up flag so that it can be passed along with the Apple Event. | 23 // Set up flag so that it can be passed along with the Apple Event. |
| 24 base::mac::ScopedCFTypeRef<CFStringRef> silentLaunchFlag( | 24 base::ScopedCFTypeRef<CFStringRef> silentLaunchFlag( |
| 25 base::SysUTF8ToCFStringRef(silent)); | 25 base::SysUTF8ToCFStringRef(silent)); |
| 26 CFStringRef flags[] = { silentLaunchFlag }; | 26 CFStringRef flags[] = { silentLaunchFlag }; |
| 27 // Argv array that will be passed. | 27 // Argv array that will be passed. |
| 28 base::mac::ScopedCFTypeRef<CFArrayRef> passArgv( | 28 base::ScopedCFTypeRef<CFArrayRef> passArgv( |
| 29 CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks)); | 29 CFArrayCreate(NULL, (const void**)flags, 1, &kCFTypeArrayCallBacks)); |
| 30 FSRef ref; | 30 FSRef ref; |
| 31 // Get Chrome's bundle ID. | 31 // Get Chrome's bundle ID. |
| 32 std::string bundleID = base::mac::BaseBundleID(); | 32 std::string bundleID = base::mac::BaseBundleID(); |
| 33 base::mac::ScopedCFTypeRef<CFStringRef> bundleIDCF( | 33 base::ScopedCFTypeRef<CFStringRef> bundleIDCF( |
| 34 base::SysUTF8ToCFStringRef(bundleID)); | 34 base::SysUTF8ToCFStringRef(bundleID)); |
| 35 // Use Launch Services to locate Chrome using its bundleID. | 35 // Use Launch Services to locate Chrome using its bundleID. |
| 36 OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, | 36 OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, |
| 37 NULL, &ref, NULL); | 37 NULL, &ref, NULL); |
| 38 | 38 |
| 39 if (status != noErr) { | 39 if (status != noErr) { |
| 40 OSSTATUS_LOG(ERROR, status) << "Failed to make path ref"; | 40 OSSTATUS_LOG(ERROR, status) << "Failed to make path ref"; |
| 41 return; | 41 return; |
| 42 } | 42 } |
| 43 // Actually create the Apple Event. | 43 // Actually create the Apple Event. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 void RegisterServiceEventHandler() { | 77 void RegisterServiceEventHandler() { |
| 78 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 78 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; |
| 79 [em setEventHandler:[ServiceEventHandler class] | 79 [em setEventHandler:[ServiceEventHandler class] |
| 80 andSelector:@selector(submitPrint:) | 80 andSelector:@selector(submitPrint:) |
| 81 forEventClass:cloud_print::kAECloudPrintClass | 81 forEventClass:cloud_print::kAECloudPrintClass |
| 82 andEventID:cloud_print::kAECloudPrintClass]; | 82 andEventID:cloud_print::kAECloudPrintClass]; |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace chrome_service_mac | 85 } // namespace chrome_service_mac |
| OLD | NEW |