From 1e6084fb600d783056abde8a05207ab3bef7e9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 28 Aug 2020 11:33:18 +0000 Subject: [PATCH] Bug 1661137 - Decrement the document viewer's destroy blocker earlier. r=bobowen Do it as soon as we're done printing, rather than waiting until the print timer dies. Differential Revision: https://phabricator.services.mozilla.com/D88569 --- layout/printing/nsPagePrintTimer.cpp | 13 ++++++++++--- layout/printing/nsPagePrintTimer.h | 9 +++------ layout/printing/nsPrintJob.cpp | 3 +-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/layout/printing/nsPagePrintTimer.cpp b/layout/printing/nsPagePrintTimer.cpp index 31453c44a417..b1f27c74f962 100644 --- a/layout/printing/nsPagePrintTimer.cpp +++ b/layout/printing/nsPagePrintTimer.cpp @@ -14,9 +14,16 @@ using namespace mozilla; NS_IMPL_ISUPPORTS_INHERITED(nsPagePrintTimer, mozilla::Runnable, nsITimerCallback) -nsPagePrintTimer::~nsPagePrintTimer() { - // This matches the IncrementDestroyBlockedCount call in the constructor. - mDocViewerPrint->DecrementDestroyBlockedCount(); +nsPagePrintTimer::~nsPagePrintTimer() { Disconnect(); } + +void nsPagePrintTimer::Disconnect() { + mPrintJob = nullptr; + mPrintObj = nullptr; + if (mDocViewerPrint) { + // This matches the IncrementDestroyBlockedCount call in the constructor. + mDocViewerPrint->DecrementDestroyBlockedCount(); + mDocViewerPrint = nullptr; + } } nsresult nsPagePrintTimer::StartTimer(bool aUseDelay) { diff --git a/layout/printing/nsPagePrintTimer.h b/layout/printing/nsPagePrintTimer.h index 700416587884..7b633881997b 100644 --- a/layout/printing/nsPagePrintTimer.h +++ b/layout/printing/nsPagePrintTimer.h @@ -30,7 +30,7 @@ class nsPagePrintTimer final : public mozilla::Runnable, mozilla::dom::Document* aDocument, uint32_t aDelay) : Runnable("nsPagePrintTimer"), mPrintJob(aPrintJob), - mDocViewerPrint(*aDocViewerPrint), + mDocViewerPrint(aDocViewerPrint), mDocument(aDocument), mDelay(aDelay), mFiringCount(0), @@ -52,10 +52,7 @@ class nsPagePrintTimer final : public mozilla::Runnable, void WaitForRemotePrint(); void RemotePrintFinished(); - void Disconnect() { - mPrintJob = nullptr; - mPrintObj = nullptr; - } + void Disconnect(); private: ~nsPagePrintTimer(); @@ -66,7 +63,7 @@ class nsPagePrintTimer final : public mozilla::Runnable, void Fail(); nsPrintJob* mPrintJob; - const mozilla::OwningNonNull mDocViewerPrint; + nsCOMPtr mDocViewerPrint; RefPtr mDocument; nsCOMPtr mTimer; nsCOMPtr mWatchDogTimer; diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index b2fd1963bebb..687119f011df 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -2556,9 +2556,8 @@ nsresult nsPrintJob::StartPagePrintTimer(const UniquePtr& aPO) { nsCOMPtr doc = cv->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); - RefPtr timer = + mPagePrintTimer = new nsPagePrintTimer(this, mDocViewerPrint, doc, printPageDelay); - timer.forget(&mPagePrintTimer); nsCOMPtr printSession; nsresult rv =