| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 scoped_ptr<DEVMODE[]> ticket = printing::XpsTicketToDevMode(printer_name, | 462 scoped_ptr<DEVMODE[]> ticket = printing::XpsTicketToDevMode(printer_name, |
| 463 xps_ticket); | 463 xps_ticket); |
| 464 if (!ticket) | 464 if (!ticket) |
| 465 return default.Pass(); | 465 return default.Pass(); |
| 466 | 466 |
| 467 return ticket.Pass(); | 467 return ticket.Pass(); |
| 468 } | 468 } |
| 469 | 469 |
| 470 PRINTING_EXPORT scoped_ptr<DEVMODE[]> CreateDevMode(HANDLE printer, | 470 PRINTING_EXPORT scoped_ptr<DEVMODE[]> CreateDevMode(HANDLE printer, |
| 471 DEVMODE* in) { | 471 DEVMODE* in) { |
| 472 DWORD flags = in ? (DM_IN_BUFFER) : 0; | 472 LONG buffer_size = DocumentProperties(NULL, printer, L"", NULL, NULL, 0); |
| 473 LONG buffer_size = DocumentProperties(NULL, printer, L"", NULL, in, flags); | |
| 474 if (buffer_size <= 0) | 473 if (buffer_size <= 0) |
| 475 return scoped_ptr<DEVMODE[]>(); | 474 return scoped_ptr<DEVMODE[]>(); |
| 475 CHECK_GE(buffer_size, static_cast<int>(sizeof(DEVMODE))); |
| 476 scoped_ptr<DEVMODE[]> out( | 476 scoped_ptr<DEVMODE[]> out( |
| 477 reinterpret_cast<DEVMODE*>(new uint8[buffer_size])); | 477 reinterpret_cast<DEVMODE*>(new uint8[buffer_size])); |
| 478 flags |= DM_OUT_BUFFER; | 478 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER; |
| 479 if (DocumentProperties(NULL, printer, L"", out.get(), in, flags) != IDOK) | 479 if (DocumentProperties(NULL, printer, L"", out.get(), in, flags) != IDOK) |
| 480 return scoped_ptr<DEVMODE[]>(); | 480 return scoped_ptr<DEVMODE[]>(); |
| 481 DCHECK_EQ(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra); | 481 CHECK_GE(buffer_size, out.get()->dmSize + out.get()->dmDriverExtra); |
| 482 return out.Pass(); | 482 return out.Pass(); |
| 483 } | 483 } |
| 484 | 484 |
| 485 } // namespace printing | 485 } // namespace printing |
| OLD | NEW |