From 3fcbbc857f89ea643ea9d60caedc2e057f5ba468 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Wed, 22 Feb 2012 16:53:58 +0100 Subject: [PATCH] Bug 728939 - Part 1: Changing a URI's hash should update document.URL. r=bz --HG-- extra : rebase_source : a41d88a9375d60a05ed61a6214003762119b7370 --- docshell/base/nsDocShell.cpp | 48 ++++++++++++++---------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 8385cffa807..04227a98612 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -8327,15 +8327,14 @@ nsDocShell::InternalLoad(nsIURI * aURI, NS_SUCCEEDED(splitRv2) && curBeforeHash.Equals(newBeforeHash); - // XXX rename - bool sameDocument = false; + bool historyNavBetweenSameDoc = false; if (mOSHE && aSHEntry) { // We're doing a history load. - mOSHE->SharesDocumentWith(aSHEntry, &sameDocument); + mOSHE->SharesDocumentWith(aSHEntry, &historyNavBetweenSameDoc); #ifdef DEBUG - if (sameDocument) { + if (historyNavBetweenSameDoc) { nsCOMPtr currentPostData; mOSHE->GetPostData(getter_AddRefs(currentPostData)); NS_ASSERTION(currentPostData == aPostData, @@ -8348,8 +8347,8 @@ nsDocShell::InternalLoad(nsIURI * aURI, // for the same document. We do a short-circuited load under two // circumstances. Either // - // a) we're navigating between two different SHEntries which have the - // same document identifiers, or + // a) we're navigating between two different SHEntries which share a + // document, or // // 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 @@ -8358,15 +8357,10 @@ nsDocShell::InternalLoad(nsIURI * aURI, // The restriction tha the SHEntries in (a) must be different ensures // that history.go(0) and the like trigger full refreshes, rather than // short-circuited loads. - bool doShortCircuitedLoad = (sameDocument && mOSHE != aSHEntry) || - (!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); + bool doShortCircuitedLoad = + (historyNavBetweenSameDoc && mOSHE != aSHEntry) || + (!aSHEntry && aPostData == nsnull && + sameExceptHashes && !newHash.IsEmpty()); if (doShortCircuitedLoad) { // 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 - nsCOMPtr newURI; - mOSHE->GetURI(getter_AddRefs(newURI)); - NS_ENSURE_TRUE(newURI, NS_ERROR_FAILURE); - nsCOMPtr doc = - do_GetInterface(GetAsSupports(this)); - NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); - - doc->SetDocumentURI(newURI); - } + // Set the doc's URI according to the new history entry's URI. + nsCOMPtr doc = + do_GetInterface(GetAsSupports(this)); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + doc->SetDocumentURI(aURI); SetDocCurrentStateObj(mOSHE); // Dispatch the popstate and hashchange events, as appropriate. nsCOMPtr window = do_QueryInterface(mScriptGlobal); if (window) { - // Need the doHashchange check here since sameDocument is - // false if we're navigating to a new shentry (i.e. a aSHEntry - // is null), such as when clicking a . - if (sameDocument || doHashchange) { + // Fire a hashchange event URIs differ, and only in their hashes. + bool doHashchange = sameExceptHashes && !curHash.Equals(newHash); + + if (historyNavBetweenSameDoc || doHashchange) { window->DispatchSyncPopState(); }