Fix for form values not maintained while going forward. bug # 16377. r=law

This commit is contained in:
radha%netscape.com 1999-10-28 20:29:43 +00:00
Родитель 399470f1e9
Коммит 7634ef385a
3 изменённых файлов: 72 добавлений и 62 удалений

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

@ -2015,10 +2015,10 @@ nsWebShell::DoLoadURL(nsIURI * aUri,
rv = docViewer->GetPresShell(*getter_AddRefs(presShell)); rv = docViewer->GetPresShell(*getter_AddRefs(presShell));
if (NS_SUCCEEDED(rv) && presShell) { if (NS_SUCCEEDED(rv) && presShell) {
/* Pass OnStartDocument notifications to the docloaderobserver /* Pass OnStartDocument notifications to the docloaderobserver
* so that urlbar, forward/back buttons will * so that urlbar, forward/back buttons will
* behave properly when going to named anchors * behave properly when going to named anchors
*/ */
nsCOMPtr<nsIChannel> dummyChannel; nsCOMPtr<nsIChannel> dummyChannel;
rv = NS_OpenURI(getter_AddRefs(dummyChannel), aUri, nsnull); rv = NS_OpenURI(getter_AddRefs(dummyChannel), aUri, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -2147,6 +2147,7 @@ nsWebShell::LoadURI(nsIURI * aUri,
mHistoryIndex++; mHistoryIndex++;
} }
else { else {
// Replace the current history index with this URL // Replace the current history index with this URL
nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex); nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex);
if (nsnull != u) { if (nsnull != u) {
@ -2278,28 +2279,29 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec,
} }
} }
/* /*
* Before the new page is added to the session history, * Save the history state for the current index iff this loadurl() request
* save the history information of the previous page in * is not from SH. When the request comes from SH, aModifyHistory will
* session history * be false and nsSessionHistory.cpp takes of this.
*/ */
if (shist) {
nsCOMPtr<nsISupports> historyState=nsnull; PRInt32 indix;
rv = GetHistoryState(getter_AddRefs(historyState)); shist->GetCurrentIndex(&indix);
// Get the history object for the previous page. if (indix >= 0 && (aModifyHistory)) {
if (NS_SUCCEEDED(rv) && shist) { nsCOMPtr<nsISupports> historyState;
PRInt32 indix=0; rv = GetHistoryState(getter_AddRefs(historyState));
shist->GetCurrentIndex(&indix); if (NS_SUCCEEDED(rv) && historyState)
// Save it in session history shist->SetHistoryObjectForIndex(indix, historyState);
shist->SetHistoryObjectForIndex(indix, historyState); }
} }
/* Set the History state object for the current page in the /* Set the History state object for the current page in the
* presentation shell. If it is a new page being visited, * presentation shell. If it is a new page being visited,
* aHistoryState is null. If the load is coming from * aHistoryState is null. If the load is coming from
* session History, it will be set to the cached history object by * session History, it will be set to the cached history object by
* session History. * session History.
*/ */
SetHistoryState(aHistoryState); if (aHistoryState)
SetHistoryState(aHistoryState);
/* /*
* Set mURL to spec so that session history can get * Set mURL to spec so that session history can get
@ -2315,12 +2317,12 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec,
ret = shist->Add(this); ret = shist->Add(this);
} }
/* If we are going "Back" from a non-frame page to a frame page, /* If we are going "Back" from a non-frame page to a frame page,
* session history will change the mURL to the right value * session history will change the mURL to the right value
* for smoother redraw. So, create a new nsIURI based on mURL, * for smoother redraw. So, create a new nsIURI based on mURL,
* so that it will work right in such situations. * so that it will work right in such situations.
*/ */
nsAutoString urlstr(mURL); nsAutoString urlstr(mURL);
nsCOMPtr<nsIURI> newURI; nsCOMPtr<nsIURI> newURI;
rv = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull); rv = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull);
@ -2431,7 +2433,7 @@ nsWebShell::Back(void)
NS_IMETHODIMP NS_IMETHODIMP
nsWebShell::CanBack(void) nsWebShell::CanBack(void)
{ {
return (mHistoryIndex > mHistory.Count() - 1 ? NS_OK : NS_COMFALSE); return ((mHistoryIndex-1) > - 1 ? NS_OK : NS_COMFALSE);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -2449,7 +2451,6 @@ nsWebShell::CanForward(void)
NS_IMETHODIMP NS_IMETHODIMP
nsWebShell::GoTo(PRInt32 aHistoryIndex) nsWebShell::GoTo(PRInt32 aHistoryIndex)
{ {
#ifdef OLD_HISTORY
nsresult rv = NS_ERROR_ILLEGAL_VALUE; nsresult rv = NS_ERROR_ILLEGAL_VALUE;
if ((aHistoryIndex >= 0) && if ((aHistoryIndex >= 0) &&
(aHistoryIndex < mHistory.Count())) { (aHistoryIndex < mHistory.Count())) {
@ -2481,13 +2482,6 @@ nsWebShell::GoTo(PRInt32 aHistoryIndex)
nsnull); // referrer nsnull); // referrer
} }
return rv; return rv;
#else
if (mSHist)
return mSHist->Goto(aHistoryIndex, this, PR_FALSE);
return NS_OK;
#endif
} }
@ -2735,7 +2729,11 @@ nsWebShell::GetHistoryState(nsISupports** aLayoutHistoryState)
rv = docv->GetPresShell(*getter_AddRefs(shell)); rv = docv->GetPresShell(*getter_AddRefs(shell));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = shell->GetHistoryState((nsILayoutHistoryState**) aLayoutHistoryState); rv = shell->GetHistoryState((nsILayoutHistoryState**) aLayoutHistoryState);
NS_ADDREF(*aLayoutHistoryState); /* The following line was added by mistake in one of the previous checkins. It
* causes a leak of nsHistorylayoutState. But removing it causes a crash.
* Eric Pollmann(pollmann@netscape.com) is investigating it. Bug # 16496
*/
NS_ADDREF(*aLayoutHistoryState);
} }
} }
} }

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

@ -2015,10 +2015,10 @@ nsWebShell::DoLoadURL(nsIURI * aUri,
rv = docViewer->GetPresShell(*getter_AddRefs(presShell)); rv = docViewer->GetPresShell(*getter_AddRefs(presShell));
if (NS_SUCCEEDED(rv) && presShell) { if (NS_SUCCEEDED(rv) && presShell) {
/* Pass OnStartDocument notifications to the docloaderobserver /* Pass OnStartDocument notifications to the docloaderobserver
* so that urlbar, forward/back buttons will * so that urlbar, forward/back buttons will
* behave properly when going to named anchors * behave properly when going to named anchors
*/ */
nsCOMPtr<nsIChannel> dummyChannel; nsCOMPtr<nsIChannel> dummyChannel;
rv = NS_OpenURI(getter_AddRefs(dummyChannel), aUri, nsnull); rv = NS_OpenURI(getter_AddRefs(dummyChannel), aUri, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -2147,6 +2147,7 @@ nsWebShell::LoadURI(nsIURI * aUri,
mHistoryIndex++; mHistoryIndex++;
} }
else { else {
// Replace the current history index with this URL // Replace the current history index with this URL
nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex); nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex);
if (nsnull != u) { if (nsnull != u) {
@ -2278,28 +2279,29 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec,
} }
} }
/* /*
* Before the new page is added to the session history, * Save the history state for the current index iff this loadurl() request
* save the history information of the previous page in * is not from SH. When the request comes from SH, aModifyHistory will
* session history * be false and nsSessionHistory.cpp takes of this.
*/ */
if (shist) {
nsCOMPtr<nsISupports> historyState=nsnull; PRInt32 indix;
rv = GetHistoryState(getter_AddRefs(historyState)); shist->GetCurrentIndex(&indix);
// Get the history object for the previous page. if (indix >= 0 && (aModifyHistory)) {
if (NS_SUCCEEDED(rv) && shist) { nsCOMPtr<nsISupports> historyState;
PRInt32 indix=0; rv = GetHistoryState(getter_AddRefs(historyState));
shist->GetCurrentIndex(&indix); if (NS_SUCCEEDED(rv) && historyState)
// Save it in session history shist->SetHistoryObjectForIndex(indix, historyState);
shist->SetHistoryObjectForIndex(indix, historyState); }
} }
/* Set the History state object for the current page in the /* Set the History state object for the current page in the
* presentation shell. If it is a new page being visited, * presentation shell. If it is a new page being visited,
* aHistoryState is null. If the load is coming from * aHistoryState is null. If the load is coming from
* session History, it will be set to the cached history object by * session History, it will be set to the cached history object by
* session History. * session History.
*/ */
SetHistoryState(aHistoryState); if (aHistoryState)
SetHistoryState(aHistoryState);
/* /*
* Set mURL to spec so that session history can get * Set mURL to spec so that session history can get
@ -2315,12 +2317,12 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec,
ret = shist->Add(this); ret = shist->Add(this);
} }
/* If we are going "Back" from a non-frame page to a frame page, /* If we are going "Back" from a non-frame page to a frame page,
* session history will change the mURL to the right value * session history will change the mURL to the right value
* for smoother redraw. So, create a new nsIURI based on mURL, * for smoother redraw. So, create a new nsIURI based on mURL,
* so that it will work right in such situations. * so that it will work right in such situations.
*/ */
nsAutoString urlstr(mURL); nsAutoString urlstr(mURL);
nsCOMPtr<nsIURI> newURI; nsCOMPtr<nsIURI> newURI;
rv = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull); rv = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull);
@ -2431,7 +2433,7 @@ nsWebShell::Back(void)
NS_IMETHODIMP NS_IMETHODIMP
nsWebShell::CanBack(void) nsWebShell::CanBack(void)
{ {
return (mHistoryIndex > mHistory.Count() - 1 ? NS_OK : NS_COMFALSE); return ((mHistoryIndex-1) > - 1 ? NS_OK : NS_COMFALSE);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -2449,7 +2451,6 @@ nsWebShell::CanForward(void)
NS_IMETHODIMP NS_IMETHODIMP
nsWebShell::GoTo(PRInt32 aHistoryIndex) nsWebShell::GoTo(PRInt32 aHistoryIndex)
{ {
#ifdef OLD_HISTORY
nsresult rv = NS_ERROR_ILLEGAL_VALUE; nsresult rv = NS_ERROR_ILLEGAL_VALUE;
if ((aHistoryIndex >= 0) && if ((aHistoryIndex >= 0) &&
(aHistoryIndex < mHistory.Count())) { (aHistoryIndex < mHistory.Count())) {
@ -2481,13 +2482,6 @@ nsWebShell::GoTo(PRInt32 aHistoryIndex)
nsnull); // referrer nsnull); // referrer
} }
return rv; return rv;
#else
if (mSHist)
return mSHist->Goto(aHistoryIndex, this, PR_FALSE);
return NS_OK;
#endif
} }
@ -2735,7 +2729,11 @@ nsWebShell::GetHistoryState(nsISupports** aLayoutHistoryState)
rv = docv->GetPresShell(*getter_AddRefs(shell)); rv = docv->GetPresShell(*getter_AddRefs(shell));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = shell->GetHistoryState((nsILayoutHistoryState**) aLayoutHistoryState); rv = shell->GetHistoryState((nsILayoutHistoryState**) aLayoutHistoryState);
NS_ADDREF(*aLayoutHistoryState); /* The following line was added by mistake in one of the previous checkins. It
* causes a leak of nsHistorylayoutState. But removing it causes a crash.
* Eric Pollmann(pollmann@netscape.com) is investigating it. Bug # 16496
*/
NS_ADDREF(*aLayoutHistoryState);
} }
} }
} }

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

@ -1108,9 +1108,23 @@ nsSessionHistory::Goto(PRInt32 aGotoIndex, nsIWebShell * prev, PRBool aIsReload)
if (APP_DEBUG && url) printf("nsSessionHistory::Goto, Trying to load URL %s\n", url); if (APP_DEBUG && url) printf("nsSessionHistory::Goto, Trying to load URL %s\n", url);
Recycle (url); Recycle (url);
mHistoryCurrentIndex = aGotoIndex;
if (hCurrentEntry != nsnull) // Save the history state for the current index before loading the next one
int indix = 0;
GetCurrentIndex(&indix);
PRBool isInHist=PR_FALSE;
if (indix >= 0) {
nsCOMPtr<nsISupports> historyState;
nsresult rv = prev->GetHistoryState(getter_AddRefs(historyState));
if (NS_SUCCEEDED(rv) && historyState)
SetHistoryObjectForIndex(indix, historyState);
}
// Set the new current index
mHistoryCurrentIndex = aGotoIndex;
if (hCurrentEntry != nsnull) {
result = hCurrentEntry->Load(prev, aIsReload); result = hCurrentEntry->Load(prev, aIsReload);
}
if (!result) { if (!result) {
mIsLoadingDoc = PR_FALSE; mIsLoadingDoc = PR_FALSE;
mHistoryEntryInLoad = (nsHistoryEntry *) nsnull; mHistoryEntryInLoad = (nsHistoryEntry *) nsnull;