Bug 680727 - Part 2: docshell should pass a reloaded page to global history. r=smaug

This commit is contained in:
Oonishi Atsushi 2012-03-28 21:51:01 +02:00
parent 2231b2fb05
commit 3f253a7806

View File

@ -9263,9 +9263,7 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
} }
#endif #endif
bool updateHistory = true;
bool equalUri = false; bool equalUri = false;
bool shAvailable = true;
// Get the post data from the channel // Get the post data from the channel
nsCOMPtr<nsIInputStream> inputStream; nsCOMPtr<nsIInputStream> inputStream;
@ -9292,6 +9290,15 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
} }
} }
} }
// Determine if this type of load should update history.
bool updateGHistory = !(aLoadType == LOAD_BYPASS_HISTORY ||
aLoadType == LOAD_ERROR_PAGE ||
aLoadType & LOAD_CMD_HISTORY);
// We don't update session history on reload.
bool updateSHistory = updateGHistory && (!(aLoadType & LOAD_CMD_RELOAD));
/* Create SH Entry (mLSHE) only if there is a SessionHistory object (mSessionHistory) in /* Create SH Entry (mLSHE) only if there is a SessionHistory object (mSessionHistory) in
* the current frame or in the root docshell * the current frame or in the root docshell
*/ */
@ -9299,26 +9306,26 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
if (!rootSH) { if (!rootSH) {
// Get the handle to SH from the root docshell // Get the handle to SH from the root docshell
GetRootSessionHistory(getter_AddRefs(rootSH)); GetRootSessionHistory(getter_AddRefs(rootSH));
if (!rootSH) if (!rootSH) {
shAvailable = false; updateSHistory = false;
updateGHistory = false; // XXX Why global history too?
}
} // rootSH } // rootSH
// Determine if this type of load should update history.
if (aLoadType == LOAD_BYPASS_HISTORY ||
aLoadType == LOAD_ERROR_PAGE ||
aLoadType & LOAD_CMD_HISTORY ||
aLoadType & LOAD_CMD_RELOAD)
updateHistory = false;
// Check if the url to be loaded is the same as the one already loaded. // Check if the url to be loaded is the same as the one already loaded.
if (mCurrentURI) if (mCurrentURI)
aURI->Equals(mCurrentURI, &equalUri); aURI->Equals(mCurrentURI, &equalUri);
#ifdef DEBUG #ifdef DEBUG
bool shAvailable = (rootSH != nsnull);
// XXX This log message is almost useless because |updateSHistory|
// and |updateGHistory| are not correct at this point.
PR_LOG(gDocShellLog, PR_LOG_DEBUG, PR_LOG(gDocShellLog, PR_LOG_DEBUG,
(" shAvailable=%i updateHistory=%i equalURI=%i\n", (" shAvailable=%i updateSHistory=%i updateGHistory=%i"
shAvailable, updateHistory, equalUri)); " equalURI=%i\n",
shAvailable, updateSHistory, updateGHistory, equalUri));
if (shAvailable && mCurrentURI && !mOSHE && aLoadType != LOAD_ERROR_PAGE) { if (shAvailable && mCurrentURI && !mOSHE && aLoadType != LOAD_ERROR_PAGE) {
NS_ASSERTION(NS_IsAboutBlank(mCurrentURI), "no SHEntry for a non-transient viewer?"); NS_ASSERTION(NS_IsAboutBlank(mCurrentURI), "no SHEntry for a non-transient viewer?");
@ -9366,8 +9373,9 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
(aLoadType == LOAD_RELOAD_BYPASS_CACHE || (aLoadType == LOAD_RELOAD_BYPASS_CACHE ||
aLoadType == LOAD_RELOAD_BYPASS_PROXY || aLoadType == LOAD_RELOAD_BYPASS_PROXY ||
aLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE)) { aLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE)) {
NS_ASSERTION(!updateHistory, NS_ASSERTION(!updateSHistory,
"We shouldn't be updating history for forced reloads!"); "We shouldn't be updating session history for forced"
" reloads!");
nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(aChannel)); nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(aChannel));
nsCOMPtr<nsISupports> cacheKey; nsCOMPtr<nsISupports> cacheKey;
@ -9405,7 +9413,7 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
ClearFrameHistory(mOSHE); ClearFrameHistory(mOSHE);
} }
if (updateHistory && shAvailable) { if (updateSHistory) {
// Update session history if necessary... // Update session history if necessary...
if (!mLSHE && (mItemType == typeContent) && mURIResultedInDocument) { if (!mLSHE && (mItemType == typeContent) && mURIResultedInDocument) {
/* This is a fresh page getting loaded for the first time /* This is a fresh page getting loaded for the first time
@ -9415,24 +9423,31 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
(void) AddToSessionHistory(aURI, aChannel, aOwner, aCloneSHChildren, (void) AddToSessionHistory(aURI, aChannel, aOwner, aCloneSHChildren,
getter_AddRefs(mLSHE)); getter_AddRefs(mLSHE));
} }
}
if (aAddToGlobalHistory) { // If this is a POST request, we do not want to include this in global
// If this is a POST request, we do not want to include this in global // history.
// history. if (updateGHistory &&
if (!ChannelIsPost(aChannel)) { aAddToGlobalHistory &&
nsCOMPtr<nsIURI> previousURI; !ChannelIsPost(aChannel)) {
PRUint32 previousFlags = 0; nsCOMPtr<nsIURI> previousURI;
ExtractLastVisit(aChannel, getter_AddRefs(previousURI), PRUint32 previousFlags = 0;
&previousFlags);
nsCOMPtr<nsIURI> referrer; if (aLoadType & LOAD_CMD_RELOAD) {
// Treat referrer as null if there is an error getting it. // On a reload request, we don't set redirecting flags.
(void)NS_GetReferrerFromChannel(aChannel, previousURI = aURI;
getter_AddRefs(referrer)); } else {
ExtractLastVisit(aChannel, getter_AddRefs(previousURI),
AddURIVisit(aURI, referrer, previousURI, previousFlags); &previousFlags);
}
} }
// Note: We don't use |referrer| when our global history is
// based on IHistory.
nsCOMPtr<nsIURI> referrer;
// Treat referrer as null if there is an error getting it.
(void)NS_GetReferrerFromChannel(aChannel, getter_AddRefs(referrer));
AddURIVisit(aURI, referrer, previousURI, previousFlags);
} }
// If this was a history load or a refresh, // If this was a history load or a refresh,