Extension settings in a tab in Mozilla 7

In addition to settings in the Addon Manager, Firefox 7 also supports extension settings in a tab. Here's a quick bit of code you can use to provide backwards-compatibility.

Put this file at chrome://mynamespace/content/redirect.xul, point your optionsURL there, and set optionsType to 3.

<?xml version="1.0" ?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"><![CDATA[

const Ci = Components.interfaces;
const Cu = Components.utils;

Cu.import('resource://gre/modules/Services.jsm');

const FAKE_OPTIONS_URL = 'chrome://mynamespace/content/redirect.xul';
const REAL_OPTIONS_URL = 'chrome://mynamespace/content/settings.xul';

window.onload = function () {
var topWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);

if (topWindow.document.documentURI == FAKE_OPTIONS_URL) {
let recentWindow = Services.wm.getMostRecentWindow('navigator:browser');
if (recentWindow && 'switchToTabHavingURI' in recentWindow) {
recentWindow.switchToTabHavingURI(REAL_OPTIONS_URL, true);
} else {
window.openDialog(REAL_OPTIONS_URL, null, 'width=1000,height=600,centerscreen,chrome');
}
setTimeout(window.close, 0);
} else {
location.replace (REAL_OPTIONS_URL);
}
};

//]]></script>
</window>

The code will open REAL_OPTIONS_URL in a new tab in Firefox 4+ and SeaMonkey 2.1+, and a window in anything else.