Bug 1376693 - part1: Make nsPrintEngine::SetupToPrintContent() return early if mPrt->mPrintObject isn't initialized r=dholbert
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 19 Jul 2017 13:50:35 +0900
changeset 418260 7c792959ed4c9fdc4ca51c357e0b8d9708feb712
parent 418259 33dd57cd02636fbfa2fc2ff0e4459ec170750572
child 418261 f1cae5c666a6c94690e1eec8ea3998650ff91b7a
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1376693
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1376693 - part1: Make nsPrintEngine::SetupToPrintContent() return early if mPrt->mPrintObject isn't initialized r=dholbert nsPrintObject::mPresShell and nsPrintObject::mPresContext are initialized by nsPrintEngine::ReflowPrintObject(). However, while nsPrintEngine::DoCommonPrint() is initializing mPrt and mPrintObject, destroying nsAutoScriptBlocker may cause calling nsDocumentViewer::Destroy() or nsPrintEngine::FinishPrintPreview() directly. Then, nsPrintEngine::SetupToPrintContent() will be called. Therefore, nsPrintEngine::SetupToPrintContent() sometimes see uninitialized mPrt, or mPrt->mPrintObject->mPresShell and mPrt->mPrintObject->mPresContext. Therefore, this patch makes nsPrintEngine::SetupToPrintContent() check whether the necessary objects are already initialized. When one of them is not initialized as expected, it won't to do anything. Note that mPrt->mPrintObject is never nullptr with current design, but this patch makes the method check it for preventing similar crash which might be regressed with other bug fix in the future. MozReview-Commit-ID: JKfObRm5enm
layout/printing/nsPrintEngine.cpp
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -1678,17 +1678,26 @@ nsPrintEngine::ReconstructAndReflow(bool
   }
   return NS_OK;
 }
 
 //-------------------------------------------------------
 nsresult
 nsPrintEngine::SetupToPrintContent()
 {
-  if (NS_WARN_IF(!mPrt)) {
+  // This method may be called while DoCommonPrint() initializes the instance
+  // when its script blocker goes out of scope.  In such case, this cannot do
+  // its job as expected because some objects in mPrt have not been initialized
+  // yet but they are necessary.
+  // Note: it shouldn't be possible for mPrt->mPrintObject to be null; we
+  // just check it for good measure, as we check its owner & members.
+  if (NS_WARN_IF(!mPrt) ||
+      NS_WARN_IF(!mPrt->mPrintObject) ||
+      NS_WARN_IF(!mPrt->mPrintObject->mPresShell) ||
+      NS_WARN_IF(!mPrt->mPrintObject->mPresContext)) {
     return NS_ERROR_FAILURE;
   }
 
   bool didReconstruction = false;
 
   // This method works with mPrt->mPrintObject.  So, we need to guarantee that
   // it won't be deleted in this method.  We achieve this by holding a strong
   // local reference to mPrt, which in turn keeps mPrintObject alive.