| Index: printing/backend/print_backend_win.cc
|
| diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc
|
| index 01be277fe11f72dc23cb987fddaa2a5f30dcd6b2..843143dd8a006f8a3f2948cf998a7c53e07ff053 100644
|
| --- a/printing/backend/print_backend_win.cc
|
| +++ b/printing/backend/print_backend_win.cc
|
| @@ -7,6 +7,8 @@
|
| #include <objidl.h>
|
| #include <winspool.h>
|
|
|
| +#include "base/file_path.h"
|
| +#include "base/file_version_info.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/string_piece.h"
|
| #include "base/utf_string_conversions.h"
|
| @@ -47,6 +49,9 @@ class PrintBackendWin : public PrintBackend {
|
| virtual bool GetPrinterCapsAndDefaults(const std::string& printer_name,
|
| PrinterCapsAndDefaults* printer_info);
|
|
|
| + virtual bool GetPrinterDriverInfo(const std::string& printer_name,
|
| + PrinterDriverInfo* driver_info);
|
| +
|
| virtual bool IsValidPrinter(const std::string& printer_name);
|
| };
|
|
|
| @@ -131,12 +136,11 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
|
| 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);
|
| + ScopedPrinterHandle printer_handle;
|
| + OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()),
|
| + printer_handle.Receive(), NULL);
|
| DCHECK(printer_handle);
|
| - if (printer_handle) {
|
| + if (printer_handle.IsValid()) {
|
| LONG devmode_size = DocumentProperties(
|
| NULL, printer_handle, const_cast<LPTSTR>(printer_name_wide.c_str()),
|
| NULL, NULL, 0);
|
| @@ -166,24 +170,56 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
|
| printer_info->defaults_mime_type = "text/xml";
|
| }
|
| }
|
| - ClosePrinter(printer_handle);
|
| }
|
| XPSModule::CloseProvider(provider);
|
| }
|
| return true;
|
| }
|
|
|
| -bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
|
| +// Gets the information about driver for a specific printer.
|
| +bool PrintBackendWin::GetPrinterDriverInfo(const std::string& printer_name,
|
| + PrinterDriverInfo* driver_info) {
|
| + DCHECK(driver_info);
|
| + ScopedPrinterHandle printer_handle;
|
| 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);
|
| + if (!::OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()),
|
| + printer_handle.Receive(), NULL)) {
|
| + return false;
|
| + }
|
| + DCHECK(printer_handle.IsValid());
|
| + DWORD bytes_needed = 0;
|
| + ::GetPrinterDriver(printer_handle, NULL, 6, NULL, 0, &bytes_needed);
|
| + scoped_array<BYTE> driver_info_buffer(new BYTE[bytes_needed]);
|
| + if (!::GetPrinterDriver(printer_handle, NULL, 6, driver_info_buffer.get(),
|
| + bytes_needed, &bytes_needed)) {
|
| + return false;
|
| }
|
| - return ret;
|
| + if (!bytes_needed)
|
| + return false;
|
| + const DRIVER_INFO_6* driver_info_6 =
|
| + reinterpret_cast<DRIVER_INFO_6*>(driver_info_buffer.get());
|
| +
|
| + if (driver_info_6->pName)
|
| + driver_info->driver_name = WideToUTF8(driver_info_6->pName);
|
| +
|
| + if (driver_info_6->pDriverPath) {
|
| + scoped_ptr<FileVersionInfo> version_info(
|
| + FileVersionInfo::CreateFileVersionInfo(
|
| + FilePath(driver_info_6->pDriverPath)));
|
| + driver_info->driver_version = WideToUTF8(version_info->file_version());
|
| + driver_info->product_name = WideToUTF8(version_info->product_name());
|
| + driver_info->product_version = WideToUTF8(version_info->product_version());
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool PrintBackendWin::IsValidPrinter(const std::string& printer_name) {
|
| + std::wstring printer_name_wide = UTF8ToWide(printer_name);
|
| + ScopedPrinterHandle printer_handle;
|
| + OpenPrinter(const_cast<LPTSTR>(printer_name_wide.c_str()),
|
| + printer_handle.Receive(), NULL);
|
| + return printer_handle.IsValid();
|
| }
|
|
|
| scoped_refptr<PrintBackend> PrintBackend::CreateInstance(
|
|
|