Bug 1382118 - Make nsPrintEngine::AfterNetworkPrint() do nothing if mPtr is nullptr r?dholbert
According to the crash reports, nsPrintEngine::AfterNetworkPrint() may be called after nsPrintEngine::Destroy() is called. In this case, the method should do nothing because it's already been destroyed.
MozReview-Commit-ID: IwY9fR1OUwU
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -1943,16 +1943,28 @@ nsPrintEngine::InitPrintDocConstruction(
AfterNetworkPrint(aHandleError);
}
return rv;
}
nsresult
nsPrintEngine::AfterNetworkPrint(bool aHandleError)
{
+ // If Destroy() has already been called, mPtr is nullptr. Then, the instance
+ // needs to do nothing anymore in this method.
+ // Note: it shouldn't be possible for mPrt->mPrintObject to be null; we
+ // just check it for good measure, as we check its owner.
+ // Note: it shouldn't be possible for mPrt->mPrintObject->mDocShell to be
+ // null; we just check it for good measure, as we check its owner.
+ if (!mPrt ||
+ NS_WARN_IF(!mPrt->mPrintObject) ||
+ NS_WARN_IF(!mPrt->mPrintObject->mDocShell)) {
+ return NS_ERROR_FAILURE;
+ }
+
nsCOMPtr<nsIWebProgress> webProgress = do_QueryInterface(mPrt->mPrintObject->mDocShell);
webProgress->RemoveProgressListener(
static_cast<nsIWebProgressListener*>(this));
nsresult rv;
if (mIsDoingPrinting) {
rv = DocumentReadyForPrinting();