diff options
Diffstat (limited to 'cloud_print/virtual_driver')
-rw-r--r-- | cloud_print/virtual_driver/posix/backend.gyp | 56 | ||||
-rw-r--r-- | cloud_print/virtual_driver/posix/install_cloud_print_driver_mac.mm | 20 | ||||
-rw-r--r-- | cloud_print/virtual_driver/posix/installer_util_mac.h | 16 | ||||
-rw-r--r-- | cloud_print/virtual_driver/posix/installer_util_mac.mm | 65 | ||||
-rw-r--r-- | cloud_print/virtual_driver/posix/printer_driver_util_mac.mm | 120 | ||||
-rw-r--r-- | cloud_print/virtual_driver/posix/uninstall_cloud_print_driver_mac.mm | 20 | ||||
-rw-r--r-- | cloud_print/virtual_driver/virtual_driver_posix.gyp (renamed from cloud_print/virtual_driver/virtual_driver_linux.gyp) | 7 |
7 files changed, 285 insertions, 19 deletions
diff --git a/cloud_print/virtual_driver/posix/backend.gyp b/cloud_print/virtual_driver/posix/backend.gyp index 6f25dba..df6e49b 100644 --- a/cloud_print/virtual_driver/posix/backend.gyp +++ b/cloud_print/virtual_driver/posix/backend.gyp @@ -4,27 +4,57 @@ { 'target_defaults': { - 'include_dirs': [ - '../..' - ], - 'variables': { - 'chromium_code': 1 - } + 'variables': { 'chromium_code':1 }, }, - 'targets' : [ + 'targets': [ { 'target_name': 'GCP-driver', 'type': 'executable', 'dependencies': [ '../../../base/base.gyp:base', ], - 'sources' : [ - 'virtual_driver_posix.cc', + 'sources': [ 'printer_driver_util_linux.cc', 'printer_driver_util_posix.h', + 'printer_driver_util_mac.mm', + 'virtual_driver_posix.cc', '../virtual_driver_switches.cc', - '../virtual_driver_switches.h', - ] - }, - ], + ], + 'conditions': [ + ['OS=="mac"', { + 'sources!': ['../virtual_driver_switches.cc'], + 'libraries': ['ScriptingBridge.framework'], + }], + ], + }], + 'conditions': [ + ['OS=="mac"', { + 'targets' : [ + { + 'target_name': 'GCP-install', + 'type': 'executable', + 'dependencies': [ + '../../../base/base.gyp:base', + ], + 'sources' : [ + 'install_cloud_print_driver_mac.mm', + 'installer_util_mac.h', + 'installer_util_mac.mm' + ], + }, + { + 'target_name': 'GCP-uninstall', + 'type': 'executable', + 'dependencies': [ + '../../../base/base.gyp:base', + ], + 'sources' : [ + 'installer_util_mac.h', + 'installer_util_mac.mm', + 'uninstall_cloud_print_driver_mac.mm', + ], + }, + ], + }], + ], } diff --git a/cloud_print/virtual_driver/posix/install_cloud_print_driver_mac.mm b/cloud_print/virtual_driver/posix/install_cloud_print_driver_mac.mm new file mode 100644 index 0000000..0d3f44c2 --- /dev/null +++ b/cloud_print/virtual_driver/posix/install_cloud_print_driver_mac.mm @@ -0,0 +1,20 @@ +// Copyright (c) 2011 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 <ApplicationServices/ApplicationServices.h> +#import <Foundation/NSAutoreleasePool.h> + +#include "cloud_print/virtual_driver/posix/installer_util_mac.h" + +const AEEventClass kAECloudPrintInstallClass= 'GCPi'; + +// Installer for Virtual Driver on Mac. Sends an Apple Event to +// Chrome, launching it if necessary. The Apple Event registers +// the virtual driver with the service process. +int main() { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + cloud_print::sendServiceProcessEvent(kAECloudPrintInstallClass); + [pool release]; + return 0; +} diff --git a/cloud_print/virtual_driver/posix/installer_util_mac.h b/cloud_print/virtual_driver/posix/installer_util_mac.h new file mode 100644 index 0000000..9983313 --- /dev/null +++ b/cloud_print/virtual_driver/posix/installer_util_mac.h @@ -0,0 +1,16 @@ +// Copyright (c) 2011 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. + +#ifndef CLOUD_PRINT_VIRTUAL_POSIX_INSTALLER_UTIL_MAC_H_ +#define CLOUD_PRINT_VIRTUAL_POSIX_INSTALLER_UTIL_MAC_H_ +#pragma once + +#import <ApplicationServices/ApplicationServices.h> + +namespace cloud_print { +void sendServiceProcessEvent(const AEEventClass sendClass); +} // namespace cloud_print + +#endif // CLOUD_PRINT_VIRTUAL_POSIX_INSTALLER_UTIL_MAC_H_ + diff --git a/cloud_print/virtual_driver/posix/installer_util_mac.mm b/cloud_print/virtual_driver/posix/installer_util_mac.mm new file mode 100644 index 0000000..c6179c1 --- /dev/null +++ b/cloud_print/virtual_driver/posix/installer_util_mac.mm @@ -0,0 +1,65 @@ +// Copyright (c) 2011 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. + +#include "cloud_print/virtual_driver/posix/installer_util_mac.h" + +#import <ApplicationServices/ApplicationServices.h> +#import <Foundation/NSAutoreleasePool.h> +#import <Foundation/NSAppleEventDescriptor.h> +#import <CoreServices/CoreServices.h> + +#include "base/mac/foundation_util.h" + +#include <stdlib.h> +#include <string> +#include <iostream> + +namespace cloud_print { +// Sends an event of a class Type sendClass to the Chromium +// service process. Used to install and uninstall the Cloud +// Print driver on Mac. +void sendServiceProcessEvent(const AEEventClass sendClass) { + FSRef ref; + OSStatus status = noErr; + CFURLRef* kDontWantURL = NULL; + + std::string bundleID = base::mac::BaseBundleID(); + CFStringRef bundleIDCF = CFStringCreateWithCString(NULL, bundleID.c_str(), + kCFStringEncodingUTF8); + + status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, NULL, + &ref, kDontWantURL); + + if (status != noErr) { + std::cerr << "Failed to make path ref"; + std::cerr << GetMacOSStatusErrorString(status); + std::cerr << GetMacOSStatusCommentString(status); + exit(-1); + } + + NSAppleEventDescriptor* sendEvent = + [NSAppleEventDescriptor appleEventWithEventClass:sendClass + eventID:sendClass + targetDescriptor:nil + returnID:kAutoGenerateReturnID + transactionID:kAnyTransactionID]; + if (sendEvent == nil) { + // Write to system error log using cerr. + std::cerr << "Unable to create Apple Event"; + } + LSApplicationParameters params = { 0, kLSLaunchDefaults, &ref, NULL, NULL, + NULL, NULL }; + AEDesc* initialEvent = const_cast<AEDesc*> ([sendEvent aeDesc]); + params.initialEvent = static_cast<AppleEvent*> (initialEvent); + status = LSOpenApplication(¶ms, NULL); + + if (status != noErr) { + std::cerr << "Unable to launch Chrome to install"; + std::cerr << GetMacOSStatusErrorString(status); + std::cerr << GetMacOSStatusCommentString(status); + exit(-1); + } +} + +} // namespace cloud_print diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm b/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm new file mode 100644 index 0000000..d85e3ff --- /dev/null +++ b/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm @@ -0,0 +1,120 @@ +// Copyright (c) 2011 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. + +#include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" + +#import <ApplicationServices/ApplicationServices.h> +#import <CoreServices/CoreServices.h> +#import <Foundation/NSAutoreleasePool.h> +#import <Foundation/NSAppleEventDescriptor.h> +#import <ScriptingBridge/SBApplication.h> + +#include "base/logging.h" +#include "base/mac/foundation_util.h" + +#include <cups/backend.h> + +#include <stdlib.h> +#include <string> + +// Duplicated is content/common/cloud_print_class_mac.h +const AEEventClass kAECloudPrintClass = 'GCPp'; + +namespace cloud_print { +// Checks to see whether the browser process, whose bundle ID +// is specified by bundle ID, is running. +bool IsBrowserRunning(std::string bundleID) { + SBApplication* app = [SBApplication applicationWithBundleIdentifier: + [NSString stringWithUTF8String:bundleID.c_str()]]; + if ([app isRunning]) { + return true; + } + return false; +} +} // namespace cloud_print + +void LaunchPrintDialog(const std::string& outputPath, + const std::string& jobTitle, + const std::string& user) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + OSStatus status = noErr; + FSRef ref; + // Get the bundleID of the browser. + std::string bundleID = base::mac::BaseBundleID(); + // If the browser is running, send the event to it. + // Otherwise, send the event to the service process. + if (!cloud_print::IsBrowserRunning(bundleID)) { + // Generate the bundle ID for the Service process. + bundleID = bundleID + ".helper"; + } + CFStringRef bundleIDCF = CFStringCreateWithCString( + NULL, + bundleID.c_str(), + kCFStringEncodingUTF8); + CFURLRef* kDontWantURL = NULL; + // Locate the service process with the help of the bundle ID. + status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, + NULL, &ref, kDontWantURL); + + if (status != noErr) { + LOG(ERROR) << "Couldn't locate the process to send Apple Event"; + exit(CUPS_BACKEND_CANCEL); + } + + // Create the actual Apple Event. + NSAppleEventDescriptor* event = + [NSAppleEventDescriptor appleEventWithEventClass:kAECloudPrintClass + eventID:kAECloudPrintClass + targetDescriptor:nil + returnID:kAutoGenerateReturnID + transactionID:kAnyTransactionID]; + + if(event == nil) { + LOG(ERROR) << "Unable to Create Event"; + exit(CUPS_BACKEND_CANCEL); + } + + // Create the AppleEvent parameters. + NSAppleEventDescriptor* printPath = + [NSAppleEventDescriptor descriptorWithString: + [NSString stringWithUTF8String:outputPath.c_str()]]; + NSAppleEventDescriptor* title = + [NSAppleEventDescriptor descriptorWithString: + [NSString stringWithUTF8String:jobTitle.c_str()]]; + NSAppleEventDescriptor* mime = [NSAppleEventDescriptor + descriptorWithString:@"application/pdf"]; + + // Create and populate the list of parameters. + // Note that the array starts at index 1. + NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor listDescriptor]; + + if(parameters == nil) { + LOG(ERROR) << "Unable to Create Paramters"; + exit(CUPS_BACKEND_CANCEL); + } + + [parameters insertDescriptor:mime atIndex:1]; + [parameters insertDescriptor:printPath atIndex:2]; + [parameters insertDescriptor:title atIndex:3]; + [event setParamDescriptor:parameters forKeyword:kAECloudPrintClass]; + + // Set the application launch parameters. + // We are just using launch services to deliver our Apple Event. + LSApplicationParameters params = { + 0, kLSLaunchDefaults , &ref, NULL, NULL, NULL, NULL }; + + AEDesc* initialEvent = const_cast<AEDesc*> ([event aeDesc]); + params.initialEvent = static_cast<AppleEvent*> (initialEvent); + // Deliver the Apple Event using launch services. + status = LSOpenApplication(¶ms, NULL); + if (status != noErr) { + LOG(ERROR) << "Unable to launch"; + LOG(ERROR) << GetMacOSStatusErrorString(status); + LOG(ERROR) << GetMacOSStatusCommentString(status); + exit(CUPS_BACKEND_CANCEL); + } + + [pool release]; + return; +} diff --git a/cloud_print/virtual_driver/posix/uninstall_cloud_print_driver_mac.mm b/cloud_print/virtual_driver/posix/uninstall_cloud_print_driver_mac.mm new file mode 100644 index 0000000..adb7edc --- /dev/null +++ b/cloud_print/virtual_driver/posix/uninstall_cloud_print_driver_mac.mm @@ -0,0 +1,20 @@ +// Copyright (c) 2011 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 <ApplicationServices/ApplicationServices.h> +#import <Foundation/NSAutoreleasePool.h> + +#include "cloud_print/virtual_driver/posix/installer_util_mac.h" + +const AEEventClass kAECloudPrintUninstallClass = 'GCPu'; + +// Uninstaller for Virtual Driver on Mac. Sends an Apple Event to +// Chrome, launching it if necessary. The Apple Event unregisters +// the virtual driver with the service process. +int main() { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + cloud_print::sendServiceProcessEvent(kAECloudPrintUninstallClass); + [pool release]; + return 0; +} diff --git a/cloud_print/virtual_driver/virtual_driver_linux.gyp b/cloud_print/virtual_driver/virtual_driver_posix.gyp index 53fa411..cb458ec 100644 --- a/cloud_print/virtual_driver/virtual_driver_linux.gyp +++ b/cloud_print/virtual_driver/virtual_driver_posix.gyp @@ -4,7 +4,7 @@ { 'targets': [ { - 'target_name': 'virtual_driver', + 'target_name': 'virtual_driver_posix', 'type': 'none', 'dependencies': [ 'posix/backend.gyp:*', @@ -13,8 +13,3 @@ ], } -# Local Variables: -# tab-width:2 -# indent-tabs-mode:nil -# End: -# vim: set expandtab tabstop=2 shiftwidth=2: |