diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index a299bf980b70..83c6109b091c 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4132,7 +4132,16 @@ nsDocShell::IsPrintingOrPP(bool aDisplayErrorDialog) bool nsDocShell::IsNavigationAllowed(bool aDisplayPrintErrorDialog) { - return !IsPrintingOrPP(aDisplayPrintErrorDialog) && !mFiredUnloadEvent; + bool isAllowed = !IsPrintingOrPP(aDisplayPrintErrorDialog) && !mFiredUnloadEvent; + if (!isAllowed) { + return false; + } + if (!mContentViewer) { + return true; + } + bool firingBeforeUnload; + mContentViewer->GetBeforeUnloadFiring(&firingBeforeUnload); + return !firingBeforeUnload; } //***************************************************************************** diff --git a/docshell/base/nsIContentViewer.idl b/docshell/base/nsIContentViewer.idl index 38d642315dc3..f8d0a45bf2b5 100644 --- a/docshell/base/nsIContentViewer.idl +++ b/docshell/base/nsIContentViewer.idl @@ -28,7 +28,7 @@ class nsDOMNavigationTiming; [ptr] native nsViewPtr(nsView); [ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming); -[scriptable, builtinclass, uuid(1b22be51-efe8-42ac-a9a0-06f50f39beee)] +[scriptable, builtinclass, uuid(a73d693a-6260-468a-ae64-d64237f0858c)] interface nsIContentViewer : nsISupports { @@ -58,6 +58,12 @@ interface nsIContentViewer : nsISupports [noscript,nostdcall] boolean permitUnloadInternal(in boolean aCallerClosesWindow, inout boolean aShouldPrompt); + /** + * Exposes whether we're in the process of firing the beforeunload event. + * In this case, the corresponding docshell will not allow navigation. + */ + readonly attribute boolean beforeUnloadFiring; + /** * Works in tandem with permitUnload, if the caller decides not to close the * window it indicated it will, it is the caller's responsibility to reset diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 51c7d6bfdab0..c88b6054bd5a 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -1239,6 +1239,13 @@ nsDocumentViewer::PermitUnloadInternal(bool aCallerClosesWindow, return NS_OK; } +NS_IMETHODIMP +nsDocumentViewer::GetBeforeUnloadFiring(bool* aInEvent) +{ + *aInEvent = mInPermitUnload; + return NS_OK; +} + NS_IMETHODIMP nsDocumentViewer::ResetCloseWindow() {