Re: Having trouble with Embedding Mozilla
Greg Bowyer <[email protected]> Thu, 12 Jul 2007 13:23:39 +0100
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Message-ID | <7MOdnX-VoMIAgAvbnZ2dnUVZ_r6vnZ2d__11009.2063122012$1184243117$gmane$org@mozilla.org> |
No if you use the JavaXPCom route it will use the same VM as embedded XulRunner / Gecko. Note that you need to generate both the interface, and the typelib (the xpt) for an xpcom component for Javascript to be able to consume it. J.J. Zhuang wrote: > An update on my question. I finally got it to work. Now the embedded mozilla can run my simple xul app just fine and a window can pop up. > > My question now becomes how I can access java classes from javascripts running in the embedded xul app? If I use java xpcom, will the xul app try to create another VM instance using java plugin? I certainly want the VM to be the same as the embedding VM. > > Thanks for any input you have! > > J.J. Zhuang > > > ----- "J.J. Zhuang" <[email protected]> wrote: >> I'm trying out embedding mozilla in my java program. I followed the >> example give at this URL: >> >> http://developer.mozilla.org/en/docs/JavaXPCOM:Embedding_Mozilla_in_a_Java_Application_using_JavaXPCOM >> >> Here's my code: >> >> public class SimpleLauncher { >> >> public static class LocationProvider implements >> IAppFileLocProvider { >> >> File grePath; >> >> public LocationProvider(File grePath) { >> this.grePath = grePath; >> } >> >> public File getFile(String aProp, boolean[] aPersistent) { >> System.out.println(aProp); >> System.out.println(aPersistent); >> >> File file = null; >> if (aProp.equals("GreD") || aProp.equals("GreComsD")) { >> file = grePath; >> if (aProp.equals("GreComsD")) { >> file = new File(file, "components"); >> } >> } else if (aProp.equals("MozBinD") || >> aProp.equals("CurProcD") >> || aProp.equals("ComsD") || aProp.equals("ProfD")) >> { >> file = grePath; >> if (aProp.equals("ComsD")) { >> file = new File(file, "components"); >> } >> } >> return file; >> } >> >> public File[] getFiles(String aProp) { >> System.out.println(aProp); >> >> File[] files = null; >> if (aProp.equals("APluginsDL")) { >> files = new File[1]; >> files[0] = new File(grePath, "plugins"); >> } >> return files; >> } >> } >> >> public static void main(String[] args) { >> >> Mozilla mozilla = Mozilla.getInstance(); >> GREVersionRange[] range = new GREVersionRange[1]; >> range[0] = new GREVersionRange("1.8.0", true, "1.9", false); >> // work with trunk nightly version 1.9a1 >> >> try { >> File grePath = Mozilla.getGREPathWithProperties(range, >> null); >> System.out.println(grePath.toString()); >> >> mozilla.initialize(grePath); >> LocationProvider locProvider = new >> LocationProvider(grePath); >> mozilla.initEmbedding(grePath, grePath, locProvider); >> >> // Now we need to start an XUL application, so we get an >> instance of >> // the >> // XPCOM service manager >> nsIServiceManager serviceManager = >> mozilla.getServiceManager(); >> >> // Now we need to get the >> @mozilla.org/toolkit/app-startup;1 >> // service: >> nsIAppStartup appStartup = (nsIAppStartup) serviceManager >> .getServiceByContractID( >> "@mozilla.org/toolkit/app-startup;1", >> nsIAppStartup.NS_IAPPSTARTUP_IID); >> >> // Get the nsIWindowWatcher interface to the above >> nsIWindowCreator windowCreator = (nsIWindowCreator) >> appStartup >> >> .queryInterface(nsIWindowCreator.NS_IWINDOWCREATOR_IID); >> >> // Get the window watcher service >> nsIWindowWatcher windowWatcher = (nsIWindowWatcher) >> serviceManager >> .getServiceByContractID( >> "@mozilla.org/embedcomp/window-watcher;1", >> nsIWindowWatcher.NS_IWINDOWWATCHER_IID); >> >> // Set the window creator (from step 6) >> windowWatcher.setWindowCreator(windowCreator); >> >> // Create the root XUL window: >> nsIDOMWindow win = windowWatcher.openWindow(null, >> "chrome://your-app/content/window.xul", >> "mywindow", >> "chrome,resizable,centerscreen", null); >> >> // Set this as the active window >> windowWatcher.setActiveWindow(win); >> >> // Hand over the application to xpcom/xul, this will >> block: >> appStartup.run(); >> >> } catch (FileNotFoundException e) { >> // this exception is thrown if greGREPathWithProperties >> cannot find >> // a GRE >> } catch (XPCOMException e) { >> // this exception is thrown if initEmbedding failed >> } >> >> } >> } >> >> I can see that the correct xulrunner is found and the >> LocationProvider.getFile() is being called. Obviously the url >> "chrome://your-app/content/window.xul" should be replaced with >> something real. But no matter what I try nothing happens. I don't >> see any window popping up. I'm on Mac OS X and have not tried this on >> Windows. Has anyone ever got this to work following the instructions? >> >> Thanks for your help! >> >> J.J. Zhuang >