fix: check printer list when no default printers (#25515)
This commit is contained in:
parent
ea76788b67
commit
15c30c5649
2 changed files with 15 additions and 5 deletions
|
@ -392,10 +392,20 @@ base::string16 GetDefaultPrinterAsync() {
|
||||||
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
|
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
|
||||||
base::BlockingType::MAY_BLOCK);
|
base::BlockingType::MAY_BLOCK);
|
||||||
|
|
||||||
scoped_refptr<printing::PrintBackend> backend =
|
scoped_refptr<printing::PrintBackend> print_backend =
|
||||||
printing::PrintBackend::CreateInstance(
|
printing::PrintBackend::CreateInstance(
|
||||||
g_browser_process->GetApplicationLocale());
|
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);
|
return base::UTF8ToUTF16(printer_name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2184,8 +2194,8 @@ void WebContents::Print(gin::Arguments* args) {
|
||||||
std::move(callback), device_name, silent));
|
std::move(callback), device_name, silent));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<printing::PrinterBasicInfo> WebContents::GetPrinterList() {
|
printing::PrinterList WebContents::GetPrinterList() {
|
||||||
std::vector<printing::PrinterBasicInfo> printers;
|
printing::PrinterList printers;
|
||||||
auto print_backend = printing::PrintBackend::CreateInstance(
|
auto print_backend = printing::PrintBackend::CreateInstance(
|
||||||
g_browser_process->GetApplicationLocale());
|
g_browser_process->GetApplicationLocale());
|
||||||
{
|
{
|
||||||
|
|
|
@ -263,7 +263,7 @@ class WebContents : public gin::Wrappable<WebContents>,
|
||||||
bool silent,
|
bool silent,
|
||||||
base::string16 default_printer);
|
base::string16 default_printer);
|
||||||
void Print(gin::Arguments* args);
|
void Print(gin::Arguments* args);
|
||||||
std::vector<printing::PrinterBasicInfo> GetPrinterList();
|
printing::PrinterList GetPrinterList();
|
||||||
// Print current page as PDF.
|
// Print current page as PDF.
|
||||||
v8::Local<v8::Promise> PrintToPDF(base::DictionaryValue settings);
|
v8::Local<v8::Promise> PrintToPDF(base::DictionaryValue settings);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue