I have authored a couple Firefox plugins with precisely this requirement.
One strategy is to use the JavaScript-to-Java bridge in Firefox, which permits the use of Java RMI. I found this approach slow and unstable, and the multithreading is painful.
My current solution is to open a localhost
socket and use a textual protocol to communicate. See the XULPlanet developer guide on sockets for how to open and read/write with sockets in Firefox JavaScript, and there's a Sun tutorial on sockets in Java.
The source code to one plugin I wrote (for Firefox and Eclipse) is available under the X11 aka MIT license: Firedoclipse source. Under the lib
directory is a component called jsjr
, with several Java classes and a JavaScript XPCOM object that implement remote method invocation between Java and JavaScript. The test
directory contains some unit tests. This remote method invocation would be overkill for sending only one kind of message in one direction, but you might find the code helpful.