fix: check printer list when no default printers (#25606)

This commit is contained in:
Shelley Vohr
2020-09-23 15:44:19 -07:00
committed by GitHub
parent 894d41ef5a
commit 0b75053fdc
2 changed files with 15 additions and 5 deletions

View File

@@ -381,10 +381,20 @@ base::string16 GetDefaultPrinterAsync() {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
scoped_refptr<printing::PrintBackend> backend =
scoped_refptr<printing::PrintBackend> print_backend =
printing::PrintBackend::CreateInstance(
nullptr, g_browser_process->GetApplicationLocale());
std::string printer_name = backend->GetDefaultPrinterName();
std::string printer_name = print_backend->GetDefaultPrinterName();
// Some devices won't have a default printer, so we should
// also check for existing printers and pick the first
// one should it exist.
if (printer_name.empty()) {
printing::PrinterList printers;
print_backend->EnumeratePrinters(&printers);
if (printers.size() > 0)
printer_name = printers.front().printer_name;
}
return base::UTF8ToUTF16(printer_name);
}
#endif
@@ -2139,8 +2149,8 @@ void WebContents::Print(gin_helper::Arguments* args) {
std::move(callback), device_name, silent));
}
std::vector<printing::PrinterBasicInfo> WebContents::GetPrinterList() {
std::vector<printing::PrinterBasicInfo> printers;
printing::PrinterList WebContents::GetPrinterList() {
printing::PrinterList printers;
auto print_backend = printing::PrintBackend::CreateInstance(
nullptr, g_browser_process->GetApplicationLocale());
{

View File

@@ -246,7 +246,7 @@ class WebContents : public gin_helper::TrackableObject<WebContents>,
bool silent,
base::string16 default_printer);
void Print(gin_helper::Arguments* args);
std::vector<printing::PrinterBasicInfo> GetPrinterList();
printing::PrinterList GetPrinterList();
// Print current page as PDF.
v8::Local<v8::Promise> PrintToPDF(base::DictionaryValue settings);
#endif