Attempt to fix splitwindow focus stuff -- bug 305032. Issue found by mrbkap, patch by bzbarsky, r=mrbkap, sr=jst a=asa

git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@181184 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mrbkap%gmail.com
2005-09-28 23:03:08 +00:00
parent b2baa803e6
commit 108d77ceaa
6 changed files with 45 additions and 32 deletions

View File

@@ -83,7 +83,7 @@ public:
virtual JSObject *GetGlobalJSObject();
virtual void OnFinalize(JSObject *aObject);
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
virtual nsresult SetNewArguments(JSObject *aArguments);
virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv);
// nsIScriptObjectPrincipal methods
virtual nsIPrincipal* GetPrincipal();
@@ -309,7 +309,7 @@ nsXBLDocGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
}
nsresult
nsXBLDocGlobalObject::SetNewArguments(JSObject *aArguments)
nsXBLDocGlobalObject::SetNewArguments(PRUint32 aArgc, jsval* aArgv)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;

View File

@@ -105,7 +105,7 @@ public:
virtual JSObject *GetGlobalJSObject();
virtual void OnFinalize(JSObject *aObject);
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
virtual nsresult SetNewArguments(JSObject *aArguments);
virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv);
// nsIScriptObjectPrincipal methods
virtual nsIPrincipal* GetPrincipal();
@@ -936,7 +936,7 @@ nsXULPDGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
}
nsresult
nsXULPDGlobalObject::SetNewArguments(JSObject *aArguments)
nsXULPDGlobalObject::SetNewArguments(PRUint32 aArgc, jsval* aArgv)
{
NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;

View File

@@ -50,10 +50,11 @@ class nsIDocShell;
class nsIDOMWindowInternal;
class nsIScriptGlobalObjectOwner;
struct JSObject;
typedef long jsval;
#define NS_ISCRIPTGLOBALOBJECT_IID \
{ 0xd4ddb2f8, 0x385f, 0x4baa, \
{ 0xba, 0x69, 0x6c, 0x42, 0xb3, 0xc2, 0xd0, 0xd0 } }
{ 0xd0db67fc, 0x50f7, 0x4573, \
{ 0x87, 0x3e, 0x5b, 0x33, 0x0b, 0x13, 0x21, 0x81 } }
/**
* The JavaScript specific global object. This often used to store
@@ -110,12 +111,13 @@ public:
*/
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0;
/** Set a new arguments object for this window. This will be set on
/**
* Set a new arguments array for this window. This will be set on
* the window right away (if there's an existing document) and it
* will also be installed on the window when the next document is
* loaded.
* loaded. If argc is nonzero, argv must be non-null.
*/
virtual nsresult SetNewArguments(JSObject *aArguments) = 0;
virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv) = 0;
};
#endif

View File

@@ -1639,19 +1639,43 @@ nsGlobalWindow::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
}
nsresult
nsGlobalWindow::SetNewArguments(JSObject *aArguments)
nsGlobalWindow::SetNewArguments(PRUint32 aArgc, jsval* aArgv)
{
FORWARD_TO_OUTER(SetNewArguments, (aArguments), NS_ERROR_NOT_INITIALIZED);
FORWARD_TO_OUTER(SetNewArguments, (aArgc, aArgv), NS_ERROR_NOT_INITIALIZED);
JSContext *cx;
NS_ENSURE_TRUE(aArguments && mContext &&
NS_ENSURE_TRUE(mContext &&
(cx = (JSContext *)mContext->GetNativeContext()),
NS_ERROR_NOT_INITIALIZED);
if (mArguments) {
::JS_UnlockGCThing(cx, mArguments);
mArguments = nsnull;
}
if (aArgc == 0) {
return NS_OK;
}
NS_ASSERTION(aArgv, "Must have argv!");
// Freeze the outer here so that we don't create a bogus new inner
// just because we're trying to resolve the Array class on cx.
// Resolving it for window.arguments on the outer window should be
// fine, I think.
Freeze();
JSObject *argArray = ::JS_NewArrayObject(cx, aArgc, aArgv);
Thaw();
NS_ENSURE_TRUE(argArray, NS_ERROR_OUT_OF_MEMORY);
// Note that currentInner may be non-null if someone's doing a
// window.open with an existing window name.
nsGlobalWindow *currentInner = GetCurrentInnerWindowInternal();
jsval args = OBJECT_TO_JSVAL(argArray);
jsval args = OBJECT_TO_JSVAL(aArguments);
// The object newborn keeps argArray alive across this set.
if (currentInner && currentInner->mJSObject) {
if (!::JS_SetProperty(cx, currentInner->mJSObject, "arguments", &args)) {
return NS_ERROR_FAILURE;
@@ -1660,7 +1684,7 @@ nsGlobalWindow::SetNewArguments(JSObject *aArguments)
// Hold on to the arguments so that we can re-set them once the next
// document is loaded.
mArguments = aArguments;
mArguments = argArray;
::JS_LockGCThing(cx, mArguments);
return NS_OK;

View File

@@ -169,7 +169,7 @@ public:
virtual JSObject *GetGlobalJSObject();
virtual void OnFinalize(JSObject *aJSObject);
virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
virtual nsresult SetNewArguments(JSObject *aArguments);
virtual nsresult SetNewArguments(PRUint32 aArgc, jsval* aArgv);
// nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal();
@@ -398,6 +398,7 @@ protected:
void Freeze()
{
NS_ASSERTION(!IsFrozen(), "Double-freezing?");
mIsFrozen = PR_TRUE;
}

View File

@@ -1744,25 +1744,11 @@ nsWindowWatcher::AttachArguments(nsIDOMWindow *aWindow,
if (argc == 0)
return NS_OK;
// copy the extra parameters into a JS Array and attach it
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow));
NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_UNEXPECTED);
nsIScriptContext *scriptContext = scriptGlobal->GetContext();
nsresult rv = NS_OK;
if (scriptContext) {
JSContext *cx;
cx = (JSContext *)scriptContext->GetNativeContext();
JSObject *args;
args = ::JS_NewArrayObject(cx, argc, argv);
if (args) {
rv = scriptGlobal->SetNewArguments(args);
}
}
return rv;
// Just ask the global to attach the args for us
return scriptGlobal->SetNewArguments(argc, argv);
}
nsresult