Monday 14 June 2010

Creating Chrome Extensions with GWT

After creating some Chrome extensions and GWT applications, it came natural to try combining both and get rid of JavaScript ;-)

I tried creating 3 GWT modules for background, options and popup with corresponding EntryPoint classes. An interesting effect came up ... while options' onModuleLoad() gets invoked every time, as expected, the behaviour of the popup is somewhat different ... it gets invoked only the very first time. Since I am not able to notice when the popup is re-opened, it is unfortunately a dead-end.

There is no a simple how-to anywhere on internet, so I followed the most famous example, the Speed Tracer, in hope to be able to understand and reuse the code there.

First, the good part, there is a GWT module in the Speed Tracer source doing partial wrapping of the Chrome Extension JavaScript API (com.google.gwt.chrome.crx.Extension), as well as the implementation of a special linker for producing Extensions.

Unfortunately, the following basic questions remain open:

  1. Should the IFRAME or the SSO linker be used?
  2. How should the extension's manifest file be produced? The Speed Tracer is using an abstract class, extending BrowserAction and being annotated with @ManifestInfo (specifying the name and icons for the browser action type of extension). My hope was to be able to provide the manifest file directly, but there might be a much nicer solution in the GWT Chrome Extension module.
  3. How should the wrapper classes be used? They contain protected default constructors, so I guess something along the lines of GWT.create() ... but not sure.

Also, just came to my mind that there is yet no official name for the thing, so before I start using multiple variations, it is required to define the name and the goal:

Ideally, the creation of a Chrome Extension should be possible with usage of a special SSO linker and a GWT module wrapping up all Chrome Extensions API's in JavaScript.  (possible name: GWT4CE - GWT for Chrome Extensions)

Very likely, all required knowledge is already in the code repository of the Speed Tracer project. Maybe there is some nice person involved in the project who is willing to extract the code and provide some jump-start notes.

So much for now ... more after the very much needed 8 hours of sleep ;-)

Update:  After watching the IO session on GWT linkers found out the following additional resources:

  1. gwt-firefox-extension on http://code.google.com/p/gwt-firefox-extension
  2. gwt-chrome on http://code.google.com/p/gwt-chrome
  3. chrudson chrome extension with gwt on http://code.google.com/p/chrudson
  4. gwt-gae-bookmarks, a weekend project from gal.dolber using lots of technology including chrome extension with gwt on http://code.google.com/p/gwt-gae-bookmarks
The gwt-firefox-extension is maintained by Matt Mastracci from DotSpot who did a very nice session about GWT Linkers on this year's Google IO.  I am wondering why didn't he publish something similar for Chrome Extension?!
Despite it's very promising title, the gwt-chrome seems to be abandon. The last two projects look rather promising and I will keep this post updated as I go through them.


4 comments:

  1. Speed Tracer contains all Chrom API Binding for GWT. Check it.
    http://code.google.com/p/speedtracer/source/browse/trunk/src/client/ui/#ui/src/com/google/gwt/chrome

    ReplyDelete
  2. Hi DK, I've just followed pretty much the same path as you have- investigated gwt-chrome and gwt-gae-bookmarks, as well as Speedtracer in an effort to get a simple Hello World-type project going.

    Have you had any luck in figuring things out since this blog posting?

    ReplyDelete
  3. Were there any success on this? I need a base to work from to build a Chrome Extension for my project.

    ReplyDelete
    Replies
    1. You can check out a simple example with code on how to build a chrome extension with GWT here:
      http://tech-drum.blogspot.ch/2012/06/building-chrome-extensions-with-gwt.html

      Delete