Firefox Mobile Add-on – Cloud Viewer

I just put together a simple restartless add-on, Cloud Viewer, that integrates the Google Docs Viewer into Firefox Mobile. I saw a few similar add-ons on AMO for desktop Firefox, but none for Firefox Mobile. Opera and Dolphin also have add-ons integrating support for online document viewers.

The concept is pretty nice, especially for mobile devices: Open online documents in an online viewer. No need to waste time downloading the file and waste space on your device saving the file. Google’s viewer supports Powertpoint (PPT), Word (DOC, DOCX), Excel (XLS, XLSX), PDF and some non-web image formats. The viewer even uses a mobile UI when running on devices.

Restartless Fun – The Details

I wanted the add-on to be restartless because restartless add-ons rock. I also wanted the add-on to work at a deeper level than a context menu. I could have put a menu item on the context menu to open links in Google’s viewer, but that wouldn’t work on links that weren’t directly pointing to the file – think Google search results. The link Google gives you in a search result redirects you to the actual file, so a context menu item wouldn’t be the best solution. The redirection issue occurs more than you think on the web. Instead, I override an XPCOM component the controls how Firefox treats files the browser doesn’t natively handle. Normally, this component (nsIHelperAppLauncherDialog) starts a file download and will open the file using a local application.

Cloud Viewer overrides the component. I check the extension of the direct URI to the file and if supported, I ask the user if we should open the file in an online viewer. Since the add-on is restartless, I can’t use the normal method of registering JS XPCOM components. I have to manually register and unregister the component myself. This worked fine and was pretty easy. See the source code.

I really think we should be writing more restartless add-ons, especially the simple ones. Great UX and a really small download. Only 2.5KB XPI file for Cloud Viewer. The internal support for restartless add-ons will only keep getting better.

12 Comments

  1. Jos said,

    March 20, 2011 @ 4:14 pm

    Would it be possible to use WebODF? That way the viewer also works for people without an account at a cloud.

  2. Mark Finkle said,

    March 20, 2011 @ 4:28 pm

    @Jos – I don’t think the Google Docs Viewer requires a Google account to use. Seems to work fine for me without needing to log into Google. Even so, I’ll look into supporting other online viewers. As long as the viewer has a good mobile UI and an easy API – it should be easy to add support.

  3. Jos said,

    March 20, 2011 @ 5:02 pm

    WebODF is a FOSS project I work on. You could simply include the code. It’s only a few kb. I’ve tried making a Firefox plugin for it but did not pull it off in a couple of hours and gave up. If the WebODF javascript is in the XPI, viewing an ODF document would require no additional HTTP requests.

    Here’s a demo:
    https://demo.webodf.org/demo/
    The central canvas is WebODF, the rest is there for the demo.

  4. Screwtape said,

    March 20, 2011 @ 5:46 pm

    Man, this is EXACTLY the extension I’ve wanted for desktop Firefox. Would it be possible to port it?

  5. Mark Finkle said,

    March 20, 2011 @ 5:54 pm

    @Screwtape – There are already 3 (or more) add-ons on AMO that do the same thing for desktop Firefox. I link to two in the post. Let em know if Cloud Viewer does something different than those add-ons and I can try to port it over.

  6. Andrea said,

    March 20, 2011 @ 10:31 pm

    Do you know whether there’s a similar extension for Thunderbird?

  7. Mark Finkle: Firefox Mobile Add-on – Cloud Viewer | Firefox Latest News said,

    March 21, 2011 @ 6:14 am

    […] Planet Mozilla No Comments March 21, 2011 By Giovanni Panasiti in Planet Mozilla Tags: Addon, Cloud, Finkle, Firefox, Mark, Mobile, Viewer « Mozilla Releases Firefox 4 RC2 – ConceivablyTech […]

  8. Firefox Mobile Add-on – Cloud Viewer | Maemo Nokia N900 said,

    March 21, 2011 @ 11:01 am

    […] for Mobile Firefox Mobile Add-on – Cloud Viewer – http://starkravingfinkle.org/blog… 21 hours […]

  9. Thoms Kroter said,

    March 21, 2011 @ 2:37 pm

    hey,
    i tried to install this add-on on my nokia n900 but it said that “it is not compatible with MicroBin v.3.5″.

  10. hle said,

    March 23, 2011 @ 3:19 pm

    Can you provide an update about what is no longer working in addons whit this new multi process mechanism is in place. For example it seems it is in fennec no longer possible to get get a file object from a page loaded with a chrome url. I don’t really see why this is no longer working an makes access to sqlite db very difficult. For example loading a webpage with chrome://[addon/conntent/…] this code will fail
    var dbFile = Components.classes[ “@mozilla.org/file/directory_service;1″ ].getService(Components.interfaces.nsIProperties) .get(“ProfD”, Components.interfaces.nsIFile);

    It would be good to have an overview to see a broad range of the limitations – or is this just a bug? In general the difference makes it very hard to develop addon for both, desktop and mobile as long as there are different approaches. Nothing against something new, but it should be not only implemented to the mobile version.

  11. Mark Finkle said,

    March 24, 2011 @ 2:20 pm

    @Thoms – The add-on works in Firefox, not MicroB

  12. Andrea said,

    March 25, 2011 @ 5:34 am

    This is a very requested feature for Thunderbird, as you can see from this GetSatisfaction thread:

    http://getsatisfaction.com/mozilla_messaging/topics/attachment_preview_add_on_for_thunderbird

    Any chance to see it ported?

RSS feed for comments on this post