зеркало из https://github.com/mozilla/gecko-dev.git
Added confirm and prompt to window object.
This commit is contained in:
Родитель
dc2dad2c04
Коммит
e43183b897
|
@ -116,7 +116,11 @@ public:
|
|||
|
||||
NS_IMETHOD Dump(const nsString& aStr)=0;
|
||||
|
||||
NS_IMETHOD Alert(const nsString& aStr)=0;
|
||||
NS_IMETHOD Alert(JSContext *cx, jsval *argv, PRUint32 argc)=0;
|
||||
|
||||
NS_IMETHOD Confirm(JSContext *cx, jsval *argv, PRUint32 argc, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aReturn)=0;
|
||||
|
||||
NS_IMETHOD Focus()=0;
|
||||
|
||||
|
@ -206,7 +210,9 @@ public:
|
|||
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset); \
|
||||
NS_IMETHOD Equals(nsIDOMWindow* aWindow, PRBool* aReturn); \
|
||||
NS_IMETHOD Dump(const nsString& aStr); \
|
||||
NS_IMETHOD Alert(const nsString& aStr); \
|
||||
NS_IMETHOD Alert(JSContext *cx, jsval *argv, PRUint32 argc); \
|
||||
NS_IMETHOD Confirm(JSContext *cx, jsval *argv, PRUint32 argc, PRBool* aReturn); \
|
||||
NS_IMETHOD Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aReturn); \
|
||||
NS_IMETHOD Focus(); \
|
||||
NS_IMETHOD Blur(); \
|
||||
NS_IMETHOD Close(); \
|
||||
|
@ -275,7 +281,9 @@ public:
|
|||
NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset) { return _to SetPageYOffset(aPageYOffset); } \
|
||||
NS_IMETHOD Equals(nsIDOMWindow* aWindow, PRBool* aReturn) { return _to Equals(aWindow, aReturn); } \
|
||||
NS_IMETHOD Dump(const nsString& aStr) { return _to Dump(aStr); } \
|
||||
NS_IMETHOD Alert(const nsString& aStr) { return _to Alert(aStr); } \
|
||||
NS_IMETHOD Alert(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Alert(cx, argv, argc); } \
|
||||
NS_IMETHOD Confirm(JSContext *cx, jsval *argv, PRUint32 argc, PRBool* aReturn) { return _to Confirm(cx, argv, argc, aReturn); } \
|
||||
NS_IMETHOD Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aReturn) { return _to Prompt(cx, argv, argc, aReturn); } \
|
||||
NS_IMETHOD Focus() { return _to Focus(); } \
|
||||
NS_IMETHOD Blur() { return _to Blur(); } \
|
||||
NS_IMETHOD Close() { return _to Close(); } \
|
||||
|
|
|
@ -34,7 +34,9 @@
|
|||
boolean Equals(in Window window);
|
||||
|
||||
void dump(in wstring str);
|
||||
void alert(in wstring str);
|
||||
void alert(/* ... */);
|
||||
boolean confirm(/* ... */);
|
||||
DOMString prompt(/* ... */);
|
||||
void focus();
|
||||
void blur();
|
||||
void close();
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "nsIDOMLoadListener.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsIDOMPaintListener.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsIScriptEventListener.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsIBrowserWindow.h"
|
||||
|
@ -943,9 +944,17 @@ GlobalWindowImpl::Dump(const nsString& aStr)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::Alert(const nsString& aStr)
|
||||
GlobalWindowImpl::Alert(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
nsresult ret;
|
||||
nsAutoString str;
|
||||
|
||||
if (argc > 0) {
|
||||
nsJSUtils::nsConvertJSValToString(str, cx, argv[0]);
|
||||
}
|
||||
else {
|
||||
str.SetString("undefined");
|
||||
}
|
||||
|
||||
nsIWebShell *rootWebShell;
|
||||
ret = mWebShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
||||
|
@ -955,7 +964,78 @@ GlobalWindowImpl::Alert(const nsString& aStr)
|
|||
if (nsnull != rootContainer) {
|
||||
nsINetSupport *support;
|
||||
if (NS_OK == (ret = rootContainer->QueryInterface(kINetSupportIID, (void**)&support))) {
|
||||
support->Alert(aStr);
|
||||
support->Alert(str);
|
||||
NS_RELEASE(support);
|
||||
}
|
||||
NS_RELEASE(rootContainer);
|
||||
}
|
||||
NS_RELEASE(rootWebShell);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::Confirm(JSContext *cx, jsval *argv, PRUint32 argc, PRBool* aReturn)
|
||||
{
|
||||
nsresult ret;
|
||||
nsAutoString str;
|
||||
|
||||
if (argc > 0) {
|
||||
nsJSUtils::nsConvertJSValToString(str, cx, argv[0]);
|
||||
}
|
||||
else {
|
||||
str.SetString("undefined");
|
||||
}
|
||||
|
||||
nsIWebShell *rootWebShell;
|
||||
ret = mWebShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
||||
if (nsnull != rootWebShell) {
|
||||
nsIWebShellContainer *rootContainer;
|
||||
ret = rootWebShell->GetContainer(rootContainer);
|
||||
if (nsnull != rootContainer) {
|
||||
nsINetSupport *support;
|
||||
if (NS_OK == (ret = rootContainer->QueryInterface(kINetSupportIID, (void**)&support))) {
|
||||
*aReturn = support->Confirm(str);
|
||||
NS_RELEASE(support);
|
||||
}
|
||||
NS_RELEASE(rootContainer);
|
||||
}
|
||||
NS_RELEASE(rootWebShell);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aReturn)
|
||||
{
|
||||
nsresult ret;
|
||||
nsAutoString str, initial;
|
||||
|
||||
if (argc > 0) {
|
||||
nsJSUtils::nsConvertJSValToString(str, cx, argv[0]);
|
||||
|
||||
if (argc > 1) {
|
||||
nsJSUtils::nsConvertJSValToString(initial, cx, argv[1]);
|
||||
}
|
||||
else {
|
||||
initial.SetString("undefined");
|
||||
}
|
||||
}
|
||||
|
||||
nsIWebShell *rootWebShell;
|
||||
ret = mWebShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
||||
if (nsnull != rootWebShell) {
|
||||
nsIWebShellContainer *rootContainer;
|
||||
ret = rootWebShell->GetContainer(rootContainer);
|
||||
if (nsnull != rootContainer) {
|
||||
nsINetSupport *support;
|
||||
if (NS_OK == (ret = rootContainer->QueryInterface(kINetSupportIID, (void**)&support))) {
|
||||
if (!support->Prompt(str, initial, aReturn)) {
|
||||
// XXX Need to check return value and return null if the
|
||||
// user hits cancel. Currently, we can only return a
|
||||
// string reference.
|
||||
aReturn.SetString("");
|
||||
}
|
||||
NS_RELEASE(support);
|
||||
}
|
||||
NS_RELEASE(rootContainer);
|
||||
|
@ -963,8 +1043,6 @@ GlobalWindowImpl::Alert(const nsString& aStr)
|
|||
NS_RELEASE(rootWebShell);
|
||||
}
|
||||
return ret;
|
||||
// XXX Temporary
|
||||
//return Dump(aStr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -134,7 +134,9 @@ public:
|
|||
NS_IMETHOD Equals(nsIDOMWindow* aWindow, PRBool* aReturn);
|
||||
|
||||
NS_IMETHOD Dump(const nsString& aStr);
|
||||
NS_IMETHOD Alert(const nsString& aStr);
|
||||
NS_IMETHOD Alert(JSContext *cx, jsval *argv, PRUint32 argc);
|
||||
NS_IMETHOD Confirm(JSContext *cx, jsval *argv, PRUint32 argc, PRBool* aReturn);
|
||||
NS_IMETHOD Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aReturn);
|
||||
NS_IMETHOD Focus();
|
||||
NS_IMETHOD Blur();
|
||||
NS_IMETHOD Close();
|
||||
|
|
|
@ -1026,7 +1026,6 @@ WindowAlert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsAutoString b0;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
|
@ -1050,18 +1049,114 @@ WindowAlert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
if (argc >= 0) {
|
||||
|
||||
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
|
||||
|
||||
if (NS_OK != nativeThis->Alert(b0)) {
|
||||
if (NS_OK != nativeThis->Alert(cx, argv+0, argc-0)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function alert requires 1 parameters");
|
||||
JS_ReportError(cx, "Function alert requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Confirm
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowConfirm(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
PRBool nativeRet;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "window.confirm", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// 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->Confirm(cx, argv+0, argc-0, &nativeRet)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL(nativeRet);
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function confirm requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Prompt
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowPrompt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsAutoString nativeRet;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "window.prompt", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// 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->Prompt(cx, argv+0, argc-0, nativeRet)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval);
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function prompt requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -2531,7 +2626,9 @@ static JSFunctionSpec WindowMethods[] =
|
|||
{
|
||||
{"Equals", WindowEquals, 1},
|
||||
{"dump", WindowDump, 1},
|
||||
{"alert", WindowAlert, 1},
|
||||
{"alert", WindowAlert, 0},
|
||||
{"confirm", WindowConfirm, 0},
|
||||
{"prompt", WindowPrompt, 0},
|
||||
{"focus", WindowFocus, 0},
|
||||
{"blur", WindowBlur, 0},
|
||||
{"close", WindowClose, 0},
|
||||
|
|
Загрузка…
Ссылка в новой задаче