From d1ac48fef29b28ec1266546b65ee78e5675dfbd5 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 13 Jan 2014 15:08:55 -0500 Subject: [PATCH] Bug 881487. Make anchor scrolls on wyciwyg documents work correctly. r=smaug --- docshell/base/nsDocShell.cpp | 25 +++++---- ...ile_anchor_scroll_after_document_open.html | 15 +++++ docshell/test/mochitest.ini | 2 + ...est_anchor_scroll_after_document_open.html | 55 +++++++++++++++++++ 4 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 docshell/test/file_anchor_scroll_after_document_open.html create mode 100644 docshell/test/test_anchor_scroll_after_document_open.html diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index a2f95ff0e51..a95989d5158 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -9115,13 +9115,21 @@ nsDocShell::InternalLoad(nsIURI * aURI, aLoadType == LOAD_HISTORY || aLoadType == LOAD_LINK) { - // Split mCurrentURI and aURI on the '#' character. Make sure we read + nsCOMPtr currentURI; + if (sURIFixup && mCurrentURI) { + rv = sURIFixup->CreateExposableURI(mCurrentURI, + getter_AddRefs(currentURI)); + NS_ENSURE_SUCCESS(rv, rv); + } else { + currentURI = mCurrentURI; + } + // Split currentURI and aURI on the '#' character. Make sure we read // the return values of SplitURIAtHash; if it fails, we don't want to // allow a short-circuited navigation. nsAutoCString curBeforeHash, curHash, newBeforeHash, newHash; nsresult splitRv1, splitRv2; - splitRv1 = mCurrentURI ? - nsContentUtils::SplitURIAtHash(mCurrentURI, + splitRv1 = currentURI ? + nsContentUtils::SplitURIAtHash(currentURI, curBeforeHash, curHash) : NS_ERROR_FAILURE; splitRv2 = nsContentUtils::SplitURIAtHash(aURI, newBeforeHash, newHash); @@ -9179,9 +9187,6 @@ nsDocShell::InternalLoad(nsIURI * aURI, mDocumentRequest->Cancel(NS_BINDING_ABORTED); } - // Save the current URI; we need it if we fire a hashchange later. - nsCOMPtr oldURI = mCurrentURI; - // Save the position of the scrollers. nscoord cx = 0, cy = 0; GetCurScrollPos(ScrollOrientation_X, &cx); @@ -9342,15 +9347,15 @@ nsDocShell::InternalLoad(nsIURI * aURI, } if (doHashchange) { - // Make sure to use oldURI here, not mCurrentURI, because by - // now, mCurrentURI has changed! - win->DispatchAsyncHashchange(oldURI, aURI); + // Note that currentURI hasn't changed because it's on the + // stack, so we can just use it directly as the old URI. + win->DispatchAsyncHashchange(currentURI, aURI); } } // Inform the favicon service that the favicon for oldURI also // applies to aURI. - CopyFavicon(oldURI, aURI, mInPrivateBrowsing); + CopyFavicon(currentURI, aURI, mInPrivateBrowsing); return NS_OK; } diff --git a/docshell/test/file_anchor_scroll_after_document_open.html b/docshell/test/file_anchor_scroll_after_document_open.html new file mode 100644 index 00000000000..7903380eac6 --- /dev/null +++ b/docshell/test/file_anchor_scroll_after_document_open.html @@ -0,0 +1,15 @@ + + diff --git a/docshell/test/mochitest.ini b/docshell/test/mochitest.ini index 4776de84e0f..44953253301 100644 --- a/docshell/test/mochitest.ini +++ b/docshell/test/mochitest.ini @@ -11,6 +11,7 @@ support-files = bug668513_redirect.html bug668513_redirect.html^headers^ bug691547_frame.html + file_anchor_scroll_after_document_open.html file_bug385434_1.html file_bug385434_2.html file_bug385434_3.html @@ -33,6 +34,7 @@ support-files = file_bug728939.html historyframes.html +[test_anchor_scroll_after_document_open.html] [test_bfcache_plus_hash.html] [test_bug123696.html] [test_bug369814.html] diff --git a/docshell/test/test_anchor_scroll_after_document_open.html b/docshell/test/test_anchor_scroll_after_document_open.html new file mode 100644 index 00000000000..93fa4615b42 --- /dev/null +++ b/docshell/test/test_anchor_scroll_after_document_open.html @@ -0,0 +1,55 @@ + + + + + + Test for Bug 881487 + + + + + +Mozilla Bug 881487 +

+ + +

+ +
+
+ +