From 3828124cd5dc7c82385eb47b4cd10108d72d6ac4 Mon Sep 17 00:00:00 2001 From: "honzab.moz%firemni.cz" Date: Wed, 18 Nov 2009 16:43:10 +0000 Subject: [PATCH] Bug 514232, r=bzbarsky + bug 529119 - Funky behavior with XUL error pages, r=bzbarsky git-svn-id: svn://10.0.0.236/trunk@259021 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 85 ++++++++++++------ mozilla/docshell/test/Makefile.in | 3 + mozilla/docshell/test/bug529119-window.html | 7 ++ mozilla/docshell/test/test_bug529119-1.html | 99 +++++++++++++++++++++ mozilla/docshell/test/test_bug529119-2.html | 90 +++++++++++++++++++ 5 files changed, 255 insertions(+), 29 deletions(-) create mode 100644 mozilla/docshell/test/bug529119-window.html create mode 100644 mozilla/docshell/test/test_bug529119-1.html create mode 100644 mozilla/docshell/test/test_bug529119-2.html diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index f4981bba77b..1392abb68cb 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -3251,35 +3251,14 @@ nsDocShell::LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL, spec.get(), NS_ConvertUTF16toUTF8(aURL).get(), chanName.get())); } #endif - // Create an shistory entry for the old load, if we have a channel - if (aFailedChannel) { - mURIResultedInDocument = PR_TRUE; - OnLoadingSite(aFailedChannel, PR_TRUE, PR_FALSE); - } else if (aURI) { - mURIResultedInDocument = PR_TRUE; - OnNewURI(aURI, nsnull, mLoadType, PR_TRUE, PR_FALSE); - } - // Be sure to have a correct mLSHE, it may have been cleared by - // EndPageLoad. See bug 302115. - if (mSessionHistory && !mLSHE) { - PRInt32 idx; - mSessionHistory->GetRequestedIndex(&idx); - if (idx == -1) - mSessionHistory->GetIndex(&idx); - - nsCOMPtr entry; - mSessionHistory->GetEntryAtIndex(idx, PR_FALSE, - getter_AddRefs(entry)); - mLSHE = do_QueryInterface(entry); - } - + mFailedChannel = aFailedChannel; + mFailedURI = aURI; + mFailedLoadType = mLoadType; + nsCAutoString url; nsCAutoString charset; if (aURI) { - // Set our current URI - SetCurrentURI(aURI); - nsresult rv = aURI->GetSpec(url); rv |= aURI->GetOriginCharset(charset); NS_ENSURE_SUCCESS(rv, rv); @@ -3405,10 +3384,15 @@ nsDocShell::Stop(PRUint32 aStopFlags) // Revoke any pending event related to content viewer restoration mRestorePresentationEvent.Revoke(); - if (mLoadType == LOAD_ERROR_PAGE && mLSHE) { - // Since error page loads never unset mLSHE, do so now - SetHistoryEntry(&mOSHE, mLSHE); - SetHistoryEntry(&mLSHE, nsnull); + if (mLoadType == LOAD_ERROR_PAGE) { + if (mLSHE) { + // Since error page loads never unset mLSHE, do so now + SetHistoryEntry(&mOSHE, mLSHE); + SetHistoryEntry(&mLSHE, nsnull); + } + + mFailedChannel = nsnull; + mFailedURI = nsnull; } if (nsIWebNavigation::STOP_CONTENT & aStopFlags) { @@ -6138,6 +6122,49 @@ nsDocShell::CreateContentViewer(const char *aContentType, // notifications before we've called Embed(). See bug 284993. mURIResultedInDocument = PR_TRUE; + if (mLoadType == LOAD_ERROR_PAGE) { + // We need to set the SH entry and our current URI here and not + // at the moment we load the page. We want the same behavior + // of Stop() as for a normal page load. See bug 514232 for details. + + // Revert mLoadType to load type to state the page load failed, + // following function calls need it. + mLoadType = mFailedLoadType; + + nsCOMPtr failedChannel = mFailedChannel; + nsCOMPtr failedURI = mFailedURI; + mFailedChannel = nsnull; + mFailedURI = nsnull; + + // Create an shistory entry for the old load, if we have a channel + if (failedChannel) { + mURIResultedInDocument = PR_TRUE; + OnLoadingSite(failedChannel, PR_TRUE, PR_FALSE); + } else if (failedURI) { + mURIResultedInDocument = PR_TRUE; + OnNewURI(failedURI, nsnull, nsnull, mLoadType, PR_TRUE, PR_FALSE); + } + + // Be sure to have a correct mLSHE, it may have been cleared by + // EndPageLoad. See bug 302115. + if (mSessionHistory && !mLSHE) { + PRInt32 idx; + mSessionHistory->GetRequestedIndex(&idx); + if (idx == -1) + mSessionHistory->GetIndex(&idx); + + nsCOMPtr entry; + mSessionHistory->GetEntryAtIndex(idx, PR_FALSE, + getter_AddRefs(entry)); + mLSHE = do_QueryInterface(entry); + } + + // Set our current URI + SetCurrentURI(failedURI); + + mLoadType = LOAD_ERROR_PAGE; + } + PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE); // let's try resetting the load group if we need to... diff --git a/mozilla/docshell/test/Makefile.in b/mozilla/docshell/test/Makefile.in index 5566f3f69cc..101fafb1119 100644 --- a/mozilla/docshell/test/Makefile.in +++ b/mozilla/docshell/test/Makefile.in @@ -70,6 +70,9 @@ _TEST_FILES = \ test_bug402210.html \ test_bug475636.html \ file_bug475636.sjs \ + test_bug529119-1.html \ + test_bug529119-2.html \ + bug529119-window.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/mozilla/docshell/test/bug529119-window.html b/mozilla/docshell/test/bug529119-window.html new file mode 100644 index 00000000000..f1908835a73 --- /dev/null +++ b/mozilla/docshell/test/bug529119-window.html @@ -0,0 +1,7 @@ + + + +Test bug 529119, sub-window + + + diff --git a/mozilla/docshell/test/test_bug529119-1.html b/mozilla/docshell/test/test_bug529119-1.html new file mode 100644 index 00000000000..7a864ac9cac --- /dev/null +++ b/mozilla/docshell/test/test_bug529119-1.html @@ -0,0 +1,99 @@ + + + +Test bug 529119 + + + + + + + + + diff --git a/mozilla/docshell/test/test_bug529119-2.html b/mozilla/docshell/test/test_bug529119-2.html new file mode 100644 index 00000000000..db33c06598d --- /dev/null +++ b/mozilla/docshell/test/test_bug529119-2.html @@ -0,0 +1,90 @@ + + + +Test bug 529119 + + + + + + + + +