summaryrefslogtreecommitdiffstats
path: root/cloud_print
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-13 17:59:12 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-13 17:59:12 +0000
commit04eb2a4471cd1bcfbedd711360d5eaa1dc0d2bdf (patch)
tree362cd7f2f654274794672ce3b1c2383c9acb4b5e /cloud_print
parent509d9b37a4c35fbc6210b3232d79e777cec0ff3a (diff)
downloadchromium_src-04eb2a4471cd1bcfbedd711360d5eaa1dc0d2bdf.zip
chromium_src-04eb2a4471cd1bcfbedd711360d5eaa1dc0d2bdf.tar.gz
chromium_src-04eb2a4471cd1bcfbedd711360d5eaa1dc0d2bdf.tar.bz2
Revert 92378 because it broke Win Builder (dbg)(shared) - Additional Commits for Linux printer driver
Initial commit for Linux virtual printer BUG= TEST= Review URL: http://codereview.chromium.org/7222011 TBR=abeera@google.com Review URL: http://codereview.chromium.org/7354024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92379 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print')
-rw-r--r--cloud_print/virtual_driver/posix/backend.gyp32
-rw-r--r--cloud_print/virtual_driver/posix/printer_driver_util_linux.cc48
-rw-r--r--cloud_print/virtual_driver/posix/printer_driver_util_posix.h12
-rw-r--r--cloud_print/virtual_driver/posix/virtual_driver_posix.cc156
-rw-r--r--cloud_print/virtual_driver/virtual_driver_linux.gyp20
-rw-r--r--cloud_print/virtual_driver/virtual_driver_switches.cc13
-rw-r--r--cloud_print/virtual_driver/virtual_driver_switches.h33
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/port_monitor.cc24
-rw-r--r--cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp1
9 files changed, 23 insertions, 316 deletions
diff --git a/cloud_print/virtual_driver/posix/backend.gyp b/cloud_print/virtual_driver/posix/backend.gyp
deleted file mode 100644
index 8492a80..0000000
--- a/cloud_print/virtual_driver/posix/backend.gyp
+++ /dev/null
@@ -1,32 +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': {
- 'include_dirs': [
- '../..'
- ],
- },
- 'targets' : [
- {
- 'target_name': 'GCP-driver',
- 'type': 'executable',
- 'dependencies': [
- '../../../base/base.gyp:base',
- ],
- 'msvs_guid': '8D06D53B-289E-4f99-99FC-77C77DB478A8',
- 'sources' : [
- 'virtual_driver_posix.cc',
- 'printer_driver_util_linux.cc',
- '../virtual_driver_switches.cc',
- ]
- },
- ],
-}
-
-# Local Variables:
-# tab-width:2
-# indent-tabs-mode:nil
-# End:
-# vim: set expandtab tabstop=2 shiftwidth=2:
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 119a4b5..0000000
--- a/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc
+++ /dev/null
@@ -1,48 +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"
-
-void LaunchPrintDialog(std::string output_path, std::string job_title,
- std::string current_user) {
- 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);
- LOG(INFO) << "Call to chrome is " << command_line.command_line_string();
-
- if(system(command_line.command_line_string().c_str())== -1 ) {
- LOG(ERROR) << "Unable to call Chrome";
- exit(CUPS_BACKEND_CANCEL);
- }
-
- else {
- LOG(INFO) << "Call to Chrome succeeded";
- }
-}
-
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 4d8d7a5..0000000
--- a/cloud_print/virtual_driver/posix/printer_driver_util_posix.h
+++ /dev/null
@@ -1,12 +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_LINUX_PRINTER_DRIVER_UTIL_POSIX_H_
-#define CLOUD_PRINT_VIRTUAL_DRIVER_LINUX_PRINTER_DRIVER_UTIL_POSIX_H_
-#pragma once
-#include <string>
-
-void LaunchPrintDialog(std::string output_path, std::string job_title,
- std::string current_user);
-
-#endif // CLOUD_PRINT_VIRTUAL_DRIVER_LINUX_PRINTER_DRIVER_UTIL_POSIX_H_
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 868228a..0000000
--- a/cloud_print/virtual_driver/posix/virtual_driver_posix.cc
+++ /dev/null
@@ -1,156 +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 <cups/backend.h>
-
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.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"
-
-using namespace std;
-
-int 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,128,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);
-}
-
-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(setgid(calling_user->pw_gid)==-1) {
- LOG(ERROR) << "Unable to set group ID";
- 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";
-}
-
-
-
-// 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;
- }
-
- //AtExitManager is necessary to use the path service.
- base::AtExitManager aemanager;
- // File handler for the temporary PDF we pass onto Chrome.
- FILE* output_pdf;
- //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;
-
- // 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];
- file_name = current_user + "-" + job_title + "-" + job_id;
- FilePath output_path = temp_dir.Append(file_name);
-
- // Read from file if specified.
- if(argc==7){
- 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.
- WriteToTemp(input_pdf,output_path);
- }
- // Otherwise, read from stdin.
- else{
- WriteToTemp(stdin, output_path);
- }
-
- // Set File permissions to allow non-sudo user to read spool file.
- if(chmod(output_path.value().c_str(),S_IRUSR|S_IWUSR|S_IROTH|S_IWOTH)!=0) {
- LOG(ERROR)<<"Unable to change file permissions";
- return CUPS_BACKEND_CANCEL;
- }
-
- pid_t pid=fork();
-
- if(!pid) {
- // In child process.
-
- // Set the user to the one that initiated print job.
- SetUser(argv[2]);
-
- // Launch Chrome and pass the print job onto Cloud Print.
- LaunchPrintDialog(output_path.value(), job_title, current_user);
-
- return 0;
- }// back in parent process.
- // wait for child, then terminate.
- waitpid(pid,NULL,0);
- return 0;
-}// main
diff --git a/cloud_print/virtual_driver/virtual_driver_linux.gyp b/cloud_print/virtual_driver/virtual_driver_linux.gyp
deleted file mode 100644
index 53fa411..0000000
--- a/cloud_print/virtual_driver/virtual_driver_linux.gyp
+++ /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.
-{
- 'targets': [
- {
- 'target_name': 'virtual_driver',
- 'type': 'none',
- 'dependencies': [
- 'posix/backend.gyp:*',
- ],
- },
- ],
-}
-
-# Local Variables:
-# tab-width:2
-# indent-tabs-mode:nil
-# End:
-# vim: set expandtab tabstop=2 shiftwidth=2:
diff --git a/cloud_print/virtual_driver/virtual_driver_switches.cc b/cloud_print/virtual_driver/virtual_driver_switches.cc
deleted file mode 100644
index 59022f1..0000000
--- a/cloud_print/virtual_driver/virtual_driver_switches.cc
+++ /dev/null
@@ -1,13 +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/virtual_driver_switches.h"
-
-namespace switches {
-const char kCloudPrintDeleteFile[] = "cloud-print-delete-file";
-const char kCloudPrintFile[] = "cloud-print-file";
-const char kCloudPrintJobTitle[] = "cloud-print-job-title";
-const char kCloudPrintFileType[] = "cloud-print-file-type";
-} //namespace switches
-
diff --git a/cloud_print/virtual_driver/virtual_driver_switches.h b/cloud_print/virtual_driver/virtual_driver_switches.h
deleted file mode 100644
index aa8f127..0000000
--- a/cloud_print/virtual_driver/virtual_driver_switches.h
+++ /dev/null
@@ -1,33 +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_VIRTUAL_DRIVER_SWITCHES_H
-#define CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H
-#pragma once
-
-namespace switches {
-// These constants are duplicated from chrome/common/chrome_switches.cc
-// in order to avoid dependency problems.
-// TODO(abodenha@chromium.org) Reunify them in some sensible manner.
-// Bug: www.crbug.com/88991
-
-// Used with kCloudPrintFile. Tells Chrome to delete the file when
-// finished displaying the print dialog.
-extern const char kCloudPrintDeleteFile[];
-
-// Tells chrome to display the cloud print dialog and upload the
-// specified file for printing.
-extern const char kCloudPrintFile[];
-
-// Used with kCloudPrintFile to specify a title for the resulting print
-// job.
-extern const char kCloudPrintJobTitle[];
-
-// Specifies the mime type to be used when uploading data from the
-// file referenced by cloud-print-file.
-// Defaults to "application/pdf" if unspecified.
-extern const char kCloudPrintFileType[];
-} //namespace switches
-
-#endif // CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H
diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
index 0c196ba1..562d0b8 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
@@ -25,7 +25,29 @@
#include "cloud_print/virtual_driver/win/port_monitor/spooler_win.h"
#include "cloud_print/virtual_driver/win/virtual_driver_consts.h"
#include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
-#include "cloud_print/virtual_driver/virtual_driver_switches.h"
+
+namespace switches {
+// These constants are duplicated from chrome/common/chrome_switches.cc
+// in order to avoid dependency problems.
+// TODO(abodenha@chromium.org) Reunify them in some sensible manner.
+
+// Used with kCloudPrintFile. Tells Chrome to delete the file when
+// finished displaying the print dialog.
+const char kCloudPrintDeleteFile[] = "cloud-print-delete-file";
+
+// Tells chrome to display the cloud print dialog and upload the
+// specified file for printing.
+const char kCloudPrintFile[] = "cloud-print-file";
+
+// Used with kCloudPrintFile to specify a title for the resulting print
+// job.
+const char kCloudPrintJobTitle[] = "cloud-print-job-title";
+
+// Specifies the mime type to be used when uploading data from the
+// file referenced by cloud-print-file.
+// Defaults to "application/pdf" if unspecified.
+const char kCloudPrintFileType[] = "cloud-print-file-type";
+}
namespace cloud_print {
diff --git a/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp b/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp
index 0a15c14..e04c25f 100644
--- a/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp
+++ b/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp
@@ -17,7 +17,6 @@
'userenv.lib',
],
'sources': [
- '../../virtual_driver_switches.cc',
'../virtual_driver_consts.h',
'../virtual_driver_consts.cc',
'../virtual_driver_helpers.h',