Extension Developers – Breaking News

Some extension developers using nightly versions of Firefox 3 may have noticed (as Doron Rosenberg did) that a recent change caused some extensions to break. Bug 414836 changed the ID of the used in browser.xul, the main Firefox window (“navigator-toolbox” was changed to “browser-toolbox”). Doron filed bug 415099 to try to get the initial problem fixed another way. I don’t think that will happen as the other ways which were tried caused Ts regressions.

Doron also posted a workaround that nicely handles the problem:
(assuming you are overlaying a vbox into the toolbox)


 
  


  



    ...

You frequently see this approach used in XUL overlays that target Firefox and Thunderbird too.

Ratty (on IRC) also notes that other element IDs have changed too. I am going to get a list of the changes and post them to the MDC article on updating extensions.

Snarky Note: The original bug was a problem in the data persisted in localstore.rdf which would have been much easier to fix if it was localstore.sqlite

Update: Other toolbar related element IDs have been changed as well (in bug 404109) so I thought I’d let you know sooner than later:
“nav-bar” -> “navigation-toolbar”
“PersonalToolbar” -> “personal-toolbar”

Extension Developers – More On Updating

We have been putting out the call for extension developers to start the process of updating their extension to workin Firefox 3. It’s never fun when your extension breaks because of changes in Firefox, but everyone wants to make the platform better. In doing so, we had to break some eggs.

On the bright side, extension developers seem to be really charging ahead full steam. In addition to finding signs of extension update work being done on developer websites, #extdev on Mozilla IRC has been pretty active. I have also noticed posts on Mozillazine forums too.

I thought I’d list a few issues I have seen come up during update discussions:

  • event.preventBubble() has been removed in Firefox 3. It was deprecated in Firefox 2 and code should be using event.stopPropagation(), which also works in Firefox 2.
  • Using window.addEventListener("load", myFunc, true) to listen for web content page loads does not work anymore. Changes were made to improve security and this was fallout from those changes. You should be using gBrowser.addEventListener("load", myFunc, true) anyway. Listening for “load” events on the Firefox main window is a bit overkill. Listening for the event on the tabbed browser makes more sense and works (in Firefox 2 as well).
  • The XUL popup system (popup, menupopup & tooltip) has been significantly overhauled in Firefox 3. Some methods were deprecated (showPopup), some were added (openPopup & openPopupAtScreen) and a whole new type of popup was added (panel). See the new Popup Guide for more information.

There is a wiki page listing a bunch of stuff extension developers should consider or to watch when updating. If you find something, add it to the list.

One of the other benefits of updating early is the potential for helping us find Firefox bugs. We recently had an extension fail to update to Firefox 3 for no apparent reason. It was doing nothing different than when running in Firefox 2 and didn’t seem to hit any of the other know update issues.

Turns out, the extension adds a utility method to the Array prototype which worked fine in Firefox 2, but caused weird exceptions in Firefox 3. The exception ocurred in places where Firefox 3 added uses of for each on Arrays, which is a no-no. The problem didn’t show up in any tests because Firefox 3 doesn’t add anything to the Array prototype. We are fixing this in Firefox, but it could happen to other extensions if they use for each on Arrays. Perhaps the best advice is to always be defensive when dealing with things that could pollute the global namespace – shared by Firefox and all of its extensions.

FOSDEM 2008

Looks like I am headed to Brussels for FOSDEM this year. I was invited to present on Mozilla Prism, along with some coverage of new things in Firefox 3. Which reminds me that I need to blog more about Prism.

For those that don’t know, FOSDEM sets aside rooms for some Open Source projects to use during the conference. There is a Mozilla room where people can get together and talk about all things Mozilla for 2 days. One of the sessions (or workshops) we could do in the Mozilla room is a “Updating Extensions to Firefox 3” or “What’s New for XUL Applications” or even some “How Do I Do … “.

A fairly large contingent has signed up on the wiki.

Extension Developers – Firefox 3 is Coming!

  • Do you or someone you know write extensions for Firefox? Yeah, its pretty easy to do, adds cool enhancements to Firefox and a great way to get stinking rich.
  • Did you hear Firefox 3 is in beta release? There are a ton of new features and lots of work on the internals. Definitely worth trying out.
  • Have you tried to install your extension in Firefox 3 yet? What! Why not? Don’t you realize that other Firefox 3 beta users are trying to use your extension and are cursing you cause you haven’t taken the time to update it yet?

Ok, so the sky isn’t falling yet, but now is a great time for extension developers to get those extensions updated to Firefox 3. The crew at addons.mozilla.org have a bit of information concerning the update for extensions hosted there. The Mozilla Developer Center has a page dedicated to the new features and changes in Firefox 3.

Who knows, your extension might just need a simple bump in the old . On the other hand, it could require more involved overlay changes, JavaScript refactoring or binary component updating.

You might need to worry if your extension:

  • Uses nsIPasswordManager – this has been replaced by nsILoginManager.
  • Depends on History or Bookmarks – these systems were replaced by the Places framework. It’s much more convenient and easy to use, but it will break your old code.
  • Overlays or modifies the Bookmark Manager – this window was significantly updated to support the new bookmarks functionality.
  • Modifies the location bar or its autocomplete dropdown – the awesome bar changes will likely cause some code changes for you.
  • Hosted on a HTTP (non-secure) website – add-ons are now required to provide a secure method for obtaining updates before they can be installed. Add-ons hosted on AMO (addons.mozilla.org) don’t need to worry about this, AMO uses HTTPS.
  • Overlays or modifies the Download Manager – features new and improved APIs, including support for multiple progress listeners and a redesigned user interface.

Procrastination is the enemy! You can do this and #extdev and #addons on Mozilla IRC can help.

JavaScript Code Modules

XPCOM – It’s a place most XUL application and extension developers would rather avoid. There are times when XPCOM components are needed and developers have to bite-the-bullet. A few examples are commandline handlers, autocomplete implementations and the new custom query processors for XUL templates. If you’re lucky, you can use JavaScript to implement the XPCOM component.

Another very common use case in extensions is sharing data across browser windows. Technically, a JavaScript XPCOM component is the right way to go. But yeah, it’s XPCOM.

Well, Firefox 3 (Gecko 1.9) offers a new, simple, non-XPCOM method of sharing data: JavaScript Code Modules. Of course, you can use JS modules for lots of other purposes too. Check it out using a Firefox 3 beta or a nightly XUL Runner.

New Datasources for XUL Templating [Part 3]

I have talked a bit about the new built-in datasources (XML and SQL) developers can use with XUL templating (guide and tutorial). I wanted to wrapup my little foray into XUL template datasources by also talking about custom datasources.

A generic framework for adding any kind of datasource (bug 321170) was created as part of the work to make the new XML and SQL datasources. Creating a custom datasource involves implementing 2 new XPCOM interfaces: nsIXULTemplateQueryProcessor and nsIXULTemplateResult.

With the help of Peter van Hardenberg (of Songbird), I got a simple JavaScript implementation working and available on MDC. The sample is fairly basic, but you could extend it to expose any kind of backend datasource.