Bug 881487. Make anchor scrolls on wyciwyg documents work correctly. r=smaug

This commit is contained in:
Boris Zbarsky 2014-01-13 15:08:55 -05:00
parent 5c6d029281
commit b0ecdedaba
4 changed files with 87 additions and 10 deletions

View File

@ -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<nsIURI> 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<nsIURI> 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;
}

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<script>
if (location.hash == "#target") {
parent.postMessage("haveHash", "*");
} else {
document.addEventListener("DOMContentLoaded", function() {
document.open();
document.write("<!DOCTYPE html><html style='height: 100%'><body style='height: 100%'><div style='height: 200%'></div><div id='target'></div></body></html>");
document.close();
// Notify parent via postMessage, since otherwise exceptions will not get
// caught by its onerror handler.
parent.postMessage("doTest", "*");
});
}
</script>

View File

@ -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]

View File

@ -0,0 +1,55 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=881487
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 881487</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 881487 **/
SimpleTest.waitForExplicitFinish();
// Child needs to invoke us, otherwise our onload will fire before the child
// has done the write/close bit.
var gotOnload = false;
addLoadEvent(function() {
gotOnload = true;
});
onmessage = function handleMessage(msg) {
if (msg.data == "doTest") {
if (!gotOnload) {
addLoadEvent(function() { handleMessage(msg); });
return;
}
frames[0].onscroll = function() {
ok(true, "Got a scroll event");
SimpleTest.finish();
}
frames[0].location.hash = "#target";
return;
}
if (msg.data == "haveHash") {
ok(false, "Child got reloaded");
} else {
ok(false, "Unexpected message");
}
SimpleTest.finish();
}
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=881487">Mozilla Bug 881487</a>
<p id="display">
<!-- iframe goes here so it can scroll -->
<iframe src="file_anchor_scroll_after_document_open.html"></iframe>
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>