Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Unified Diff: printing/backend/print_backend_win.cc

Issue 9516010: Added PrinterDriverInfo and PrintBackend::GetPrinterDriverInfo for windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « printing/backend/print_backend_cups.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/backend/print_backend_win.cc
diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc
index 9995005fa53cf570c328a715a45539996853a130..8377551522deb2a88d0359f52e9e663e60f28cb2 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);
};
@@ -171,10 +176,48 @@ bool PrintBackendWin::GetPrinterCapsAndDefaults(
return true;
}
+// 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;
+ if (!::OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).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 (!bytes_needed || !driver_info_buffer.get())
+ return false;
+ if (!::GetPrinterDriver(printer_handle, NULL, 6, driver_info_buffer.get(),
+ bytes_needed, &bytes_needed)) {
+ return false;
+ }
+ 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()),
+ OpenPrinter(const_cast<LPTSTR>(UTF8ToWide(printer_name).c_str()),
printer_handle.Receive(), NULL);
return printer_handle.IsValid();
}
« no previous file with comments | « printing/backend/print_backend_cups.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698