I'm going to develop a Firefox extension which uses some Java classes.
The extension gets the value of <input type="file">
fields, using Javascript.
The Java class I'm going to create is the following:
public class Firefox {
public static String inFileName;
public static void main(String[] args) throws IOException {
inFileName = "";
try {
inFileName = args[0];
} catch (Exception ex) {}
}
On Javascript, I have to use Java reflection in order to access Java classes.
In this manner I can create my Java object:
var fileInput = e.explicitOriginalTarget; // is an object HTMLInputElement, I get this when a file is selected
strArray = java.lang.reflect.Array.newInstance(java.lang.Class.forName("java.net.URL"),3);
classLoader = java.net.URLClassLoader.newInstance(strArray);
parameters = java.lang.reflect.Array.newInstance(java.lang.Class.forName("java.lang.String"),1);
parameters[0]= fileInput.value;
var aClass = java.lang.Class.forName("Firefox", true, classLoader);
var aStaticMethod = aClass.getMethod("main", [parameters.getClass()]); //gets the main(String[] args) method, here I get the exception*
var myJava = aStaticMethod.invoke(null, [parameters]); //invokes the main method
I've been trying this extension on Firefox-3.5b4 and everything goes fine, but when I try it on Firefox-3.0.10 I get the following exception*:
`InternalError: Unable to convert JavaScript value class [Ljava.lang.String; to Java value of type java.lang.Class[]`
For example, putting the following line before the main method invokation:
alert(parameters + " - " + parameters[0]);
on both Firefox-3.0.10 and 3.5b4 I get an alert window which says:
`[Ljava.lang.String;@194ca6c - /root/demo.pdf` //demo.pdf is the selected file
But only on 3.0.10 I get the exception, ONLY on my GNU/Linux machine. On Windows XP instead I have no problems on both Firefox versions!
Note that on both Windows and Linux the Java plugin version is 6 update 13.
Where am I wrong? Is it a possible bug on Firefox-3.0.10 Javascript engine or must I do any other thing before getting the main(...) method?