Bug 728939 - Part 1: Changing a URI's hash should update document.URL. r=bz

--HG--
extra : rebase_source : a41d88a9375d60a05ed61a6214003762119b7370
This commit is contained in:
Justin Lebar 2012-02-22 16:53:58 +01:00
parent 4ac8d2dffb
commit d7c3e50635

View File

@ -8327,15 +8327,14 @@ nsDocShell::InternalLoad(nsIURI * aURI,
NS_SUCCEEDED(splitRv2) && NS_SUCCEEDED(splitRv2) &&
curBeforeHash.Equals(newBeforeHash); curBeforeHash.Equals(newBeforeHash);
// XXX rename bool historyNavBetweenSameDoc = false;
bool sameDocument = false;
if (mOSHE && aSHEntry) { if (mOSHE && aSHEntry) {
// We're doing a history load. // We're doing a history load.
mOSHE->SharesDocumentWith(aSHEntry, &sameDocument); mOSHE->SharesDocumentWith(aSHEntry, &historyNavBetweenSameDoc);
#ifdef DEBUG #ifdef DEBUG
if (sameDocument) { if (historyNavBetweenSameDoc) {
nsCOMPtr<nsIInputStream> currentPostData; nsCOMPtr<nsIInputStream> currentPostData;
mOSHE->GetPostData(getter_AddRefs(currentPostData)); mOSHE->GetPostData(getter_AddRefs(currentPostData));
NS_ASSERTION(currentPostData == aPostData, NS_ASSERTION(currentPostData == aPostData,
@ -8348,8 +8347,8 @@ nsDocShell::InternalLoad(nsIURI * aURI,
// for the same document. We do a short-circuited load under two // for the same document. We do a short-circuited load under two
// circumstances. Either // circumstances. Either
// //
// a) we're navigating between two different SHEntries which have the // a) we're navigating between two different SHEntries which share a
// same document identifiers, or // document, or
// //
// b) we're navigating to a new shentry whose URI differs from the // b) we're navigating to a new shentry whose URI differs from the
// current URI only in its hash, the new hash is non-empty, and // current URI only in its hash, the new hash is non-empty, and
@ -8358,15 +8357,10 @@ nsDocShell::InternalLoad(nsIURI * aURI,
// The restriction tha the SHEntries in (a) must be different ensures // The restriction tha the SHEntries in (a) must be different ensures
// that history.go(0) and the like trigger full refreshes, rather than // that history.go(0) and the like trigger full refreshes, rather than
// short-circuited loads. // short-circuited loads.
bool doShortCircuitedLoad = (sameDocument && mOSHE != aSHEntry) || bool doShortCircuitedLoad =
(!aSHEntry && aPostData == nsnull && (historyNavBetweenSameDoc && mOSHE != aSHEntry) ||
sameExceptHashes && !newHash.IsEmpty()); (!aSHEntry && aPostData == nsnull &&
sameExceptHashes && !newHash.IsEmpty());
// Fire a hashchange event if we're doing a short-circuited load and the
// URIs differ only in their hashes.
bool doHashchange = doShortCircuitedLoad &&
sameExceptHashes &&
!curHash.Equals(newHash);
if (doShortCircuitedLoad) { if (doShortCircuitedLoad) {
// Save the current URI; we need it if we fire a hashchange later. // Save the current URI; we need it if we fire a hashchange later.
@ -8496,27 +8490,21 @@ nsDocShell::InternalLoad(nsIURI * aURI,
} }
} }
if (sameDocument) { // Set the doc's URI according to the new history entry's URI.
// Set the doc's URI according to the new history entry's URI nsCOMPtr<nsIDocument> doc =
nsCOMPtr<nsIURI> newURI; do_GetInterface(GetAsSupports(this));
mOSHE->GetURI(getter_AddRefs(newURI)); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(newURI, NS_ERROR_FAILURE); doc->SetDocumentURI(aURI);
nsCOMPtr<nsIDocument> doc =
do_GetInterface(GetAsSupports(this));
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
doc->SetDocumentURI(newURI);
}
SetDocCurrentStateObj(mOSHE); SetDocCurrentStateObj(mOSHE);
// Dispatch the popstate and hashchange events, as appropriate. // Dispatch the popstate and hashchange events, as appropriate.
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mScriptGlobal); nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mScriptGlobal);
if (window) { if (window) {
// Need the doHashchange check here since sameDocument is // Fire a hashchange event URIs differ, and only in their hashes.
// false if we're navigating to a new shentry (i.e. a aSHEntry bool doHashchange = sameExceptHashes && !curHash.Equals(newHash);
// is null), such as when clicking a <a href="#foo">.
if (sameDocument || doHashchange) { if (historyNavBetweenSameDoc || doHashchange) {
window->DispatchSyncPopState(); window->DispatchSyncPopState();
} }