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 =