Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: check printer list when no default printers (#25606)
  • Loading branch information
codebytere committed Sep 23, 2020
1 parent 894d41e commit 0b75053
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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());
{
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_web_contents.h
Expand Up @@ -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
Expand Down

0 comments on commit 0b75053

Please sign in to comment.