OLD | NEW |
---|---|
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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 output_file_name, | 260 output_file_name, |
254 progress_event, | 261 progress_event, |
255 completion_event, | 262 completion_event, |
256 printable_pages_on, | 263 printable_pages_on, |
257 printable_pages_on_count, | 264 printable_pages_on_count, |
258 xps_print_job, | 265 xps_print_job, |
259 document_stream, | 266 document_stream, |
260 print_ticket_stream); | 267 print_ticket_stream); |
261 } | 268 } |
262 | 269 |
270 const PRINTER_INFO_2* GetPrinterInfo2(HANDLE printer, | |
271 scoped_array<BYTE>* buffer) { | |
272 DCHECK(printer); | |
273 DCHECK(buffer); | |
274 DWORD bytes_needed = 0; | |
275 const DWORD kLevel = 2; | |
276 ::GetPrinter(printer, kLevel, NULL, 0, &bytes_needed); | |
277 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.
| |
278 if (!bytes_needed || !buffer->get()) | |
279 return NULL; | |
280 if (!::GetPrinter(printer, kLevel, buffer->get(), bytes_needed, | |
281 &bytes_needed)) { | |
282 return NULL; | |
283 } | |
284 if (!bytes_needed) | |
gene
2012/03/21 21:07:22
This looks unnecessary
Vitaly Buka (NO REVIEWS)
2012/03/21 21:23:01
Done.
| |
285 return NULL; | |
286 return reinterpret_cast<const PRINTER_INFO_2*>(buffer->get()); | |
287 } | |
288 | |
289 const DRIVER_INFO_6* GetDriverInfo6(HANDLE printer, | |
290 scoped_array<BYTE>* buffer) { | |
291 DCHECK(printer); | |
292 DCHECK(buffer); | |
293 DWORD bytes_needed = 0; | |
294 const DWORD kLevel = 6; | |
295 ::GetPrinterDriver(printer, NULL, kLevel, NULL, 0, &bytes_needed); | |
296 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.
| |
297 if (!bytes_needed || !buffer->get()) | |
298 return NULL; | |
299 if (!::GetPrinterDriver(printer, NULL, kLevel, buffer->get(), bytes_needed, | |
300 &bytes_needed)) { | |
301 return NULL; | |
302 } | |
303 if (!bytes_needed) | |
gene
2012/03/21 21:07:22
This looks unnecessary
Vitaly Buka (NO REVIEWS)
2012/03/21 21:23:01
Done.
| |
304 return NULL; | |
305 return reinterpret_cast<const DRIVER_INFO_6*>(buffer->get()); | |
306 } | |
307 | |
308 void InitBasicPrinterInfo( | |
309 const PRINTER_INFO_2* printer, | |
310 const DRIVER_INFO_6* driver, | |
311 PrinterBasicInfo* printer_info) { | |
312 DCHECK(printer); | |
313 DCHECK(driver); | |
314 DCHECK(printer_info); | |
315 if (printer) { | |
316 printer_info->printer_name = WideToUTF8(printer->pPrinterName); | |
317 if (printer->pComment) | |
318 printer_info->printer_description = | |
319 WideToUTF8(printer->pComment); | |
320 if (printer->pLocation) | |
321 printer_info->options[kLocationTagName] = | |
322 WideToUTF8(printer->pLocation); | |
323 if (printer->pDriverName) | |
324 printer_info->options[kDriverNameTagName] = | |
325 WideToUTF8(printer->pDriverName); | |
326 printer_info->printer_status = printer->Status; | |
327 } | |
328 if (driver) { | |
329 std::string driver_info = GetDriverInfo(driver); | |
330 if (!driver_info.empty()) | |
331 printer_info->options[kDriverInfoTagName] = driver_info; | |
332 } | |
333 } | |
334 | |
335 std::string GetDriverInfo(const DRIVER_INFO_6* driver) { | |
336 DCHECK(driver); | |
337 if (!driver) | |
338 return std::string(); | |
339 | |
340 std::string info[4]; | |
341 if (driver->pName) | |
342 info[0] = WideToUTF8(driver->pName); | |
343 | |
344 if (driver->pDriverPath) { | |
345 scoped_ptr<FileVersionInfo> version_info( | |
346 FileVersionInfo::CreateFileVersionInfo( | |
347 FilePath(driver->pDriverPath))); | |
348 info[1] = WideToUTF8(version_info->file_version()); | |
349 info[2] = WideToUTF8(version_info->product_name()); | |
350 info[3] = WideToUTF8(version_info->product_version()); | |
351 } | |
352 | |
353 std::string driver_info; | |
354 for (size_t i = 0; i < arraysize(info); ++i) { | |
355 std::replace(info[i].begin(), info[i].end(), ';', ','); | |
356 driver_info.append(info[i]); | |
357 driver_info.append(";"); | |
358 } | |
359 return driver_info; | |
360 } | |
361 | |
263 } // namespace printing | 362 } // namespace printing |
OLD | NEW |