Mozilla Add-ons Workshop,
20 septembre 2008
Laurent Jouanneau
Récupérer une préférence avec XPCOM :
var prefs =
Components
.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("browser.zoom.");
var isZoom = prefs.getBoolPref("full");
Avec FUEL :
var isZoom = Application
.prefs
.getValue("browser.zoom.full", true);
Application.prefs....has("foo.bar").getValue("foo.bar", "default").setValue("foo.bar","valeur")Application.prefs....get("foo.bar")Application.extensions
.get("extensionid").prefs.get("foo.bar")Récupèrer un objet Extension :
var ext = Application.extensions.get("extension_id")
Permet de stocker des données durant le temps de vie de l'application
Application.storage...
.has(name).get(name, defaultvalue).set(name, value)= stockage centralisé pour toutes les fenêtres
function onUninstall(event) {
// code...
}
var ext = Application.extensions.get("extension_id");
ext.events.addEventListener("uninstall", onUninstall);
ext.events.removeEventListener("uninstall", onUninstall);
var win = Application.activeWindowwin.tabswin.activeTabwin.open(nsIURIobject)win.events
function onTabOpen(event) {
// faire quelque chose
}
var activeWin = Application.activeWindow;
activeWin.events.addListener("TabOpen", onTabOpen);
var browserTab = activeWin.open(url("http://mozilla.org"));
// helper (pourquoi pas plus simple ?)
function url(spec) {
var ios = Components
.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return ios.newURI(spec, null, null);
}
tab.documenttab.focus()tab.close()tab.moveBefore(otherTab)tab.moveToEnd()+/- redondance avec la balise tabbrowser
addBookmark(titre, URI), addSeparator(),
addFolder(titre), remove()id, title, description, typeannotationsparent, childreneventsremove()id, title, uri, description,
keywords, typeannotationsparentevents
var bookmark =
Application.bookmarks.toolbar
.addBookmark("Mozilla", url("http://www.mozilla.com"));
bookmark.keyword = "webdev";
alert(bookmark.title);
alert(bookmark.uri.spec);
bookmark.events.addListener("change",
function(event) { alert(event.data); });
bookmark.title = "MoCo"; // should alert "title"