Archive for the 'Extension Development' Category

Events don’t fire after customizing the toolbar?

Wednesday, July 18th, 2007

There used to be a bug in Gecko where calling removeChild on a node with an event listener attached makes the node lose the event listener. This bug is present in Firefox 2.0, but won’t be in Firefox 3.0. One unexpected result of this bug is that if the user customizes their toolbar, all event […]

Returning an array from a JavaScript XPCOM

Wednesday, May 9th, 2007

IDL
The second last word is the type of the objects in the array.
void getArray(out unsigned long count, [array, size_is(count), retval] out string retv);
XPCOM

getArray: function(count) {
var returnValue = [”foo”, “bar”, “baz”];
count.value = returnValue.size;
return returnValue;
}
Calling code

var xpcom = Components.classes[”@example.com;1″].getService(Components.interfaces.nsIExample);
var array = xpcom.getArray({});

Data URIs and XBL

Monday, April 30th, 2007

XBL lets you define behaviour by specifying a CSS property. Most of the time, these bindings define how controls act. In the case of user styles, they can do things like moving and removing elements (for ad blocking, for example). And just like people like to include images in their styles by way of data […]

Extension integration: It’s All Text!

Tuesday, March 13th, 2007

It’s All Text! is an extension that lets the user edit textboxes with their favourite editor. As was the case with Rainbowpicker, it has sensible default behaviour - it applies to all HTML text areas. Unlike Rainbowpicker, It’s All Text! has a well-defined, simple API to extend its functionality into other areas.
We must load […]

Extension integration: Rainbowpicker

Friday, March 9th, 2007

This is the first in a series of posts about integrating extensions with other extensions. That is, providing advanced functionality in your extension based on the presence of other extensions.
Rainbowpicker is an extension that changes the way XUL colorpickers work - for button type colorpickers, instead of the default behaviour where a drop down is […]

Opening links from menus, the right way

Tuesday, February 6th, 2007

Here’s what I currently do to open a link from a menu, respecting what the user actually wants to happen and without repeating code.
<!– … –>
<menuitem oncommand=”myExtension.foo(event)” onclick=”checkForMiddleClick(this, event)”/>
<!– … –>
/* … */
foo: function(event) {
myExtension.openURL(event, “theKey”);
},
openURL: function(event, key) {
openUILinkIn(myExtension.urlStrings.getString(key), whereToOpenLink(event));
},
/* … */
What to take note of:

openUILinkIn, whereToOpenLink, and checkForMiddleClick are part […]

Avoiding extension conflicts

Tuesday, February 6th, 2007

Problems that occur when two specific extensions are installed are difficult to debug. You often won’t see the problem yourself, it’ll be some user reporting it. You have to lasso them long enough to figure out that that indeed is what’s happening rather than some system-specific or a difficult-to-reproduce bug. Once the conflicting extension is […]

Creating a data URI from a file

Sunday, January 28th, 2007

Data URIs are a way of making a URI that actually contains the data inside it. They’re useful when you want to include normally external resources within another file (in my instance, including images in user styles).
The data URI kitchen is an online resource that lets you generate data URIs from files. But what if […]

Watching user input

Saturday, January 27th, 2007

A problem often encountered when making interfaces with JavaScript is how to get a function to run whenever a user changes the value of a text field. onchange only happens when the focus leaves the control, onkeyup will pick up useless strokes (like arrow keys) and won’t pick up on changes done by the mouse […]

Showing a menupopup in multiple places

Friday, January 26th, 2007

Sometimes in an extension you want to show the same menupopup in multiple places. Some users like status bar icons, some like using things under Tools, some like a toolbar button. (For the love of god, don’t put it everywhere by default! Put in some sensible defaults and rely on prefs or user styles for […]

Adventures in development - Web standards and Firefox extensions