| Index: chrome/browser/printing/print_view_manager_base.cc
|
| diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc
|
| index ec9d732681a34fb113ce7f81a3ec0eb318de9f03..c8028f4f234ebae6b311433a2f2b98543a9369f9 100644
|
| --- a/chrome/browser/printing/print_view_manager_base.cc
|
| +++ b/chrome/browser/printing/print_view_manager_base.cc
|
| @@ -32,7 +32,6 @@
|
| #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/features/features.h"
|
| @@ -71,7 +70,6 @@
|
|
|
| PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
|
| : PrintManager(web_contents),
|
| - printing_rfh_(nullptr),
|
| printing_succeeded_(false),
|
| inside_inner_message_loop_(false),
|
| #if !defined(OS_MACOSX)
|
| @@ -82,8 +80,9 @@
|
| Profile* profile =
|
| Profile::FromBrowserContext(web_contents->GetBrowserContext());
|
| printing_enabled_.Init(
|
| - prefs::kPrintingEnabled, profile->GetPrefs(),
|
| - base::Bind(&PrintViewManagerBase::UpdatePrintingEnabled,
|
| + prefs::kPrintingEnabled,
|
| + profile->GetPrefs(),
|
| + base::Bind(&PrintViewManagerBase::UpdateScriptedPrintingBlocked,
|
| base::Unretained(this)));
|
| }
|
|
|
| @@ -93,24 +92,36 @@
|
| }
|
|
|
| #if BUILDFLAG(ENABLE_BASIC_PRINTING)
|
| -bool PrintViewManagerBase::PrintNow(content::RenderFrameHost* rfh) {
|
| - DisconnectFromCurrentPrintJob();
|
| -
|
| - SetPrintingRFH(rfh);
|
| - int32_t id = rfh->GetRoutingID();
|
| - return PrintNowInternal(rfh, base::MakeUnique<PrintMsg_PrintPages>(id));
|
| -}
|
| -#endif
|
| -
|
| -void PrintViewManagerBase::UpdatePrintingEnabled() {
|
| - web_contents()->ForEachFrame(
|
| - base::Bind(&PrintViewManagerBase::SendPrintingEnabled,
|
| - base::Unretained(this), printing_enabled_.GetValue()));
|
| +bool PrintViewManagerBase::PrintNow() {
|
| + return PrintNowInternal(new PrintMsg_PrintPages(routing_id()));
|
| +}
|
| +#endif
|
| +
|
| +void PrintViewManagerBase::UpdateScriptedPrintingBlocked() {
|
| + Send(new PrintMsg_SetScriptedPrintingBlocked(
|
| + routing_id(),
|
| + !printing_enabled_.GetValue()));
|
| }
|
|
|
| void PrintViewManagerBase::NavigationStopped() {
|
| // Cancel the current job, wait for the worker to finish.
|
| TerminatePrintJob(true);
|
| +}
|
| +
|
| +void PrintViewManagerBase::RenderProcessGone(base::TerminationStatus status) {
|
| + PrintManager::RenderProcessGone(status);
|
| + ReleasePrinterQuery();
|
| +
|
| + if (!print_job_.get())
|
| + return;
|
| +
|
| + scoped_refptr<PrintedDocument> document(print_job_->document());
|
| + if (document.get()) {
|
| + // If IsComplete() returns false, the document isn't completely rendered.
|
| + // Since our renderer is gone, there's nothing to do, cancel it. Otherwise,
|
| + // the print job may finish without problem.
|
| + TerminatePrintJob(!document->IsComplete());
|
| + }
|
| }
|
|
|
| base::string16 PrintViewManagerBase::RenderSourceName() {
|
| @@ -225,35 +236,10 @@
|
| }
|
|
|
| void PrintViewManagerBase::DidStartLoading() {
|
| - UpdatePrintingEnabled();
|
| -}
|
| -
|
| -void PrintViewManagerBase::RenderFrameDeleted(
|
| - content::RenderFrameHost* render_frame_host) {
|
| - // Terminates or cancels the print job if one was pending.
|
| - if (render_frame_host != printing_rfh_)
|
| - return;
|
| -
|
| - printing_rfh_ = nullptr;
|
| -
|
| - PrintManager::PrintingRenderFrameDeleted();
|
| - ReleasePrinterQuery();
|
| -
|
| - if (!print_job_.get())
|
| - return;
|
| -
|
| - scoped_refptr<PrintedDocument> document(print_job_->document());
|
| - if (document.get()) {
|
| - // If IsComplete() returns false, the document isn't completely rendered.
|
| - // Since our renderer is gone, there's nothing to do, cancel it. Otherwise,
|
| - // the print job may finish without problem.
|
| - TerminatePrintJob(!document->IsComplete());
|
| - }
|
| -}
|
| -
|
| -bool PrintViewManagerBase::OnMessageReceived(
|
| - const IPC::Message& message,
|
| - content::RenderFrameHost* render_frame_host) {
|
| + UpdateScriptedPrintingBlocked();
|
| +}
|
| +
|
| +bool PrintViewManagerBase::OnMessageReceived(const IPC::Message& message) {
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(PrintViewManagerBase, message)
|
| IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage)
|
| @@ -261,7 +247,7 @@
|
| OnShowInvalidPrinterSettingsError)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
| - return handled || PrintManager::OnMessageReceived(message, render_frame_host);
|
| + return handled || PrintManager::OnMessageReceived(message);
|
| }
|
|
|
| void PrintViewManagerBase::Observe(
|
| @@ -373,7 +359,7 @@
|
| bool PrintViewManagerBase::CreateNewPrintJob(PrintJobWorkerOwner* job) {
|
| DCHECK(!inside_inner_message_loop_);
|
|
|
| - // Disconnect the current |print_job_|.
|
| + // Disconnect the current print_job_.
|
| DisconnectFromCurrentPrintJob();
|
|
|
| // We can't print if there is no renderer.
|
| @@ -418,6 +404,12 @@
|
| #endif
|
| }
|
|
|
| +void PrintViewManagerBase::PrintingDone(bool success) {
|
| + if (!print_job_.get())
|
| + return;
|
| + Send(new PrintMsg_PrintingDone(routing_id(), success));
|
| +}
|
| +
|
| void PrintViewManagerBase::TerminatePrintJob(bool cancel) {
|
| if (!print_job_.get())
|
| return;
|
| @@ -439,23 +431,16 @@
|
| }
|
|
|
| void PrintViewManagerBase::ReleasePrintJob() {
|
| - content::RenderFrameHost* rfh = printing_rfh_;
|
| - printing_rfh_ = nullptr;
|
| -
|
| if (!print_job_.get())
|
| return;
|
|
|
| - if (rfh) {
|
| - auto msg = base::MakeUnique<PrintMsg_PrintingDone>(rfh->GetRoutingID(),
|
| - printing_succeeded_);
|
| - rfh->Send(msg.release());
|
| - }
|
| + PrintingDone(printing_succeeded_);
|
|
|
| registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_EVENT,
|
| content::Source<PrintJob>(print_job_.get()));
|
| print_job_->DisconnectSource();
|
| // Don't close the worker thread.
|
| - print_job_ = nullptr;
|
| + print_job_ = NULL;
|
| }
|
|
|
| bool PrintViewManagerBase::RunInnerMessageLoop() {
|
| @@ -524,18 +509,14 @@
|
| return true;
|
| }
|
|
|
| -bool PrintViewManagerBase::PrintNowInternal(
|
| - content::RenderFrameHost* rfh,
|
| - std::unique_ptr<IPC::Message> message) {
|
| +bool PrintViewManagerBase::PrintNowInternal(IPC::Message* message) {
|
| // Don't print / print preview interstitials or crashed tabs.
|
| - if (web_contents()->ShowingInterstitialPage() || web_contents()->IsCrashed())
|
| - return false;
|
| - return rfh->Send(message.release());
|
| -}
|
| -
|
| -void PrintViewManagerBase::SetPrintingRFH(content::RenderFrameHost* rfh) {
|
| - DCHECK(!printing_rfh_);
|
| - printing_rfh_ = rfh;
|
| + if (web_contents()->ShowingInterstitialPage() ||
|
| + web_contents()->IsCrashed()) {
|
| + delete message;
|
| + return false;
|
| + }
|
| + return Send(message);
|
| }
|
|
|
| void PrintViewManagerBase::ReleasePrinterQuery() {
|
| @@ -559,9 +540,4 @@
|
| base::Bind(&PrinterQuery::StopWorker, printer_query));
|
| }
|
|
|
| -void PrintViewManagerBase::SendPrintingEnabled(bool enabled,
|
| - content::RenderFrameHost* rfh) {
|
| - rfh->Send(new PrintMsg_SetPrintingEnabled(rfh->GetRoutingID(), enabled));
|
| -}
|
| -
|
| } // namespace printing
|
|
|