зеркало из https://github.com/mozilla/pjs.git
Add Equals() method to Window class to support comparison of XPConnect-wrapped nsIDOMWindow and idlc Window.
This commit is contained in:
Родитель
af7eee2a74
Коммит
260cb728dc
|
@ -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(); } \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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},
|
||||
|
|
Загрузка…
Ссылка в новой задаче