From 159c9722a0f3fe26f5852eb929fda23bcdd765a9 Mon Sep 17 00:00:00 2001 From: "mats.palmgren%bredband.net" Date: Sun, 31 Dec 2006 08:13:56 +0000 Subject: [PATCH] Crash [@ nsPrintEngine::PrintPreview] when trying to print preview a display:none iframe. b=365004 r=sharparrow1 sr=roc git-svn-id: svn://10.0.0.236/trunk@217579 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsDocumentViewer.cpp | 57 ++++++++++++++++-------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index f69f3578606..249e38a3add 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -23,6 +23,7 @@ * Contributor(s): * Dan Rosen * Roland Mainz + * Mats Palmgren * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -509,10 +510,10 @@ void DocumentViewerImpl::PrepareToStartLoad() // Note: operator new zeros our memory, so no need to init things to null. DocumentViewerImpl::DocumentViewerImpl(nsPresContext* aPresContext) : mPresContext(aPresContext), + mTextZoom(1.0), mIsSticky(PR_TRUE), mHintCharsetSource(kCharsetUninitialized), - mIsPageMode(PR_FALSE), - mTextZoom(1.0) + mIsPageMode(PR_FALSE) { PrepareToStartLoad(); } @@ -994,6 +995,9 @@ DocumentViewerImpl::DumpContentToPPM(const char* aFileName) delete[] buf; } + else { + status = "OOM"; + } surface->Unlock(); } context->DestroyDrawingSurface(surface); @@ -3463,14 +3467,12 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, nsCOMPtr presShell; docShell->GetPresShell(getter_AddRefs(presShell)); - - if (!presShell) { - // A frame that's not displayed can't be printed! - PR_PL(("Printing Stopped - PreShell was NULL!")); - return NS_OK; + if (!presShell || !mDocument || !mDeviceContext || !mParentWidget) { + PR_PL(("Can't Print without pres shell, document etc")); + return NS_ERROR_FAILURE; } - nsresult rv = NS_ERROR_FAILURE; + nsresult rv; // if we are printing another URL, then exit // the reason we check here is because this method can be called while @@ -3493,13 +3495,19 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, mPrintEngine = new nsPrintEngine(); NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY); + rv = mPrintEngine->Initialize(this, docShell, mDocument, + mDeviceContext, mParentWidget, #ifdef NS_DEBUG - mPrintEngine->Initialize(this, docShell, mDocument, - mDeviceContext, mParentWidget, mDebugFile); + mDebugFile #else - mPrintEngine->Initialize(this, docShell, mDocument, - mDeviceContext, mParentWidget, nsnull); + nsnull #endif + ); + if (NS_FAILED(rv)) { + mPrintEngine->Destroy(); + mPrintEngine = nsnull; + return rv; + } } rv = mPrintEngine->Print(aPrintSettings, aWebProgressListener); @@ -3539,19 +3547,32 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings, } #endif + nsCOMPtr docShell(do_QueryReferent(mContainer)); + NS_ASSERTION(docShell, "This has to be a docshell"); + nsCOMPtr presShell; + docShell->GetPresShell(getter_AddRefs(presShell)); + if (!presShell || !mDocument || !mDeviceContext || !mParentWidget) { + PR_PL(("Can't Print Preview without pres shell, document etc")); + return NS_ERROR_FAILURE; + } + if (!mPrintEngine) { mPrintEngine = new nsPrintEngine(); NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY); - mPrintEngine->Initialize(this, - nsCOMPtr(do_QueryReferent(mContainer)), - mDocument, mDeviceContext, mParentWidget, + rv = mPrintEngine->Initialize(this, docShell, mDocument, + mDeviceContext, mParentWidget, #ifdef NS_DEBUG - mDebugFile + mDebugFile #else - nsnull + nsnull #endif - ); + ); + if (NS_FAILED(rv)) { + mPrintEngine->Destroy(); + mPrintEngine = nsnull; + return rv; + } } rv = mPrintEngine->PrintPreview(aPrintSettings, aChildDOMWin, aWebProgressListener);