Re: WebRunner doesn't work in java embedding

"J.J. Zhuang" <[email protected]> Wed, 5 Sep 2007 00:59:05 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.java
Message-ID <534878546.136471188979145957.JavaMail.root__18277.4926223376$1188979376$gmane$org@dogfood.zimbra.com>
I should add that the WebRunner app runs just fine when not embedded in java, meaning directly using xulrunner to execute.

And I'm doing everything on Mac OS X.

Thanks for any help!

J.J. Zhuang


----- "J.J. Zhuang" <[email protected]> wrote:
> Hi,
> 
> I'm having some trouble to run a XUL application like WebRunner
> (http://wiki.mozilla.org/WebRunner) in XULRunner embedded in Java. 
> Following the example given by
> http://developer.mozilla.org/en/docs/JavaXPCOM:Embedding_Mozilla_in_a_Java_Application_using_JavaXPCOM
> I can run any simple XUL application just fine.  However when I tried
> to run WebRunner, the javascript calls to xpcom doesn't seem to work.
> 
> The WebRunner app has a xul file like this:
> 
> <?xml version="1.0"?>
> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
> 
> <window
> xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
>         id="webrunner"
>         windowtype="webrunner:main"
>         title="WebRunner"
>         width="750" height="550"
>         screenX="10" screenY="10"
>         persist="width,height,screenX,screenY">
> 
>   <script type="text/javascript"
> src="chrome://global/content/globalOverlay.js"/>
>   <script type="text/javascript" src="webrunner.js"/>
> 
>   <popupset>
>     <popup id="main-popup">
>       <menuitem id="cut-menuitem" label="Cut"
> oncommand="goDoCommand('cmd_cut');"/>
>       <menuitem id="copy-menuitem" label="Copy"
> oncommand="goDoCommand('cmd_copy');"/>
>       <menuitem id="paste-menuitem" label="Paste"
> oncommand="goDoCommand('cmd_paste');"/>
>       <menuitem id="delete-menuitem" label="Delete"
> oncommand="goDoCommand('cmd_delete');"/>
>       <menuitem id="selectall-menuitem" label="Select All"
> oncommand="goDoCommand('cmd_selectAll');"/>
>     </popup>
>   </popupset>
> 
>   <browser id="main-browser" flex="1" type="content-primary"
> context="main-popup"/>
> 
>   <statusbar>
>     <statusbarpanel id="status" label="" crop="end" flex="1"/>
>     <progressmeter id="progress" mode="determined" value="0%"
> style="display: none"/>
>     <statusbarpanel id="security" label="" style="display: none"/>
>   </statusbar>
> 
> </window>
> 
> When embedded in Java, the main window titled "WebRunner" with
> statusbar pops up just fine, but the javascript (webrunner.js) calls
> to xpcom objects don't seem to work.  Here's the javascript part that
> matters:
> 
> const nsIWebProgress = Components.interfaces.nsIWebProgress;
> const nsIWebProgressListener =
> Components.interfaces.nsIWebProgressListener;
> 
> window.addEventListener("load", startup, false);
> window.addEventListener("unload", shutdown, false);
> 
> function startup()
> {
>   // hookup the browser window callbacks
>   window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
>         .getInterface(Components.interfaces.nsIWebNavigation)
>         .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
>         .treeOwner
>         .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
>         .getInterface(Components.interfaces.nsIXULWindow)
>         .XULBrowserWindow = gXULBrowserWindow;
> 
>   // hookup global webprogress listener
>   var dls = Components.classes["@mozilla.org/docloaderservice;1"].
>                       
> getService(Components.interfaces.nsIWebProgress);
>   dls.addProgressListener(browserProgressListener,
> nsIWebProgress.NOTIFY_ALL);
> 
> 
>   var browserContext = document.getElementById("main-popup");
>   browserContext.addEventListener("popupshowing", popupShowing,
> false);
> 
>   var cl =
> window.arguments[0].QueryInterface(Components.interfaces.nsICommandLine);
>   var startURI = cl.handleFlagWithParam("uri", false);
>   if (startURI == null) {
>     startURI = "http://mozilla.org"
>   }
> 
>   var browser = document.getElementById("main-browser");
>   browser.webNavigation.loadURI(startURI, 0, null, null, null);
> }
> 
> function shutdown()
> {
>   window.removeEventListener("load", startup, false);
>   window.removeEventListener("unload", shutdown, false);
> 
>   var browserContext = document.getElementById("main-popup");
>   browserContext.removeEventListener("popupshowing", popupShowing,
> false);
> }
> 
> What should happen is that the browser in the main window goes to url
> http://mozilla.org on load.  Instead, nothing happens.  At first I
> thought somehow the startup() function didn't run.  But that's not the
> case.  If I add something like 'alert("Hello");" to startup() it works
> just fine.  That gives me the impression that when being embedded in
> java, somehow all the xpcom calls from javascript are silently
> failing.
> 
> Please advise whether this should work, and if so how to fix it.
> 
> Thanks in advance for your help!
> 
> J.J. Zhuang
> _______________________________________________
> dev-tech-java mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-java