2nd pass . . .

getInterfaceByProgID returns an array of interfaces that the service 
implements.

js> getInterfaceByProgID('@mozilla.org/network/io-service;1');
nsIIOService
js> getInterfaceByProgID('@mozilla.org/image/decoder;2?type=image/jpeg');
nsIOutputStream,imgIDecoder
js>  getInterfaceByProgID('@mozilla.org/network/stream-io-channel;1');
nsIChannel,nsIInterfaceRequestor,nsIStreamProvider,nsIRequest,nsIStreamIOChannel,nsIRequestObserver,nsIStreamListener,nsIProgressEventSink
js>  getInterfaceByProgID('@mozilla.org/network/file-transport-service;1');
nsIFileTransportService
js> getInterfaceByProgID('@mozilla.org/thread;1');
nsIThread
js> getInterfaceByProgID('@mozilla.org/document-charset-info;1');
nsIDocumentCharsetInfo
js> getInterfaceByProgID('@mozilla.org/file/local;1');
nsILocalFile,nsIFile
js> getInterfaceByProgID('eat me');
null

/*****************************************************/
function getInterfaceByProgID(aProgID)
{

   var C     = Components;
   var iface = C.interfaces;
   var c     = C.classes;
   var res   = new Array();
   var list;
   var inst;

   if(!aProgID)
   {
     throw C.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS;
     return null;
   }

   if(typeof(c[aProgID])=='undefined')
     return null;

   inst=c[aProgID].getService();

   for(list in iface)
   {
     try
     {
       if(typeof(iface[list])!='undefined')
         if(typeof(inst.QueryInterface(iface[list]))=='object' && 
list!='nsISupports')
           res.push(list);
     }

     catch(e){}
   }

   return (res !="" ? res : null);

}
/*****************************************************/


Reply via email to