From 70f0bb4639067512ce85e2d1e97bd05b82c64b15 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 18 Jul 2017 19:03:36 +0900 Subject: [PATCH] Bug 1376693 - part2: Make nsPrintEngine::DoCommonPrint() stop initializing the instance when the owner stops using the instance r=dholbert nsPrintEngine::FinishPrintPreview() may be called when nsAutoScriptBlocker is destroyed in nsPrintEngine::DoCommonPrint(). That means that the owner stopped print preview with the instance. In this case, nsPrintEngine::DoCommonPrint() doesn't need to keep initializing the instance anymore. MozReview-Commit-ID: DRQfmyW9FEL --HG-- extra : rebase_source : a49c0f5c74c24710334559496d173c3bae08db01 --- layout/printing/nsPrintEngine.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index e41fafb230bd..fedf3c3cd4ee 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -536,6 +536,14 @@ nsPrintEngine::DoCommonPrint(bool aIsPrintPreview, printData->mPrintObject); } + // The nsAutoScriptBlocker above will now have been destroyed, which may + // cause our print/print-preview operation to finish. In this case, we + // should immediately return an error code so that the root caller knows + // it shouldn't continue to do anything with this instance. + if (mIsDestroying || (aIsPrintPreview && !GetIsCreatingPrintPreview())) { + return NS_ERROR_FAILURE; + } + if (!aIsPrintPreview) { SetIsPrinting(true); } @@ -3602,6 +3610,13 @@ nsPrintEngine::FinishPrintPreview() rv = DocumentReadyForPrinting(); + // Note that this method may be called while the instance is being + // initialized. Some methods which initialize the instance (e.g., + // DoCommonPrint) may need to stop initializing and return error if + // this is called. Therefore it's important to set IsCreatingPrintPreview + // state to false here. If you need to remove this call of + // SetIsCreatingPrintPreview here, you need to keep them being able to + // check whether the owner stopped using this instance. SetIsCreatingPrintPreview(false); // mPrt may be cleared during a call of nsPrintData::OnEndPrinting()