Re: XPCOM Component Written in Java
Alberto <[email protected]> Thu, 5 Mar 2009 05:41:49 -0800 (PST)
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <239c5407-0360-4319-b5fd-2dc200d2f58c__37955.381422262$1236260867$gmane$org@d19g2000yqb.googlegroups.com> |
Hi all, i probably have been a bit misunderstood, so i'll try to explain what i'm trying to do. I already wrote a firefox extension using the LiveConnect work around (as suggested by https://developer.mozilla.org/en/Java_in_Firefox_Extensions). But LiveConnect has some unsolved issues (such as it's not working properly on mac osx) and it's gonna not to be supported anymore, so i was trying to figure out if there was a way (searching the web i already discovered that it's not gonna be an easy one!!) to implement an XPCom completely in java so that it would be accessible from XUL/ Javascript framework running either on firefox or on xulrunner itself. AFAICS the big problem is the absense of the Java Component Loader (as the project maintainer Pedemonte said in http://markmail.org/message/vxlaqmdmx2pk3to4) so that the registration of a component written in java seems to be impossible, and it seems that the official development driven by Pedemonte stopped 2 years ago... Did anyone try to download the sources of the project and to build it? Which are the issues still uncovered? Is there anybody but Pedemonte working on this component? If no solution have been found yet where I can find the sourcecode so that i could try to fix/update it on my own? On Jan 28, 3:57 pm, Derrick Rice <[email protected]> wrote: > On Jan 28, 12:55 am, Brett Zamir <[email protected]> wrote: > > > > > Sorry if this doesn't pertain to your needs (and my own knowledge of Java is quite limited), but for anyone confused about using LiveConnect in Mozilla, this thread was very helpful, as an apparent developer working on LiveConnect answered questions about its status. Basically, we have to wait for update 12 to be released (in Q1) to fix a significant bug for loading classes. > > > Brett > > > ----- Original Message ---- > > From: Derrick Rice <[email protected]> > > To: [email protected] > > Sent: Tuesday, January 27, 2009 3:02:03 AM > > Subject: Re: XPCOM Component Written in Java > > > On Jan 26, 1:18 pm, [email protected] wrote: > > > On Jan 26, 4:19 pm, Derrick Rice <[email protected]> wrote: > > > > > On Jan 26, 11:11 am, Derrick Rice <[email protected]> wrote: > > > > > > On Jan 26, 9:41 am, Alberto <[email protected]> wrote: > > > > > > > On Jan 23, 11:16 pm, Derrick Rice <[email protected]> wrote: > > > > > > > > I've also posted this to the mozswing mailing list, since that's what > > > > > > > I'm using. But this seems to be a core XPCOM problem I'm having. > > > > > > > > Let me just say that this I am not looking to start a VM from > > > > > > > mozilla... my entire application is java, with mozilla used via JNI > > > > > > > (mozswing/JavaXPCOM). What I want to know is why my components cannot > > > > > > > be directly access by the javascript, yet they seem to interact in > > > > > > > other ways. > > > > > > > > ------------------------------------------ > > > > > > > > What is so confusing is that I see the javascript > > > > > > > successfully interacting with the java, but as soon as I attempt to > > > > > > > explicitly call a function, it falls. > > > > > > > > Goal: Create a new XPCOM component which will be written in Java and > > > > > > > installed in my mozswing application. Use it from javascript. > > > > > > > > Steps and results: > > > > > > > > 1. Create a new interface idl and compile it into an *.xpt and java > > > > > > > interface. [OK] > > > > > > > 2. On mozswing initialization, install a factory for this interface > > > > > > > that will generate java objects. This is no different than how I've > > > > > > > installed java factories for other already existing interfaces.[OK] > > > > > > > 3. After installing the factory, add the component to the "JavaScript > > > > > > > global property" category, so that it is accessible to website > > > > > > > javascript. [OK] > > > > > > > 4. Since the interface extends nsIClassInfo and my component (which I > > > > > > > generate in the factory) can also queryInterface to > > > > > > > nsISecurityCheckedComponent, I can allow it to be used from the web > > > > > > > page. > > > > > > > > *** At this point I can successfully create and invoke my component > > > > > > > through XPCOM with JAVA: > > > > > > > XPCOMUtils.create("<contract id>", myInterface.class).callFunction() > > > > > > > > 5. Generate a test HTML page with javascript that accesses the item > > > > > > > [This is where things go bad] > > > > > > > > var instance = window.myComponent.QueryInterface > > > > > > > (Components.interface.nsIMyNewInterface); > > > > > > > alert(instance); // yields [xpconnect wrapped > > > > > > > nsIMyNewInterface] > > > > > > > alert(instance.member); // yields the value of the member > > > > > > > alert(instance.callFunction); // yields function > > > > > > > callFunction() { [native code] } > > > > > > > instance.callFunction(); // generates an error, see below > > > > > > > > [Exception... "Component returned failure code: 0x80004001 > > > > > > > (NS_ERROR_NOT_IMPLEMENTED) [nsIMyNewInterface.callFunction]" > > > > > > > nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame > > > > > > > :: webpage.html :: run :: line 15" data: no] > > > > > > > > If I throw print statements into my java component, I see it being > > > > > > > access (QueryInterface is called and so are the > > > > > > > nsISecurityCheckedComponent functions). This indicates to me that > > > > > > > it's clearly possible for the javascript to communicate with the java. > > > > > > > It's already taking place when I call QueryInterface. But if I try > > > > > > > to call something else, it fails. > > > > > > > > Am I running into a natural limitation of JavaXPCOM? How can I > > > > > > > communicate back to my existing java application from javascript > > > > > > > XPCOM? > > > > > > > > Problems solved: > > > > > > > * accessing XPCOM from javascript > > > > > > > * installing XPCOM factories from java > > > > > > > * making components visible and accessible to webpages > > > > > > > > Problems existing: > > > > > > > * using my components from javascript > > > > > > > > I saw someone else had this problem but saw no solution:http://osdir.com/ml/mozilla.devel.java/2006-01/msg00007.html > > > > > > > > Again, any help here would be seriously appreciated. Even if it's > > > > > > > just a little insight. > > > > > > > Even if i'm some step behind you i guess I could probably help you. > > > > > > I succeded (from java,not javascript yet) to register the XPcom object > > > > > > created implementing the interface and to access its method. > > > > > > What I'm still not able to do is register the XPcom object > > > > > > independently from running the java code,either in a dynamic way or in > > > > > > a static one. > > > > > > Since I guess you succeeded in doing that can you help me out? > > > > > > Thanks in advance > > > > > > I don't know if I 100% understand your question, but I'll give 2 > > > > > answers, because I think 1 of them might be what you're looking for. > > > > > > 1) If your intention is to run mozilla embedded in a java application, > > > > > then you can register the java component in java code. It sounds like > > > > > this is what you've been able to do. This is done by installing a > > > > > factory. This is my mozswing code... I don't know if any of it is > > > > > specific to mozswing or is just javaxpcom (which mozswing is built on > > > > > top of) > > > > > > ObjectFactory factory = new ObjectFactory(); // implements nsIFactory > > > > > XPCOMUtils.register(myContractID, factory); // this calls > > > > > nsIComponentRegistrar.registerFactory for me > > > > > > 2) What it sounds like you want to do, though, is register a java > > > > > component without having to originally run mozilla in java. That is > > > > > "independently" from java, as you put it. My understanding is that to > > > > > do this, you need to use LiveConnect[1]. Read this page about 'Java > > > > > in Firefox Extensions' [2]. > > > > > > The difference is that in 2) I don't think you have a single JVM. I > > > > > think a JVM is created on demand and kept open for your extension. > > > > > Other extensions might not use the same JVM. And if you ran mozilla > > > > > embedded in Java, you would probably still create a new JVM. Not at > > > > > all what I'm after. > > > > > > [1]https://developer.mozilla.org/en/LiveConnect > > > > > [2]https://developer.mozilla.org/en/Java_in_Firefox_Extensions > > > > > > For reference, what I followed was the instructions in these 3 posts, > > > > > but adapted it for Java. > > > > > > "Exposing XPCOM Components in Javascript"http://weblogs.mozillazine.org/weirdal/archives/017188.htmlhttp://web... > > > > > > If I didn't answer your question, please do clarify and I'll try to > > > > > help. > > > > > and for clarity, I can do the following: > > > > > * write an xpcom component in java, and access it from java > > > > * write an xpcom component in javascript, and access it from > > > > javascript > > > > * write an xpcom component in javascript, and access it from java > > > > > I CANNOT > > > > > * write an xpcom component in java, and access it from javascript. > > > > I am assuming that you are using the java embedding, the fact that you > > > can see it calling the QueryInterface is a good sign that you are > > > almost there, chances are there is a small mistake stopping the JS > > > talking to the java. > > > > Reading through your message you appear to be attempting to access the > > > XPCom component from a webpage. I am pretty sure what you are > > > experiencing is not so much a problem with Java but rather the XPCom > > > security subsystem getting in the way, this is done on purpose to stop > > > webpages from being able to use arbitrary XPCom interfaces (imagine > > > the fun if say all the Local File stuff could be used by someone > > > malicious). > > > > Can you try getting / using the component from a Xul page ? > > > > You will probably want to look at the docs for XPConnect (XPConnect is > > > the JS XPCom binding glue docs are herehttps://developer.mozilla.org/en/XPConnect) > > > particularly those about XPConnect wrappers (herehttps://developer.mozilla.org/en/XPConnect_wrappers) > > > Hmmm, some of my updates aren't getting posted here. Maybe I'm > > replying wrong, but I'm trying again. Sorry if this spams. > > > Yes, I'm using java embedded mozilla. > > > I'll try that, but I'm skeptical. I don't have any trouble when I > > implement in javascript with what should be the same logic. I only > > have trouble when it's implemented in Java. > > > Also, I just noticed: "wrapJavaObject" in the JavaXPCOM code base. Do > > I need to call this explicitly? It supposedly returns a C++ pointer > > for my Java object, which XPConnect might be able to handle more > > appropriately? > > _______________________________________________ > > dev-tech-java mailing list > > [email protected]://lists.mozilla.org/listinfo/dev-tech-java > > FYI Adding my interface into the Mozilla-Interfaces.jar does not fix > this. I'm going to try using my component from xulrunner though. If > anyone has some real brain-dead examples I could use, that'd be > helpful, as I haven't written any xul stuff before (and likely won't > again).