using java instead of xpcom

9 views
Skip to first unread message

Fabio Serra

unread,
Sep 26, 2006, 9:04:29 AM9/26/06
to
Today I have realized :-) that I can use java from javascript in chrome
environment and in this case there is no security restriction. So, my question
is: what is the trade-off using java instead of xpcom for certain type of
operation?
I have never read any article or tutorial promoting the use of some java classes
from javascript in chrome environment. Why? There is something wrong in this
approach?
Thanks in advance.
Eg:

function readFile() {
var fname = "D:/tmp/test.txt";
try {
var fin = new java.io.FileInputStream(fname);
var ins = new java.io.DataInputStream(fin);
var fcontent = "";
while(ins.available() !=0) {
console.debug(ins.readLine()) //firebug console
}

}catch(ex) {
console.debug(ex);
}finally {
ins.close();
}
}

Anatolij Kupriyanov

unread,
Sep 26, 2006, 9:07:59 AM9/26/06
to
Fabio Serra wrote:

Not sure, what do you mean? You can use java via xpcom only. But not only java, you can use C++, python, javascript in
the same way as java. What's difference?

Fabio Serra

unread,
Sep 26, 2006, 9:30:44 AM9/26/06
to

I'm a little confused, sorry. :-)

Are you saying that with a standard Firefox 2.0 I can create a python object in
the same way as java?

I can write to a local file using javascript in this way?

var out = new java.io.BufferedWriter(new java.io.FileWriter("test.txt"));
out.write("Hello World");


What surprised me is that I can use every j2se classes out-of-the-box without
any security restriction (in chrome).
I think that there are some cases where is easier using java than an XPCOM
component.

Christian Biesinger

unread,
Sep 26, 2006, 11:33:17 AM9/26/06
to dev-tec...@lists.mozilla.org
Anatolij Kupriyanov wrote:
> Not sure, what do you mean? You can use java via xpcom only.

That's not true. You can use Java directly too, like his code sample
showed... Using Java via XPCOM doesn't work in a standard Firefox
(neither does Python).

Anatolij Kupriyanov

unread,
Sep 26, 2006, 6:49:50 PM9/26/06
to
Fabio Serra wrote:

>> Not sure, what do you mean? You can use java via xpcom only. But not
>> only java, you can use C++, python, javascript in the same way as java.
>> What's difference?
> I'm a little confused, sorry. :-)
>
> Are you saying that with a standard Firefox 2.0 I can create a python object in
> the same way as java?

I feel I don't know what is the "way as java"... ;)
But ActiveState Komodo is built on mozilla platform with python.

> I can write to a local file using javascript in this way?
>
> var out = new java.io.BufferedWriter(new java.io.FileWriter("test.txt"));
> out.write("Hello World");

Yes, but JavaScript doesn't contain io stuff. So you have to use other xpcom-components, like
"@mozilla.org/network/file-output-stream;1"

> What surprised me is that I can use every j2se classes out-of-the-box without
> any security restriction (in chrome).

Of course, mozilla doesn't have any access to JVM internals.

> I think that there are some cases where is easier using java than an XPCOM
> component.

Yeah... maybe... but not all cases definitely. Just make dependencies on the 20-25 mb JRE only just for writing a
file... moreover you can make it with mozilla-native components.

Reply all
Reply to author
Forward
0 new messages