-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "[email protected]"}, | |
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