From ec63eef8998923e4cc76903b7bde36cfc4de24d1 Mon Sep 17 00:00:00 2001 From: "radha%netscape.com" Date: Sat, 22 Sep 2001 00:07:42 +0000 Subject: [PATCH] Fix for bus 92824. Update index in session History only after onStartLoad notifications come for the page. r=adamlaock sr=rpotts git-svn-id: svn://10.0.0.236/trunk@103496 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/shistory/public/nsISHEntry.idl | 2 +- .../shistory/public/nsISHistoryInternal.idl | 5 ++ .../components/shistory/src/nsSHEntry.cpp | 10 +-- .../xpfe/components/shistory/src/nsSHEntry.h | 2 +- .../components/shistory/src/nsSHistory.cpp | 70 ++++++++++--------- .../xpfe/components/shistory/src/nsSHistory.h | 3 +- 6 files changed, 50 insertions(+), 42 deletions(-) diff --git a/mozilla/xpfe/components/shistory/public/nsISHEntry.idl b/mozilla/xpfe/components/shistory/public/nsISHEntry.idl index eeae10a9989..9ccb7cba9fb 100644 --- a/mozilla/xpfe/components/shistory/public/nsISHEntry.idl +++ b/mozilla/xpfe/components/shistory/public/nsISHEntry.idl @@ -75,7 +75,7 @@ attribute unsigned long ID; attribute nsISupports cacheKey; /** attribute to indicate whether layoutHistoryState should be saved */ -attribute boolean saveHistoryStateFlag; +attribute boolean saveLayoutStateFlag; /** attribute to indicate whether the page is already expired in cache */ attribute boolean expirationStatus; diff --git a/mozilla/xpfe/components/shistory/public/nsISHistoryInternal.idl b/mozilla/xpfe/components/shistory/public/nsISHistoryInternal.idl index b1bccb23aca..17bb7925201 100644 --- a/mozilla/xpfe/components/shistory/public/nsISHistoryInternal.idl +++ b/mozilla/xpfe/components/shistory/public/nsISHistoryInternal.idl @@ -56,4 +56,9 @@ interface nsISHistoryInternal: nsISupports */ attribute nsIDocShell rootDocShell; + /** + * Update the index maintained by sessionHistory + */ + void updateIndex(); + }; diff --git a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp index 8eeda0a2abe..fbe7a4637d8 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp +++ b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp @@ -223,17 +223,17 @@ NS_IMETHODIMP nsSHEntry::SetCacheKey(nsISupports* aCacheKey) return NS_OK; } -NS_IMETHODIMP nsSHEntry::GetSaveHistoryStateFlag(PRBool * aFlag) +NS_IMETHODIMP nsSHEntry::GetSaveLayoutStateFlag(PRBool * aFlag) { NS_ENSURE_ARG_POINTER(aFlag); - *aFlag = mSaveHistoryState; + *aFlag = mSaveLayoutState; return NS_OK; } -NS_IMETHODIMP nsSHEntry::SetSaveHistoryStateFlag(PRBool aFlag) +NS_IMETHODIMP nsSHEntry::SetSaveLayoutStateFlag(PRBool aFlag) { - mSaveHistoryState = aFlag; + mSaveLayoutState = aFlag; return NS_OK; } @@ -273,7 +273,7 @@ nsSHEntry::Create(nsIURI * aURI, const PRUnichar * aTitle, nsIDOMDocument * aDOM SetIsSubFrame(PR_FALSE); // By default we save HistoryLayoutState - SetSaveHistoryStateFlag(PR_TRUE); + SetSaveLayoutStateFlag(PR_TRUE); //By default the page is not expired SetExpirationStatus(PR_FALSE); diff --git a/mozilla/xpfe/components/shistory/src/nsSHEntry.h b/mozilla/xpfe/components/shistory/src/nsSHEntry.h index 645f808048a..6a9dc73ee4a 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHEntry.h +++ b/mozilla/xpfe/components/shistory/src/nsSHEntry.h @@ -65,7 +65,7 @@ private: PRUint32 mLoadType; PRUint32 mID; PRBool mIsFrameNavigation; - PRBool mSaveHistoryState; + PRBool mSaveLayoutState; PRPackedBool mExpired; nsCOMPtr mCacheKey; nsISHEntry * mParent; // weak reference diff --git a/mozilla/xpfe/components/shistory/src/nsSHistory.cpp b/mozilla/xpfe/components/shistory/src/nsSHistory.cpp index da23d7a631c..c5ad43ed74e 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHistory.cpp +++ b/mozilla/xpfe/components/shistory/src/nsSHistory.cpp @@ -44,7 +44,7 @@ static PRInt32 gHistoryMaxSize = 0; //*** nsSHistory: Object Management //***************************************************************************** -nsSHistory::nsSHistory() : mListRoot(nsnull), mIndex(-1), mLength(0) +nsSHistory::nsSHistory() : mListRoot(nsnull), mIndex(-1), mLength(0), mRequestedIndex(-1) { NS_INIT_REFCNT(); } @@ -512,6 +512,14 @@ nsSHistory::Reload(PRUint32 aReloadFlags) return LoadEntry(mIndex, loadType); } +NS_IMETHODIMP +nsSHistory::UpdateIndex() +{ + // Update the actual index with the right value. + mIndex = mRequestedIndex; + return NS_OK; +} + NS_IMETHODIMP nsSHistory::Stop(PRUint32 aStopFlags) { @@ -576,17 +584,17 @@ nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType) { nsCOMPtr docShell; nsCOMPtr shEntry; - PRInt32 oldIndex = mIndex; + // Keep note of requested history index in mRequestedIndex. + mRequestedIndex = aIndex; nsCOMPtr prevEntry; - GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(prevEntry)); - mIndex = aIndex; + GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(prevEntry)); nsCOMPtr nextEntry; - GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(nextEntry)); + GetEntryAtIndex(mRequestedIndex, PR_FALSE, getter_AddRefs(nextEntry)); nsCOMPtr nHEntry(do_QueryInterface(nextEntry)); - if (!nextEntry || !prevEntry || !nHEntry) { - mIndex = oldIndex; + if (!nextEntry || !prevEntry || !nHEntry) { + mRequestedIndex = -1; return NS_ERROR_FAILURE; } @@ -595,18 +603,19 @@ nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType) // Get the uri for the entry we are about to visit nsCOMPtr nextURI; nHEntry->GetURI(getter_AddRefs(nextURI)); + if(mListener) { nsCOMPtr listener(do_QueryReferent(mListener)); if (listener) { - if (mIndex+1 == oldIndex) { + if (mIndex+1 == mRequestedIndex) { // We are going back one entry. Send GoBack notifications listener->OnHistoryGoBack(nextURI, &canNavigate); } - else if (mIndex-1 == oldIndex) { + else if (mIndex-1 == mRequestedIndex) { // We are going forward. Send GoForward notification listener->OnHistoryGoForward(nextURI, &canNavigate); } - else if (mIndex != oldIndex) { + else if (mIndex != mRequestedIndex) { // We are going somewhere else. This is not reload either listener->OnHistoryGotoIndex(mIndex, nextURI, &canNavigate); } @@ -614,9 +623,8 @@ nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType) } if (!canNavigate) { - // reset the index back to what it was, if the listener - // asked us not to proceed with the operation. - mIndex = oldIndex; + // If the listener asked us not to proceed with + // the operation, simply return. return NS_OK; // XXX Maybe I can return some other error code? } @@ -630,7 +638,7 @@ nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType) } nsCOMPtr loadInfo; - if (oldIndex == aIndex) { + if (mRequestedIndex == mIndex) { // Possibly a reload case docShell = mRootDocShell; } @@ -642,17 +650,19 @@ nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType) */ PRBool result = CompareSHEntry(prevEntry, nextEntry, mRootDocShell, getter_AddRefs(docShell), - getter_AddRefs(shEntry)); - if (!result) { + getter_AddRefs(shEntry)); + if (!result || !shEntry) { /* There was an error in finding the entry and docshell - * where the load should happen. Reset the index back - * to what it was. Return failure. - */ - mIndex = oldIndex; + * where the load should happen,return error. + */ + mRequestedIndex = -1; return NS_ERROR_FAILURE; } - else { + else { nextEntry = shEntry; + // Set the Subframe flag of the entry to indicate that + // it is subframe navigation + nextEntry->SetIsSubFrame(PR_TRUE); } } // (pCount >0) else @@ -660,10 +670,10 @@ nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType) } - if (!docShell || !nextEntry || !mRootDocShell) { + if (!docShell || !mRootDocShell) { // we did not successfully go to the proper index. - // reset mIndex to what it was before returning error - mIndex = oldIndex; + // return error. + mRequestedIndex = -1; return NS_ERROR_FAILURE; } @@ -671,21 +681,13 @@ nsSHistory::LoadEntry(PRInt32 aIndex, long aLoadType) * This will be passed on to child subframes later in nsDocShell, * so that proper loadType is maintained through out a frameset */ - nextEntry->SetLoadType(aLoadType); - + nextEntry->SetLoadType(aLoadType); mRootDocShell->CreateLoadInfo (getter_AddRefs(loadInfo)); loadInfo->SetLoadType(aLoadType); loadInfo->SetSHEntry(nextEntry); // Time to initiate a document load - nsresult rv = docShell->LoadURI(nextURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE); - /* If the loadURI call failed for some reason, - * reset mIndex to what it was. so that back/forward - * won't misbehave - */ - if (!NS_SUCCEEDED(rv)) - mIndex = oldIndex; - return rv; + return docShell->LoadURI(nextURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE); } diff --git a/mozilla/xpfe/components/shistory/src/nsSHistory.h b/mozilla/xpfe/components/shistory/src/nsSHistory.h index 11efe4978d8..12a7dd952ea 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHistory.h +++ b/mozilla/xpfe/components/shistory/src/nsSHistory.h @@ -66,6 +66,7 @@ protected: nsCOMPtr mListRoot; PRInt32 mIndex; PRInt32 mLength; + PRInt32 mRequestedIndex; // Session History listener nsWeakPtr mListener; // Weak reference. Do not refcount this. @@ -88,7 +89,7 @@ protected: virtual ~nsSHEnumerator(); private: PRInt32 mIndex; - nsSHistory * mSHistory; + nsSHistory * mSHistory; };