зеркало из https://github.com/mozilla/pjs.git
bug 123770. extend xpconnect to use dynamic 'additional' interface info managers to support dynamic type info. Also, abstract out the Components.interfaces object and make the items use a bit less memory. r=dbradley sr=vidur
This commit is contained in:
Родитель
a37fc12bb6
Коммит
65e43ae322
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -12,4 +12,5 @@ xpcjsid.idl
|
|||
nsIScriptError.idl
|
||||
mozIJSSubScriptLoader.idl
|
||||
nsIXPCScriptable.idl
|
||||
nsIXPCScriptNotify.idl
|
||||
nsIXPCScriptNotify.idl
|
||||
nsIScriptableInterfaces.idl
|
||||
|
|
|
@ -52,6 +52,7 @@ XPIDLSRCS = \
|
|||
nsIScriptError.idl \
|
||||
mozIJSSubScriptLoader.idl \
|
||||
nsIXPCScriptNotify.idl \
|
||||
nsIScriptableInterfaces.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -47,6 +47,7 @@ XPIDLSRCS = \
|
|||
.\nsIScriptError.idl \
|
||||
.\mozIJSSubScriptLoader.idl \
|
||||
.\nsIXPCScriptNotify.idl \
|
||||
.\nsIScriptableInterfaces.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* -*- 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2002 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Bandhauer <jband@netscape.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU Public License (the "GPL"), in which case the
|
||||
* provisions of the GPL are applicable instead of those above.
|
||||
* If you wish to allow use of your version of this file only
|
||||
* under the terms of the GPL and not to allow others to use your
|
||||
* version of this file under the NPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this
|
||||
* file under either the NPL or the GPL.
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIInterfaceInfoManager.idl"
|
||||
|
||||
/**
|
||||
* Interface used as Components.interfaces (and elsewhere)
|
||||
* (interesting stuff only reflected into JavaScript)
|
||||
*/
|
||||
[scriptable, uuid(01c78c65-31da-456b-90bf-da39d09fdcbf)]
|
||||
interface nsIScriptableInterfaces : nsISupports
|
||||
{
|
||||
[noscript] attribute nsIInterfaceInfoManager manager;
|
||||
};
|
||||
|
||||
%{C++
|
||||
// The contractID for the implementation built into xpconnect
|
||||
#define NS_SCRIPTABLE_INTERFACES_CONTRACTID "@mozilla.org/scriptableinterfaces;1"
|
||||
%}
|
||||
|
||||
|
|
@ -37,15 +37,7 @@
|
|||
#include "xpcexception.idl"
|
||||
#include "xpcjsid.idl"
|
||||
#include "nsIComponentManager.idl"
|
||||
|
||||
/**
|
||||
* interface of Components.interfaces
|
||||
* (interesting stuff only reflected into JavaScript)
|
||||
*/
|
||||
[scriptable, uuid(4b62a640-d26c-11d2-9842-006008962422)]
|
||||
interface nsIXPCComponents_Interfaces : nsISupports
|
||||
{
|
||||
};
|
||||
#include "nsIScriptableInterfaces.idl"
|
||||
|
||||
/**
|
||||
* interface of Components.classes
|
||||
|
@ -119,7 +111,7 @@ interface nsIXPCConstructor : nsISupports
|
|||
[scriptable, uuid(42624f80-d26c-11d2-9842-006008962422)]
|
||||
interface nsIXPCComponents : nsISupports
|
||||
{
|
||||
readonly attribute nsIXPCComponents_Interfaces interfaces;
|
||||
readonly attribute nsIScriptableInterfaces interfaces;
|
||||
readonly attribute nsIXPCComponents_Classes classes;
|
||||
readonly attribute nsIXPCComponents_ClassesByID classesByID;
|
||||
readonly attribute nsIStackFrame stack;
|
||||
|
|
|
@ -961,6 +961,9 @@ main(int argc, char **argv)
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
/* XXXbe writeme */
|
||||
#if 0
|
||||
|
||||
#include "jsatom.h"
|
||||
#ifdef DEBUG
|
||||
int
|
||||
|
@ -1002,3 +1005,5 @@ void Datom(JSAtom *atom) { if (atom) DumpAtom(&atom->entry, 0, gErrFile); }
|
|||
//void Dxpc(int depth) {Dobj(GetXPConnect(), depth);}
|
||||
JS_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -68,7 +68,9 @@ nsXPConnect::nsXPConnect()
|
|||
// then we'll set this up later as needed.
|
||||
CreateRuntime();
|
||||
|
||||
mInterfaceInfoManager = XPTI_GetInterfaceInfoManager();
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
||||
dont_AddRef(XPTI_GetInterfaceInfoManager());
|
||||
CallQueryInterface(iim, &mInterfaceInfoManager);
|
||||
|
||||
nsServiceManager::GetService(XPC_CONTEXT_STACK_CONTRACTID,
|
||||
NS_GET_IID(nsIThreadJSContextStack),
|
||||
|
@ -241,16 +243,14 @@ nsXPConnect::ReleaseXPConnectSingleton()
|
|||
|
||||
// static
|
||||
nsresult
|
||||
nsXPConnect::GetInterfaceInfoManager(nsIInterfaceInfoManager** iim,
|
||||
nsXPConnect::GetInterfaceInfoManager(nsIInterfaceInfoSuperManager** iim,
|
||||
nsXPConnect* xpc /*= nsnull*/)
|
||||
{
|
||||
nsIInterfaceInfoManager* temp;
|
||||
|
||||
if(!xpc && !(xpc = GetXPConnect()))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*iim = temp = xpc->mInterfaceInfoManager;
|
||||
NS_IF_ADDREF(temp);
|
||||
*iim = xpc->mInterfaceInfoManager;
|
||||
NS_IF_ADDREF(*iim);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -342,6 +342,67 @@ nsXPConnect::FindMainThread()
|
|||
return gMainThread;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef PRBool (*InfoTester)(nsIInterfaceInfoManager* manager, const void* data,
|
||||
nsIInterfaceInfo** info);
|
||||
|
||||
static PRBool IIDTester(nsIInterfaceInfoManager* manager, const void* data,
|
||||
nsIInterfaceInfo** info)
|
||||
{
|
||||
return NS_SUCCEEDED(manager->GetInfoForIID((const nsIID *) data, info)) &&
|
||||
*info;
|
||||
}
|
||||
|
||||
static PRBool NameTester(nsIInterfaceInfoManager* manager, const void* data,
|
||||
nsIInterfaceInfo** info)
|
||||
{
|
||||
return NS_SUCCEEDED(manager->GetInfoForName((const char *) data, info)) &&
|
||||
*info;
|
||||
}
|
||||
|
||||
static nsresult FindInfo(InfoTester tester, const void* data,
|
||||
nsIInterfaceInfoSuperManager* iism,
|
||||
nsIInterfaceInfo** info)
|
||||
{
|
||||
if(tester(iism, data, info))
|
||||
return NS_OK;
|
||||
|
||||
// If not found, then let's ask additional managers.
|
||||
|
||||
PRBool yes;
|
||||
nsCOMPtr<nsISimpleEnumerator> list;
|
||||
|
||||
if(NS_SUCCEEDED(iism->HasAdditionalManagers(&yes)) && yes &&
|
||||
NS_SUCCEEDED(iism->EnumerateAdditionalManagers(getter_AddRefs(list))) &&
|
||||
list)
|
||||
{
|
||||
PRBool more;
|
||||
nsCOMPtr<nsIInterfaceInfoManager> current;
|
||||
|
||||
while(NS_SUCCEEDED(list->HasMoreElements(&more)) && more &&
|
||||
NS_SUCCEEDED(list->GetNext(getter_AddRefs(current))) && current)
|
||||
{
|
||||
if(tester(current, data, info))
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXPConnect::GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info)
|
||||
{
|
||||
return FindInfo(IIDTester, aIID, mInterfaceInfoManager, info);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXPConnect::GetInfoForName(const char * name, nsIInterfaceInfo** info)
|
||||
{
|
||||
return FindInfo(NameTester, name, mInterfaceInfoManager, info);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
// nsIXPConnect interface methods...
|
||||
|
|
|
@ -91,30 +91,10 @@ char * xpc_CheckAccessList(const PRUnichar* wideName, const char* list[])
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
class nsXPCComponents_Interfaces :
|
||||
public nsIXPCComponents_Interfaces,
|
||||
public nsIXPCScriptable
|
||||
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
||||
, public nsISecurityCheckedComponent
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
// all the interface method declarations...
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIXPCCOMPONENTS_INTERFACES
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
#endif
|
||||
|
||||
public:
|
||||
nsXPCComponents_Interfaces();
|
||||
virtual ~nsXPCComponents_Interfaces();
|
||||
};
|
||||
|
||||
nsXPCComponents_Interfaces::nsXPCComponents_Interfaces()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mManager = dont_AddRef(XPTI_GetInterfaceInfoManager());
|
||||
}
|
||||
|
||||
nsXPCComponents_Interfaces::~nsXPCComponents_Interfaces()
|
||||
|
@ -123,13 +103,26 @@ nsXPCComponents_Interfaces::~nsXPCComponents_Interfaces()
|
|||
}
|
||||
|
||||
|
||||
/* [noscript] attribute nsIInterfaceInfoManager manager; */
|
||||
NS_IMETHODIMP nsXPCComponents_Interfaces::GetManager(nsIInterfaceInfoManager * *aManager)
|
||||
{
|
||||
*aManager = mManager;
|
||||
NS_IF_ADDREF(*aManager);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsXPCComponents_Interfaces::SetManager(nsIInterfaceInfoManager * aManager)
|
||||
{
|
||||
mManager = aManager;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsXPCComponents_Interfaces)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIXPCComponents_Interfaces)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIScriptableInterfaces)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
|
||||
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
||||
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
|
||||
#endif
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCComponents_Interfaces)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptableInterfaces)
|
||||
NS_INTERFACE_MAP_END_THREADSAFE
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsXPCComponents_Interfaces)
|
||||
|
@ -158,10 +151,8 @@ nsXPCComponents_Interfaces::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
|
|||
{
|
||||
case JSENUMERATE_INIT:
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfoManager>
|
||||
iim(dont_AddRef(XPTI_GetInterfaceInfoManager()));
|
||||
|
||||
if(!iim || NS_FAILED(iim->EnumerateInterfaces(&e)) || !e ||
|
||||
if(!mManager ||
|
||||
NS_FAILED(mManager->EnumerateInterfaces(&e)) || !e ||
|
||||
NS_FAILED(e->First()))
|
||||
|
||||
{
|
||||
|
@ -231,12 +222,19 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
|||
{
|
||||
const char* name = nsnull;
|
||||
|
||||
if(JSVAL_IS_STRING(id) &&
|
||||
if(mManager &&
|
||||
JSVAL_IS_STRING(id) &&
|
||||
nsnull != (name = JS_GetStringBytes(JSVAL_TO_STRING(id))) &&
|
||||
name[0] != '{') // we only allow interfaces by name here
|
||||
{
|
||||
nsCOMPtr<nsIJSIID> nsid =
|
||||
dont_AddRef(NS_STATIC_CAST(nsIJSIID*,nsJSIID::NewID(name)));
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
mManager->GetInfoForName(name, getter_AddRefs(info));
|
||||
if(!info)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIJSIID> nsid =
|
||||
dont_AddRef(NS_STATIC_CAST(nsIJSIID*, nsJSIID::NewID(info)));
|
||||
|
||||
if(nsid)
|
||||
{
|
||||
nsCOMPtr<nsIXPConnect> xpc;
|
||||
|
@ -1392,7 +1390,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
|||
// argv[1] is an iid name string
|
||||
// XXXjband support passing "Components.interfaces.foo"?
|
||||
|
||||
nsCOMPtr<nsIXPCComponents_Interfaces> ifaces;
|
||||
nsCOMPtr<nsIScriptableInterfaces> ifaces;
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
JSObject* ifacesObj = nsnull;
|
||||
|
||||
|
@ -1402,7 +1400,7 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
|||
|
||||
if(NS_FAILED(comp->GetInterfaces(getter_AddRefs(ifaces))) ||
|
||||
NS_FAILED(xpc->WrapNative(cx, obj, ifaces,
|
||||
NS_GET_IID(nsIXPCComponents_Interfaces),
|
||||
NS_GET_IID(nsIScriptableInterfaces),
|
||||
getter_AddRefs(holder))) || !holder ||
|
||||
NS_FAILED(holder->GetJSObject(&ifacesObj)) || !ifacesObj)
|
||||
{
|
||||
|
@ -1432,9 +1430,15 @@ nsXPCComponents_Constructor::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
|
|||
}
|
||||
else
|
||||
{
|
||||
cInterfaceID =
|
||||
dont_AddRef(
|
||||
NS_STATIC_CAST(nsIJSIID*, nsJSIID::NewID("nsISupports")));
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
xpc->GetInfoForIID(&NS_GET_IID(nsISupports), getter_AddRefs(info));
|
||||
|
||||
if(info)
|
||||
{
|
||||
cInterfaceID =
|
||||
dont_AddRef(
|
||||
NS_STATIC_CAST(nsIJSIID*, nsJSIID::NewID(info)));
|
||||
}
|
||||
if(!cInterfaceID)
|
||||
return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
|
||||
}
|
||||
|
@ -1560,8 +1564,8 @@ nsXPCComponents::~nsXPCComponents()
|
|||
}
|
||||
|
||||
/*******************************************/
|
||||
#define XPC_IMPL_GET_OBJ_METHOD(_n) \
|
||||
NS_IMETHODIMP nsXPCComponents::Get##_n(nsIXPCComponents_##_n * *a##_n) { \
|
||||
#define XPC_IMPL_GET_OBJ_METHOD(_b, _n) \
|
||||
NS_IMETHODIMP nsXPCComponents::Get##_n(_b##_n * *a##_n) { \
|
||||
NS_ENSURE_ARG_POINTER(a##_n); \
|
||||
if(!m##_n) { \
|
||||
if(!(m##_n = new nsXPCComponents_##_n())) { \
|
||||
|
@ -1575,13 +1579,13 @@ NS_IMETHODIMP nsXPCComponents::Get##_n(nsIXPCComponents_##_n * *a##_n) { \
|
|||
return NS_OK; \
|
||||
}
|
||||
|
||||
XPC_IMPL_GET_OBJ_METHOD(Interfaces);
|
||||
XPC_IMPL_GET_OBJ_METHOD(Classes);
|
||||
XPC_IMPL_GET_OBJ_METHOD(ClassesByID);
|
||||
XPC_IMPL_GET_OBJ_METHOD(Results);
|
||||
XPC_IMPL_GET_OBJ_METHOD(ID);
|
||||
XPC_IMPL_GET_OBJ_METHOD(Exception);
|
||||
XPC_IMPL_GET_OBJ_METHOD(Constructor);
|
||||
XPC_IMPL_GET_OBJ_METHOD(nsIScriptable, Interfaces);
|
||||
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Classes);
|
||||
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, ClassesByID);
|
||||
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Results);
|
||||
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, ID);
|
||||
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Exception);
|
||||
XPC_IMPL_GET_OBJ_METHOD(nsIXPCComponents_, Constructor);
|
||||
|
||||
#undef XPC_IMPL_GET_OBJ_METHOD
|
||||
/*******************************************/
|
||||
|
|
|
@ -392,98 +392,82 @@ NS_IMPL_CI_INTERFACE_GETTER2(nsJSIID, nsIJSID, nsIJSIID)
|
|||
nsIXPCScriptable::ALLOW_PROP_MODS_DURING_RESOLVE
|
||||
#include "xpc_map_end.h" /* This will #undef the above */
|
||||
|
||||
nsJSIID::nsJSIID()
|
||||
|
||||
nsJSIID::nsJSIID(nsIInterfaceInfo* aInfo)
|
||||
: mInfo(aInfo)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsJSIID::~nsJSIID() {}
|
||||
|
||||
// If mInfo is present we use it and ignore mDetails, else we use mDetails.
|
||||
|
||||
NS_IMETHODIMP nsJSIID::GetName(char * *aName)
|
||||
{ResolveName(); return mDetails.GetName(aName);}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::GetNumber(char * *aNumber)
|
||||
{return mDetails.GetNumber(aNumber);}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::GetId(nsID* *aId)
|
||||
{return mDetails.GetId(aId);}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::GetValid(PRBool *aValid)
|
||||
{return mDetails.GetValid(aValid);}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::Equals(nsIJSID *other, PRBool *_retval)
|
||||
{return mDetails.Equals(other, _retval);}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::Initialize(const char *idString)
|
||||
{return mDetails.Initialize(idString);}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::ToString(char **_retval)
|
||||
{ResolveName(); return mDetails.ToString(_retval);}
|
||||
|
||||
void
|
||||
nsJSIID::ResolveName()
|
||||
{
|
||||
if(!mDetails.NameIsSet())
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim;
|
||||
nsXPConnect::GetInterfaceInfoManager(getter_AddRefs(iim));
|
||||
if(iim)
|
||||
{
|
||||
char* name;
|
||||
if(NS_SUCCEEDED(iim->GetNameForIID(mDetails.GetID(), &name)) && name)
|
||||
{
|
||||
mDetails.SetName(name);
|
||||
nsMemory::Free(name);
|
||||
}
|
||||
}
|
||||
if(!mDetails.NameIsSet())
|
||||
mDetails.SetNameToNoString();
|
||||
}
|
||||
return mInfo->GetName(aName);
|
||||
}
|
||||
|
||||
//static
|
||||
nsJSIID*
|
||||
nsJSIID::NewID(const char* str)
|
||||
NS_IMETHODIMP nsJSIID::GetNumber(char * *aNumber)
|
||||
{
|
||||
const nsIID* id;
|
||||
mInfo->GetIIDShared(&id);
|
||||
char* str = id->ToString();
|
||||
if(!str)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
*aNumber = (char*) nsMemory::Clone(str, strlen(str)+1);
|
||||
PR_Free(str);
|
||||
return *aNumber ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::GetId(nsID* *aId)
|
||||
{
|
||||
return mInfo->GetIID((nsIID**)aId);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::GetValid(PRBool *aValid)
|
||||
{
|
||||
*aValid = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::Equals(nsIJSID *other, PRBool *_retval)
|
||||
{
|
||||
nsID* otherID;
|
||||
if(NS_SUCCEEDED(other->GetId(&otherID)))
|
||||
{
|
||||
NS_ASSERTION(0,"no string");
|
||||
mInfo->IsIID((nsIID*)otherID, _retval);
|
||||
nsMemory::Free(otherID);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::Initialize(const char *idString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsJSIID::ToString(char **_retval)
|
||||
{
|
||||
return mInfo->GetName(_retval);
|
||||
}
|
||||
|
||||
// static
|
||||
nsJSIID*
|
||||
nsJSIID::NewID(nsIInterfaceInfo* aInfo)
|
||||
{
|
||||
if(!aInfo)
|
||||
{
|
||||
NS_ERROR("no info");
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsJSIID* idObj = new nsJSIID();
|
||||
if(idObj)
|
||||
{
|
||||
PRBool success = PR_FALSE;
|
||||
NS_ADDREF(idObj);
|
||||
PRBool canScript;
|
||||
if(NS_FAILED(aInfo->IsScriptable(&canScript)) || !canScript)
|
||||
return nsnull;
|
||||
|
||||
if(str[0] == '{')
|
||||
{
|
||||
if(NS_SUCCEEDED(idObj->Initialize(str)))
|
||||
success = PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim;
|
||||
nsXPConnect::GetInterfaceInfoManager(getter_AddRefs(iim));
|
||||
if(iim)
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfo> iinfo;
|
||||
PRBool canScript;
|
||||
nsID* pid;
|
||||
if(NS_SUCCEEDED(iim->GetInfoForName(str,
|
||||
getter_AddRefs(iinfo))) &&
|
||||
NS_SUCCEEDED(iinfo->IsScriptable(&canScript)) && canScript &&
|
||||
NS_SUCCEEDED(iinfo->GetIID(&pid)) && pid)
|
||||
{
|
||||
success = idObj->mDetails.InitWithName(*pid, str);
|
||||
nsMemory::Free(pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!success)
|
||||
NS_RELEASE(idObj);
|
||||
}
|
||||
nsJSIID* idObj = new nsJSIID(aInfo);
|
||||
NS_IF_ADDREF(idObj);
|
||||
return idObj;
|
||||
}
|
||||
|
||||
|
@ -498,7 +482,11 @@ nsJSIID::NewResolve(nsIXPConnectWrappedNative *wrapper,
|
|||
XPCCallContext ccx(JS_CALLER, cx);
|
||||
|
||||
AutoMarkingNativeInterfacePtr iface(ccx);
|
||||
iface = XPCNativeInterface::GetNewOrUsed(ccx, mDetails.GetID());
|
||||
|
||||
const nsIID* iid;
|
||||
mInfo->GetIIDShared(&iid);
|
||||
|
||||
iface = XPCNativeInterface::GetNewOrUsed(ccx, iid);
|
||||
|
||||
if(!iface)
|
||||
return NS_OK;
|
||||
|
@ -536,7 +524,11 @@ nsJSIID::Enumerate(nsIXPConnectWrappedNative *wrapper,
|
|||
XPCCallContext ccx(JS_CALLER, cx);
|
||||
|
||||
AutoMarkingNativeInterfacePtr iface(ccx);
|
||||
iface = XPCNativeInterface::GetNewOrUsed(ccx, mDetails.GetID());
|
||||
|
||||
const nsIID* iid;
|
||||
mInfo->GetIIDShared(&iid);
|
||||
|
||||
iface = XPCNativeInterface::GetNewOrUsed(ccx, iid);
|
||||
|
||||
if(!iface)
|
||||
return NS_OK;
|
||||
|
@ -577,10 +569,13 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
|||
if(!other_wrapper)
|
||||
return NS_OK;
|
||||
|
||||
const nsIID* iid;
|
||||
mInfo->GetIIDShared(&iid);
|
||||
|
||||
// We'll trust the interface set of the wrapper if this is known
|
||||
// to be an interface that the objects *expects* to be able to
|
||||
// handle.
|
||||
if(other_wrapper->HasInterfaceNoQI(*mDetails.GetID()))
|
||||
if(other_wrapper->HasInterfaceNoQI(*iid))
|
||||
{
|
||||
*bp = JS_TRUE;
|
||||
return NS_OK;
|
||||
|
@ -590,7 +585,7 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
|
|||
XPCCallContext ccx(JS_CALLER, cx);
|
||||
|
||||
AutoMarkingNativeInterfacePtr iface(ccx);
|
||||
iface = XPCNativeInterface::GetNewOrUsed(ccx, mDetails.GetID());
|
||||
iface = XPCNativeInterface::GetNewOrUsed(ccx, iid);
|
||||
|
||||
if(iface && other_wrapper->FindTearOff(ccx, iface))
|
||||
*bp = JS_TRUE;
|
||||
|
|
|
@ -48,12 +48,18 @@ NS_DECL_CLASSINFO(XPCVariant)
|
|||
|
||||
#define XPCVARIANT_CONTRACTID "@mozilla.org/xpcvariant;1"
|
||||
|
||||
// {FE4F7592-C1FC-4662-AC83-538841318803}
|
||||
#define SCRIPTABLE_INTERFACES_CID \
|
||||
{0xfe4f7592, 0xc1fc, 0x4662, \
|
||||
{ 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCException)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect, nsXPConnect::GetSingleton)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIJSContextStack, nsXPCThreadJSContextStackImpl::GetSingleton)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIJSRuntimeService, nsJSRuntimeServiceImpl::GetSingleton)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCComponents_Interfaces)
|
||||
|
||||
NS_DECL_CLASSINFO(nsXPCException)
|
||||
|
||||
|
@ -64,6 +70,7 @@ static const nsModuleComponentInfo components[] = {
|
|||
{nsnull, NS_XPCEXCEPTION_CID, XPC_EXCEPTION_CONTRACTID, nsXPCExceptionConstructor, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(nsXPCException), nsnull, &NS_CLASSINFO_NAME(nsXPCException)},
|
||||
{nsnull, NS_JS_RUNTIME_SERVICE_CID, XPC_RUNTIME_CONTRACTID, nsIJSRuntimeServiceConstructor},
|
||||
{NS_SCRIPTERROR_CLASSNAME, NS_SCRIPTERROR_CID, NS_SCRIPTERROR_CONTRACTID, nsScriptErrorConstructor },
|
||||
{nsnull, SCRIPTABLE_INTERFACES_CID, NS_SCRIPTABLE_INTERFACES_CONTRACTID, nsXPCComponents_InterfacesConstructor },
|
||||
{nsnull, XPCVARIANT_CID, XPCVARIANT_CONTRACTID, nsnull, nsnull, nsnull, nsnull, NS_CI_INTERFACE_GETTER_NAME(XPCVariant), nsnull, &NS_CLASSINFO_NAME(XPCVariant)}
|
||||
};
|
||||
|
||||
|
|
|
@ -381,7 +381,7 @@ public:
|
|||
static nsIJSRuntimeService* GetJSRuntimeService(nsXPConnect* xpc = nsnull);
|
||||
|
||||
// Gets addref'd pointer
|
||||
static nsresult GetInterfaceInfoManager(nsIInterfaceInfoManager** iim,
|
||||
static nsresult GetInterfaceInfoManager(nsIInterfaceInfoSuperManager** iim,
|
||||
nsXPConnect* xpc = nsnull);
|
||||
|
||||
// Gets addref'd pointer
|
||||
|
@ -411,6 +411,9 @@ public:
|
|||
|
||||
JSBool IsShuttingDown() const {return mShuttingDown;}
|
||||
|
||||
nsresult GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info);
|
||||
nsresult GetInfoForName(const char * name, nsIInterfaceInfo** info);
|
||||
|
||||
protected:
|
||||
nsXPConnect();
|
||||
|
||||
|
@ -427,7 +430,7 @@ private:
|
|||
static PRThread* gMainThread;
|
||||
|
||||
XPCJSRuntime* mRuntime;
|
||||
nsIInterfaceInfoManager* mInterfaceInfoManager;
|
||||
nsIInterfaceInfoSuperManager* mInterfaceInfoManager;
|
||||
nsIThreadJSContextStack* mContextStack;
|
||||
nsIXPCSecurityManager* mDefaultSecurityManager;
|
||||
PRUint16 mDefaultSecurityManagerFlags;
|
||||
|
@ -2529,16 +2532,14 @@ public:
|
|||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
#endif
|
||||
|
||||
static nsJSIID* NewID(const char* str);
|
||||
static nsJSIID* NewID(nsIInterfaceInfo* aInfo);
|
||||
|
||||
nsJSIID();
|
||||
nsJSIID(nsIInterfaceInfo* aInfo);
|
||||
nsJSIID(); // not implemented
|
||||
virtual ~nsJSIID();
|
||||
|
||||
private:
|
||||
void ResolveName();
|
||||
|
||||
private:
|
||||
nsJSID mDetails;
|
||||
nsCOMPtr<nsIInterfaceInfo> mInfo;
|
||||
};
|
||||
|
||||
// nsJSCID
|
||||
|
@ -2822,6 +2823,33 @@ private:
|
|||
nsXPCComponents_Constructor* mConstructor;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
class nsXPCComponents_Interfaces :
|
||||
public nsIScriptableInterfaces,
|
||||
public nsIXPCScriptable
|
||||
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
||||
, public nsISecurityCheckedComponent
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
// all the interface method declarations...
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCRIPTABLEINTERFACES
|
||||
NS_DECL_NSIXPCSCRIPTABLE
|
||||
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
#endif
|
||||
|
||||
public:
|
||||
nsXPCComponents_Interfaces();
|
||||
virtual ~nsXPCComponents_Interfaces();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIInterfaceInfoManager> mManager;
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern JSObject*
|
||||
|
|
|
@ -133,21 +133,17 @@ nsXPCWrappedJSClass::GetNewOrUsed(XPCCallContext& ccx, REFNSIID aIID,
|
|||
|
||||
if(!clazz)
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iimgr;
|
||||
nsXPConnect::GetInterfaceInfoManager(getter_AddRefs(iimgr));
|
||||
if(iimgr)
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
ccx.GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||
if(info)
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
if(NS_SUCCEEDED(iimgr->GetInfoForIID(&aIID, getter_AddRefs(info))))
|
||||
PRBool canScript;
|
||||
if(NS_SUCCEEDED(info->IsScriptable(&canScript)) && canScript &&
|
||||
nsXPConnect::IsISupportsDescendant(info))
|
||||
{
|
||||
PRBool canScript;
|
||||
if(NS_SUCCEEDED(info->IsScriptable(&canScript)) && canScript &&
|
||||
nsXPConnect::IsISupportsDescendant(info))
|
||||
{
|
||||
clazz = new nsXPCWrappedJSClass(ccx, aIID, info);
|
||||
if(!clazz->mDescriptors)
|
||||
NS_RELEASE(clazz); // sets clazz to nsnull
|
||||
}
|
||||
clazz = new nsXPCWrappedJSClass(ccx, aIID, info);
|
||||
if(clazz && !clazz->mDescriptors)
|
||||
NS_RELEASE(clazz); // sets clazz to nsnull
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,12 +238,8 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
|
|||
// We so often ask for nsISupports that we can short-circuit the test...
|
||||
if(!aIID.Equals(NS_GET_IID(nsISupports)))
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iimgr;
|
||||
nsXPConnect::GetInterfaceInfoManager(getter_AddRefs(iimgr));
|
||||
if(!iimgr)
|
||||
return nsnull;
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
iimgr->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||
ccx.GetXPConnect()->GetInfoForIID(&aIID, getter_AddRefs(info));
|
||||
if(!info)
|
||||
return nsnull;
|
||||
PRBool canScript;
|
||||
|
|
|
@ -186,13 +186,9 @@ XPCNativeInterface::GetNewOrUsed(XPCCallContext& ccx, const nsIID* iid)
|
|||
if(iface)
|
||||
return iface;
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iimgr;
|
||||
nsXPConnect::GetInterfaceInfoManager(getter_AddRefs(iimgr));
|
||||
if(!iimgr)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
if(NS_FAILED(iimgr->GetInfoForIID(iid, getter_AddRefs(info))) ||!info)
|
||||
ccx.GetXPConnect()->GetInfoForIID(iid, getter_AddRefs(info));
|
||||
if(!info)
|
||||
return nsnull;
|
||||
|
||||
iface = NewInstance(ccx, info);
|
||||
|
@ -269,16 +265,9 @@ XPCNativeInterface::GetNewOrUsed(XPCCallContext& ccx, nsIInterfaceInfo* info)
|
|||
XPCNativeInterface*
|
||||
XPCNativeInterface::GetNewOrUsed(XPCCallContext& ccx, const char* name)
|
||||
{
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iimgr;
|
||||
nsXPConnect::GetInterfaceInfoManager(getter_AddRefs(iimgr));
|
||||
if(!iimgr)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfo> info;
|
||||
if(NS_FAILED(iimgr->GetInfoForName(name, getter_AddRefs(info))) || !info)
|
||||
return nsnull;
|
||||
|
||||
return GetNewOrUsed(ccx, info);
|
||||
ccx.GetXPConnect()->GetInfoForName(name, getter_AddRefs(info));
|
||||
return info ? GetNewOrUsed(ccx, info) : nsnull;
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
NS_DECL_CLASSINFO(xpcTestCallJS)
|
||||
NS_DECL_CLASSINFO(xpcTestChild2)
|
||||
|
||||
// XXX contractids need to be standardized!
|
||||
static const nsModuleComponentInfo components[] = {
|
||||
{nsnull, NS_ECHO_CID, "@mozilla.org/js/xpc/test/Echo;1", xpctest::ConstructEcho },
|
||||
{nsnull, NS_CHILD_CID, "@mozilla.org/js/xpc/test/Child;1", xpctest::ConstructChild },
|
||||
|
|
Загрузка…
Ссылка в новой задаче