From f07e4b883fa1ac3cecea1f618228976569e43840 Mon Sep 17 00:00:00 2001 From: cku Date: Thu, 30 Nov 2017 11:55:12 +0800 Subject: [PATCH] Bug 1399787 - Part 11.c. Add assertions to make sure no page-done callback from the PrintTarget after the print job done. r=jwatt MozReview-Commit-ID: FsDqjpy2wtR --HG-- extra : rebase_source : 40b66df0674e5a571e647e17957032c6bfedd28e --- layout/printing/ipc/RemotePrintJobParent.cpp | 11 +++++++++++ layout/printing/ipc/RemotePrintJobParent.h | 1 + layout/printing/nsPrintEngine.cpp | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/layout/printing/ipc/RemotePrintJobParent.cpp b/layout/printing/ipc/RemotePrintJobParent.cpp index 6c8ace92b57a..af2af987fdad 100644 --- a/layout/printing/ipc/RemotePrintJobParent.cpp +++ b/layout/printing/ipc/RemotePrintJobParent.cpp @@ -27,6 +27,7 @@ namespace layout { RemotePrintJobParent::RemotePrintJobParent(nsIPrintSettings* aPrintSettings) : mPrintSettings(aPrintSettings) + , mIsDoingPrinting(false) { MOZ_COUNT_CTOR(RemotePrintJobParent); } @@ -92,6 +93,8 @@ RemotePrintJobParent::InitializePrintDevice(const nsString& aDocumentTitle, mPrintDeviceContext->RegisterPageDoneCallback([this](nsresult aResult) { PageDone(aResult); }); } + mIsDoingPrinting = true; + return NS_OK; } @@ -151,6 +154,8 @@ RemotePrintJobParent::PrintPage(PRFileDescStream& aRecording) void RemotePrintJobParent::PageDone(nsresult aResult) { + MOZ_ASSERT(mIsDoingPrinting); + if (NS_FAILED(aResult)) { Unused << SendAbortPrint(aResult); } else { @@ -181,6 +186,8 @@ RemotePrintJobParent::RecvFinalizePrint() mPrintDeviceContext->UnregisterPageDoneCallback(); } + mIsDoingPrinting = false; + Unused << Send__delete__(this); return IPC_OK(); } @@ -193,6 +200,8 @@ RemotePrintJobParent::RecvAbortPrint(const nsresult& aRv) mPrintDeviceContext->UnregisterPageDoneCallback(); } + mIsDoingPrinting = false; + Unused << Send__delete__(this); return IPC_OK(); } @@ -265,6 +274,8 @@ RemotePrintJobParent::ActorDestroy(ActorDestroyReason aWhy) if (mPrintDeviceContext) { mPrintDeviceContext->UnregisterPageDoneCallback(); } + + mIsDoingPrinting = false; } } // namespace layout diff --git a/layout/printing/ipc/RemotePrintJobParent.h b/layout/printing/ipc/RemotePrintJobParent.h index 4758ec32efe7..df319ce7890f 100644 --- a/layout/printing/ipc/RemotePrintJobParent.h +++ b/layout/printing/ipc/RemotePrintJobParent.h @@ -87,6 +87,7 @@ private: UniquePtr mPrintTranslator; nsCOMArray mPrintProgressListeners; PRFileDescStream mCurrentPageStream; + bool mIsDoingPrinting; }; } // namespace layout diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index c6a4827a491c..2319171c8899 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -2869,6 +2869,17 @@ nsPrintEngine::PrintPage(nsPrintObject* aPO, return donePrinting; } +void +nsPrintEngine::PageDone(nsresult aResult) +{ + MOZ_ASSERT(mIsDoingPrinting); + + // mPagePrintTimer might be released during RemotePrintFinished, keep a + // reference here to make sure it lives long enough. + RefPtr timer = mPagePrintTimer; + timer->RemotePrintFinished(); +} + //----------------------------------------------------------------- //-- Done: Printing Methods //-----------------------------------------------------------------