eBlogzilla

Friday, March 19, 2010

How To Call Java From XPCOM

It is quite easy to call Java methods directly from the extension. You can find a lot of information how to do that here. But there is no information how to call java from JavaScript XPCOM. java keyword is not available here.

There is one trick that allow you to get reference on java variable from XPCOM:
const Cc = Components.classes;
const Ci = Components.interfaces;

var java = Cc["@mozilla.org/appshell/window-mediator;1"].
             getService(Ci.nsIWindowMediator).
             getMostRecentWindow("navigator:browser").java;
Very simple, but not very obvious.