Extension Developers – FUEL Change

For any extension developers out there using FUEL, I checked in a small, but breaking change (bug 421235). FUEL’s bookmark wrappers only supported bookmark items found on the bookmark menu, which was the only bookmark root available at the time. Things have changed and now bookmark roots exist for menu items, toolbar items, tags and unfiled items.

We updated FUEL to support the new roots, but this could cause existing code to break:

Before change:
Application.bookmarks => BookmarkFolder

After change:
Application.bookmarks => BookmarkRoots

So, code that does something like this:

Application.bookmarks.addBookmark("A cool bookmark", bookmarkURI);

Should now use:

Application.bookmarks.menu.addBookmark("A cool bookmark", bookmarkURI);

Of course, Application.bookmarks.toolbar, Application.bookmarks.tags and Application.bookmarks.unfiled can be used now too.

Extensions, Firefox 3 & T-Shirts

As part of our drive to get as many add-ons updated to work in Firefox 3 as possible, AMO has a new T-Shirt promotion. Get your extension or theme updated to at least Firefox 3.0b3 and you can claim a t-shirt. AMO editors can also claim a t-shirt (lucky dogs). Sign into AMO and go to the developer tools panel to see the “T-Shirt Request” link. Sign up by March 18th to be able to get your t-shirt.

There’s more! If your add-on is in the top 50 most used by Firefox 3 users when Firefox 3 is released, Mozilla will sponsor a party to help you celebrate your success. Polvi has more details.

Stop by #extdev on Mozilla IRC if you need help or just want to talk extensions. We’ll be waiting…

Mozilla 2 – The Future of the Mozilla Platform

Firefox 3 is not even out the door, but work has started on the next refactoring of the Mozilla platform. Dubbed Mozilla 2 (FF3 is built on Mozilla 1.9), it is a chance to make lots of interesting, even scary, changes to the platform. For some background on Mozilla 2 go back and read Brendan’s post. Also, read the Mozilla 2 wiki pages.

Actually, lots of work has already been completed and lots more work is underway. Checkout the notes from the status meetings. You can call in every Wednesday to hear what’s happening. The work on ActionMonkey and XPCOMGC is pretty exciting stuff (for geeks, I know).

Another of the more exciting goals of Mozilla 2 is the move to use more JavaScript and less C++. Yes, C++ is great for those times you really need it (performance & native APIs), but JavaScript can handle many things better, easier and without a compiler. Mozilla 2 is adding a lot of improvements to JavaScript as well, making it faster too.

Less C++ is really part of the “Less Binary Code” theme of Mozilla 2. Another part of that theme is reducing our XPCOM footprint. Benjamin Smedberg recently posted some information about goals for XPCOM in Mozilla 2 to the Wiki and Newsgroup. See Benjamin’s older post on XPCOM changes too. I encourage any extension, embedders and XUL application developers who use binary code to go and read the information.

Extension Developers – Native JSON Parsing

Firefox 3 is using JSON to store data in several places – such as bookmark backups, session restore, and offline manifests. Originally, JSON parsing was scattered through the code. Then it was consolidated to JSON.jsm, a JavaScript code module. Eventually, it was converted into nsIJSON.idl, a C++ XPCOM Component. What does this mean to extension and application developers? Well, you now have access to JSON encoding and decoding routines that can be a lot faster (more in a bit) than the JavaScript counterparts.

var testObj - { name: "Jimmy", age: 25, loves: ["XULRunner", "sunrises", "Mt Dew"] };

// encode to string using javascript implementation
Components.utils.import("resource://gre/modules/json.jsm");
var testJS = JSON.toString(testObj);

// encode to string using native implementation
var Ci = Components.interfaces;
var Cc = Components.classes;

var nativeJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
var testNative = nativeJSON.encode(testObj);

Of course, you can also encode to a string using the json2.js code at json.org

I put together a little benchmark (on bug 410890) to get a feel for the speed improvements that could be obtained using native JSON parsing. The code iterates over a fixed chunk of JSON (taken from Robert Sayre’s unit tests) multiple times. The number of iterations are on the x-axis while the milliseconds required are on the y-axis:

Encoding
json-object-encode.png

Decoding
json-object-decode.png

I found that John Resig did some JSON benchmarking last year, so I made a second benchmark script (same bug) that used his 1600 item array as the JSON source. This code takes the 1600 item array and breaks it into variable sized chunks, then sends those different sized chunks into the JSON parsers. The chunk size is on the x-axis while the milliseconds required are on the y-axis:

Encoding
json-array-encode.png

Decoding
json-array-decode.png

The tests show a very nice performance improvement for encoding JavaScript objects to JSON data. The performance improvements for decoding JSON data into JavaScript objects is smaller, but still very worthwhile. For the curious, the original native JSON code was further optimized to increase the improvements.

Note: Currently, native JSON is only available to privileged code with access to XPCOM. This means that web content JavaScript is not yet able to access the feature. Working is moving ahead in this bug to get these APIs exposed to web content as well. Exposing APIs to web content is something that needs to be thought out and perhaps standardized. There was a proposal to add JSON encoding/decoding to ES4, which seems to have been dropped. Maybe the WHAT WG will draft something.

Check out John Resig’s post on the State of JSON for lots more information on JSON, web content and standards.

Extension Developers – Win Some / Lose Some

Good News

The extension breaking changes made to the Firefox 3 toolbar IDs has been reverted and patched to get the same result in a different way. Any extensions that broke in a nightly version of Firefox 3 should be working correctly now. We also made sure to get the fix into Firefox 3 beta 3. Big “thank you” goes out to Dave, Dão and Gavin for helping me get the patch right and to Connor and Beltzner for making this a critical enough to get into Beta 3.

Bad News

Scriptable IO is a new extension convenience library added to Firefox 3 (bug 380813). It has a lot of nice methods for doing IO without doing much XPCOM. Unfortunately, we found a problem which is related to Scriptable IO, but I haven’t figured out exactly how yet. To fix the problem, we had to backout Scriptable IO for now. We also had some other issues with the API that need to be worked through.

I know of at least one Firefox 3 compatible extension has been affected by this backout. The workarounds are to use the more verbose XPCOM versions of the features. Hopefully, we can take a look getting Scriptable IO back in the future.

Extension Developers – Unbreaking News

Just an update on the breaking changes I mentioned. We are working on a different fix for the original bug, so hopefully, we won’t need to change the XUL element ID’s. You can follow the progress of this alternate fix here.

It looks like we can revert the element ID’s back to their previous values, not break extensions and get the intended visual changes in Firefox 3. I would suggest extension developers hold off on making any changes to overlays.

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.

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.