diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-25 20:05:44 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-25 20:05:44 +0000 |
commit | 8e553f499860ac0b3bdea8326b7bc95a7650e250 (patch) | |
tree | 7c28ec6cbfae93e10038d97507a936a6e918aa2b /printing | |
parent | 992848f4eb2e39e73b0bc2932253e9396eaf0369 (diff) | |
download | chromium_src-8e553f499860ac0b3bdea8326b7bc95a7650e250.zip chromium_src-8e553f499860ac0b3bdea8326b7bc95a7650e250.tar.gz chromium_src-8e553f499860ac0b3bdea8326b7bc95a7650e250.tar.bz2 |
Move useful printing backend code from chrome/service/cloud_print to printing/backend.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3945003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/backend/cups_helper.cc | 44 | ||||
-rw-r--r-- | printing/backend/cups_helper.h | 31 | ||||
-rw-r--r-- | printing/backend/print_backend.cc | 15 | ||||
-rw-r--r-- | printing/backend/print_backend.h | 70 | ||||
-rw-r--r-- | printing/backend/print_backend_consts.cc | 10 | ||||
-rw-r--r-- | printing/backend/print_backend_consts.h | 12 | ||||
-rw-r--r-- | printing/backend/print_backend_cups.cc | 224 | ||||
-rw-r--r-- | printing/backend/print_backend_dummy.cc | 23 | ||||
-rw-r--r-- | printing/backend/print_backend_win.cc | 179 | ||||
-rw-r--r-- | printing/backend/win_helper.cc | 17 | ||||
-rw-r--r-- | printing/backend/win_helper.h | 16 | ||||
-rw-r--r-- | printing/printing.gyp | 57 |
12 files changed, 687 insertions, 11 deletions
diff --git a/printing/backend/cups_helper.cc b/printing/backend/cups_helper.cc new file mode 100644 index 0000000..2c3b853 --- /dev/null +++ b/printing/backend/cups_helper.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2010 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 "printing/backend/cups_helper.h" + +#include "base/logging.h" +#include "googleurl/src/gurl.h" + +namespace printing { + +// Default port for IPP print servers. +static const int kDefaultIPPServerPort = 631; + +// Helper wrapper around http_t structure, with connection and cleanup +// functionality. +HttpConnectionCUPS::HttpConnectionCUPS(const GURL& print_server_url) + : http_(NULL) { + // If we have an empty url, use default print server. + if (print_server_url.is_empty()) + return; + + int port = print_server_url.IntPort(); + if (port == url_parse::PORT_UNSPECIFIED) + port = kDefaultIPPServerPort; + + http_ = httpConnectEncrypt(print_server_url.host().c_str(), port, + HTTP_ENCRYPT_NEVER); + if (http_ == NULL) { + LOG(ERROR) << "CP_CUPS: Failed connecting to print server: " << + print_server_url; + } +} + +HttpConnectionCUPS::~HttpConnectionCUPS() { + if (http_ != NULL) + httpClose(http_); +} + +http_t* HttpConnectionCUPS::http() { + return http_; +} + +} // namespace printing diff --git a/printing/backend/cups_helper.h b/printing/backend/cups_helper.h new file mode 100644 index 0000000..16841bc --- /dev/null +++ b/printing/backend/cups_helper.h @@ -0,0 +1,31 @@ +// Copyright (c) 2010 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 PRINTING_BACKEND_CUPS_HELPER_H_ +#define PRINTING_BACKEND_CUPS_HELPER_H_ +#pragma once + +#include <cups/cups.h> + +class GURL; + +// These are helper functions for dealing with CUPS. +namespace printing { + +// Helper wrapper around http_t structure, with connection and cleanup +// functionality. +class HttpConnectionCUPS { + public: + explicit HttpConnectionCUPS(const GURL& print_server_url); + ~HttpConnectionCUPS(); + + http_t* http(); + + private: + http_t* http_; +}; + +} // namespace printing + +#endif // PRINTING_BACKEND_CUPS_HELPER_H_ diff --git a/printing/backend/print_backend.cc b/printing/backend/print_backend.cc new file mode 100644 index 0000000..307897d --- /dev/null +++ b/printing/backend/print_backend.cc @@ -0,0 +1,15 @@ +// Copyright (c) 2010 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 "printing/backend/print_backend.h" + +namespace printing { + +PrinterBasicInfo::PrinterBasicInfo() : printer_status(0) {} + +PrinterBasicInfo::~PrinterBasicInfo() {} + +PrintBackend::~PrintBackend() {} + +} // namespace printing diff --git a/printing/backend/print_backend.h b/printing/backend/print_backend.h new file mode 100644 index 0000000..3b55268 --- /dev/null +++ b/printing/backend/print_backend.h @@ -0,0 +1,70 @@ +// Copyright (c) 2010 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 PRINTING_BACKEND_PRINT_BACKEND_H_ +#define PRINTING_BACKEND_PRINT_BACKEND_H_ +#pragma once + +#include <map> +#include <string> +#include <vector> + +#include "base/ref_counted.h" + +class DictionaryValue; + +// This is the interface for platform-specific code for a print backend +namespace printing { + +struct PrinterBasicInfo { + PrinterBasicInfo(); + ~PrinterBasicInfo(); + + std::string printer_name; + std::string printer_description; + int printer_status; + std::map<std::string, std::string> options; +}; + +typedef std::vector<PrinterBasicInfo> PrinterList; + +struct PrinterCapsAndDefaults { + std::string printer_capabilities; + std::string caps_mime_type; + std::string printer_defaults; + std::string defaults_mime_type; +}; + +// PrintBackend class will provide interface for different print backends +// (Windows, CUPS) to implement. User will call CreateInstance() to +// obtain available print backend. +// Please note, that PrintBackend is not platform specific, but rather +// print system specific. For example, CUPS is available on both Linux and Mac, +// but not available on ChromeOS, etc. This design allows us to add more +// functionality on some platforms, while reusing core (CUPS) functions. +class PrintBackend : public base::RefCountedThreadSafe<PrintBackend> { + public: + virtual ~PrintBackend(); + + // Enumerates the list of installed local and network printers. + virtual void EnumeratePrinters(PrinterList* printer_list) = 0; + + // Gets the capabilities and defaults for a specific printer. + virtual bool GetPrinterCapsAndDefaults( + const std::string& printer_name, + PrinterCapsAndDefaults* printer_info) = 0; + + // Returns true if printer_name points to a valid printer. + virtual bool IsValidPrinter(const std::string& printer_name) = 0; + + // Allocate a print backend. If |print_backend_settings| is NULL, default + // settings will be used. + // Return NULL if no print backend available. + static scoped_refptr<PrintBackend> CreateInstance( + const DictionaryValue* print_backend_settings); +}; + +} // namespace printing + +#endif // PRINTING_BACKEND_PRINT_BACKEND_H_ diff --git a/printing/backend/print_backend_consts.cc b/printing/backend/print_backend_consts.cc new file mode 100644 index 0000000..77a0020 --- /dev/null +++ b/printing/backend/print_backend_consts.cc @@ -0,0 +1,10 @@ +// Copyright (c) 2010 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. + +// Constant defines used in the print backend code + +#include "printing/backend/print_backend_consts.h" + +const char kLocationTagName[] = "location"; +const char kDriverNameTagName[] = "drivername"; diff --git a/printing/backend/print_backend_consts.h b/printing/backend/print_backend_consts.h new file mode 100644 index 0000000..003a87d --- /dev/null +++ b/printing/backend/print_backend_consts.h @@ -0,0 +1,12 @@ +// Copyright (c) 2010 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 PRINTING_BACKEND_PRINT_BACKEND_CONSTS_H_ +#define PRINTING_BACKEND_PRINT_BACKEND_CONSTS_H_ +#pragma once + +extern const char kLocationTagName[]; +extern const char kDriverNameTagName[]; + +#endif // PRINTING_BACKEND_PRINT_BACKEND_CONSTS_H_ diff --git a/printing/backend/print_backend_cups.cc b/printing/backend/print_backend_cups.cc new file mode 100644 index 0000000..9693299 --- /dev/null +++ b/printing/backend/print_backend_cups.cc @@ -0,0 +1,224 @@ +// Copyright (c) 2010 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 "printing/backend/print_backend.h" + +#include <dlfcn.h> +#include <errno.h> +#include <gcrypt.h> +#include <pthread.h> + +#include "base/file_util.h" +#include "base/lock.h" +#include "base/logging.h" +#include "base/singleton.h" +#include "base/string_number_conversions.h" +#include "base/values.h" +#include "googleurl/src/gurl.h" +#include "printing/backend/cups_helper.h" + +GCRY_THREAD_OPTION_PTHREAD_IMPL; + +namespace { + +// Init GCrypt library (needed for CUPS) using pthreads. +// There exists a bug in CUPS library, where it crashed with: "ath.c:184: +// _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed." +// It happened when multiple threads tried printing simultaneously. +// Google search for 'gnutls thread safety' provided a solution that +// initialized gcrypt and gnutls. + +// Initially, we linked with -lgnutls and simply called gnutls_global_init(), +// but this did not work well since we build one binary on Ubuntu Hardy and +// expect it to run on many Linux distros. (See http://crbug.com/46954) +// So instead we use dlopen() and dlsym() to dynamically load and call +// gnutls_global_init(). + +class GcryptInitializer { + public: + GcryptInitializer() { + Init(); + } + + private: + void Init() { + gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); + const char* kGnuTlsFile = "libgnutls.so"; + void* gnutls_lib = dlopen(kGnuTlsFile, RTLD_NOW); + if (!gnutls_lib) { + LOG(ERROR) << "Cannot load " << kGnuTlsFile; + return; + } + const char* kGnuTlsInitFuncName = "gnutls_global_init"; + int (*pgnutls_global_init)(void) = reinterpret_cast<int(*)()>( + dlsym(gnutls_lib, kGnuTlsInitFuncName)); + if (!pgnutls_global_init) { + LOG(ERROR) << "Could not find " << kGnuTlsInitFuncName + << " in " << kGnuTlsFile; + return; + } + if ((*pgnutls_global_init)() != 0) + LOG(ERROR) << "Gnutls initialization failed"; + } +}; + +} // namespace + +namespace printing { + +static const char kCUPSPrinterInfoOpt[] = "printer-info"; +static const char kCUPSPrinterStateOpt[] = "printer-state"; +static const char kCUPSPrintServerURL[] = "print_server_url"; + +class PrintBackendCUPS : public PrintBackend { + public: + explicit PrintBackendCUPS(const GURL& print_server_url); + virtual ~PrintBackendCUPS() {} + + // PrintBackend implementation. + virtual void EnumeratePrinters(PrinterList* printer_list); + + virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, + PrinterCapsAndDefaults* printer_info); + + virtual bool IsValidPrinter(const std::string& printer_name); + + private: + // Following functions are wrappers around corresponding CUPS functions. + // <functions>2() are called when print server is specified, and plain + // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT + // in the <functions>2(), it does not work in CUPS prior to 1.4. + int GetDests(cups_dest_t** dests); + FilePath GetPPD(const char* name); + + GURL print_server_url_; +}; + +PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url) + : print_server_url_(print_server_url) { +} + +void PrintBackendCUPS::EnumeratePrinters(PrinterList* printer_list) { + DCHECK(printer_list); + printer_list->clear(); + + cups_dest_t* destinations = NULL; + int num_dests = GetDests(&destinations); + + for (int printer_index = 0; printer_index < num_dests; printer_index++) { + const cups_dest_t& printer = destinations[printer_index]; + + PrinterBasicInfo printer_info; + printer_info.printer_name = printer.name; + + const char* info = cupsGetOption(kCUPSPrinterInfoOpt, + printer.num_options, printer.options); + if (info != NULL) + printer_info.printer_description = info; + + const char* state = cupsGetOption(kCUPSPrinterStateOpt, + printer.num_options, printer.options); + if (state != NULL) + base::StringToInt(state, &printer_info.printer_status); + + // Store printer options. + for (int opt_index = 0; opt_index < printer.num_options; opt_index++) { + printer_info.options[printer.options[opt_index].name] = + printer.options[opt_index].value; + } + + printer_list->push_back(printer_info); + } + + cupsFreeDests(num_dests, destinations); + + LOG(INFO) << "CUPS: Enumerated " << printer_list->size() << " printers."; +} + +bool PrintBackendCUPS::GetPrinterCapsAndDefaults( + const std::string& printer_name, + PrinterCapsAndDefaults* printer_info) { + DCHECK(printer_info); + + LOG(INFO) << "CUPS: Getting Caps and Defaults for: " << printer_name; + + FilePath ppd_path(GetPPD(printer_name.c_str())); + // In some cases CUPS failed to get ppd file. + if (ppd_path.empty()) { + LOG(ERROR) << "CUPS: Failed to get PPD for: " << printer_name; + return false; + } + + std::string content; + bool res = file_util::ReadFileToString(ppd_path, &content); + + file_util::Delete(ppd_path, false); + + if (res) { + printer_info->printer_capabilities.swap(content); + printer_info->caps_mime_type = "application/pagemaker"; + // In CUPS, printer defaults is a part of PPD file. Nothing to upload here. + printer_info->printer_defaults.clear(); + printer_info->defaults_mime_type.clear(); + } + + return res; +} + +bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { + // This is not very efficient way to get specific printer info. CUPS 1.4 + // supports cupsGetNamedDest() function. However, CUPS 1.4 is not available + // everywhere (for example, it supported from Mac OS 10.6 only). + PrinterList printer_list; + EnumeratePrinters(&printer_list); + + PrinterList::iterator it; + for (it = printer_list.begin(); it != printer_list.end(); ++it) + if (it->printer_name == printer_name) + return true; + return false; +} + +scoped_refptr<PrintBackend> PrintBackend::CreateInstance( + const DictionaryValue* print_backend_settings) { + // Initialize gcrypt library. + Singleton<GcryptInitializer>::get(); + + std::string print_server_url_str; + if (print_backend_settings) { + print_backend_settings->GetString(kCUPSPrintServerURL, + &print_server_url_str); + } + GURL print_server_url(print_server_url_str.c_str()); + return new PrintBackendCUPS(print_server_url); +} + +int PrintBackendCUPS::GetDests(cups_dest_t** dests) { + if (print_server_url_.is_empty()) { // Use default (local) print server. + return cupsGetDests(dests); + } else { + HttpConnectionCUPS http(print_server_url_); + return cupsGetDests2(http.http(), dests); + } +} + +FilePath PrintBackendCUPS::GetPPD(const char* name) { + // cupsGetPPD returns a filename stored in a static buffer in CUPS. + // Protect this code with lock. + static Lock ppd_lock; + AutoLock ppd_autolock(ppd_lock); + FilePath ppd_path; + const char* ppd_file_path = NULL; + if (print_server_url_.is_empty()) { // Use default (local) print server. + ppd_file_path = cupsGetPPD(name); + } else { + HttpConnectionCUPS http(print_server_url_); + ppd_file_path = cupsGetPPD2(http.http(), name); + } + if (ppd_file_path) + ppd_path = FilePath(ppd_file_path); + return ppd_path; +} + +} // namespace printing diff --git a/printing/backend/print_backend_dummy.cc b/printing/backend/print_backend_dummy.cc new file mode 100644 index 0000000..008f00b --- /dev/null +++ b/printing/backend/print_backend_dummy.cc @@ -0,0 +1,23 @@ +// Copyright (c) 2010 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. + +// This is dummy implementation for all configurations where there is no +// print backend. +#if !defined(PRINT_BACKEND_AVAILABLE) + +#include "printing/backend/print_backend.h" + +#include "base/logging.h" + +namespace printing { + +scoped_refptr<PrintBackend> PrintBackend::CreateInstance( + const DictionaryValue* print_backend_settings) { + NOTREACHED(); + return NULL; +} + +} // namespace printing + +#endif // PRINT_BACKEND_AVAILABLE diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc new file mode 100644 index 0000000..4cfd400 --- /dev/null +++ b/printing/backend/print_backend_win.cc @@ -0,0 +1,179 @@ +// Copyright (c) 2010 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 "printing/backend/print_backend.h" + +#include <objidl.h> +#include <prntvpt.h> +#include <winspool.h> + +#include "base/scoped_ptr.h" +#include "base/string_piece.h" +#include "base/utf_string_conversions.h" +#include "base/win/scoped_bstr.h" +#include "base/win/scoped_comptr.h" +#include "base/win/scoped_hglobal.h" +#include "printing/backend/print_backend_consts.h" +#include "printing/backend/win_helper.h" + +#pragma comment(lib, "prntvpt.lib") + +using base::win::ScopedBstr; +using base::win::ScopedComPtr; +using base::win::ScopedHGlobal; + +namespace { + +HRESULT StreamOnHGlobalToString(IStream* stream, std::string* out) { + DCHECK(stream); + DCHECK(out); + HGLOBAL hdata = NULL; + HRESULT hr = GetHGlobalFromStream(stream, &hdata); + if (SUCCEEDED(hr)) { + DCHECK(hdata); + ScopedHGlobal<char> locked_data(hdata); + out->assign(locked_data.release(), locked_data.Size()); + } + return hr; +} + +} // namespace + +namespace printing { + +class PrintBackendWin : public PrintBackend { + public: + PrintBackendWin() {} + virtual ~PrintBackendWin() {} + + virtual void EnumeratePrinters(PrinterList* printer_list); + + virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name, + PrinterCapsAndDefaults* printer_info); + + virtual bool IsValidPrinter(const std::string& printer_name); +}; + +void PrintBackendWin::EnumeratePrinters(PrinterList* printer_list) { + DCHECK(printer_list); + DWORD bytes_needed = 0; + DWORD count_returned = 0; + BOOL ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, + NULL, 0, &bytes_needed, &count_returned); + if (0 != bytes_needed) { + scoped_ptr<BYTE> printer_info_buffer(new BYTE[bytes_needed]); + ret = EnumPrinters(PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, + printer_info_buffer.get(), bytes_needed, &bytes_needed, + &count_returned); + DCHECK(ret); + PRINTER_INFO_2* printer_info = + reinterpret_cast<PRINTER_INFO_2*>(printer_info_buffer.get()); + for (DWORD index = 0; index < count_returned; index++) { + PrinterBasicInfo info; + info.printer_name = WideToUTF8(printer_info[index].pPrinterName); + if (printer_info[index].pComment) + info.printer_description = WideToUTF8(printer_info[index].pComment); + info.printer_status = printer_info[index].Status; + if (printer_info[index].pLocation) + info.options[kLocationTagName] = + WideToUTF8(printer_info[index].pLocation); + if (printer_info[index].pDriverName) + info.options[kDriverNameTagName] = + WideToUTF8(printer_info[index].pDriverName); + printer_list->push_back(info); + } + } +} + +bool PrintBackendWin::GetPrinterCapsAndDefaults( + const std::string& printer_name, + PrinterCapsAndDefaults* printer_info) { + if (!printing::InitXPSModule()) { + // TODO(sanjeevr): Handle legacy proxy case (with no prntvpt.dll) + return false; + } + if (!IsValidPrinter(printer_name)) { + return false; + } + DCHECK(printer_info); + HPTPROVIDER provider = NULL; + std::wstring printer_name_wide = UTF8ToWide(printer_name); + HRESULT hr = PTOpenProvider(printer_name_wide.c_str(), 1, &provider); + DCHECK(SUCCEEDED(hr)); + if (provider) { + ScopedComPtr<IStream> print_capabilities_stream; + hr = CreateStreamOnHGlobal(NULL, TRUE, + print_capabilities_stream.Receive()); + DCHECK(SUCCEEDED(hr)); + if (print_capabilities_stream) { + ScopedBstr error; + hr = PTGetPrintCapabilities(provider, NULL, print_capabilities_stream, + error.Receive()); + DCHECK(SUCCEEDED(hr)); + if (FAILED(hr)) { + return false; + } + hr = StreamOnHGlobalToString(print_capabilities_stream.get(), + &printer_info->printer_capabilities); + DCHECK(SUCCEEDED(hr)); + printer_info->caps_mime_type = "text/xml"; + } + // TODO(sanjeevr): Add ScopedPrinterHandle + HANDLE printer_handle = NULL; + OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()), &printer_handle, + NULL); + DCHECK(printer_handle); + if (printer_handle) { + DWORD devmode_size = DocumentProperties( + NULL, printer_handle, const_cast<LPTSTR>(printer_name_wide.c_str()), + NULL, NULL, 0); + DCHECK_NE(0U, devmode_size); + scoped_ptr<BYTE> devmode_out_buffer(new BYTE[devmode_size]); + DEVMODE* devmode_out = + reinterpret_cast<DEVMODE*>(devmode_out_buffer.get()); + DocumentProperties( + NULL, printer_handle, const_cast<LPTSTR>(printer_name_wide.c_str()), + devmode_out, NULL, DM_OUT_BUFFER); + ScopedComPtr<IStream> printer_defaults_stream; + hr = CreateStreamOnHGlobal(NULL, TRUE, + printer_defaults_stream.Receive()); + DCHECK(SUCCEEDED(hr)); + if (printer_defaults_stream) { + hr = PTConvertDevModeToPrintTicket(provider, devmode_size, + devmode_out, kPTJobScope, + printer_defaults_stream); + DCHECK(SUCCEEDED(hr)); + if (SUCCEEDED(hr)) { + hr = StreamOnHGlobalToString(printer_defaults_stream.get(), + &printer_info->printer_defaults); + DCHECK(SUCCEEDED(hr)); + printer_info->defaults_mime_type = "text/xml"; + } + } + ClosePrinter(printer_handle); + } + PTCloseProvider(provider); + } + return true; +} + +bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) { + std::wstring printer_name_wide = UTF8ToWide(printer_name); + HANDLE printer_handle = NULL; + OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()), &printer_handle, + NULL); + bool ret = false; + if (printer_handle) { + ret = true; + ClosePrinter(printer_handle); + } + return ret; +} + +scoped_refptr<PrintBackend> PrintBackend::CreateInstance( + const DictionaryValue* print_backend_settings) { + return new PrintBackendWin; +} + +} // namespace printing diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc new file mode 100644 index 0000000..a5f515f --- /dev/null +++ b/printing/backend/win_helper.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2010 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 "printing/backend/win_helper.h" + + +#include <windows.h> + +namespace printing { + +bool InitXPSModule() { + HMODULE prntvpt_module = LoadLibrary(L"prntvpt.dll"); + return (NULL != prntvpt_module); +} + +} // namespace printing diff --git a/printing/backend/win_helper.h b/printing/backend/win_helper.h new file mode 100644 index 0000000..a779ad7 --- /dev/null +++ b/printing/backend/win_helper.h @@ -0,0 +1,16 @@ +// Copyright (c) 2010 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 PRINTING_BACKEND_WIN_HELPER_H_ +#define PRINTING_BACKEND_WIN_HELPER_H_ +#pragma once + +// These are helper functions for dealing with Windows Printing. +namespace printing { + +bool InitXPSModule(); + +} // namespace printing + +#endif // PRINTING_BACKEND_WIN_HELPER_H_ diff --git a/printing/printing.gyp b/printing/printing.gyp index 2970a90..a9f36e5 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Copyright (c) 2010 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. @@ -24,6 +24,11 @@ '..', ], 'sources': [ + 'backend/print_backend.cc', + 'backend/print_backend.h', + 'backend/print_backend_consts.cc', + 'backend/print_backend_consts.h', + 'backend/print_backend_dummy.cc', 'emf_win.cc', 'emf_win.h', 'image.cc', @@ -40,29 +45,29 @@ 'page_range.h', 'page_setup.cc', 'page_setup.h', - 'pdf_metafile_mac.h', 'pdf_metafile_mac.cc', - 'pdf_ps_metafile_cairo.h', + 'pdf_metafile_mac.h', 'pdf_ps_metafile_cairo.cc', - 'print_settings.cc', - 'print_settings.h', - 'printed_document.cc', + 'pdf_ps_metafile_cairo.h', 'printed_document_cairo.cc', + 'printed_document.cc', + 'printed_document.h', 'printed_document_mac.cc', 'printed_document_posix.cc', 'printed_document_win.cc', - 'printed_document.h', 'printed_page.cc', 'printed_page.h', 'printed_pages_source.h', - 'printing_context.h', - 'printing_context.cc', - 'printing_context_cairo.h', 'printing_context_cairo.cc', + 'printing_context_cairo.h', + 'printing_context.cc', + 'printing_context.h', 'printing_context_mac.h', 'printing_context_mac.mm', - 'printing_context_win.h', 'printing_context_win.cc', + 'printing_context_win.h', + 'print_settings.cc', + 'print_settings.h', 'units.cc', 'units.h', ], @@ -88,6 +93,36 @@ '../build/linux/system.gyp:gtkprint', ], }], + ['OS=="win"', { + 'defines': [ + # PRINT_BACKEND_AVAILABLE disables the default dummy implementation + # of the print backend and enables a custom implementation instead. + 'PRINT_BACKEND_AVAILABLE', + ], + 'sources': [ + 'backend/win_helper.cc', + 'backend/win_helper.h', + 'backend/print_backend_win.cc', + ], + }], + ['use_cups==1', { + 'link_settings': { + 'libraries': [ + '-lcups', + '-lgcrypt', + ], + }, + 'defines': [ + # PRINT_BACKEND_AVAILABLE disables the default dummy implementation + # of the print backend and enables a custom implementation instead. + 'PRINT_BACKEND_AVAILABLE', + ], + 'sources': [ + 'backend/cups_helper.cc', + 'backend/cups_helper.h', + 'backend/print_backend_cups.cc', + ], + }], ], }, { |