mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-19 09:30:44 +00:00
Adding window.close(), fixing window.opener, window.name
This commit is contained in:
parent
984ac268fd
commit
12c01ec243
@ -15,6 +15,7 @@
|
||||
void alert(in wstring str);
|
||||
void focus();
|
||||
void blur();
|
||||
void close();
|
||||
|
||||
void clearTimeout(in long timerID);
|
||||
void clearInterval(in long timerID);
|
||||
|
@ -73,6 +73,8 @@ public:
|
||||
|
||||
NS_IMETHOD Blur()=0;
|
||||
|
||||
NS_IMETHOD Close()=0;
|
||||
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID)=0;
|
||||
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID)=0;
|
||||
@ -106,6 +108,7 @@ public:
|
||||
NS_IMETHOD Alert(const nsString& aStr); \
|
||||
NS_IMETHOD Focus(); \
|
||||
NS_IMETHOD Blur(); \
|
||||
NS_IMETHOD Close(); \
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID); \
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID); \
|
||||
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn); \
|
||||
@ -135,6 +138,7 @@ public:
|
||||
NS_IMETHOD Alert(const nsString& aStr) { return _to##Alert(aStr); } \
|
||||
NS_IMETHOD Focus() { return _to##Focus(); } \
|
||||
NS_IMETHOD Blur() { return _to##Blur(); } \
|
||||
NS_IMETHOD Close() { return _to##Close(); } \
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID) { return _to##ClearTimeout(aTimerID); } \
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID) { return _to##ClearInterval(aTimerID); } \
|
||||
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc, PRInt32* aReturn) { return _to##SetTimeout(cx, argv, argc, aReturn); } \
|
||||
|
@ -478,6 +478,21 @@ GlobalWindowImpl::Blur()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::Close()
|
||||
{
|
||||
// Basic security check. If window has opener and therefore was opened from JS it can be
|
||||
// closed. Need to add additional checks and privilege based closing
|
||||
if (nsnull != mOpener) {
|
||||
nsIBrowserWindow *mBrowser;
|
||||
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
||||
mBrowser->Close();
|
||||
NS_RELEASE(mBrowser);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
GlobalWindowImpl::ClearTimeoutOrInterval(PRInt32 aTimerID)
|
||||
{
|
||||
@ -909,8 +924,7 @@ GlobalWindowImpl::Open(JSContext *cx,
|
||||
PRUint32 mChrome = 0;
|
||||
PRInt32 mWidth, mHeight;
|
||||
PRInt32 mLeft, mTop;
|
||||
nsString mName;
|
||||
nsAutoString mAbsURL;
|
||||
nsAutoString mAbsURL, mName;
|
||||
JSString* str;
|
||||
*aReturn = nsnull;
|
||||
|
||||
@ -1038,6 +1052,8 @@ GlobalWindowImpl::Open(JSContext *cx,
|
||||
NS_IF_RELEASE(mNewContextOwner);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mNewWebShell->SetName(mName);
|
||||
|
||||
NS_RELEASE(mNewWindow);
|
||||
NS_RELEASE(mNewWebShell);
|
||||
@ -1050,7 +1066,7 @@ GlobalWindowImpl::Open(JSContext *cx,
|
||||
}
|
||||
|
||||
/* Set opener */
|
||||
mNewGlobalObject->SetOpenerWindow(mNewDOMWindow);
|
||||
mNewGlobalObject->SetOpenerWindow(this);
|
||||
|
||||
NS_IF_RELEASE(mNewGlobalObject);
|
||||
|
||||
|
@ -90,6 +90,7 @@ public:
|
||||
NS_IMETHOD Alert(const nsString& aStr);
|
||||
NS_IMETHOD Focus();
|
||||
NS_IMETHOD Blur();
|
||||
NS_IMETHOD Close();
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID);
|
||||
NS_IMETHOD ClearInterval(PRInt32 aTimerID);
|
||||
NS_IMETHOD SetTimeout(JSContext *cx, jsval *argv, PRUint32 argc,
|
||||
|
@ -678,6 +678,39 @@ WindowBlur(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Close
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowClose(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->Close()) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function close requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method ClearTimeout
|
||||
//
|
||||
@ -921,6 +954,7 @@ static JSFunctionSpec WindowMethods[] =
|
||||
{"alert", WindowAlert, 1},
|
||||
{"focus", WindowFocus, 0},
|
||||
{"blur", WindowBlur, 0},
|
||||
{"close", WindowClose, 0},
|
||||
{"clearTimeout", WindowClearTimeout, 1},
|
||||
{"clearInterval", WindowClearInterval, 1},
|
||||
{"setTimeout", WindowSetTimeout, 0},
|
||||
|
Loading…
x
Reference in New Issue
Block a user