gwt-firefox-extension window chrome oncommand

49 views
Skip to first unread message

Jason Thrasher

unread,
Oct 23, 2010, 4:32:37 AM10/23/10
to DotSpots Open Source
Hi DotSpots folks,
I've got a working GWT project that builds a trivial Firefox
extension, but have a blocker: how can I get Firefox's window chrome
to call into my GWT/JavaScript code from the menuitem "oncommand"
within the xul?

The JavaScript console reports this error:
XULSchoolChrome is not defined

I've tried referencing the script object using $wnd and $doc with no
luck.

The moving parts are:
overlay.xul [SNIP]
<menuitem
id="xulschoolhello-hello-menu-item"
label="&hello;"
accesskey="&item.accesskey;"
oncommand="XULSchoolChrome.BrowserOverlay.sayHello(event);" />
[SNIP]

entry point:
public class MyFirefoxExtension extends ExtensionEntryPoint {
public void onExtensionStart() {
init();
}
private static native void init()
/*-{
$wnd.XULSchoolChrome = {};
$wnd.XULSchoolChrome.BrowserOverlay = {
sayHello : function(aEvent) {
$wnd.alert("in sayHello");
}
};
}-*/;
}

thank you,
Jason

Matt Mastracci

unread,
Oct 23, 2010, 11:37:51 AM10/23/10
to dotspots-o...@googlegroups.com
Hi Jason,

The $wnd and $doc variables are just lightweight stubs in gwt-firefox-extension. They're used to stub out some dependencies that GWT has on a browser window.

Since your Firefox extension runs as a headless component, it doesn't live within a window. There are two ways you can get a hold of a window.

The first way (my preference) is listening for window open events like the Tabs class does. When the window opens, you can then hook it with your script functions:


The second way is putting a script in a browser overlay that creates your component (as a service) and calls an exported method. This will get a reference to your existing component service and call a method on it. This requires you to generate IDL for your component:

<script type="application/x-javascript">
Components.classes["@com.dotspots/singleton;1"].getService().registerWindow(window);
</script>

Jason Thrasher

unread,
Oct 24, 2010, 3:50:01 AM10/24/10
to DotSpots Open Source
Hi Matt,
Okay, $wnd and $doc won't work then. It's actually not important that
I have a reference to the window object itself, rather I'm writing a
harness for use by Selenium tests to do things that vanilla Se won't,
like manage file downloads. So ultimately I'll need to call my
extension's JS from the Se JS.

I see that the DotSpots extension is doing something very similar to
what I want using IDL, so I'm digging into that route (and learning
about IDL). You've got xul like:

<menuitem id="dotSpotsToolsPreferences" label="&dotSpots-
Preferences;"
oncommand="dotSpots.goPreferences(event);
event.stopPropagation();" />

I assume it's the IDL that's providing access to the dotSpots object
for oncommand? How is dotSpots exposed from within GWT?

I tried using window open events, but wasn't able to get it to work.
I was trying to hook into the Browser.contentWindow, is that what
you'd use?

Thanks,
Jason




On Oct 23, 8:37 am, Matt Mastracci <matt...@dotspots.com> wrote:
> Hi Jason,
>
> The $wnd and $doc variables are just lightweight stubs in gwt-firefox-extension. They're used to stub out some dependencies that GWT has on a browser window.
>
> Since your Firefox extension runs as a headless component, it doesn't live within a window. There are two ways you can get a hold of a window.
>
> The first way (my preference) is listening for window open events like the Tabs class does. When the window opens, you can then hook it with your script functions:
>
> http://code.google.com/p/gwt-firefox-extension/source/browse/trunk/sr...
Reply all
Reply to author
Forward
0 new messages