Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check printer list when no default printers #25606

Merged
merged 1 commit into from Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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