Index: printing/backend/win_helper.cc |
diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc |
index b163a65ece970a3c25d139d63ef5ebf73acdfb5b..ffac3ecab2874f38b1b3694b7a1475e908cd5fa4 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, |
@@ -57,6 +64,45 @@ PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL; |
PTReleaseMemoryProc g_release_memory_proc = NULL; |
PTCloseProviderProc g_close_provider_proc = NULL; |
StartXpsPrintJobProc g_start_xps_print_job_proc = NULL; |
+ |
+const PRINTER_INFO_2* GetPrinterInfo2(HANDLE printer, |
gene
2012/03/21 22:53:09
Could you please add a small comment that this fun
Vitaly Buka (NO REVIEWS)
2012/03/21 23:03:10
Done.
|
+ scoped_array<BYTE>* buffer) { |
+ DCHECK(printer); |
+ DCHECK(buffer); |
+ DWORD bytes_needed = 0; |
+ const DWORD kLevel = 2; |
+ ::GetPrinter(printer, kLevel, NULL, 0, &bytes_needed); |
+ if (!bytes_needed) |
+ return NULL; |
+ buffer->reset(new BYTE[bytes_needed]); |
+ if (!bytes_needed || !buffer->get()) |
gene
2012/03/21 22:53:09
you probably don't need this anymore
Vitaly Buka (NO REVIEWS)
2012/03/21 23:03:10
Done.
|
+ return NULL; |
+ if (!::GetPrinter(printer, kLevel, buffer->get(), bytes_needed, |
+ &bytes_needed)) { |
+ 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); |
+ if (!bytes_needed) |
+ return NULL; |
+ buffer->reset(new BYTE[bytes_needed]); |
+ if (!bytes_needed || !buffer->get()) |
gene
2012/03/21 22:53:09
you probably don't need this anymore
Vitaly Buka (NO REVIEWS)
2012/03/21 23:03:10
Done.
|
+ return NULL; |
+ if (!::GetPrinterDriver(printer, NULL, kLevel, buffer->get(), bytes_needed, |
+ &bytes_needed)) { |
+ return NULL; |
+ } |
+ return reinterpret_cast<const DRIVER_INFO_6*>(buffer->get()); |
+} |
+ |
} |
namespace printing { |
@@ -260,4 +306,69 @@ HRESULT XPSPrintModule::StartXpsPrintJob( |
print_ticket_stream); |
} |
+bool InitBasicPrinterInfo(HANDLE printer, PrinterBasicInfo* printer_info) { |
+ DCHECK(printer); |
+ DCHECK(printer_info); |
+ if (!printer) |
+ return false; |
+ |
+ scoped_array<BYTE> printer_info_buffer; |
+ const PRINTER_INFO_2* info2 = GetPrinterInfo2(printer, &printer_info_buffer); |
+ if (!info2) |
+ return false; |
+ |
+ if (!info2) |
gene
2012/03/21 22:53:09
duplicate
Vitaly Buka (NO REVIEWS)
2012/03/21 23:03:10
Done.
Common! Compiler should fix that :-).
|
+ return false; |
+ printer_info->printer_name = WideToUTF8(info2->pPrinterName); |
+ if (info2->pComment) |
+ printer_info->printer_description = |
+ WideToUTF8(info2->pComment); |
+ if (info2->pLocation) |
+ printer_info->options[kLocationTagName] = |
+ WideToUTF8(info2->pLocation); |
+ if (info2->pDriverName) |
+ printer_info->options[kDriverNameTagName] = |
+ WideToUTF8(info2->pDriverName); |
+ printer_info->printer_status = info2->Status; |
+ |
+ std::string driver_info = GetDriverInfo(printer); |
+ if (!driver_info.empty()) |
+ printer_info->options[kDriverInfoTagName] = driver_info; |
+ return true; |
+} |
+ |
+std::string GetDriverInfo(HANDLE printer) { |
+ DCHECK(printer); |
+ std::string driver_info; |
gene
2012/03/21 22:53:09
move this definition down where it first used (for
Vitaly Buka (NO REVIEWS)
2012/03/21 23:03:10
I use that as empty string to return.
|
+ |
+ if (!printer) |
+ return driver_info; |
+ |
+ scoped_array<BYTE> driver_info_buffer; |
+ const DRIVER_INFO_6* driver = GetDriverInfo6(printer, &driver_info_buffer); |
+ if (!driver) |
+ return driver_info; |
+ |
+ 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()); |
+ } |
+ |
+ |
+ 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 |