Fix for bug # 72197 javascript urls cause problems with history r= rpotts sr=blizzard

This commit is contained in:
radha%netscape.com 2001-05-15 22:26:19 +00:00
Родитель d4bef6d7ce
Коммит b1eefd23cb
4 изменённых файлов: 56 добавлений и 18 удалений

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

@ -302,6 +302,13 @@ public:
*/
NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled) = 0;
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled) = 0;
/**
* Called to set/get information if the script context is
* currently processing a script tag
*/
NS_IMETHOD GetProcessingScriptTag(PRBool * aResult) =0;
NS_IMETHOD SetProcessingScriptTag(PRBool aResult) =0;
};
#endif // nsIScriptContext_h__

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

@ -356,6 +356,7 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime)
mTerminationFunc = nsnull;
mScriptsEnabled = PR_TRUE;
mBranchCallbackCount = 0;
mProcessingScriptTag=PR_FALSE;
}
const char kScriptSecurityManagerContractID[] = NS_SCRIPTSECURITYMANAGER_CONTRACTID;
@ -1389,6 +1390,21 @@ nsJSContext::SetScriptsEnabled(PRBool aEnabled)
return NS_OK;
}
NS_IMETHODIMP
nsJSContext::GetProcessingScriptTag(PRBool * aResult)
{
*aResult = mProcessingScriptTag;
return NS_OK;
}
NS_IMETHODIMP
nsJSContext::SetProcessingScriptTag(PRBool aFlag)
{
mProcessingScriptTag = aFlag;
return NS_OK;
}
nsJSEnvironment *nsJSEnvironment::sTheEnvironment = nsnull;
nsJSEnvironment *

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

@ -104,6 +104,9 @@ public:
NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled);
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled);
NS_IMETHOD GetProcessingScriptTag(PRBool * aResult);
NS_IMETHOD SetProcessingScriptTag(PRBool aResult);
protected:
nsresult InitClasses();
nsresult InitializeExternalClasses();
@ -124,6 +127,7 @@ private:
PRUint32 mBranchCallbackCount;
PRUint32 mDefaultJSOptions;
PRBool mProcessingScriptTag;
static int PR_CALLBACK JSOptionChangedCallback(const char *pref, void *data);

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

@ -416,23 +416,35 @@ LocationImpl::SetHrefWithBase(const nsAReadableString& aHref,
if(NS_FAILED(rv))
return rv;
// Check if docshell is currently loading a document.
// If so, this request from JS is probably part of a onload
// handler or a simple script tag with a
// location.href="new location" for redirection.
// In such a case, request a replace load, so that
// the new url will replace the existing url in SH.
// NOTE: this will not be the case if a event handler had a
// location.href in it or a JS timer went off well after
// the current document is loaded. In such cases, we will
// append the new url to SH.
// This solution is tricky. Hopefully it isn't going to bite
// anywhere else. This is part of solution for bug # 39938
PRUint32 busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
mDocShell->GetBusyFlags(&busyFlags);
/* 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.
* In other cases, for example if a event handler or a JS timer
* had a location.href in it, we want to do a normal load,
* so that the new url will be appended to Session History.
* This solution is tricky. Hopefully it isn't going to bite
* anywhere else. This is part of solution for bug # 39938, 72197
*
*/
PRBool inScriptTag=PR_FALSE;
// Get JSContext from stack.
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result));
if (aReplace || (busyFlags & nsIDocShell::BUSY_FLAGS_BUSY)) {
if (stack) {
JSContext *cx;
result = stack->Peek(&cx);
if (cx) {
nsIScriptContext* scriptCX = (nsIScriptContext*)JS_GetContextPrivate(cx);
if (scriptCX) {
scriptCX->GetProcessingScriptTag(&inScriptTag);
}
} //cx
} // stack
if (aReplace || inScriptTag) {
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);
}
@ -732,14 +744,13 @@ LocationImpl::Replace(const nsAReadableString& aUrl)
// Get JSContext from stack.
nsCOMPtr<nsIJSContextStack>
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
if (stack) {
JSContext *cx;
rv = stack->Peek(&cx);
NS_ENSURE_SUCCESS(rv, rv);
if (cx) {
return SetHrefWithContext(cx, aUrl, PR_TRUE);
}