bug 860027 - remove XPTIInterfaceInfoManager::EnumerateInterfaces() r=bholley r=bsmedberg

This commit is contained in:
Trevor Saunders 2013-04-09 16:00:21 -04:00
Родитель 43ddfa5b42
Коммит 971acb8d4c
3 изменённых файлов: 51 добавлений и 113 удалений

Просмотреть файл

@ -34,6 +34,7 @@
#include "nsJSEnvironment.h"
#include "nsXMLHttpRequest.h"
#include "mozilla/Telemetry.h"
#include "mozilla/XPTInterfaceInfoManager.h"
#include "nsDOMClassInfoID.h"
using namespace mozilla;
@ -120,7 +121,7 @@ public:
virtual ~nsXPCComponents_Interfaces();
private:
nsCOMPtr<nsIInterfaceInfoManager> mManager;
nsCOMArray<nsIInterfaceInfo> mInterfaces;
};
/* void getInterfaces (out uint32_t count, [array, size_is (count), retval]
@ -215,9 +216,9 @@ nsXPCComponents_Interfaces::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
return NS_ERROR_NOT_AVAILABLE;
}
nsXPCComponents_Interfaces::nsXPCComponents_Interfaces() :
mManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID))
nsXPCComponents_Interfaces::nsXPCComponents_Interfaces()
{
XPTInterfaceInfoManager::GetSingleton()->GetScriptableInterfaces(mInterfaces);
}
nsXPCComponents_Interfaces::~nsXPCComponents_Interfaces()
@ -254,64 +255,36 @@ nsXPCComponents_Interfaces::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
uint32_t enum_op, jsval * statep,
jsid * idp, bool *_retval)
{
nsIEnumerator* e;
switch (enum_op) {
case JSENUMERATE_INIT:
case JSENUMERATE_INIT_ALL:
{
if (!mManager ||
NS_FAILED(mManager->EnumerateInterfaces(&e)) || !e ||
NS_FAILED(e->First()))
{
*statep = JSVAL_NULL;
return NS_ERROR_UNEXPECTED;
}
*statep = PRIVATE_TO_JSVAL(e);
*statep = JSVAL_ZERO;
if (idp)
*idp = INT_TO_JSID(0); // indicate that we don't know the count
*idp = INT_TO_JSID(mInterfaces.Length());
return NS_OK;
}
case JSENUMERATE_NEXT:
{
nsCOMPtr<nsISupports> isup;
uint32_t idx = JSVAL_TO_INT(*statep);
nsIInterfaceInfo* interface = mInterfaces.SafeElementAt(idx);
*statep = UINT_TO_JSVAL(idx + 1);
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
if (interface) {
JSString* idstr;
const char* name;
while (1) {
if (static_cast<nsresult>(NS_ENUMERATOR_FALSE) == e->IsDone() &&
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) {
e->Next();
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
if (iface) {
JSString* idstr;
const char* name;
bool scriptable;
if (NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
!scriptable) {
continue;
}
if (NS_SUCCEEDED(iface->GetNameShared(&name)) && name &&
nullptr != (idstr = JS_NewStringCopyZ(cx, name)) &&
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp)) {
return NS_OK;
}
}
if (NS_SUCCEEDED(interface->GetNameShared(&name)) && name &&
nullptr != (idstr = JS_NewStringCopyZ(cx, name)) &&
JS_ValueToId(cx, STRING_TO_JSVAL(idstr), idp)) {
return NS_OK;
}
// else...
break;
}
// FALL THROUGH
// fall through
}
case JSENUMERATE_DESTROY:
default:
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
NS_IF_RELEASE(e);
*statep = JSVAL_NULL;
return NS_OK;
}
@ -327,7 +300,7 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
if (!mManager || !JSID_IS_STRING(id))
if (!JSID_IS_STRING(id))
return NS_OK;
JSAutoByteString name;
@ -336,7 +309,8 @@ nsXPCComponents_Interfaces::NewResolve(nsIXPConnectWrappedNative *wrapper,
// we only allow interfaces by name here
if (name.encodeLatin1(cx, str) && name.ptr()[0] != '{') {
nsCOMPtr<nsIInterfaceInfo> info;
mManager->GetInfoForName(name.ptr(), getter_AddRefs(info));
XPTInterfaceInfoManager::GetSingleton()->
GetInfoForName(name.ptr(), getter_AddRefs(info));
if (!info)
return NS_OK;
@ -428,7 +402,7 @@ public:
virtual ~nsXPCComponents_InterfacesByID();
private:
nsCOMPtr<nsIInterfaceInfoManager> mManager;
nsCOMArray<nsIInterfaceInfo> mInterfaces;
};
/***************************************************************************/
@ -524,9 +498,9 @@ nsXPCComponents_InterfacesByID::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
return NS_ERROR_NOT_AVAILABLE;
}
nsXPCComponents_InterfacesByID::nsXPCComponents_InterfacesByID() :
mManager(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID))
nsXPCComponents_InterfacesByID::nsXPCComponents_InterfacesByID()
{
XPTInterfaceInfoManager::GetSingleton()->GetScriptableInterfaces(mInterfaces);
}
nsXPCComponents_InterfacesByID::~nsXPCComponents_InterfacesByID()
@ -561,68 +535,38 @@ nsXPCComponents_InterfacesByID::NewEnumerate(nsIXPConnectWrappedNative *wrapper,
uint32_t enum_op, jsval * statep,
jsid * idp, bool *_retval)
{
nsIEnumerator* e;
switch (enum_op) {
case JSENUMERATE_INIT:
case JSENUMERATE_INIT_ALL:
{
if (!mManager ||
NS_FAILED(mManager->EnumerateInterfaces(&e)) || !e ||
NS_FAILED(e->First()))
{
*statep = JSVAL_NULL;
return NS_ERROR_UNEXPECTED;
}
*statep = PRIVATE_TO_JSVAL(e);
*statep = JSVAL_ZERO;
if (idp)
*idp = INT_TO_JSID(0); // indicate that we don't know the count
*idp = INT_TO_JSID(mInterfaces.Length());
return NS_OK;
}
case JSENUMERATE_NEXT:
{
nsCOMPtr<nsISupports> isup;
uint32_t idx = JSVAL_TO_INT(*statep);
nsIInterfaceInfo* interface = mInterfaces.SafeElementAt(idx);
*statep = UINT_TO_JSVAL(idx + 1);
if (interface) {
nsIID const *iid;
char idstr[NSID_LENGTH];
JSString* jsstr;
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
while (1) {
if (static_cast<nsresult>(NS_ENUMERATOR_FALSE) == e->IsDone() &&
NS_SUCCEEDED(e->CurrentItem(getter_AddRefs(isup))) && isup) {
e->Next();
nsCOMPtr<nsIInterfaceInfo> iface(do_QueryInterface(isup));
if (iface) {
nsIID const *iid;
char idstr[NSID_LENGTH];
JSString* jsstr;
bool scriptable;
if (NS_SUCCEEDED(iface->IsScriptable(&scriptable)) &&
!scriptable) {
continue;
}
if (NS_SUCCEEDED(iface->GetIIDShared(&iid))) {
iid->ToProvidedString(idstr);
jsstr = JS_NewStringCopyZ(cx, idstr);
if (jsstr &&
JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp)) {
return NS_OK;
}
}
if (NS_SUCCEEDED(interface->GetIIDShared(&iid))) {
iid->ToProvidedString(idstr);
jsstr = JS_NewStringCopyZ(cx, idstr);
if (jsstr && JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp)) {
return NS_OK;
}
}
// else...
break;
}
// FALL THROUGH
}
case JSENUMERATE_DESTROY:
default:
e = (nsIEnumerator*) JSVAL_TO_PRIVATE(*statep);
NS_IF_RELEASE(e);
*statep = JSVAL_NULL;
return NS_OK;
}
@ -637,10 +581,6 @@ nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
if (!mManager || !JSID_IS_STRING(id))
return NS_OK;
RootedString str(cx, JSID_TO_STRING(id));
if (38 != JS_GetStringLength(str))
return NS_OK;
@ -651,7 +591,8 @@ nsXPCComponents_InterfacesByID::NewResolve(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
nsCOMPtr<nsIInterfaceInfo> info;
mManager->GetInfoForIID(&iid, getter_AddRefs(info));
XPTInterfaceInfoManager::GetSingleton()->
GetInfoForIID(&iid, getter_AddRefs(info));
if (!info)
return NS_OK;

Просмотреть файл

@ -12,7 +12,7 @@
#include "nsISimpleEnumerator.idl"
/* this is NOT intended to be scriptable */
[uuid(8B161900-BE2B-11d2-9831-006008962422)]
[uuid(1d53d8d9-1d92-428f-b5cc-198b55e897d7)]
interface nsIInterfaceInfoManager : nsISupports
{
nsIInterfaceInfo getInfoForIID(in nsIIDPtr iid);
@ -21,8 +21,6 @@ interface nsIInterfaceInfoManager : nsISupports
nsIIDPtr getIIDForName(in string name);
string getNameForIID(in nsIIDPtr iid);
nsIEnumerator enumerateInterfaces();
void autoRegisterInterfaces();
nsIEnumerator enumerateInterfacesWhoseNamesStartWith(in string prefix);

Просмотреть файл

@ -268,32 +268,31 @@ XPTInterfaceInfoManager::GetNameForIID(const nsIID * iid, char **_retval)
static PLDHashOperator
xpti_ArrayAppender(const char* name, xptiInterfaceEntry* entry, void* arg)
{
nsISupportsArray* array = (nsISupportsArray*) arg;
nsCOMArray<nsIInterfaceInfo>* array = static_cast<nsCOMArray<nsIInterfaceInfo>*>(arg);
nsCOMPtr<nsIInterfaceInfo> ii;
if (NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii))))
if (NS_SUCCEEDED(EntryToInfo(entry, getter_AddRefs(ii)))) {
bool scriptable = false;
ii->IsScriptable(&scriptable);
if (scriptable) {
array->AppendElement(ii);
}
}
return PL_DHASH_NEXT;
}
/* nsIEnumerator enumerateInterfaces (); */
NS_IMETHODIMP
XPTInterfaceInfoManager::EnumerateInterfaces(nsIEnumerator **_retval)
void
XPTInterfaceInfoManager::GetScriptableInterfaces(nsCOMArray<nsIInterfaceInfo>& aInterfaces)
{
// I didn't want to incur the size overhead of using nsHashtable just to
// make building an enumerator easier. So, this code makes a snapshot of
// the table using an nsISupportsArray and builds an enumerator for that.
// We can afford this transient cost.
nsCOMPtr<nsISupportsArray> array;
NS_NewISupportsArray(getter_AddRefs(array));
if (!array)
return NS_ERROR_UNEXPECTED;
ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
mWorkingSet.mNameTable.EnumerateRead(xpti_ArrayAppender, array);
return array->Enumerate(_retval);
aInterfaces.SetCapacity(mWorkingSet.mNameTable.Count());
mWorkingSet.mNameTable.EnumerateRead(xpti_ArrayAppender, &aInterfaces);
}
struct ArrayAndPrefix