diff --git a/dom/public/base/nsIDOMWindow.h b/dom/public/base/nsIDOMWindow.h index 595c7175f72..d7ff82de29c 100644 --- a/dom/public/base/nsIDOMWindow.h +++ b/dom/public/base/nsIDOMWindow.h @@ -97,6 +97,8 @@ public: NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset)=0; NS_IMETHOD SetPageYOffset(PRInt32 aPageYOffset)=0; + NS_IMETHOD Equals(nsIDOMWindow* aWindow, PRBool* aReturn)=0; + NS_IMETHOD Dump(const nsString& aStr)=0; NS_IMETHOD Alert(const nsString& aStr)=0; @@ -182,6 +184,7 @@ public: NS_IMETHOD SetPageXOffset(PRInt32 aPageXOffset); \ NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset); \ 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 Focus(); \ @@ -244,6 +247,7 @@ public: NS_IMETHOD SetPageXOffset(PRInt32 aPageXOffset) { return _to SetPageXOffset(aPageXOffset); } \ NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset) { return _to GetPageYOffset(aPageYOffset); } \ 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 Focus() { return _to Focus(); } \ diff --git a/dom/public/domstubs.idl b/dom/public/domstubs.idl index 1962ddfe770..72cb37273ff 100644 --- a/dom/public/domstubs.idl +++ b/dom/public/domstubs.idl @@ -32,18 +32,58 @@ * mozilla/rdf/public/xulstubs.idl */ -[scriptable, uuid(a6cf906b-15b3-11d2-932e-00805f8add32)] -interface nsIDOMWindow : nsISupports {}; - -[scriptable, uuid(a6cf907d-15b3-11d2-932e-00805f8add32)] -interface nsIDOMNodeList : nsISupports {}; - [scriptable, uuid(a6cf907c-15b3-11d2-932e-00805f8add32)] interface nsIDOMNode : nsISupports {}; [scriptable, uuid(a6cf9078-15b3-11d2-932e-00805f8add32)] interface nsIDOMElement : nsIDOMNode {}; +[scriptable, uuid(a6cf9075-15b3-11d2-932e-00805f8add32)] +interface nsIDOMDocument : nsIDOMNode {}; + +[scriptable, uuid(a6cf907d-15b3-11d2-932e-00805f8add32)] +interface nsIDOMNodeList : nsISupports {}; + +[scriptable, uuid(a6cf906e-15b3-11d2-932e-00805f8add32)] +interface nsIDOMNavigator : nsISupports {}; + +[scriptable, uuid(77947960-b4af-11d2-bd93-00805f8ae3f4)] +interface nsIDOMScreen : nsISupports {}; + +[scriptable, uuid(896d1d20-b4c4-11d2-bd93-00805f8ae3f4)] +interface nsIDOMHistory : nsISupports {}; + +[scriptable, uuid(a6cf906f-15b3-11d2-932e-00805f8add32)] +interface nsIDOMWindowCollection : nsISupports {}; + +[scriptable, uuid(a6cf906b-15b3-11d2-932e-00805f8add32)] +interface nsIDOMWindow : nsISupports { + readonly attribute nsIDOMWindow window; + readonly attribute nsIDOMWindow self; + readonly attribute nsIDOMDocument document; + readonly attribute nsIDOMNavigator navigator; + readonly attribute nsIDOMScreen screen; + readonly attribute nsIDOMHistory history; + readonly attribute nsIDOMWindow parent; + readonly attribute nsIDOMWindow top; + readonly attribute boolean closed; + readonly attribute nsIDOMWindowCollection frames; + attribute nsIDOMWindow opener; + attribute wstring status; + attribute wstring defaultStatus; + attribute wstring name; + attribute long innerWidth; + attribute long innerHeight; + attribute long outerWidth; + attribute long outerHeight; + attribute long screenX; + attribute long screenY; + attribute long pageXOffset; + attribute long pageYOffset; + + boolean Equals(in nsIDOMWindow aWindow); +}; + %{C++ #endif diff --git a/dom/public/idl/base/Window.idl b/dom/public/idl/base/Window.idl index 5aab6e08ba9..e4d9c846548 100644 --- a/dom/public/idl/base/Window.idl +++ b/dom/public/idl/base/Window.idl @@ -1,7 +1,6 @@ interface Window { /* IID: { 0xa6cf906b, 0x15b3, 0x11d2, \ { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */ - readonly attribute Window window; readonly attribute Window self; readonly attribute Document document; @@ -25,6 +24,8 @@ attribute long pageXOffset; attribute long pageYOffset; + boolean Equals(in Window window); + void dump(in wstring str); void alert(in wstring str); void focus(); diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index d1c89f2cf6f..7bc3e92c3d3 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -779,6 +779,16 @@ GlobalWindowImpl::SetPageYOffset(PRInt32 aPageYOffset) return NS_OK; } +NS_IMETHODIMP +GlobalWindowImpl::Equals(nsIDOMWindow* aWindow, PRBool* aReturn) +{ + // XXX This is a hack that we need until the DOM is implemented in + // XPIDL. It allows us to test if an XPIDL-wrapped nsIDOMWindow is + // equal to an idlc wrapped Window. + *aReturn = (aWindow == NS_STATIC_CAST(nsIDOMWindow*, this)); + return NS_OK; +} + NS_IMETHODIMP GlobalWindowImpl::Dump(const nsString& aStr) { diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 5626c30f239..b7cd116d65b 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -122,6 +122,8 @@ public: NS_IMETHOD GetPageYOffset(PRInt32* aPageYOffset); 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 Focus(); diff --git a/dom/src/base/nsJSWindow.cpp b/dom/src/base/nsJSWindow.cpp index ee6d0648b3d..ccc57124c2f 100644 --- a/dom/src/base/nsJSWindow.cpp +++ b/dom/src/base/nsJSWindow.cpp @@ -780,6 +780,64 @@ ResolveWindow(JSContext *cx, JSObject *obj, jsval id) } +// +// Native method Equals +// +PR_STATIC_CALLBACK(JSBool) +WindowEquals(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMWindow *nativeThis = (nsIDOMWindow*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + PRBool nativeRet; + nsIDOMWindowPtr b0; + + *rval = JSVAL_NULL; + + nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); + nsIScriptSecurityManager *secMan; + if (NS_OK == scriptCX->GetSecurityManager(&secMan)) { + PRBool ok; + secMan->CheckScriptAccess(scriptCX, obj, "window.equals", &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 >= 1) { + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIWindowIID, + "Window", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->Equals(b0, &nativeRet)) { + return JS_FALSE; + } + + *rval = BOOLEAN_TO_JSVAL(nativeRet); + } + else { + JS_ReportError(cx, "Function Equals requires 1 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + // // Native method Dump // @@ -2407,6 +2465,7 @@ static JSPropertySpec WindowProperties[] = // static JSFunctionSpec WindowMethods[] = { + {"Equals", WindowEquals, 1}, {"dump", WindowDump, 1}, {"alert", WindowAlert, 1}, {"focus", WindowFocus, 0},