diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index cf3f9d6be1c..f94ac3446f7 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -504,6 +504,12 @@ ConvertDocShellLoadInfoToLoadType(nsDocShellInfoLoadType aDocShellLoadType) case nsIDocShellLoadInfo::loadBypassHistory: loadType = LOAD_BYPASS_HISTORY; break; + case nsIDocShellLoadInfo::loadStopContent: + loadType = LOAD_STOP_CONTENT; + break; + case nsIDocShellLoadInfo::loadStopContentAndReplace: + loadType = LOAD_STOP_CONTENT_AND_REPLACE; + break; } return loadType; @@ -548,6 +554,12 @@ nsDocShell::ConvertLoadTypeToDocShellLoadInfo(PRUint32 aLoadType) case LOAD_BYPASS_HISTORY: docShellLoadType = nsIDocShellLoadInfo::loadBypassHistory; break; + case LOAD_STOP_CONTENT: + docShellLoadType = nsIDocShellLoadInfo::loadStopContent; + break; + case LOAD_STOP_CONTENT_AND_REPLACE: + docShellLoadType = nsIDocShellLoadInfo::loadStopContentAndReplace; + break; } return docShellLoadType; @@ -603,7 +615,8 @@ nsDocShell::LoadURI(nsIURI * aURI, } #endif - if (!shEntry && loadType != LOAD_NORMAL_REPLACE) { + if (!shEntry && + !LOAD_TYPE_HAS_FLAGS(loadType, LOAD_FLAGS_REPLACE_HISTORY)) { // First verify if this is a subframe. nsCOMPtr parentAsItem; GetSameTypeParent(getter_AddRefs(parentAsItem)); @@ -4310,6 +4323,7 @@ nsDocShell::Embed(nsIContentViewer * aContentViewer, switch (mLoadType) { case LOAD_RELOAD_CHARSET_CHANGE: //don't perserve history in charset reload case LOAD_NORMAL_REPLACE: + case LOAD_STOP_CONTENT_AND_REPLACE: case LOAD_RELOAD_BYPASS_CACHE: case LOAD_RELOAD_BYPASS_PROXY: case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE: @@ -5427,7 +5441,8 @@ nsDocShell::InternalLoad(nsIURI * aURI, } if ((aLoadType == LOAD_NORMAL || - aLoadType == LOAD_NORMAL_REPLACE || + aLoadType == LOAD_STOP_CONTENT || + LOAD_TYPE_HAS_FLAGS(aLoadType, LOAD_FLAGS_REPLACE_HISTORY) || aLoadType == LOAD_HISTORY || aLoadType == LOAD_LINK) && allowScroll) { PRBool wasAnchor = PR_FALSE; @@ -5546,7 +5561,8 @@ nsDocShell::InternalLoad(nsIURI * aURI, mContentViewer->GetPreviousViewer(getter_AddRefs(zombieViewer)); } - if (zombieViewer) { + if (zombieViewer || + LOAD_TYPE_HAS_FLAGS(aLoadType, LOAD_FLAGS_STOP_CONTENT)) { rv = Stop(nsIWebNavigation::STOP_ALL); } else { rv = Stop(nsIWebNavigation::STOP_NETWORK); @@ -5558,7 +5574,7 @@ nsDocShell::InternalLoad(nsIURI * aURI, mLoadType = aLoadType; // mLSHE should be assigned to aSHEntry, only after Stop() has - // been called. + // been called. mLSHE = aSHEntry; rv = DoURILoad(aURI, aReferrer, @@ -6319,11 +6335,12 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, nsCOMPtr root; GetSameTypeRootTreeItem(getter_AddRefs(root)); /* - * If this is a LOAD_NORMAL_REPLACE in a subframe, we use + * If this is a LOAD_FLAGS_REPLACE_HISTORY in a subframe, we use * the existing SH entry in the page and replace the url and * other vitalities. */ - if (LOAD_NORMAL_REPLACE == mLoadType && (root.get() != NS_STATIC_CAST(nsIDocShellTreeItem *, this))) { + if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY) && + root != NS_STATIC_CAST(nsIDocShellTreeItem *, this)) { // This is a subframe entry = mOSHE; nsCOMPtr shContainer(do_QueryInterface(entry)); @@ -6414,9 +6431,9 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, entry->SetExpirationStatus(PR_TRUE); - if (root.get() == NS_STATIC_CAST(nsIDocShellTreeItem *, this) && mSessionHistory) { + if (root == NS_STATIC_CAST(nsIDocShellTreeItem *, this) && mSessionHistory) { // This is the root docshell - if (mLoadType == LOAD_NORMAL_REPLACE) { + if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) { // Replace current entry in session history. PRInt32 index = 0; nsCOMPtr hEntry; @@ -6436,8 +6453,8 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, } else { // This is a subframe. - if ((mLoadType != LOAD_NORMAL_REPLACE) || - (mLoadType == LOAD_NORMAL_REPLACE && !mOSHE)) + if (!mOSHE || !LOAD_TYPE_HAS_FLAGS(mLoadType, + LOAD_FLAGS_REPLACE_HISTORY)) rv = DoAddChildSHEntry(entry, mChildOffset); } diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index d67f51cb5d4..70ec0d8b0ff 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -102,6 +102,7 @@ #define MAKE_LOAD_TYPE(type, flags) ((type) | ((flags) << 16)) +#define LOAD_TYPE_HAS_FLAGS(type, flags) ((type) & ((flags) << 16)) /* load commands were moved to nsIDocShell.h */ @@ -122,7 +123,9 @@ enum LoadType { LOAD_LINK = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_LINK), LOAD_REFRESH = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_REFRESH), LOAD_RELOAD_CHARSET_CHANGE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE), - LOAD_BYPASS_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY) + LOAD_BYPASS_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY), + LOAD_STOP_CONTENT = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_STOP_CONTENT), + LOAD_STOP_CONTENT_AND_REPLACE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_STOP_CONTENT | nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY) // NOTE: Adding a new value? Remember to update IsValidLoadType! }; static inline PRBool IsValidLoadType(PRUint32 aLoadType) @@ -140,6 +143,8 @@ static inline PRBool IsValidLoadType(PRUint32 aLoadType) case LOAD_REFRESH: case LOAD_RELOAD_CHARSET_CHANGE: case LOAD_BYPASS_HISTORY: + case LOAD_STOP_CONTENT: + case LOAD_STOP_CONTENT_AND_REPLACE: return PR_TRUE; } return PR_FALSE; diff --git a/mozilla/docshell/base/nsIDocShellLoadInfo.idl b/mozilla/docshell/base/nsIDocShellLoadInfo.idl index b8e062ad479..f9e65eba13b 100644 --- a/mozilla/docshell/base/nsIDocShellLoadInfo.idl +++ b/mozilla/docshell/base/nsIDocShellLoadInfo.idl @@ -79,6 +79,8 @@ interface nsIDocShellLoadInfo : nsISupports const long loadRefresh = 8; const long loadReloadCharsetChange = 9; const long loadBypassHistory = 10; + const long loadStopContent = 11; + const long loadStopContentAndReplace = 12; /** Contains a load type as specified by the load* constants */ attribute nsDocShellInfoLoadType loadType; diff --git a/mozilla/docshell/base/nsIWebNavigation.idl b/mozilla/docshell/base/nsIWebNavigation.idl index eb543c2c100..3c83968cef0 100644 --- a/mozilla/docshell/base/nsIWebNavigation.idl +++ b/mozilla/docshell/base/nsIWebNavigation.idl @@ -143,6 +143,14 @@ interface nsIWebNavigation : nsISupports const unsigned long LOAD_FLAGS_BYPASS_PROXY = 0x0200; // Bypass the proxy const unsigned long LOAD_FLAGS_CHARSET_CHANGE = 0x0400; // Reload because of charset change, + /** + * If this flag is set, Stop() will be called before the load starts + * and will stop both content and network activity (the default is to + * only stop network activity). Effectively, this passes the + * STOP_CONTENT flag to Stop(), in addition to the STOP_NETWORK flag. + */ + const unsigned long LOAD_FLAGS_STOP_CONTENT = 0x0800; + /** * Loads a given URI. This will give priority to loading the requested URI * in the object implementing this interface. If it can't be loaded here diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 8254ed827e1..ff84e0445e6 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -522,7 +522,7 @@ protected: // PR_TRUE for aGetInnermostURI when that's the case. nsresult GetURI(nsIURI** aURL, PRBool aGetInnermostURI = PR_FALSE); nsresult GetWritableURI(nsIURI** aURL); - nsresult SetURI(nsIURI* aURL); + nsresult SetURI(nsIURI* aURL, PRBool aReplace = PR_FALSE); nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase, PRBool aReplace); nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref, diff --git a/mozilla/dom/src/base/nsLocation.cpp b/mozilla/dom/src/base/nsLocation.cpp index 65616cf0165..818b24355a3 100644 --- a/mozilla/dom/src/base/nsLocation.cpp +++ b/mozilla/dom/src/base/nsLocation.cpp @@ -314,7 +314,7 @@ nsLocation::GetWritableURI(nsIURI** aURI) } nsresult -nsLocation::SetURI(nsIURI* aURI) +nsLocation::SetURI(nsIURI* aURI, PRBool aReplace) { if (mDocShell) { nsCOMPtr loadInfo; @@ -323,7 +323,12 @@ nsLocation::SetURI(nsIURI* aURI) if(NS_FAILED(CheckURL(aURI, getter_AddRefs(loadInfo)))) return NS_ERROR_FAILURE; - webNav->Stop(nsIWebNavigation::STOP_CONTENT); + if (aReplace) { + loadInfo->SetLoadType(nsIDocShellLoadInfo::loadStopContentAndReplace); + } else { + loadInfo->SetLoadType(nsIDocShellLoadInfo::loadStopContent); + } + return mDocShell->LoadURI(aURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE); } @@ -386,17 +391,7 @@ nsLocation::SetHash(const nsAString& aHash) if (url) { url->SetRef(NS_ConvertUCS2toUTF8(aHash)); - - if (mDocShell) { - nsCOMPtr loadInfo; - - if (NS_SUCCEEDED(CheckURL(url, getter_AddRefs(loadInfo)))) - // We're not calling nsIWebNavigation->Stop, we don't want to - // stop the load when we're just scrolling to a named anchor - // in the document. See bug 114975. - mDocShell->LoadURI(url, loadInfo, - nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE); - } + SetURI(url); } return result; @@ -506,13 +501,6 @@ nsLocation::GetHref(nsAString& aHref) NS_IMETHODIMP nsLocation::SetHref(const nsAString& aHref) { - if (!aHref.IsEmpty() && aHref.First() == PRUnichar('#')) { - // Special-case anchor loads so that we don't stop content - // Note that SetHash (or more precisely nsIURL::SetRef) deals with - // the leading '#'. - return SetHash(aHref); - } - nsAutoString oldHref; nsresult rv = NS_OK; @@ -583,15 +571,7 @@ nsLocation::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase, else result = NS_NewURI(getter_AddRefs(newUri), aHref, nsnull, baseURI); - if (newUri && mDocShell) { - nsCOMPtr loadInfo; - nsCOMPtr webNav(do_QueryInterface(mDocShell)); - - nsresult rv = CheckURL(newUri, getter_AddRefs(loadInfo)); - - if(NS_FAILED(rv)) - return rv; - + if (newUri) { /* Check with the scriptContext if it is currently processing a script tag. * If so, this must be a