diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 1ecec4d0bea9..9d5c8f8684d9 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1137,7 +1137,9 @@ void WebContents::Print(mate::Arguments* args) { } printing::PrintViewManagerBasic::FromWebContents(web_contents())-> - PrintNow(settings.silent, settings.print_background); + PrintNow(web_contents()->GetMainFrame(), + settings.silent, + settings.print_background); } void WebContents::PrintToPDF(const base::DictionaryValue& setting, diff --git a/chromium_src/chrome/browser/printing/print_view_manager_base.cc b/chromium_src/chrome/browser/printing/print_view_manager_base.cc index e61cc10d5364..67caebb63ecf 100644 --- a/chromium_src/chrome/browser/printing/print_view_manager_base.cc +++ b/chromium_src/chrome/browser/printing/print_view_manager_base.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/memory/ref_counted_memory.h" +#include "base/memory/ptr_util.h" #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "base/timer/timer.h" @@ -25,6 +26,7 @@ #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "printing/pdf_metafile_skia.h" @@ -64,9 +66,12 @@ PrintViewManagerBase::~PrintViewManagerBase() { } #if !defined(DISABLE_BASIC_PRINTING) -bool PrintViewManagerBase::PrintNow(bool silent, bool print_background) { - return PrintNowInternal(new PrintMsg_PrintPages( - routing_id(), silent, print_background)); +bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh, + bool silent, bool print_background) { + int32_t id = rfh->GetRoutingID(); + return PrintNowInternal( + rfh, + base::MakeUnique(id, silent, print_background)); } #endif // !DISABLE_BASIC_PRINTING @@ -467,13 +472,13 @@ bool PrintViewManagerBase::OpportunisticallyCreatePrintJob(int cookie) { return true; } -bool PrintViewManagerBase::PrintNowInternal(IPC::Message* message) { - // Don't print / print preview interstitials. - if (web_contents()->ShowingInterstitialPage()) { - delete message; +bool PrintViewManagerBase::PrintNowInternal( + content::RenderFrameHost* rfh, + std::unique_ptr message) { + // Don't print / print preview interstitials or crashed tabs. + if (web_contents()->ShowingInterstitialPage() || web_contents()->IsCrashed()) return false; - } - return Send(message); + return rfh->Send(message.release()); } void PrintViewManagerBase::ReleasePrinterQuery() { diff --git a/chromium_src/chrome/browser/printing/print_view_manager_base.h b/chromium_src/chrome/browser/printing/print_view_manager_base.h index 78e5729a5fb1..fbf2e2ffd022 100644 --- a/chromium_src/chrome/browser/printing/print_view_manager_base.h +++ b/chromium_src/chrome/browser/printing/print_view_manager_base.h @@ -39,7 +39,8 @@ class PrintViewManagerBase : public content::NotificationObserver, // Prints the current document immediately. Since the rendering is // asynchronous, the actual printing will not be completed on the return of // this function. Returns false if printing is impossible at the moment. - virtual bool PrintNow(bool silent, bool print_background); + virtual bool PrintNow(content::RenderFrameHost* rfh, + bool silent, bool print_background); #endif // !DISABLE_BASIC_PRINTING // PrintedPagesSource implementation. @@ -49,7 +50,8 @@ class PrintViewManagerBase : public content::NotificationObserver, explicit PrintViewManagerBase(content::WebContents* web_contents); // Helper method for Print*Now(). - bool PrintNowInternal(IPC::Message* message); + bool PrintNowInternal(content::RenderFrameHost* rfh, + std::unique_ptr message); // Terminates or cancels the print job if one was pending. virtual void RenderProcessGone(base::TerminationStatus status) override;