RES: JavaConnect and JavaScript
Murilo Camões Perrone <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Message-ID | <[email protected]> |
Javier Pedemonte,
Your example (below) is nice way of using the Java code from mozilla.
nsIServiceManager sm = Mozilla.getServiceManager();
nsIWindowWatcher watcher = (nsIWindowWatcher) sm
.getServiceByContractID(NS_WINDOWWATCHER_CONTRACTID,
nsIWindowWatcher.NS_IWINDOWWATCHER_IID);
watcher.setWindowCreate(WindowCreator);
Though, I need to entirelly use the XPIDL interface of my XPCom component
from withing JavaScript code.
Currently I am being able to instantiate Java objects from JavaScript as
XPCom objects implementing XPIDL interfaces.
JavaScript test code:
var certs =
Components.classes[javaXPComComponentID].getService(Components.interfaces.IC
ertificates);
alert( "certs = " + certs ); // certs = [xpconnect wrapped (nsISupports,
ICertificates)]
alert( "certs.Count = " + certs.Count ); // certs.Count = 0
alert( "certs.Clear = " + certs.Clear ); // certs.Clear = function
Clear() { [native code] }
certs.Clear(); // exception is thrown with code
NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED
So I could sucessfully access the attributes defined on XPIDL interface with
no get/set prefix, but there is a problem when calling the methods (which
are also described on the XPIDL interface).
I followed the steps in Java Firefox Extension example, except that I added
a shortcut so that the java object will be returned directly from Mozilla´s
Component Manager, and thus used by JavaScript as defined on the XPIDL
interface (such as ICertificates.xpt).
In my JavaScript component, the factory´s createInstance method returns new
Java object instances. First, it loads the class from a package.classname
string, then instantiates it calling the constructor.
To avoid the NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED error, I will try
to add an extra step in the process of loading the Java class.
I will use the JavaConnect´s XPCOM class instead of just calling the class
constructor.
nsIComponentManager componentManager = XPCOM.getComponentManager();
componentManager.createInstanceByContractID( ICERTIFICATES_CONTRACTID, null,
ICERTIFICATES_IID);
Then XPConnect AND JavaConnect would be both used together.
The two instructions above could be used in different ways:
* from within Java code, returning an nsISupports object
* from within JavaScript, loading XPCOM class
* maybe even from C++ code (if that would be usefull), using
JavaConnect´s DLL function entries
Makes sence?
Also, from were can I download updated JavaConnect sources?
The XulRunner nighty zip from the link below does not include it.
http://ftp.mozilla.org/pub/mozilla.org/xulrunner/nightly/latest-mozilla1.8/
----------------
Murilo Perrone
CertiSign