Skip to content

Instantly share code, notes, and snippets.

@cgranade
Forked from anonymous/x
Created October 28, 2008 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgranade/20508 to your computer and use it in GitHub Desktop.
Save cgranade/20508 to your computer and use it in GitHub Desktop.
xpc-interfaces: Provides a Ubiquity command to query interfaces supported by a contract ID.
function get_ifaces(component) {
// WARNING: This is implemented in a stupid way.
var nsis = Components.interfaces.nsISupports;
var cc = Components.classes;
var clazz = cc[component].createInstance(nsis);
var ifaces = Array();
for each (iface in Components.interfaces) {
if (clazz instanceof iface) {
ifaces.push(iface);
}
}
return ifaces;
}
/* This is a template command */
CmdUtils.CreateCommand({
name: "xpc-interfaces",
icon: "http://example.com/example.png",
homepage: "http://example.com/",
author: { name: "Christopher Granade", email: "cgranade@gmail.com"},
license: "GPL",
description: "Lists interfaces supported by an XPCOM component.",
help: "Select the contract ID of an XPCOM component.",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
var compId = input.text;
var itemTemplate = "<li><tt>${interface}</tt></li>";
var listTemplate =
"<p>Interfaces supported by <tt>${component}</tt>:</p>" +
"<ul>${interfaces}</ul>"
var errorTemplate = "<strong>${name}</strong>: ${message}";
var noCompTemplate = "<p>No such component: <tt>${component}</tt></p>";
try {
var ifaces = get_ifaces(compId);
if (ifaces == 0) {
pblock.innerHTML = CmdUtils.renderTemplate(noCompTemplate, {"component": compId});
} else {
var itemHTMLArray = ifaces.map(function (item) {
return CmdUtils.renderTemplate(itemTemplate, {"interface": item.toString()});
});
pblock.innerHTML = CmdUtils.renderTemplate(listTemplate, {"component": compId, "interfaces": itemHTMLArray.join("")});
}
} catch (e) {
pblock.innerHTML = CmdUtils.renderTemplate(errorTemplate, {"name": e.name, "message": e.message});
}
},
execute: function(input) {
CmdUtils.setSelection("You selected: "+input.html);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment