Bug 620158 - Crash while printing, r=mats, a=blocking
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 14 Jan 2011 14:27:31 +0200
changeset 60499 5882d714c8d4df8f7cf091a9e2c0dee5264e4531
parent 60498 c02435684f58c06ee516114a316ab6dfbafd91ab
child 60500 313df704acf701fac41559f121daadc625155f5c
push id18023
push useropettay@mozilla.com
push dateFri, 14 Jan 2011 14:06:41 +0000
treeherdermozilla-central@313df704acf7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats, blocking
bugs620158
milestone2.0b10pre
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 620158 - Crash while printing, r=mats, a=blocking
layout/printing/nsPrintObject.cpp
layout/printing/nsPrintObject.h
--- a/layout/printing/nsPrintObject.cpp
+++ b/layout/printing/nsPrintObject.cpp
@@ -39,37 +39,44 @@
 #include "nsIContentViewer.h"
 #include "nsIDOMDocument.h"
 #include "nsContentUtils.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsGkAtoms.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIDocShellTreeItem.h"
-
+#include "nsIBaseWindow.h"
+                                                   
 //---------------------------------------------------
 //-- nsPrintObject Class Impl
 //---------------------------------------------------
 nsPrintObject::nsPrintObject() :
   mContent(nsnull), mFrameType(eFrame), mParent(nsnull),
   mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), mPrintAsIs(PR_FALSE),
-  mSharedPresShell(PR_FALSE), mInvisible(PR_FALSE),
+  mSharedPresShell(PR_FALSE), mInvisible(PR_FALSE), mDidCreateDocShell(PR_FALSE),
   mShrinkRatio(1.0), mZoomRatio(1.0)
 {
 }
 
 
 nsPrintObject::~nsPrintObject()
 {
   for (PRUint32 i=0;i<mKids.Length();i++) {
     nsPrintObject* po = mKids[i];
     delete po;
   }
 
   DestroyPresentation();
+  if (mDidCreateDocShell && mDocShell) {
+    nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(mDocShell));
+    if (baseWin) {
+      baseWin->Destroy();
+    }
+  }                            
   mDocShell = nsnull;
   mTreeOwner = nsnull; // mTreeOwner must be released after mDocShell; 
 }
 
 //------------------------------------------------------------------
 nsresult 
 nsPrintObject::Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc,
                     PRBool aPrintPreview)
@@ -81,16 +88,17 @@ nsPrintObject::Init(nsIDocShell* aDocShe
   } else {
     mTreeOwner = do_GetInterface(aDocShell);
     nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(aDocShell);
     PRInt32 itemType = 0;
     item->GetItemType(&itemType);
     // Create a container docshell for printing.
     mDocShell = do_CreateInstance("@mozilla.org/docshell;1");
     NS_ENSURE_TRUE(mDocShell, NS_ERROR_OUT_OF_MEMORY);
+    mDidCreateDocShell = PR_TRUE;
     nsCOMPtr<nsIDocShellTreeItem> newItem = do_QueryInterface(mDocShell);
     newItem->SetItemType(itemType);
     newItem->SetTreeOwner(mTreeOwner);
   }
   NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMDocument> dummy = do_GetInterface(mDocShell);
   nsCOMPtr<nsIContentViewer> viewer;
--- a/layout/printing/nsPrintObject.h
+++ b/layout/printing/nsPrintObject.h
@@ -84,16 +84,17 @@ public:
   nsTArray<nsPrintObject*> mKids;
   nsPrintObject*   mParent;
   PRPackedBool     mHasBeenPrinted;
   PRPackedBool     mDontPrint;
   PRPackedBool     mPrintAsIs;
   PRPackedBool     mSharedPresShell;
   PRPackedBool     mInvisible;        // Indicates PO is set to not visible by CSS
   PRPackedBool     mPrintPreview;
+  PRPackedBool     mDidCreateDocShell;
   float            mShrinkRatio;
   float            mZoomRatio;
 
 private:
   nsPrintObject& operator=(const nsPrintObject& aOther); // not implemented
 
 };