From dee324f79a9bfc27cf1d92325597cea5c2b9d199 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 6 Feb 2020 00:48:51 +0900 Subject: [PATCH] fix: check WebContents in OnGetDefaultPrinter (#22041) --- shell/browser/api/electron_api_web_contents.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index af19cdfd588..eb06d1c43bd 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1745,6 +1745,14 @@ void WebContents::OnGetDefaultPrinter( base::string16 device_name, bool silent, base::string16 default_printer) { + // The content::WebContents might be already deleted at this point, and the + // PrintViewManagerBasic class does not do null check. + if (!web_contents()) { + if (print_callback) + std::move(print_callback).Run(false, "failed"); + return; + } + base::string16 printer_name = device_name.empty() ? default_printer : device_name; print_settings.SetStringKey(printing::kSettingDeviceName, printer_name);