diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index fb33ddba053..1568996078a 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -422,6 +422,7 @@ protected: PRPackedBool mEnableRendering; PRPackedBool mStopped; PRPackedBool mLoaded; + PRPackedBool mDeferredWindowClose; PRInt16 mNumURLStarts; PRInt16 mDestroyRefCount; // a second "refcount" for the document viewer's "destroy" @@ -486,6 +487,7 @@ void DocumentViewerImpl::PrepareToStartLoad() mEnableRendering = PR_TRUE; mStopped = PR_FALSE; mLoaded = PR_FALSE; + mDeferredWindowClose = PR_FALSE; #ifdef NS_PRINTING mPrintIsPending = PR_FALSE; @@ -1585,6 +1587,21 @@ DocumentViewerImpl::GetEnableRendering(PRBool* aResult) return NS_OK; } +NS_IMETHODIMP +DocumentViewerImpl::RequestWindowClose(PRBool* aCanClose) +{ +#ifdef NS_PRINTING + if (mPrintIsPending || (mPrintEngine && mPrintEngine->GetIsPrinting())) { + *aCanClose = PR_FALSE; + mDeferredWindowClose = PR_TRUE; + } else +#endif + *aCanClose = PR_TRUE; + + return NS_OK; +} + + void DocumentViewerImpl::ForceRefresh() { @@ -3817,7 +3834,12 @@ DocumentViewerImpl::OnDonePrinting() } // We are done printing, now cleanup - if (mClosingWhilePrinting) { + if (mDeferredWindowClose) { + mDeferredWindowClose = PR_FALSE; + nsCOMPtr win = do_GetInterface(mContainer); + if (win) + win->Close(); + } else if (mClosingWhilePrinting) { if (mDocument) { mDocument->SetScriptGlobalObject(nsnull); mDocument = nsnull; diff --git a/mozilla/docshell/base/nsIContentViewer.idl b/mozilla/docshell/base/nsIContentViewer.idl index 6b2b00fcba3..6489b9cb8a8 100644 --- a/mozilla/docshell/base/nsIContentViewer.idl +++ b/mozilla/docshell/base/nsIContentViewer.idl @@ -59,4 +59,12 @@ interface nsIContentViewer : nsISupports attribute boolean enableRendering; attribute boolean sticky; + + /* + * This is called when the DOM window wants to be closed. Returns true + * if the window can close immediately. Otherwise, returns false and will + * close the DOM window as soon as practical. + */ + + boolean requestWindowClose(); }; diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 88553505d8a..53bedde68e1 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -3344,6 +3344,20 @@ GlobalWindowImpl::Close() } } + // Ask the content viewer whether the toplevel window can close. + // If the content viewer returns false, it is responsible for calling + // Close() as soon as it is possible for the window to close. + // This allows us to not close the window while printing is happening. + + nsCOMPtr cv; + mDocShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + PRBool canClose; + cv->RequestWindowClose(&canClose); + if (!canClose) + return NS_OK; + } + // Fire a DOM event notifying listeners that this window is about to // be closed. The tab UI code may choose to cancel the default // action for this event, if so, we won't actually close the window diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index fb33ddba053..1568996078a 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -422,6 +422,7 @@ protected: PRPackedBool mEnableRendering; PRPackedBool mStopped; PRPackedBool mLoaded; + PRPackedBool mDeferredWindowClose; PRInt16 mNumURLStarts; PRInt16 mDestroyRefCount; // a second "refcount" for the document viewer's "destroy" @@ -486,6 +487,7 @@ void DocumentViewerImpl::PrepareToStartLoad() mEnableRendering = PR_TRUE; mStopped = PR_FALSE; mLoaded = PR_FALSE; + mDeferredWindowClose = PR_FALSE; #ifdef NS_PRINTING mPrintIsPending = PR_FALSE; @@ -1585,6 +1587,21 @@ DocumentViewerImpl::GetEnableRendering(PRBool* aResult) return NS_OK; } +NS_IMETHODIMP +DocumentViewerImpl::RequestWindowClose(PRBool* aCanClose) +{ +#ifdef NS_PRINTING + if (mPrintIsPending || (mPrintEngine && mPrintEngine->GetIsPrinting())) { + *aCanClose = PR_FALSE; + mDeferredWindowClose = PR_TRUE; + } else +#endif + *aCanClose = PR_TRUE; + + return NS_OK; +} + + void DocumentViewerImpl::ForceRefresh() { @@ -3817,7 +3834,12 @@ DocumentViewerImpl::OnDonePrinting() } // We are done printing, now cleanup - if (mClosingWhilePrinting) { + if (mDeferredWindowClose) { + mDeferredWindowClose = PR_FALSE; + nsCOMPtr win = do_GetInterface(mContainer); + if (win) + win->Close(); + } else if (mClosingWhilePrinting) { if (mDocument) { mDocument->SetScriptGlobalObject(nsnull); mDocument = nsnull;