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

Side by Side Diff: printing/backend/win_helper.cc

Issue 9812002: Include driver infor into PrinterBasicInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "printing/backend/win_helper.h" 5 #include "printing/backend/win_helper.h"
6 6
7 #include <algorithm>
8
9 #include "base/file_path.h"
10 #include "base/file_version_info.h"
7 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/utf_string_conversions.h"
13 #include "printing/backend/print_backend.h"
14 #include "printing/backend/print_backend_consts.h"
8 15
9 namespace { 16 namespace {
10 typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name, 17 typedef HRESULT (WINAPI *PTOpenProviderProc)(PCWSTR printer_name,
11 DWORD version, 18 DWORD version,
12 HPTPROVIDER *provider); 19 HPTPROVIDER *provider);
13 typedef HRESULT (WINAPI *PTGetPrintCapabilitiesProc)(HPTPROVIDER provider, 20 typedef HRESULT (WINAPI *PTGetPrintCapabilitiesProc)(HPTPROVIDER provider,
14 IStream *print_ticket, 21 IStream *print_ticket,
15 IStream *capabilities, 22 IStream *capabilities,
16 BSTR* error_message); 23 BSTR* error_message);
17 typedef HRESULT (WINAPI *PTConvertDevModeToPrintTicketProc)( 24 typedef HRESULT (WINAPI *PTConvertDevModeToPrintTicketProc)(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 IXpsPrintJobStream **print_ticket_stream); 57 IXpsPrintJobStream **print_ticket_stream);
51 58
52 PTOpenProviderProc g_open_provider_proc = NULL; 59 PTOpenProviderProc g_open_provider_proc = NULL;
53 PTGetPrintCapabilitiesProc g_get_print_capabilities_proc = NULL; 60 PTGetPrintCapabilitiesProc g_get_print_capabilities_proc = NULL;
54 PTConvertDevModeToPrintTicketProc g_convert_devmode_to_print_ticket_proc = NULL; 61 PTConvertDevModeToPrintTicketProc g_convert_devmode_to_print_ticket_proc = NULL;
55 PTConvertPrintTicketToDevModeProc g_convert_print_ticket_to_devmode_proc = NULL; 62 PTConvertPrintTicketToDevModeProc g_convert_print_ticket_to_devmode_proc = NULL;
56 PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL; 63 PTMergeAndValidatePrintTicketProc g_merge_and_validate_print_ticket_proc = NULL;
57 PTReleaseMemoryProc g_release_memory_proc = NULL; 64 PTReleaseMemoryProc g_release_memory_proc = NULL;
58 PTCloseProviderProc g_close_provider_proc = NULL; 65 PTCloseProviderProc g_close_provider_proc = NULL;
59 StartXpsPrintJobProc g_start_xps_print_job_proc = NULL; 66 StartXpsPrintJobProc g_start_xps_print_job_proc = NULL;
67
68 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.
69 scoped_array<BYTE>* buffer) {
70 DCHECK(printer);
71 DCHECK(buffer);
72 DWORD bytes_needed = 0;
73 const DWORD kLevel = 2;
74 ::GetPrinter(printer, kLevel, NULL, 0, &bytes_needed);
75 if (!bytes_needed)
76 return NULL;
77 buffer->reset(new BYTE[bytes_needed]);
78 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.
79 return NULL;
80 if (!::GetPrinter(printer, kLevel, buffer->get(), bytes_needed,
81 &bytes_needed)) {
82 return NULL;
83 }
84 return reinterpret_cast<const PRINTER_INFO_2*>(buffer->get());
85 }
86
87 const DRIVER_INFO_6* GetDriverInfo6(HANDLE printer,
88 scoped_array<BYTE>* buffer) {
89 DCHECK(printer);
90 DCHECK(buffer);
91 DWORD bytes_needed = 0;
92 const DWORD kLevel = 6;
93 ::GetPrinterDriver(printer, NULL, kLevel, NULL, 0, &bytes_needed);
94 if (!bytes_needed)
95 return NULL;
96 buffer->reset(new BYTE[bytes_needed]);
97 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.
98 return NULL;
99 if (!::GetPrinterDriver(printer, NULL, kLevel, buffer->get(), bytes_needed,
100 &bytes_needed)) {
101 return NULL;
102 }
103 return reinterpret_cast<const DRIVER_INFO_6*>(buffer->get());
104 }
105
60 } 106 }
61 107
62 namespace printing { 108 namespace printing {
63 109
64 bool XPSModule::Init() { 110 bool XPSModule::Init() {
65 static bool initialized = InitImpl(); 111 static bool initialized = InitImpl();
66 return initialized; 112 return initialized;
67 } 113 }
68 114
69 bool XPSModule::InitImpl() { 115 bool XPSModule::InitImpl() {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 output_file_name, 299 output_file_name,
254 progress_event, 300 progress_event,
255 completion_event, 301 completion_event,
256 printable_pages_on, 302 printable_pages_on,
257 printable_pages_on_count, 303 printable_pages_on_count,
258 xps_print_job, 304 xps_print_job,
259 document_stream, 305 document_stream,
260 print_ticket_stream); 306 print_ticket_stream);
261 } 307 }
262 308
309 bool InitBasicPrinterInfo(HANDLE printer, PrinterBasicInfo* printer_info) {
310 DCHECK(printer);
311 DCHECK(printer_info);
312 if (!printer)
313 return false;
314
315 scoped_array<BYTE> printer_info_buffer;
316 const PRINTER_INFO_2* info2 = GetPrinterInfo2(printer, &printer_info_buffer);
317 if (!info2)
318 return false;
319
320 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 :-).
321 return false;
322 printer_info->printer_name = WideToUTF8(info2->pPrinterName);
323 if (info2->pComment)
324 printer_info->printer_description =
325 WideToUTF8(info2->pComment);
326 if (info2->pLocation)
327 printer_info->options[kLocationTagName] =
328 WideToUTF8(info2->pLocation);
329 if (info2->pDriverName)
330 printer_info->options[kDriverNameTagName] =
331 WideToUTF8(info2->pDriverName);
332 printer_info->printer_status = info2->Status;
333
334 std::string driver_info = GetDriverInfo(printer);
335 if (!driver_info.empty())
336 printer_info->options[kDriverInfoTagName] = driver_info;
337 return true;
338 }
339
340 std::string GetDriverInfo(HANDLE printer) {
341 DCHECK(printer);
342 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.
343
344 if (!printer)
345 return driver_info;
346
347 scoped_array<BYTE> driver_info_buffer;
348 const DRIVER_INFO_6* driver = GetDriverInfo6(printer, &driver_info_buffer);
349 if (!driver)
350 return driver_info;
351
352 std::string info[4];
353 if (driver->pName)
354 info[0] = WideToUTF8(driver->pName);
355
356 if (driver->pDriverPath) {
357 scoped_ptr<FileVersionInfo> version_info(
358 FileVersionInfo::CreateFileVersionInfo(
359 FilePath(driver->pDriverPath)));
360 info[1] = WideToUTF8(version_info->file_version());
361 info[2] = WideToUTF8(version_info->product_name());
362 info[3] = WideToUTF8(version_info->product_version());
363 }
364
365
366 for (size_t i = 0; i < arraysize(info); ++i) {
367 std::replace(info[i].begin(), info[i].end(), ';', ',');
368 driver_info.append(info[i]);
369 driver_info.append(";");
370 }
371 return driver_info;
372 }
373
263 } // namespace printing 374 } // namespace printing
OLDNEW
« printing/backend/print_backend_consts.cc ('K') | « printing/backend/win_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698