зеркало из https://github.com/mozilla/gecko-dev.git
NOT YET PART OF SEAMONKEY - prepped the four files for movement to libxpt, centralized/simplified access to services, fixed InterfaceInfoImpl::GetName, removed files I forgot to remove before
This commit is contained in:
Родитель
e9bbeeaa9b
Коммит
db57fc1c82
|
@ -49,4 +49,34 @@ public:
|
|||
NS_IMETHOD GetConstant(uint16 index, const nsXPTConstant** constant) = 0;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// XXX this is here just for testing - pulled from XPConnect...
|
||||
// it can go away after nsIInterfaceInfos are being built from typelibs
|
||||
|
||||
// {159E36D0-991E-11d2-AC3F-00C09300144B}
|
||||
#define NS_ITESTXPC_FOO_IID \
|
||||
{ 0x159e36d0, 0x991e, 0x11d2, \
|
||||
{ 0xac, 0x3f, 0x0, 0xc0, 0x93, 0x0, 0x14, 0x4b } }
|
||||
|
||||
class nsITestXPCFoo : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD Test(int p1, int p2, int* retval) = 0;
|
||||
NS_IMETHOD Test2() = 0;
|
||||
};
|
||||
|
||||
// {5F9D20C0-9B6B-11d2-9FFE-000064657374}
|
||||
#define NS_ITESTXPC_FOO2_IID \
|
||||
{ 0x5f9d20c0, 0x9b6b, 0x11d2, \
|
||||
{ 0x9f, 0xfe, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
class nsITestXPCFoo2 : public nsITestXPCFoo
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
#endif /* nsIInterfaceInfo_h___ */
|
||||
|
|
|
@ -44,8 +44,19 @@ public:
|
|||
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
// XXX XXX Removed this block and switch XPC_PUBLIC_API to XPT_PUBLIC_API
|
||||
// when this code is moved to libxpt
|
||||
#include "jsapi.h"
|
||||
#ifdef EXPORT_XPC_API
|
||||
#define XPC_PUBLIC_API(t) JS_EXPORT_API(t)
|
||||
#else
|
||||
#define XPC_PUBLIC_API(t) JS_IMPORT_API(t)
|
||||
#endif
|
||||
/***************************************************************************/
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
// XXX remove this an use ServiceManager instead
|
||||
// XXX remove this and use ServiceManager instead
|
||||
XPC_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||
XPT_GetInterfaceInfoManager();
|
||||
JS_END_EXTERN_C
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include "nsISupports.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
/*
|
||||
* The linkage of XPC API functions differs depending on whether the file is
|
||||
|
@ -41,43 +43,9 @@
|
|||
#define XPC_FRIEND_API(t) XPC_PUBLIC_API(t)
|
||||
#define XPC_FRIEND_DATA(t) XPC_PUBLIC_DATA(t)
|
||||
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
|
||||
// XXX break these up into separate files...
|
||||
// XXX declare them in XPIDL :)
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// this is here just for testing...
|
||||
|
||||
// {159E36D0-991E-11d2-AC3F-00C09300144B}
|
||||
#define NS_ITESTXPC_FOO_IID \
|
||||
{ 0x159e36d0, 0x991e, 0x11d2, \
|
||||
{ 0xac, 0x3f, 0x0, 0xc0, 0x93, 0x0, 0x14, 0x4b } }
|
||||
|
||||
class nsITestXPCFoo : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD Test(int p1, int p2, int* retval) = 0;
|
||||
NS_IMETHOD Test2() = 0;
|
||||
};
|
||||
|
||||
// {5F9D20C0-9B6B-11d2-9FFE-000064657374}
|
||||
#define NS_ITESTXPC_FOO2_IID \
|
||||
{ 0x5f9d20c0, 0x9b6b, 0x11d2, \
|
||||
{ 0x9f, 0xfe, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
class nsITestXPCFoo2 : public nsITestXPCFoo
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
// forward declarations...
|
||||
class nsIXPCScriptable;
|
||||
|
@ -165,7 +133,7 @@ public:
|
|||
};
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
// XXX remove this an use ServiceManager instead
|
||||
// XXX remove this and use ServiceManager instead
|
||||
XPC_PUBLIC_API(nsIXPConnect*)
|
||||
XPC_GetXPConnect();
|
||||
JS_END_EXTERN_C
|
||||
|
|
|
@ -51,6 +51,38 @@ nsXPConnect::GetXPConnect()
|
|||
return mSelf;
|
||||
}
|
||||
|
||||
// static
|
||||
nsIAllocator*
|
||||
nsXPConnect::GetAllocator(nsXPConnect* xpc /*= NULL*/)
|
||||
{
|
||||
nsIAllocator* al;
|
||||
nsXPConnect* xpcl = xpc;
|
||||
|
||||
if(!xpcl && !(xpcl = GetXPConnect()))
|
||||
return NULL;
|
||||
if(NULL != (al = xpcl->mAllocator))
|
||||
NS_ADDREF(al);
|
||||
if(!xpc)
|
||||
NS_RELEASE(xpcl);
|
||||
return al;
|
||||
}
|
||||
|
||||
// static
|
||||
nsIInterfaceInfoManager*
|
||||
nsXPConnect::GetInterfaceInfoManager(nsXPConnect* xpc /*= NULL*/)
|
||||
{
|
||||
nsIInterfaceInfoManager* iim;
|
||||
nsXPConnect* xpcl = xpc;
|
||||
|
||||
if(!xpcl && !(xpcl = GetXPConnect()))
|
||||
return NULL;
|
||||
if(NULL != (iim = xpcl->mInterfaceInfoManager))
|
||||
NS_ADDREF(iim);
|
||||
if(!xpc)
|
||||
NS_RELEASE(xpcl);
|
||||
return iim;
|
||||
}
|
||||
|
||||
nsXPConnect::nsXPConnect()
|
||||
: mContextMap(NULL),
|
||||
mAllocator(NULL),
|
||||
|
|
|
@ -177,7 +177,6 @@ MyScriptable::DefaultValue(JSContext *cx, JSObject *obj,
|
|||
return arbitrary->DefaultValue(cx, obj, type, vp, wrapper, NULL, retval);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
class nsTestXPCFoo : public nsITestXPCFoo2
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Temporary Interface Info related stuff. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsInterfaceInfo, NS_IINTERFACEINFO_IID)
|
||||
|
||||
nsInterfaceInfo::nsInterfaceInfo(REFNSIID aIID, const char* aName,
|
||||
nsInterfaceInfo* aParent)
|
||||
: mIID(aIID),
|
||||
mName(strdup(aName)),
|
||||
mParent(aParent)
|
||||
{
|
||||
NS_PRECONDITION(aName, "bad param");
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
mMethodBaseIndex = mParent ?
|
||||
mParent->mMethodBaseIndex +
|
||||
mParent->mMethodCount : 0;
|
||||
|
||||
mConstantBaseIndex = mParent ?
|
||||
mParent->mConstantBaseIndex +
|
||||
mParent->mConstantCount : 0;
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// XXX completely bogus hardcoded stuff...
|
||||
|
||||
mMethodCount = 4;
|
||||
mMethods = new nsXPCMethodInfo[4];
|
||||
|
||||
nsXPCParamInfo* params = new nsXPCParamInfo[3];
|
||||
params[0] = nsXPCParamInfo(nsXPCParamInfo::IS_IN, nsXPCType::T_I32);
|
||||
params[1] = nsXPCParamInfo(nsXPCParamInfo::IS_IN, nsXPCType::T_I32);
|
||||
params[2] = nsXPCParamInfo(nsXPCParamInfo::IS_OUT | nsXPCParamInfo::IS_RETVAL, nsXPCType::T_I32);
|
||||
nsXPCParamInfo result = nsXPCParamInfo(nsXPCParamInfo::IS_OUT, nsXPCType::T_U32);
|
||||
|
||||
// XXX these are bogus declarations - don't call!
|
||||
mMethods[0] = nsXPCMethodInfo(0, "QueryInterface", 2, params, result);
|
||||
mMethods[1] = nsXPCMethodInfo(0, "AddRef", 0, NULL, result);
|
||||
mMethods[2] = nsXPCMethodInfo(0, "Release", 0, NULL, result);
|
||||
// this one should be callable (in test/TestXPC.cpp)
|
||||
mMethods[3] = nsXPCMethodInfo(0, "Test", 3, params, result);
|
||||
|
||||
///////
|
||||
|
||||
mConstantCount = 2;
|
||||
mConstants = new nsXPCConstant[2];
|
||||
|
||||
nsXPCVariant v;
|
||||
v.type = nsXPCType::T_I32;
|
||||
v.val.i32 = 5;
|
||||
mConstants[0] = nsXPCConstant("five", v);
|
||||
v.val.i32 = 6;
|
||||
mConstants[1] = nsXPCConstant("six", v);
|
||||
///////////////////////////////////////////////
|
||||
|
||||
|
||||
if(mParent)
|
||||
NS_ADDREF(mParent);
|
||||
}
|
||||
|
||||
nsInterfaceInfo::~nsInterfaceInfo()
|
||||
{
|
||||
if(mName)
|
||||
free(mName);
|
||||
if(mParent)
|
||||
NS_RELEASE(mParent);
|
||||
if(mMethods)
|
||||
delete [] mMethods;
|
||||
if(mConstants)
|
||||
delete [] mConstants;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceInfo::GetName(const char** name)
|
||||
{
|
||||
NS_PRECONDITION(name, "bad param");
|
||||
*name = mName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceInfo::GetIID(const nsIID** iid)
|
||||
{
|
||||
NS_PRECONDITION(iid, "bad param");
|
||||
*iid = &mIID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceInfo::GetParent(nsIInterfaceInfo** parent)
|
||||
{
|
||||
NS_PRECONDITION(parent, "bad param");
|
||||
*parent = mParent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceInfo::GetMethodCount(int* count)
|
||||
{
|
||||
NS_PRECONDITION(count, "bad param");
|
||||
*count = mMethodBaseIndex + mMethodCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceInfo::GetConstantCount(int* count)
|
||||
{
|
||||
NS_PRECONDITION(count, "bad param");
|
||||
*count = mConstantBaseIndex + mConstantCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceInfo::GetMethodInfo(unsigned index, const nsXPCMethodInfo** info)
|
||||
{
|
||||
NS_PRECONDITION(info, "bad param");
|
||||
if(index < mMethodBaseIndex)
|
||||
return mParent->GetMethodInfo(index, info);
|
||||
|
||||
if(index >= mMethodBaseIndex + mMethodCount)
|
||||
{
|
||||
NS_PRECONDITION(0, "bad param");
|
||||
*info = NULL;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// else...
|
||||
*info = &mMethods[mMethodBaseIndex+index];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceInfo::GetConstant(unsigned index, const nsXPCConstant** constant)
|
||||
{
|
||||
NS_PRECONDITION(constant, "bad param");
|
||||
if(index < mConstantBaseIndex)
|
||||
return mParent->GetConstant(index, constant);
|
||||
|
||||
if(index >= mConstantBaseIndex + mConstantCount)
|
||||
{
|
||||
NS_PRECONDITION(0, "bad param");
|
||||
*constant = NULL;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// else...
|
||||
*constant = &mConstants[mConstantBaseIndex+index];
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -1,280 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Temporary Interface Info related stuff. */
|
||||
|
||||
#ifndef xpcbogusii_h___
|
||||
#define xpcbogusii_h___
|
||||
|
||||
class nsXPCType
|
||||
{
|
||||
private:
|
||||
uint8 t; // only member
|
||||
|
||||
public:
|
||||
nsXPCType() {}
|
||||
nsXPCType(uint8 type) : t(type) {}
|
||||
|
||||
nsXPCType& operator=(uint8 type) {t = type; return *this;}
|
||||
operator uint8() const {return t;}
|
||||
|
||||
enum
|
||||
{
|
||||
IS_POINTER = 0x80,
|
||||
IS_UNIQUE_POINTER = 0x40,
|
||||
IS_REFERENCE = 0x20,
|
||||
TYPE_MASK = 0x1f,
|
||||
|
||||
T_I8 = 0,
|
||||
T_I16 = 1,
|
||||
T_I32 = 2,
|
||||
T_I64 = 3,
|
||||
T_U8 = 4,
|
||||
T_U16 = 5,
|
||||
T_U32 = 6,
|
||||
T_U64 = 7,
|
||||
T_FLOAT = 8,
|
||||
T_DOUBLE = 9,
|
||||
T_BOOL = 10,
|
||||
T_CHAR = 11,
|
||||
T_WCHAR = 12,
|
||||
T_VOID = 13,
|
||||
|
||||
T_P_I8 = IS_POINTER | 0,
|
||||
T_P_I16 = IS_POINTER | 1,
|
||||
T_P_I32 = IS_POINTER | 2,
|
||||
T_P_I64 = IS_POINTER | 3,
|
||||
T_P_U8 = IS_POINTER | 4,
|
||||
T_P_U16 = IS_POINTER | 5,
|
||||
T_P_U32 = IS_POINTER | 6,
|
||||
T_P_U64 = IS_POINTER | 7,
|
||||
T_P_FLOAT = IS_POINTER | 8,
|
||||
T_P_DOUBLE = IS_POINTER | 9,
|
||||
T_P_BOOL = IS_POINTER | 10,
|
||||
T_P_CHAR = IS_POINTER | 11,
|
||||
T_P_WCHAR = IS_POINTER | 12,
|
||||
T_P_VOID = IS_POINTER | 13,
|
||||
T_P_IID = IS_POINTER | 14,
|
||||
T_BSTR = IS_POINTER | 15,
|
||||
T_P_CHAR_STR = IS_POINTER | 16,
|
||||
T_P_WCHAR_STR = IS_POINTER | 17,
|
||||
|
||||
T_INTERFACE = 18,
|
||||
T_INTERFACE_IS = 19
|
||||
};
|
||||
};
|
||||
|
||||
// this is used only for WrappedJS stub param repackaging
|
||||
struct nsXPCMiniVariant
|
||||
{
|
||||
// No ctors or dtors so that we can use arrays of these on the stack
|
||||
// with no penalty.
|
||||
union
|
||||
{
|
||||
int8 i8;
|
||||
int16 i16;
|
||||
int32 i32;
|
||||
int64 i64;
|
||||
uint8 u8;
|
||||
uint16 u16;
|
||||
uint32 u32;
|
||||
uint64 u64;
|
||||
float f;
|
||||
double d;
|
||||
PRBool b;
|
||||
char c;
|
||||
wchar_t wc;
|
||||
void* p;
|
||||
} val;
|
||||
};
|
||||
|
||||
struct nsXPCVariant
|
||||
{
|
||||
// No ctors or dtors so that we can use arrays of these on the stack
|
||||
// with no penalty.
|
||||
union
|
||||
{
|
||||
int8 i8;
|
||||
int16 i16;
|
||||
int32 i32;
|
||||
int64 i64;
|
||||
uint8 u8;
|
||||
uint16 u16;
|
||||
uint32 u32;
|
||||
uint64 u64;
|
||||
float f;
|
||||
double d;
|
||||
PRBool b;
|
||||
char c;
|
||||
wchar_t wc;
|
||||
void* p;
|
||||
nsID id;
|
||||
|
||||
} val;
|
||||
void* ptr;
|
||||
void* ptr2;
|
||||
nsXPCType type;
|
||||
uint8 flags;
|
||||
|
||||
enum
|
||||
{
|
||||
PTR_IS_DATA = 0x1, // used for OUT params, ptr points to data in val
|
||||
VAL_IS_OWNED = 0x2 // val.p holds an alloced ptr that must be freed
|
||||
};
|
||||
|
||||
JSBool IsPtrData() const {return (JSBool) (flags & PTR_IS_DATA);}
|
||||
JSBool IsValOwned() const {return (JSBool) (flags & VAL_IS_OWNED);}
|
||||
};
|
||||
|
||||
|
||||
class nsXPCParamInfo
|
||||
{
|
||||
public:
|
||||
// XXX simple ctors, we can do better
|
||||
nsXPCParamInfo() {}
|
||||
nsXPCParamInfo(uint8 aFlags, const nsXPCType& aType)
|
||||
: mFlags(aFlags), mType(aType) {}
|
||||
|
||||
enum
|
||||
{
|
||||
IS_IN = 0x80,
|
||||
IS_OUT = 0x40,
|
||||
IS_RETVAL = 0x20
|
||||
};
|
||||
|
||||
JSBool IsIn() const {return (JSBool) (mFlags & IS_IN);}
|
||||
JSBool IsOut() const {return (JSBool) (mFlags & IS_OUT);}
|
||||
JSBool IsRetval() const {return (JSBool) (mFlags & IS_RETVAL);}
|
||||
const nsXPCType& GetType() const {return mType;}
|
||||
uint8 GetInterfaceIsArgNumber() const
|
||||
{
|
||||
NS_PRECONDITION(mType == nsXPCType::T_INTERFACE_IS,"not an interface_is");
|
||||
return mInterfaceIsArgNum;
|
||||
}
|
||||
nsIInterfaceInfo* GetInterface() const
|
||||
{
|
||||
NS_PRECONDITION(mType == nsXPCType::T_INTERFACE,"not an interface");
|
||||
return mInterface;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8 mFlags;
|
||||
nsXPCType mType;
|
||||
// XXX mostly ignoring this for now...
|
||||
union
|
||||
{
|
||||
uint8 mInterfaceIsArgNum;
|
||||
nsIInterfaceInfo* mInterface;
|
||||
};
|
||||
};
|
||||
|
||||
class nsXPCMethodInfo
|
||||
{
|
||||
public:
|
||||
// XXX simple ctors, we can do better
|
||||
// XXX the pointer stuff (especially) needs to be fixed
|
||||
nsXPCMethodInfo() {}
|
||||
nsXPCMethodInfo(uint8 aFlags,
|
||||
char* aName,
|
||||
uint8 aParamCount,
|
||||
nsXPCParamInfo* aParams,
|
||||
const nsXPCParamInfo& aResult)
|
||||
: mFlags(aFlags), mName(aName),
|
||||
mParamCount(aParamCount), mParams(aParams), mResult(aResult) {}
|
||||
|
||||
enum
|
||||
{
|
||||
IS_GETTER = 0x80,
|
||||
IS_SETTER = 0x40,
|
||||
IS_VAR_ARGS = 0x20,
|
||||
IS_CONSTRUCTOR = 0x10,
|
||||
IS_HIDDEN = 0x08
|
||||
};
|
||||
|
||||
JSBool IsGetter() const {return (JSBool) (mFlags & IS_GETTER);}
|
||||
JSBool IsSetter() const {return (JSBool) (mFlags & IS_SETTER);}
|
||||
JSBool IsVarArgs() const {return (JSBool) (mFlags & IS_VAR_ARGS);}
|
||||
JSBool IsConstructor() const {return (JSBool) (mFlags & IS_CONSTRUCTOR);}
|
||||
JSBool IsHidden() const {return (JSBool) (mFlags & IS_HIDDEN);}
|
||||
const char* GetName() const {return mName;}
|
||||
uint8 GetParamCount() const {return mParamCount;}
|
||||
const nsXPCParamInfo& GetParam(uint8 index) const
|
||||
{
|
||||
NS_PRECONDITION(index < mParamCount,"bad arg");
|
||||
return mParams[index];
|
||||
}
|
||||
const nsXPCParamInfo& GetResult() const {return mResult;}
|
||||
private:
|
||||
uint8 mFlags;
|
||||
char* mName;
|
||||
uint8 mParamCount;
|
||||
nsXPCParamInfo* mParams;
|
||||
nsXPCParamInfo mResult;
|
||||
};
|
||||
|
||||
class nsXPCConstant
|
||||
{
|
||||
public:
|
||||
// XXX simple ctors, we can do better
|
||||
nsXPCConstant() {}
|
||||
nsXPCConstant(char* aName, const nsXPCVariant& aVal)
|
||||
: mName(aName), mVal(aVal) {};
|
||||
|
||||
const char* GetName() const {return mName;}
|
||||
const nsXPCVariant& GetValue() const {return mVal;}
|
||||
private:
|
||||
char* mName;
|
||||
nsXPCVariant mVal;
|
||||
};
|
||||
|
||||
class nsInterfaceInfo : public nsIInterfaceInfo
|
||||
{
|
||||
NS_DECL_ISUPPORTS;
|
||||
|
||||
NS_IMETHOD GetName(const char** name);
|
||||
NS_IMETHOD GetIID(const nsIID** iid);
|
||||
|
||||
NS_IMETHOD GetParent(nsIInterfaceInfo** parent);
|
||||
|
||||
// these include counts of parents
|
||||
NS_IMETHOD GetMethodCount(int* count);
|
||||
NS_IMETHOD GetConstantCount(int* count);
|
||||
|
||||
// these include methods and constants of parents
|
||||
NS_IMETHOD GetMethodInfo(unsigned index, const nsXPCMethodInfo** info);
|
||||
NS_IMETHOD GetConstant(unsigned index, const nsXPCConstant** constant);
|
||||
|
||||
public:
|
||||
nsInterfaceInfo(REFNSIID aIID, const char* aName, nsInterfaceInfo* aParent);
|
||||
virtual ~nsInterfaceInfo();
|
||||
|
||||
private:
|
||||
char* mName;
|
||||
nsIID mIID;
|
||||
nsInterfaceInfo* mParent;
|
||||
|
||||
unsigned mMethodBaseIndex;
|
||||
unsigned mMethodCount;
|
||||
nsXPCMethodInfo* mMethods;
|
||||
|
||||
unsigned mConstantBaseIndex;
|
||||
unsigned mConstantCount;
|
||||
nsXPCConstant* mConstants;
|
||||
};
|
||||
|
||||
#endif /* xpcbogusii_h___ */
|
|
@ -66,23 +66,12 @@ class nsXPConnect : public nsIXPConnect
|
|||
// non-interface implementation
|
||||
public:
|
||||
static nsXPConnect* GetXPConnect();
|
||||
static nsIAllocator* GetAllocator(nsXPConnect* xpc = NULL);
|
||||
static nsIInterfaceInfoManager* GetInterfaceInfoManager(nsXPConnect* xpc = NULL);
|
||||
|
||||
XPCContext* GetContext(JSContext* cx);
|
||||
JSContext2XPCContextMap* GetContextMap() {return mContextMap;}
|
||||
nsIXPCScriptable* GetArbitraryScriptable() {return mArbitraryScriptable;}
|
||||
nsIAllocator* GetAllocator()
|
||||
{
|
||||
if(mAllocator)
|
||||
NS_ADDREF(mAllocator);
|
||||
return mAllocator;
|
||||
}
|
||||
|
||||
nsIInterfaceInfoManager* GetInterfaceInfoManager()
|
||||
{
|
||||
if(mInterfaceInfoManager)
|
||||
NS_ADDREF(mInterfaceInfoManager);
|
||||
return mInterfaceInfoManager;
|
||||
}
|
||||
|
||||
virtual ~nsXPConnect();
|
||||
private:
|
||||
|
|
|
@ -299,16 +299,17 @@ nsXPCWrappedJSMethods::GetIID(nsIID** iid)
|
|||
NS_PRECONDITION(iid, "bad param");
|
||||
|
||||
nsIAllocator* al;
|
||||
void* p;
|
||||
|
||||
al = mWrapper->GetClass()->GetXPCContext()->GetXPConnect()->GetAllocator();
|
||||
if(!al || NULL == (p = al->Alloc(sizeof(nsIID))))
|
||||
if(NULL != (al = nsXPConnect::GetAllocator()))
|
||||
{
|
||||
*iid = NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
void* p = al->Alloc(sizeof(nsIID));
|
||||
NS_RELEASE(al);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &mWrapper->GetIID(), sizeof(nsIID));
|
||||
*iid = (nsIID*)p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
NS_RELEASE(al);
|
||||
memcpy(p, &mWrapper->GetIID(), sizeof(nsIID));
|
||||
*iid = (nsIID*)p;
|
||||
return NS_OK;
|
||||
*iid = NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
|
|
@ -46,21 +46,16 @@ nsXPCWrappedJSClass::GetNewOrUsedClass(XPCContext* xpcc,
|
|||
}
|
||||
else
|
||||
{
|
||||
nsXPConnect* xpc;
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL)
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if(NULL != (iimgr = nsXPConnect::GetInterfaceInfoManager()))
|
||||
{
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if((iimgr = xpc->GetInterfaceInfoManager()) != NULL)
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
clazz = new nsXPCWrappedJSClass(xpcc, aIID, info);
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
clazz = new nsXPCWrappedJSClass(xpcc, aIID, info);
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
NS_RELEASE(iimgr);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
|
|
|
@ -328,16 +328,17 @@ nsXPCWrappedNative::GetIID(nsIID** iid)
|
|||
NS_PRECONDITION(iid, "bad param");
|
||||
|
||||
nsIAllocator* al;
|
||||
void* p;
|
||||
|
||||
al = GetClass()->GetXPCContext()->GetXPConnect()->GetAllocator();
|
||||
if(!al || NULL == (p = al->Alloc(sizeof(nsIID))))
|
||||
if(NULL != (al = nsXPConnect::GetAllocator()))
|
||||
{
|
||||
*iid = NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
void* p = al->Alloc(sizeof(nsIID));
|
||||
NS_RELEASE(al);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &GetIID(), sizeof(nsIID));
|
||||
*iid = (nsIID*)p;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
NS_RELEASE(al);
|
||||
memcpy(p, &GetIID(), sizeof(nsIID));
|
||||
*iid = (nsIID*)p;
|
||||
return NS_OK;
|
||||
*iid = NULL;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
|
|
@ -46,23 +46,18 @@ nsXPCWrappedNativeClass::GetNewOrUsedClass(XPCContext* xpcc,
|
|||
}
|
||||
else
|
||||
{
|
||||
nsXPConnect* xpc;
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL)
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if(NULL != (iimgr = nsXPConnect::GetInterfaceInfoManager()))
|
||||
{
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if((iimgr = xpc->GetInterfaceInfoManager()) != NULL)
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
nsIInterfaceInfo* info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, &info)))
|
||||
{
|
||||
clazz = new nsXPCWrappedNativeClass(xpcc, aIID, info);
|
||||
if(-1 == clazz->mMemberCount) // -1 means 'failed to init'
|
||||
NS_RELEASE(clazz); // NULLs out 'clazz'
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
clazz = new nsXPCWrappedNativeClass(xpcc, aIID, info);
|
||||
if(-1 == clazz->mMemberCount) // -1 means 'failed to init'
|
||||
NS_RELEASE(clazz); // NULLs out 'clazz'
|
||||
NS_RELEASE(info);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
NS_RELEASE(iimgr);
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
|
@ -93,16 +88,11 @@ nsXPCWrappedNativeClass::~nsXPCWrappedNativeClass()
|
|||
DestroyMemberDescriptors();
|
||||
if(mName)
|
||||
{
|
||||
nsXPConnect* xpc;
|
||||
if((xpc = nsXPConnect::GetXPConnect()) != NULL)
|
||||
nsIAllocator* al;
|
||||
if(NULL != (al = nsXPConnect::GetAllocator()))
|
||||
{
|
||||
nsIAllocator* al;
|
||||
if((al = xpc->GetAllocator()) != NULL)
|
||||
{
|
||||
al->Free(mName);
|
||||
NS_RELEASE(al);
|
||||
}
|
||||
NS_RELEASE(xpc);
|
||||
al->Free(mName);
|
||||
NS_RELEASE(al);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(mInfo);
|
||||
|
@ -144,8 +134,8 @@ nsXPCWrappedNativeClass::BuildMemberDescriptors()
|
|||
if(NS_FAILED(mInfo->GetMethodInfo(i, &info)))
|
||||
return JS_FALSE;
|
||||
|
||||
// XX perhaps this should be extended to be 'CanBeReflected()' to
|
||||
// also cover methods with non-complient signatures.
|
||||
// XXX perhaps this should be extended to be 'CanBeReflected()' to
|
||||
// also cover methods with non-compliant signatures.
|
||||
if(info->IsHidden())
|
||||
continue;
|
||||
|
||||
|
@ -282,7 +272,7 @@ isConstructorID(JSContext *cx, jsid id)
|
|||
{
|
||||
jsval idval;
|
||||
const char *property_name;
|
||||
|
||||
// XXX this could be improved by cacheing the hashed id for "constructor"
|
||||
if (JS_IdToValue(cx, id, &idval) && JSVAL_IS_STRING(idval) &&
|
||||
(property_name = JS_GetStringBytes(JSVAL_TO_STRING(idval))) != NULL) {
|
||||
if (!strcmp(property_name, "constructor")) {
|
||||
|
@ -386,6 +376,7 @@ nsXPCWrappedNativeClass::CallWrappedMethod(nsXPCWrappedNative* wrapper,
|
|||
nsresult invokeResult;
|
||||
|
||||
*vp = JSVAL_NULL;
|
||||
|
||||
// make sure we have what we need
|
||||
|
||||
if(isAttributeSet)
|
||||
|
|
|
@ -18,7 +18,16 @@
|
|||
|
||||
/* InterfaceInfo support code - some temporary. */
|
||||
|
||||
#include "xpcprivate.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIInterfaceInfo.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "xpt_struct.h"
|
||||
#include "xpt_cpp.h"
|
||||
|
||||
// declare this in the .cpp file for now
|
||||
class InterfaceInfoImpl : public nsIInterfaceInfo
|
||||
|
@ -44,10 +53,6 @@ public:
|
|||
InterfaceInfoImpl* parent);
|
||||
virtual ~InterfaceInfoImpl();
|
||||
|
||||
private:
|
||||
PRBool GetAllocator(nsIAllocator** allocator);
|
||||
void ReleaseAllocator(nsIAllocator** allocator);
|
||||
|
||||
private:
|
||||
XPTInterfaceDirectoryEntry* mEntry;
|
||||
InterfaceInfoImpl* mParent;
|
||||
|
@ -57,8 +62,6 @@ private:
|
|||
uint16 mConstantCount;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// declare this in the .cpp file for now
|
||||
class InterfaceInfoManagerImpl : public nsIInterfaceInfoManager
|
||||
{
|
||||
|
@ -75,6 +78,9 @@ class InterfaceInfoManagerImpl : public nsIInterfaceInfoManager
|
|||
public:
|
||||
InterfaceInfoManagerImpl();
|
||||
~InterfaceInfoManagerImpl();
|
||||
|
||||
static InterfaceInfoManagerImpl* GetInterfaceInfoManager();
|
||||
static nsIAllocator* GetAllocator(InterfaceInfoManagerImpl* iim = NULL);
|
||||
private:
|
||||
PRBool BuildInterfaceForEntry(uint16 index);
|
||||
|
||||
|
@ -84,6 +90,7 @@ private:
|
|||
nsIAllocator* mAllocator;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// hacked hardcoded simulation...
|
||||
|
@ -94,7 +101,7 @@ XPTParamDescriptor ResultParam[] = {
|
|||
|
||||
XPTParamDescriptor QueryInterfaceParams[2] = {
|
||||
{XPT_PD_IN, {TD_PNSIID|XPT_TDP_POINTER|XPT_TDP_REFERENCE,0}},
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_PVOID,0}}
|
||||
{XPT_PD_OUT|XPT_PD_RETVAL, {TD_INTERFACE_IS_TYPE,0}}
|
||||
};
|
||||
|
||||
XPTParamDescriptor TestParams[3] = {
|
||||
|
@ -149,12 +156,12 @@ nsXPTParamInfo::GetInterface() const
|
|||
{
|
||||
NS_PRECONDITION(GetType() == nsXPTType::T_INTERFACE,"not an interface");
|
||||
|
||||
// not optimal!
|
||||
nsIInterfaceInfoManager* mgr = XPT_GetInterfaceInfoManager();
|
||||
if(!mgr)
|
||||
nsIInterfaceInfoManager* mgr;
|
||||
if(!(mgr = InterfaceInfoManagerImpl::GetInterfaceInfoManager()))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo* info;
|
||||
// not optimal!
|
||||
mgr->GetInfoForIID(&InterfaceDirectoryEntryTable[type.type.interface].iid,
|
||||
&info);
|
||||
NS_RELEASE(mgr);
|
||||
|
@ -168,6 +175,13 @@ NS_IMPL_ISUPPORTS(InterfaceInfoManagerImpl, NS_IINTERFACEINFO_MANAGER_IID)
|
|||
|
||||
XPC_PUBLIC_API(nsIInterfaceInfoManager*)
|
||||
XPT_GetInterfaceInfoManager()
|
||||
{
|
||||
return InterfaceInfoManagerImpl::GetInterfaceInfoManager();
|
||||
}
|
||||
|
||||
// static
|
||||
InterfaceInfoManagerImpl*
|
||||
InterfaceInfoManagerImpl::GetInterfaceInfoManager()
|
||||
{
|
||||
static InterfaceInfoManagerImpl* impl = NULL;
|
||||
if(!impl)
|
||||
|
@ -178,7 +192,24 @@ XPT_GetInterfaceInfoManager()
|
|||
if(impl)
|
||||
NS_ADDREF(impl);
|
||||
return impl;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
nsIAllocator*
|
||||
InterfaceInfoManagerImpl::GetAllocator(InterfaceInfoManagerImpl* iim /*= NULL*/)
|
||||
{
|
||||
nsIAllocator* al;
|
||||
InterfaceInfoManagerImpl* iiml = iim;
|
||||
|
||||
if(!iiml && !(iiml = GetInterfaceInfoManager()))
|
||||
return NULL;
|
||||
if(NULL != (al = iiml->mAllocator))
|
||||
NS_ADDREF(al);
|
||||
if(!iim)
|
||||
NS_RELEASE(iiml);
|
||||
return al;
|
||||
}
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
||||
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
||||
|
@ -332,35 +363,20 @@ InterfaceInfoImpl::~InterfaceInfoImpl()
|
|||
NS_RELEASE(mParent);
|
||||
}
|
||||
|
||||
PRBool
|
||||
InterfaceInfoImpl::GetAllocator(nsIAllocator** allocator)
|
||||
{
|
||||
return NS_SUCCEEDED(nsServiceManager::GetService(kAllocatorCID,
|
||||
kIAllocatorIID,
|
||||
(nsISupports **)allocator));
|
||||
}
|
||||
void
|
||||
InterfaceInfoImpl::ReleaseAllocator(nsIAllocator** allocator)
|
||||
{
|
||||
nsServiceManager::ReleaseService(kAllocatorCID,
|
||||
(nsISupports *)*allocator, NULL);
|
||||
*allocator = NULL;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetName(char** name)
|
||||
{
|
||||
nsIAllocator* allocator;
|
||||
|
||||
NS_PRECONDITION(name, "bad param");
|
||||
if(GetAllocator(&allocator))
|
||||
|
||||
nsIAllocator* allocator;
|
||||
if(NULL != (allocator = InterfaceInfoManagerImpl::GetAllocator()))
|
||||
{
|
||||
int len = strlen(mEntry->name)+1;
|
||||
char* p = (char*)allocator->Alloc(len);
|
||||
ReleaseAllocator(&allocator);
|
||||
NS_RELEASE(allocator);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &mEntry->name, len);
|
||||
memcpy(p, mEntry->name, len);
|
||||
*name = p;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -373,13 +389,13 @@ InterfaceInfoImpl::GetName(char** name)
|
|||
NS_IMETHODIMP
|
||||
InterfaceInfoImpl::GetIID(nsIID** iid)
|
||||
{
|
||||
nsIAllocator* allocator;
|
||||
|
||||
NS_PRECONDITION(iid, "bad param");
|
||||
if(GetAllocator(&allocator))
|
||||
|
||||
nsIAllocator* allocator;
|
||||
if(NULL != (allocator = InterfaceInfoManagerImpl::GetAllocator()))
|
||||
{
|
||||
nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID));
|
||||
ReleaseAllocator(&allocator);
|
||||
NS_RELEASE(allocator);
|
||||
if(p)
|
||||
{
|
||||
memcpy(p, &mEntry->iid, sizeof(nsIID));
|
||||
|
|
Загрузка…
Ссылка в новой задаче