diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 17b87baab85d..bd98068a098a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -3957,6 +3957,22 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress, mEODForCurrentDocument = PR_TRUE; } + /* Check if the httpChannel has any cache-control related response headers, + * like no-store, no-cache. If so, update SHEntry so that + * when a user goes back/forward to this page, we appropriately do + * form value restoration or load from server. + */ + nsCOMPtr httpChannel(do_QueryInterface(aChannel)); + if (!httpChannel) // HttpChannel could be hiding underneath a Multipart channel. + GetHttpChannel(aChannel, getter_AddRefs(httpChannel)); + + if (httpChannel) { + // figure out if SH should be saving layout state. + PRBool discardLayoutState = ShouldDiscardLayoutState(httpChannel); + if (mLSHE && discardLayoutState && (mLoadType & LOAD_CMD_NORMAL) && (mLoadType != LOAD_BYPASS_HISTORY)) + mLSHE->SetSaveLayoutStateFlag(PR_FALSE); + } + // Clear mLSHE after calling the onLoadHandlers. This way, if the // onLoadHandler tries to load something different in // itself or one of its children, we can deal with it appropriately. @@ -5601,15 +5617,7 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, httpChannel->GetUploadStream(getter_AddRefs(inputStream)); httpChannel->GetReferrer(getter_AddRefs(referrerURI)); - // figure out if SH should be saving layout state (see bug 112564) - nsCOMPtr securityInfo; - PRBool noStore = PR_FALSE, noCache = PR_FALSE; - - httpChannel->GetSecurityInfo(getter_AddRefs(securityInfo)); - httpChannel->IsNoStoreResponse(&noStore); - httpChannel->IsNoCacheResponse(&noCache); - - discardLayoutState = noStore || (noCache && securityInfo); + discardLayoutState = ShouldDiscardLayoutState(httpChannel); } } @@ -5876,6 +5884,23 @@ nsDocShell::GetHttpChannel(nsIChannel * aChannel, nsIHttpChannel ** aReturn) return NS_OK; } +PRBool +nsDocShell::ShouldDiscardLayoutState(nsIHttpChannel * aChannel) +{ + // By default layout State will be saved. + if (!aChannel) + return PR_FALSE; + + // figure out if SH should be saving layout state + nsCOMPtr securityInfo; + PRBool noStore = PR_FALSE, noCache = PR_FALSE; + aChannel->GetSecurityInfo(getter_AddRefs(securityInfo)); + aChannel->IsNoStoreResponse(&noStore); + aChannel->IsNoCacheResponse(&noCache); + + return (noStore || (noCache && securityInfo)); +} + //***************************************************************************** // nsDocShell: Global History //***************************************************************************** diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 17f67b1e444c..6d515c46393d 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -233,6 +233,7 @@ protected: nsISHEntry * areplaceEntry, nsISHEntry ** destEntry); nsresult GetRootSessionHistory(nsISHistory ** aReturn); nsresult GetHttpChannel(nsIChannel * aChannel, nsIHttpChannel ** aReturn); + PRBool ShouldDiscardLayoutState(nsIHttpChannel * aChannel); // Global History NS_IMETHOD ShouldAddToGlobalHistory(nsIURI * aURI, PRBool * aShouldAdd);