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

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

Issue 2932043002: Printing: Remove check for Windows RPCS printers (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 const char* xps_color = color ? kXpsTicketColor : kXpsTicketMonochrome; 464 const char* xps_color = color ? kXpsTicketColor : kXpsTicketMonochrome;
465 std::string xps_ticket = base::StringPrintf(kXpsTicketTemplate, xps_color); 465 std::string xps_ticket = base::StringPrintf(kXpsTicketTemplate, xps_color);
466 std::unique_ptr<DEVMODE, base::FreeDeleter> ticket = 466 std::unique_ptr<DEVMODE, base::FreeDeleter> ticket =
467 printing::XpsTicketToDevMode(printer_name, xps_ticket); 467 printing::XpsTicketToDevMode(printer_name, xps_ticket);
468 if (!ticket) 468 if (!ticket)
469 return default_ticket; 469 return default_ticket;
470 470
471 return ticket; 471 return ticket;
472 } 472 }
473 473
474 bool IsPrinterRPCSOnly(const wchar_t* name, const wchar_t* port) {
475 int num_languages =
476 DeviceCapabilities(name, port, DC_PERSONALITY, NULL, NULL);
477 if (num_languages != 1)
478 return false;
479 std::vector<wchar_t> buf(33, 0);
480 DeviceCapabilities(name, port, DC_PERSONALITY, buf.data(), NULL);
481 static constexpr wchar_t kRPCSLanguage[] = L"RPCS";
482 return wcscmp(buf.data(), kRPCSLanguage) == 0;
483 }
484
485 bool PrinterHasValidPaperSize(const wchar_t* name, const wchar_t* port) { 474 bool PrinterHasValidPaperSize(const wchar_t* name, const wchar_t* port) {
486 return DeviceCapabilities(name, port, DC_PAPERSIZE, nullptr, nullptr) > 0; 475 return DeviceCapabilities(name, port, DC_PAPERSIZE, nullptr, nullptr) > 0;
487 } 476 }
488 477
489 std::unique_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(HANDLE printer, 478 std::unique_ptr<DEVMODE, base::FreeDeleter> CreateDevMode(HANDLE printer,
490 DEVMODE* in) { 479 DEVMODE* in) {
491 LONG buffer_size = DocumentProperties( 480 LONG buffer_size = DocumentProperties(
492 NULL, printer, const_cast<wchar_t*>(L""), NULL, NULL, 0); 481 NULL, printer, const_cast<wchar_t*>(L""), NULL, NULL, 0);
493 if (buffer_size < static_cast<int>(sizeof(DEVMODE))) 482 if (buffer_size < static_cast<int>(sizeof(DEVMODE)))
494 return nullptr; 483 return nullptr;
495 484
496 // Some drivers request buffers with size smaller than dmSize + dmDriverExtra. 485 // Some drivers request buffers with size smaller than dmSize + dmDriverExtra.
497 // crbug.com/421402 486 // crbug.com/421402
498 buffer_size *= 2; 487 buffer_size *= 2;
499 488
500 std::unique_ptr<DEVMODE, base::FreeDeleter> out( 489 std::unique_ptr<DEVMODE, base::FreeDeleter> out(
501 reinterpret_cast<DEVMODE*>(calloc(buffer_size, 1))); 490 reinterpret_cast<DEVMODE*>(calloc(buffer_size, 1)));
502 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER; 491 DWORD flags = (in ? (DM_IN_BUFFER) : 0) | DM_OUT_BUFFER;
503 492
504 PrinterInfo5 info_5; 493 PrinterInfo5 info_5;
505 if (!info_5.Init(printer)) 494 if (!info_5.Init(printer))
506 return nullptr; 495 return nullptr;
507 const wchar_t* name = info_5.get()->pPrinterName; 496 const wchar_t* name = info_5.get()->pPrinterName;
508 const wchar_t* port = info_5.get()->pPortName; 497 const wchar_t* port = info_5.get()->pPortName;
509 498
510 // Check for RPCS drivers on Windows 8+ as DocumentProperties will crash if 499 // Check that valid paper sizes exist; some old drivers return no paper sizes
511 // called on one of these printers. See crbug.com/679160. 500 // and crash in DocumentProperties if used with Win10. See crbug.com/679160,
512 // Also check that valid paper sizes exist; some old drivers return no paper
513 // sizes and crash in DocumentProperties if used with Win10. See
514 // crbug.com/724595 501 // crbug.com/724595
515 if ((base::win::GetVersion() >= base::win::VERSION_WIN8 && 502 if (!PrinterHasValidPaperSize(name, port)) {
516 IsPrinterRPCSOnly(name, port)) ||
517 !PrinterHasValidPaperSize(name, port)) {
518 return nullptr; 503 return nullptr;
519 } 504 }
520 505
521 if (DocumentProperties( 506 if (DocumentProperties(
522 NULL, printer, const_cast<wchar_t*>(L""), out.get(), in, flags) != 507 NULL, printer, const_cast<wchar_t*>(L""), out.get(), in, flags) !=
523 IDOK) { 508 IDOK) {
524 return nullptr; 509 return nullptr;
525 } 510 }
526 int size = out->dmSize; 511 int size = out->dmSize;
527 int extra_size = out->dmDriverExtra; 512 int extra_size = out->dmDriverExtra;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 *canceled = (result == IDCANCEL); 547 *canceled = (result == IDCANCEL);
563 if (result != IDOK) 548 if (result != IDOK)
564 return std::unique_ptr<DEVMODE, base::FreeDeleter>(); 549 return std::unique_ptr<DEVMODE, base::FreeDeleter>();
565 int size = out->dmSize; 550 int size = out->dmSize;
566 int extra_size = out->dmDriverExtra; 551 int extra_size = out->dmDriverExtra;
567 CHECK_GE(buffer_size, size + extra_size); 552 CHECK_GE(buffer_size, size + extra_size);
568 return out; 553 return out;
569 } 554 }
570 555
571 } // namespace printing 556 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698