Fix for bus 92824. Update index in session History only after onStartLoad notifications come for the page. r=adamlaock sr=rpotts

This commit is contained in:
radha%netscape.com 2001-09-22 00:07:42 +00:00
Родитель 1f69732c16
Коммит 7057852227
6 изменённых файлов: 50 добавлений и 42 удалений

Просмотреть файл

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

Просмотреть файл

@ -56,4 +56,9 @@ interface nsISHistoryInternal: nsISupports
*/
attribute nsIDocShell rootDocShell;
/**
* Update the index maintained by sessionHistory
*/
void updateIndex();
};

Просмотреть файл

@ -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);

Просмотреть файл

@ -65,7 +65,7 @@ private:
PRUint32 mLoadType;
PRUint32 mID;
PRBool mIsFrameNavigation;
PRBool mSaveHistoryState;
PRBool mSaveLayoutState;
PRPackedBool mExpired;
nsCOMPtr<nsISupports> mCacheKey;
nsISHEntry * mParent; // weak reference

Просмотреть файл

@ -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<nsIDocShell> docShell;
nsCOMPtr<nsISHEntry> shEntry;
PRInt32 oldIndex = mIndex;
// Keep note of requested history index in mRequestedIndex.
mRequestedIndex = aIndex;
nsCOMPtr<nsISHEntry> prevEntry;
GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(prevEntry));
mIndex = aIndex;
GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(prevEntry));
nsCOMPtr<nsISHEntry> nextEntry;
GetEntryAtIndex(mIndex, PR_FALSE, getter_AddRefs(nextEntry));
GetEntryAtIndex(mRequestedIndex, PR_FALSE, getter_AddRefs(nextEntry));
nsCOMPtr<nsIHistoryEntry> 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<nsIURI> nextURI;
nHEntry->GetURI(getter_AddRefs(nextURI));
if(mListener) {
nsCOMPtr<nsISHistoryListener> 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<nsIDocShellLoadInfo> 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);
}

Просмотреть файл

@ -66,6 +66,7 @@ protected:
nsCOMPtr<nsISHTransaction> 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;
};