Index: printing/backend/win_helper.cc |
diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc |
index b163a65ece970a3c25d139d63ef5ebf73acdfb5b..0d895acb584e19d9dd13cb8a3bbb38828d5664e3 100644 |
--- a/printing/backend/win_helper.cc |
+++ b/printing/backend/win_helper.cc |
@@ -4,7 +4,14 @@ |
#include "printing/backend/win_helper.h" |
+#include <algorithm> |
+ |
+#include "base/file_path.h" |
+#include "base/file_version_info.h" |
#include "base/logging.h" |
+#include "base/utf_string_conversions.h" |
+#include "printing/backend/print_backend.h" |
+#include "printing/backend/print_backend_consts.h" |
namespace { |
typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name, |
@@ -260,4 +267,96 @@ HRESULT XPSPrintModule::StartXpsPrintJob( |
print_ticket_stream); |
} |
+const PRINTER_INFO_2* GetPrinterInfo2(HANDLE printer, |
+ scoped_array<BYTE>* buffer) { |
+ DCHECK(printer); |
+ DCHECK(buffer); |
+ DWORD bytes_needed = 0; |
+ const DWORD kLevel = 2; |
+ ::GetPrinter(printer, kLevel, NULL, 0, &bytes_needed); |
+ buffer->reset(new BYTE[bytes_needed]); |
gene
2012/03/21 21:07:22
Let's check bytes need != 0, before trying to allo
Vitaly Buka (NO REVIEWS)
2012/03/21 21:23:01
Done.
|
+ if (!bytes_needed || !buffer->get()) |
+ return NULL; |
+ if (!::GetPrinter(printer, kLevel, buffer->get(), bytes_needed, |
+ &bytes_needed)) { |
+ return NULL; |
+ } |
+ if (!bytes_needed) |
gene
2012/03/21 21:07:22
This looks unnecessary
Vitaly Buka (NO REVIEWS)
2012/03/21 21:23:01
Done.
|
+ return NULL; |
+ return reinterpret_cast<const PRINTER_INFO_2*>(buffer->get()); |
+} |
+ |
+const DRIVER_INFO_6* GetDriverInfo6(HANDLE printer, |
+ scoped_array<BYTE>* buffer) { |
+ DCHECK(printer); |
+ DCHECK(buffer); |
+ DWORD bytes_needed = 0; |
+ const DWORD kLevel = 6; |
+ ::GetPrinterDriver(printer, NULL, kLevel, NULL, 0, &bytes_needed); |
+ buffer->reset(new BYTE[bytes_needed]); |
gene
2012/03/21 21:07:22
Let's check bytes need != 0, before trying to allo
Vitaly Buka (NO REVIEWS)
2012/03/21 21:23:01
Done.
|
+ if (!bytes_needed || !buffer->get()) |
+ return NULL; |
+ if (!::GetPrinterDriver(printer, NULL, kLevel, buffer->get(), bytes_needed, |
+ &bytes_needed)) { |
+ return NULL; |
+ } |
+ if (!bytes_needed) |
gene
2012/03/21 21:07:22
This looks unnecessary
Vitaly Buka (NO REVIEWS)
2012/03/21 21:23:01
Done.
|
+ return NULL; |
+ return reinterpret_cast<const DRIVER_INFO_6*>(buffer->get()); |
+} |
+ |
+void InitBasicPrinterInfo( |
+ const PRINTER_INFO_2* printer, |
+ const DRIVER_INFO_6* driver, |
+ PrinterBasicInfo* printer_info) { |
+ DCHECK(printer); |
+ DCHECK(driver); |
+ DCHECK(printer_info); |
+ if (printer) { |
+ printer_info->printer_name = WideToUTF8(printer->pPrinterName); |
+ if (printer->pComment) |
+ printer_info->printer_description = |
+ WideToUTF8(printer->pComment); |
+ if (printer->pLocation) |
+ printer_info->options[kLocationTagName] = |
+ WideToUTF8(printer->pLocation); |
+ if (printer->pDriverName) |
+ printer_info->options[kDriverNameTagName] = |
+ WideToUTF8(printer->pDriverName); |
+ printer_info->printer_status = printer->Status; |
+ } |
+ if (driver) { |
+ std::string driver_info = GetDriverInfo(driver); |
+ if (!driver_info.empty()) |
+ printer_info->options[kDriverInfoTagName] = driver_info; |
+ } |
+} |
+ |
+std::string GetDriverInfo(const DRIVER_INFO_6* driver) { |
+ DCHECK(driver); |
+ if (!driver) |
+ return std::string(); |
+ |
+ std::string info[4]; |
+ if (driver->pName) |
+ info[0] = WideToUTF8(driver->pName); |
+ |
+ if (driver->pDriverPath) { |
+ scoped_ptr<FileVersionInfo> version_info( |
+ FileVersionInfo::CreateFileVersionInfo( |
+ FilePath(driver->pDriverPath))); |
+ info[1] = WideToUTF8(version_info->file_version()); |
+ info[2] = WideToUTF8(version_info->product_name()); |
+ info[3] = WideToUTF8(version_info->product_version()); |
+ } |
+ |
+ std::string driver_info; |
+ for (size_t i = 0; i < arraysize(info); ++i) { |
+ std::replace(info[i].begin(), info[i].end(), ';', ','); |
+ driver_info.append(info[i]); |
+ driver_info.append(";"); |
+ } |
+ return driver_info; |
+} |
+ |
} // namespace printing |