Bug 362734 - Crash [@ nsPrintEngine::DocumentReadyForPrinting] with testcase that sets print preview, then reloads the page, patch by Andrew Smith, r=sharparrow1, sr=roc (blocking1.9 bug)
authormartijn.martijn@gmail.com
Tue, 04 Sep 2007 14:44:42 -0700
changeset 5662 f7ffc0aff33c931012fa0e224c427d9e3c437d88
parent 5661 495fa27ea4a7d6d2661c30c2d8dc6c80ec841902
child 5663 42938cc16d29900808261131fe051e1a1fc14a34
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssharparrow1, roc
bugs362734
milestone1.9a8pre
Bug 362734 - Crash [@ nsPrintEngine::DocumentReadyForPrinting] with testcase that sets print preview, then reloads the page, patch by Andrew Smith, r=sharparrow1, sr=roc (blocking1.9 bug)
layout/base/nsDocumentViewer.cpp
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -1459,16 +1459,24 @@ DocumentViewerImpl::Destroy()
 
   // All callers are supposed to call destroy to break circular
   // references.  If we do this stuff in the destructor, the
   // destructor might never be called (especially if we're being
   // used from JS.
 
 #ifdef NS_PRINTING
   if (mPrintEngine) {
+#ifdef NS_PRINT_PREVIEW
+    PRBool doingPrintPreview;
+    mPrintEngine->GetDoingPrintPreview(&doingPrintPreview);
+    if (doingPrintPreview) {
+      mPrintEngine->FinishPrintPreview();
+    }
+#endif
+
     mPrintEngine->Destroy();
     mPrintEngine = nsnull;
   }
 #endif
 
   // Avoid leaking the old viewer.
   if (mPreviousViewer) {
     mPreviousViewer->Destroy();
@@ -3446,23 +3454,16 @@ DocumentViewerImpl::Print(nsIPrintSettin
 
   rv = mPrintEngine->Print(aPrintSettings, aWebProgressListener);
   if (NS_FAILED(rv)) {
     OnDonePrinting();
   }
   return rv;
 }
 
-/** ---------------------------------------------------
- *  See documentation above in the nsIContentViewerfile class definition
- *	@update 11/01/01 rods
- *
- *  For a full and detailed understanding of the issues with
- *  PrintPreview: See the design spec that is attached to Bug 107562
- */
 NS_IMETHODIMP
 DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings, 
                                  nsIDOMWindow *aChildDOMWin, 
                                  nsIWebProgressListener* aWebProgressListener)
 {
 #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
   nsresult rv = NS_OK;
 
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -707,23 +707,16 @@ nsPrintEngine::DoCommonPrint(PRBool     
 //---------------------------------------------------------------------------------
 NS_IMETHODIMP
 nsPrintEngine::Print(nsIPrintSettings*       aPrintSettings,
                      nsIWebProgressListener* aWebProgressListener)
 {
   return CommonPrint(PR_FALSE, aPrintSettings, aWebProgressListener);
 }
 
-/** ---------------------------------------------------
- *  See documentation above in the nsIContentViewerfile class definition
- *	@update 11/01/01 rods
- *
- *  For a full and detailed understanding of the issues with
- *  PrintPreview: See the design spec that is attached to Bug 107562
- */
 NS_IMETHODIMP
 nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings, 
                                  nsIDOMWindow *aChildDOMWin, 
                                  nsIWebProgressListener* aWebProgressListener)
 {
   return CommonPrint(PR_TRUE, aPrintSettings, aWebProgressListener);
 }
 
@@ -2529,16 +2522,19 @@ nsPrintEngine::GetPageRangeForSelection(
 
 //---------------------------------------------------------------------
 void nsPrintEngine::SetIsPrinting(PRBool aIsPrinting)
 { 
   mIsDoingPrinting = aIsPrinting;
   if (mDocViewerPrint) {
     mDocViewerPrint->SetIsPrinting(aIsPrinting);
   }
+  if (mPrt && aIsPrinting) {
+    mPrt->mPreparingForPrint = PR_TRUE;
+  }
 }
 
 //---------------------------------------------------------------------
 void nsPrintEngine::SetIsPrintPreview(PRBool aIsPrintPreview) 
 { 
   mIsDoingPrintPreview = aIsPrintPreview; 
 
   if (mDocViewerPrint) {
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintEngine.h
@@ -54,26 +54,16 @@ class nsIDeviceContext;
 class nsIDocumentViewerPrint;
 class nsPrintObject;
 class nsIDocShell;
 class nsIPageSequenceFrame;
 
 //------------------------------------------------------------------------
 // nsPrintEngine Class
 //
-// mPreparingForPrint - indicates that we have started Printing but 
-//   have not gone to the timer to start printing the pages. It gets turned 
-//   off right before we go to the timer.
-//
-// mDocWasToBeDestroyed - Gets set when "someone" tries to unload the document
-//   while we were prparing to Print. This typically happens if a user starts 
-//   to print while a page is still loading. If they start printing and pause 
-//   at the print dialog and then the page comes in, we then abort printing 
-//   because the document is no longer stable.
-// 
 //------------------------------------------------------------------------
 class nsPrintEngine : public nsIObserver
 {
 public:
   // nsISupports interface...
   NS_DECL_ISUPPORTS
 
   // nsIObserver