diff options
author | abodenha@chromium.org <abodenha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 17:44:16 +0000 |
---|---|---|
committer | abodenha@chromium.org <abodenha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 17:44:16 +0000 |
commit | 72616e4eb2b89804106875786d06f648534edc74 (patch) | |
tree | 95c7649b1bc6a287360237b7e52a9ec394bb307d /cloud_print/virtual_driver | |
parent | ffb6973894ac2bf3cfe6cd1fc2c631be790a16ec (diff) | |
download | chromium_src-72616e4eb2b89804106875786d06f648534edc74.zip chromium_src-72616e4eb2b89804106875786d06f648534edc74.tar.gz chromium_src-72616e4eb2b89804106875786d06f648534edc74.tar.bz2 |
There are significant structural and functional issues with this code. I was going to remove just the Mac code, but doing so revealed issues with the Linux code as well.
BUG=111652
TEST=
Review URL: https://chromiumcodereview.appspot.com/9307087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print/virtual_driver')
14 files changed, 0 insertions, 802 deletions
diff --git a/cloud_print/virtual_driver/posix/backend.gyp b/cloud_print/virtual_driver/posix/backend.gyp deleted file mode 100644 index ae65801..0000000 --- a/cloud_print/virtual_driver/posix/backend.gyp +++ /dev/null @@ -1,76 +0,0 @@ -# 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. - -{ - 'target_defaults': { - 'variables': { 'chromium_code':1 }, - }, - 'targets': [ - { - 'target_name': 'GCP-driver', - 'type': 'executable', - 'dependencies': [ - '../../../base/base.gyp:base', - ], - 'sources': [ - 'printer_driver_util_linux.cc', - 'printer_driver_util_posix.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'], - }], - ], - }, - { - 'target_name': 'virtual_driver_posix_unittests', - 'type': 'executable', - 'dependencies': [ - '../../../base/base.gyp:base', - '../../../base/base.gyp:test_support_base', - '../../../testing/gmock.gyp:gmock', - '../../../testing/gtest.gyp:gtest', - ], - 'sources': [ - 'virtual_driver_posix_tests.cc', - 'printer_driver_util_posix.cc', - ], - }], - '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 deleted file mode 100644 index 0d3f44c2..0000000 --- a/cloud_print/virtual_driver/posix/install_cloud_print_driver_mac.mm +++ /dev/null @@ -1,20 +0,0 @@ -// 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 deleted file mode 100644 index 9983313..0000000 --- a/cloud_print/virtual_driver/posix/installer_util_mac.h +++ /dev/null @@ -1,16 +0,0 @@ -// 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 deleted file mode 100644 index 5b19866..0000000 --- a/cloud_print/virtual_driver/posix/installer_util_mac.mm +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2012 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: " - << GetMacOSStatusErrorString(status) - << " (" - << 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: " - << GetMacOSStatusErrorString(status) - << " (" - << status - << ")"; - exit(-1); - } -} - -} // namespace cloud_print diff --git a/cloud_print/virtual_driver/posix/linux_packaging/build.sh b/cloud_print/virtual_driver/posix/linux_packaging/build.sh deleted file mode 100755 index e42791f..0000000 --- a/cloud_print/virtual_driver/posix/linux_packaging/build.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -# -# 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. - -set -u -set -e - -# Change to directory in which we are located. -SCRIPTDIR=$(readlink -f "$(dirname "$0")") -cd $SCRIPTDIR - -PACKAGE_NAME="gcpdriver" - -# Clean up any old data completely -rm -rf debian - -# Target architecture to same as build host. -if [ "$(uname -m)" = "x86_64" ]; then - TARGETARCH="amd64" -else - TARGETARCH="i386" -fi - -# Set up the required directory structure -mkdir -p debian/usr/lib/cups/backend -mkdir -p debian/usr/share/ppd/GCP -mkdir -p debian/usr/share/doc/$PACKAGE_NAME -mkdir -p debian/DEBIAN -chmod 755 debian/DEBIAN - -# Copy files to the correct location -# These files are copied in by the previous GYP target. -mv postinst debian/DEBIAN -mv postrm debian/DEBIAN -mv prerm debian/DEBIAN -mv GCP-driver.ppd debian/usr/share/ppd/GCP -echo "Architecture:${TARGETARCH}" >> debian/DEBIAN/control -cat control >> debian/DEBIAN/control -mv changelog debian/usr/share/doc/$PACKAGE_NAME/ -gzip --best -f debian/usr/share/doc/$PACKAGE_NAME/changelog -mv copyright debian/usr/share/doc/$PACKAGE_NAME/ -mv GCP-driver debian/usr/lib/cups/backend - -# Set permissions as required to roll package -chmod 755 debian/DEBIAN/postinst -chmod 755 debian/DEBIAN/postrm -chmod 755 debian/DEBIAN/prerm -chmod -R 755 debian/usr -chmod 644 debian/usr/share/doc/$PACKAGE_NAME/* -chmod 644 debian/usr/share/ppd/GCP/GCP-driver.ppd - -# Actually roll the package and rename -fakeroot dpkg-deb --build debian -mv debian.deb gcp-driver.deb - -# Clean up -rm -rf debian -rm control
\ No newline at end of file diff --git a/cloud_print/virtual_driver/posix/mac_packaging/build_mac.sh b/cloud_print/virtual_driver/posix/mac_packaging/build_mac.sh deleted file mode 100755 index b142aea..0000000 --- a/cloud_print/virtual_driver/posix/mac_packaging/build_mac.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -# -# 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. - -set -u -set -e - -# Change to directory in which we are located. -SCRIPTDIR="$( cd "$( dirname "$0" )" && pwd )" -cd $SCRIPTDIR - -#### INSTALLER ##### - -# Set up the directory structure for the package -mkdir -p Resources -mkdir -p package_root/usr/libexec/cups/backend - -# Move out files to the directory structure -# These files are copied in by the GYP file, so -# we move them. -mv GCP-driver package_root/usr/libexec/cups/backend -mv GCP-driver.ppd Resources -mv GCP-install Resources -mv install.sh Resources - -# Actually build our package -/Developer/usr/bin/packagemaker \ - -d GCP-Virtual-Driver.pmdoc -t GCP-virtual-driver - - - -##### UNINSTALLER ##### - -#Clean up any old uninstaller -rm -rf uninstall_resources -mkdir uninstall_resources -mv GCP-uninstall uninstall_resources -mv uninstall.sh uninstall_resources - - -##### CLEANUP ##### -rm -rf Resources -rm -rf package_root -rm -rf GCP-Virtual-Driver.pmdoc -rm build_mac.sh
\ No newline at end of file diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc b/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc deleted file mode 100644 index b7e70cf..0000000 --- a/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc +++ /dev/null @@ -1,51 +0,0 @@ -// 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 <cups/backend.h> - -#include "base/base_paths.h" -#include "base/command_line.h" -#include "base/file_path.h" -#include "base/logging.h" -#include "base/path_service.h" - -#include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" -#include "cloud_print/virtual_driver/virtual_driver_switches.h" - -namespace printer_driver_util { - -void LaunchPrintDialog(const std::string& output_path, - const std::string& job_title, - const std::string& current_user, - const std::string& print_ticket) { - std::string set_var; - - // Set Environment variable to control display. - set_var = "/home/" + current_user + "/.Xauthority"; - if (setenv("DISPLAY", ":0.0", 0) == -1) { - LOG(ERROR) << "Unable to set DISPLAY environment variable"; - } - if (setenv("XAUTHORITY", set_var.c_str(), 0) == -1) { - LOG(ERROR) << "Unable to set XAUTHORITY environment variable"; - } - - // Construct the call to Chrome - FilePath chrome_path("google-chrome"); - FilePath job_path(output_path); - CommandLine command_line(chrome_path); - command_line.AppendSwitchPath(switches::kCloudPrintFile, job_path); - command_line.AppendSwitchNative(switches::kCloudPrintJobTitle, job_title); - command_line.AppendSwitch(switches::kCloudPrintDeleteFile); - command_line.AppendSwitchNative(switches::kCloudPrintPrintTicket, - print_ticket); - LOG(INFO) << "Call to chrome is " << command_line.GetCommandLineString(); - if (system(command_line.GetCommandLineString().c_str()) == -1) { - LOG(ERROR) << "Unable to call Chrome"; - exit(CUPS_BACKEND_CANCEL); - } - LOG(INFO) << "Call to Chrome succeeded"; -} - -} // namespace printer_driver_util - diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm b/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm deleted file mode 100644 index ddda3da..0000000 --- a/cloud_print/virtual_driver/posix/printer_driver_util_mac.mm +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) 2012 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 "base/mac/mac_logging.h" - -#include <cups/backend.h> - -#include <stdlib.h> -#include <string> - -// Duplicated is chrome/common/cloud_print/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 - -namespace printer_driver_util { -void LaunchPrintDialog(const std::string& outputPath, - const std::string& jobTitle, - const std::string& user, - const std::string& print_ticket) { - 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) { - OSSTATUS_LOG(ERROR, status) - << "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"]; - NSAppleEventDescriptor* ticket = - [NSAppleEventDescriptor descriptorWithString: - [NSString stringWithUTF8String:print_ticket.c_str()]]; - - // 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]; - [parameters insertDescriptor:ticket atIndex:4]; - [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) { - OSSTATUS_LOG(ERROR, status) << "Unable to launch"; - exit(CUPS_BACKEND_CANCEL); - } - - [pool release]; - return; -} - -} // namespace printer_driver_util diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_posix.cc b/cloud_print/virtual_driver/posix/printer_driver_util_posix.cc deleted file mode 100644 index d78f632..0000000 --- a/cloud_print/virtual_driver/posix/printer_driver_util_posix.cc +++ /dev/null @@ -1,99 +0,0 @@ -// 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 <pwd.h> -#include <stdio.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> - -#include <cups/backend.h> - -#include "base/json/json_writer.h" -#include "base/logging.h" -#include "base/string_tokenizer.h" -#include "base/values.h" - -#include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" - -namespace printer_driver_util { - -void WriteToTemp(FILE* input_pdf, FilePath output_path) { - FILE* output_pdf; - char buffer[128]; - output_pdf = fopen(output_path.value().c_str(), "w"); - if (output_pdf == NULL) { - LOG(ERROR) << "Unable to open file handle for writing output file"; - exit(CUPS_BACKEND_CANCEL); - } - // Read from input file or stdin and write to output file. - while (fgets(buffer, sizeof(buffer), input_pdf) != NULL) { - fputs(buffer, output_pdf); - } - - LOG(INFO) << "Successfully wrote output file"; - // ensure everything is written, then close the files. - fflush(output_pdf); - fclose(input_pdf); - fclose(output_pdf); -} - -// Sets the UID of the process to that of the username. -void SetUser(const char* user) { - struct passwd* calling_user = NULL; - calling_user = getpwnam(user); - if (calling_user == NULL) { - LOG(ERROR) << "Unable to get calling user"; - exit(CUPS_BACKEND_CANCEL); - } - if (!setuid(calling_user->pw_uid) == -1) { - LOG(ERROR) << "Unable to set UID"; - exit(CUPS_BACKEND_CANCEL); - } - - LOG(INFO) << "Successfully set user and group ID"; -} - -// Parses the options passed in on the command line to key value -// JSON pairs. Assumes that the input options string is of the -// format KEY=VALUE, with expressions being separated by spaces. -// Fails if print_ticket cannot be written to. -void GetOptions(const char* options, std::string* print_ticket) { - if (options == NULL) { - *(print_ticket) = "{}"; - return; - } - CStringTokenizer t(options, options + strlen(options), " "); - DictionaryValue* json_options = new DictionaryValue; - - while (t.GetNext()) { - std::string token = t.token(); - // If the token ends with a slash, that indicates - // that the next space is actually escaped - // So we append the next token onto this token - // if possible. We also replace the slash with a space - // since the JSON will expect an unescaped string. - while (token.at(token.length()-1) == '\\') { - if (t.GetNext()) { - token.replace(token.length()-1, 1, " "); - token.append(t.token()); - } else { - break; - } - } - size_t pos = token.find("="); - if (pos == std::string::npos) { - continue; - } - std::string option_name = token.substr(0, pos); - std::string option_value = token.substr(pos+1); - base::StringValue* val= base::Value::CreateStringValue(option_value); - json_options->SetWithoutPathExpansion(option_name, val); - } - base::JSONWriter::Write(json_options, /*pretty_print=*/false, print_ticket); - delete json_options; -} - -} // namespace printer_driver_util - diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_posix.h b/cloud_print/virtual_driver/posix/printer_driver_util_posix.h deleted file mode 100644 index 8631f07..0000000 --- a/cloud_print/virtual_driver/posix/printer_driver_util_posix.h +++ /dev/null @@ -1,24 +0,0 @@ -// 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_DRIVER_POSIX_PRINTER_DRIVER_UTIL_POSIX_H_ -#define CLOUD_PRINT_VIRTUAL_DRIVER_POSIX_PRINTER_DRIVER_UTIL_POSIX_H_ -#pragma once - -#include <string> - -#include "base/file_path.h" - -namespace printer_driver_util { - -void LaunchPrintDialog(const std::string& output_path, - const std::string& job_title, - const std::string& current_user, - const std::string& print_ticket); -void WriteToTemp(FILE* input_pdf, FilePath output_path); -void SetUser(const char* user); -void GetOptions(const char* options, std::string* print_ticket); - -} // namespace printer_driver_util - -#endif // CLOUD_PRINT_VIRTUAL_DRIVER_POSIX_PRINTER_DRIVER_UTIL_POSIX_H_ 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 deleted file mode 100644 index adb7edc..0000000 --- a/cloud_print/virtual_driver/posix/uninstall_cloud_print_driver_mac.mm +++ /dev/null @@ -1,20 +0,0 @@ -// 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/posix/virtual_driver_posix.cc b/cloud_print/virtual_driver/posix/virtual_driver_posix.cc deleted file mode 100644 index aac6299..0000000 --- a/cloud_print/virtual_driver/posix/virtual_driver_posix.cc +++ /dev/null @@ -1,102 +0,0 @@ -// 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 <cups/backend.h> - -#include "base/at_exit.h" -#include "base/base_paths.h" -#include "base/command_line.h" -#include "base/file_path.h" -#include "base/logging.h" -#include "base/path_service.h" - -#include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" - -// Main function for backend. -int main(int argc, const char* argv[]) { - // With no arguments, send identification string as required by CUPS. - if (argc == 1) { - printf("file GCP-driver:/ \"GCP Virtual Driver\" \"GCP Virtual Driver\" " - "\"MFG:Google Inc.;MDL:GCP Virtual Driver;DES:GCP Virtual Driver;" - "CLS:PRINTER;CMD:POSTSCRIPT;\"\n"); - return 0; - } - - if (argc < 6 || argc > 7) { - fprintf(stderr, "Usage: GCP-Driver job-id user " - "title copies options [file]\n"); - return 0; - } - - // We can run the backend as root or unpriveliged user lp - // Since we want to launch the printer dialog as the user - // that initiated the print job, we run the backend as root - // and then setuid to the user that started the print job - printer_driver_util::SetUser(argv[2]); - - // AtExitManager is necessary to use the path service. - base::AtExitManager aemanager; - // CommandLine is only setup to enable logging, never used subseqeuently. - CommandLine::Init(argc, argv); - // Location for the log file. - std::string log_location = "/var/log/GCP-Driver.log"; - - // Set up logging. - logging::InitLogging(log_location.c_str(), - logging::LOG_ONLY_TO_FILE, - logging::LOCK_LOG_FILE, - logging::APPEND_TO_OLD_LOG_FILE, - logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); - - // Temporary directory to hold the output file. - FilePath temp_dir; - // Strings to hold details of current job. - std::string current_user; - std::string set_var; - std::string job_title; - std::string job_id; - std::string file_name; - std::string print_ticket; - - // Get temp directory to hold spool file. - if (!PathService::Get(base::DIR_TEMP, &temp_dir)) { - LOG(ERROR) << "Unable to get DIR_TEMP"; - return CUPS_BACKEND_CANCEL; - } - // Get details from command line and set spool path. - current_user = argv[2]; - job_title = argv[3]; - job_id = argv[1]; - printer_driver_util::GetOptions(argv[5], &print_ticket); - file_name = current_user + "-" + job_title + "-" + job_id; - FilePath output_path = temp_dir.Append(file_name); - - // However, the input file can only be read as root. - if (!setuid(0)) { - PLOG(ERROR) << "Unable to setuid back to 0"; - } - - if (argc == 7) { - // Read from file if specified. - FILE* input_pdf = fopen(argv[6], "r"); - if (input_pdf == NULL) { - LOG(ERROR) << "Unable to read input PDF"; - return CUPS_BACKEND_CANCEL; - } - // File is opened. - printer_driver_util::WriteToTemp(input_pdf, output_path); - } else { - // Otherwise, read from stdin. - printer_driver_util::WriteToTemp(stdin, output_path); - } - - // Change back to user to launch Chrome. - printer_driver_util::SetUser(argv[2]); - PLOG(ERROR) << print_ticket; - // Launch Chrome and pass the print job onto Cloud Print. - printer_driver_util::LaunchPrintDialog(output_path.value(), job_title, - current_user, print_ticket); - - return 0; -} diff --git a/cloud_print/virtual_driver/posix/virtual_driver_posix_tests.cc b/cloud_print/virtual_driver/posix/virtual_driver_posix_tests.cc deleted file mode 100644 index 34869af..0000000 --- a/cloud_print/virtual_driver/posix/virtual_driver_posix_tests.cc +++ /dev/null @@ -1,75 +0,0 @@ -// 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" -#include "testing/gtest/include/gtest/gtest.h" - -namespace printer_driver_util { - -void test_helper(const char* input, std::string expected_output) { - std::string test; - GetOptions(input, &test); - EXPECT_EQ(expected_output, test); -} - -TEST(PrintTicketTest, HandlesEmpty) { - test_helper("", "{}"); -} - -TEST(PrintTicketTest, HandlesNull) { - test_helper(NULL, "{}"); -} - -TEST(PrintTicketTest, HandlesOneOption) { - test_helper("Resolution=500", "{\"Resolution\":\"500\"}"); -} - -TEST(PrintTicketTest, HandlesMutipleOptions) { - test_helper("Resolution=500 DPI=1100", - "{\"DPI\":\"1100\",\"Resolution\":\"500\"}"); -} - -TEST(PrintTicketTest, HandlesErrorInOptions) { - test_helper("Resolution=500 Foo DPI=1100", - "{\"DPI\":\"1100\",\"Resolution\":\"500\"}"); -} - -TEST(PrintTicketTest, HandlesMutipleSpaces) { - test_helper("Resolution=500 DPI=1100", - "{\"DPI\":\"1100\",\"Resolution\":\"500\"}"); -} - -TEST(PrintTicketTest, HandlesEscapedSpace) { - test_helper("Job\\ Owner=First\\ Last", - "{\"Job Owner\":\"First Last\"}"); -} - -TEST(PrintTicketTest, HandlesMultipleEscapedWords) { - test_helper("Job\\ Owner\\ Name=First\\ Last", - "{\"Job Owner Name\":\"First Last\"}"); -} - -TEST(PrintTicketTest, HandlesMultipleEscapedSpaces) { - test_helper("Job\\ Owner\\ \\ Name=First\\ Last", - "{\"Job Owner Name\":\"First Last\"}"); -} - -TEST(PrintTicketTest, HandlesKeyEndsInEscapedSpace) { - test_helper("Job\\ Owner\\ =First\\ Last", - "{\"Job Owner \":\"First Last\"}"); -} - -TEST(PrintTicketTest, HandlesSlashAtEnd) { - test_helper("Job\\ Owner=First\\ Last\\", - "{\"Job Owner\":\"First Last\\\\\"}"); -} - - -} // namespace printer_driver_util - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/cloud_print/virtual_driver/virtual_driver_posix.gyp b/cloud_print/virtual_driver/virtual_driver_posix.gyp deleted file mode 100644 index cb458ec..0000000 --- a/cloud_print/virtual_driver/virtual_driver_posix.gyp +++ /dev/null @@ -1,15 +0,0 @@ -# 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. -{ - 'targets': [ - { - 'target_name': 'virtual_driver_posix', - 'type': 'none', - 'dependencies': [ - 'posix/backend.gyp:*', - ], - }, - ], -} - |