Permalink
Browse files

Add a webnavigation flag to allow callers to stop content, not just stop

network activity.  Make nsLocation use this so it doesn't stop content
unnecessarily.  Bug 277224, r=darin, sr=jst
  • Loading branch information...
bzbarsky%mit.edu
bzbarsky%mit.edu committed Jan 20, 2005
1 parent 1045658 commit 9cf134eb940651ac5bc04962a0478a988e677151
@@ -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<nsIDocShellTreeItem> 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<nsIDocShellTreeItem> 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<nsISHContainer> 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<nsIHistoryEntry> 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);
}
@@ -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;
@@ -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;
@@ -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
@@ -522,7 +522,7 @@ class nsLocation : public nsIDOMLocation,
// 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,
@@ -314,7 +314,7 @@ nsLocation::GetWritableURI(nsIURI** aURI)
}
nsresult
nsLocation::SetURI(nsIURI* aURI)
nsLocation::SetURI(nsIURI* aURI, PRBool aReplace)
{
if (mDocShell) {
nsCOMPtr<nsIDocShellLoadInfo> 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<nsIDocShellLoadInfo> 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<nsIDocShellLoadInfo> loadInfo;
nsCOMPtr<nsIWebNavigation> 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 <script> tag with a location.href in it.
* we want to do a replace load, in such a situation.
@@ -626,13 +606,7 @@ nsLocation::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
} //cx
} // stack
if (aReplace || inScriptTag) {
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);
}
webNav->Stop(nsIWebNavigation::STOP_CONTENT);
return mDocShell->LoadURI(newUri, loadInfo,
nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
return SetURI(newUri, aReplace || inScriptTag);
}
return result;

0 comments on commit 9cf134e

Please sign in to comment.