Commit fb0b71be authored by Justin Lebar's avatar Justin Lebar
Browse files

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

--HG--
extra : rebase_source : a41d88a9375d60a05ed61a6214003762119b7370
parent 4b422a4e
Loading
Loading
Loading
Loading
+18 −30
Original line number Diff line number Diff line
@@ -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<nsIInputStream> 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,16 +8357,11 @@ 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) ||
        bool doShortCircuitedLoad =
          (historyNavBetweenSameDoc && 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);

        if (doShortCircuitedLoad) {
            // Save the current URI; we need it if we fire a hashchange later.
            nsCOMPtr<nsIURI> oldURI = mCurrentURI;
@@ -8496,27 +8490,21 @@ nsDocShell::InternalLoad(nsIURI * aURI,
                }
            }

            if (sameDocument) {
                // Set the doc's URI according to the new history entry's URI
                nsCOMPtr<nsIURI> newURI;
                mOSHE->GetURI(getter_AddRefs(newURI));
                NS_ENSURE_TRUE(newURI, NS_ERROR_FAILURE);
            // Set the doc's URI according to the new history entry's URI.
            nsCOMPtr<nsIDocument> doc =
              do_GetInterface(GetAsSupports(this));
            NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);

                doc->SetDocumentURI(newURI);
            }
            doc->SetDocumentURI(aURI);

            SetDocCurrentStateObj(mOSHE);

            // Dispatch the popstate and hashchange events, as appropriate.
            nsCOMPtr<nsPIDOMWindow> 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 <a href="#foo">.
                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();
                }