On 9/27/07, Carfield Yim <carfield@carfield.com.hk> wrote:

How to get instance fo nsIDownloader using javaxpcom?



It's not too difficult.  The JavaScript code you pointed to has this line:

     var nsIDownloader = Components.classes["@ mozilla.org/network/downloader;1"].createInstance(); 



The "Components" object is a helper object in Mozilla JavaScript, so we need to do things differently in JavaXPCOM.



We need to use the nsIComponentManager interface ( http://mxr.mozilla.org/mozilla1.8/source/xpcom/components/nsIComponentManager.idl), which has a createInstance() method.  So something like this: 



        nsIComponentManager compMgr = Mozilla.getInstance().getComponentManager();

        nsIDownloader createInstance = (nsIDownloader) compMgr

            .createInstance( "@ mozilla.org/network/downloader;1", null,

                    nsIDownloader.NS_IDOWNLOADER_IID );
