__________ Information from ESET NOD32 Antivirus, version of virus signature database 4463 (20090928) __________
The message was checked by ESET NOD32 Antivirus.
const CI = Components.interfaces, CC = Components.classes, CR =
Components.results;
getAddonId: function()
{
return "insert your addon's guid here including {}";
},
getAddonMetaData: function(propertyName)
{
var rdfs =
CC["@mozilla.org/rdf/rdf-service;1"].getService(CI.nsIRDFService);
var extensionDS =
CC["@mozilla.org/extensions/manager;1"].getService(CI.nsIExtensionManager).datasource;
var extension = rdfs.GetResource("urn:mozilla:item:" + getAddonId());
var fieldArc =
rdfs.GetResource("http://www.mozilla.org/2004/em-rdf#" + propertyName);
var valueLiteral = extensionDS.GetTarget(extension, fieldArc, true);
// value contains the version string
return valueLiteral.QueryInterface(CI.nsIRDFLiteral).Value;
},
getOsType: function()
{
// Returns "WINNT" on Windows Vista, XP, 2000, and NT systems;
// "Linux" on GNU/Linux; and "Darwin" on Mac OS X.
return
CC["@mozilla.org/xre/app-info;1"].getService(CI.nsIXULRuntime).OS;
},
getAddonVersion: function()
{
return getAddonMetaData("version");
> Here is how I do it (note this is generalized to permit getting other
> metadata info for your addon):
>
> It's better to use the interface, without touching the underlying RDF
datasource, since then you're less likely to be broken, for example when the
Extension Manager drops RDF:
http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/public/nsIExtensionManager.idl
So:
Components.classes["@mozilla.org/extensions/manager;1"].
getService(Components.interfaces.nsIExtensionManager).
getItemForID("ubiq...@labs.mozilla.com").version
Nickolay
> Wow, I sure like this. But I'll bet it is not available before version 3.x
> of FF and is not in version 2.x of TB. How can I tell where this is
> supported?
>
>
http://www.oxymoronical.com/experiments/xpcomref/applications/Firefox/2.0/interfaces/nsIExtensionManagersays
it is. My guess it's working since 1.5, but you'd have to check.
Nickolay
Having said this, I did a quick test and I find that your suggested
technique does indeed work for both the addon's "version" and "name"
attributes in FF and TB 2.x. This is great!
However, in another of my addons, I use my original technique to get
other metadata from the install.rdf; for example, "optionsURL". I don't
see any attribute for this in the interface provided earlier. Is there
some way, other than going to the RDF, to get metadata for which there
are no attributes defined? Am I missing something?
Thanks Again,
David
> Thanks again. The link below shows documentation for
> nsIExtensionManager. But in those docs, I see no reference to the
> attribute "version" as indicated in your last post. So I don't know what to
> make of the reference you provided. I also do not see any "version"
> attribute for nsIExtensionManager in my archived XulPlanet documentation (on
> which I always relied). So I assumed it was only in later Mozilla versions.
>
Well, I linked to
http://www.oxymoronical.com/experiments/xpcomref/applications/Firefox/2.0/interfaces/nsIExtensionManagerwhich
indicates there is getItemForID in 2.0.
I then checked
http://www.oxymoronical.com/experiments/xpcomref/applications/Firefox/2.0/interfaces/nsIUpdateItem(which
defines the object returned by getItemForID) and saw it was similar
to its current form, but didn't post the link, since you'd have to test to
be sure anyway.
Having said this, I did a quick test and I find that your suggested
> technique does indeed work for both the addon's "version" and "name"
> attributes in FF and TB 2.x. This is great!
>
Thanks for the followup!
> However, in another of my addons, I use my original technique to get other
> metadata from the install.rdf; for example, "optionsURL". I don't see any
> attribute for this in the interface provided earlier. Is there some way,
> other than going to the RDF, to get metadata for which there are no
> attributes defined? Am I missing something?
>
Probably not:
http://mxr.mozilla.org/mozilla-central/search?string=optionsURL (the
extensions.js hit) shows the Add-ons window using the data source. The
nsIUpdateItem focuses on the attributes needed for updating add-ons, so it
doesn't have optionsURL...
These interfaces could definitely be improved. If you're interesting in
helping, it might be worth talking to Dave Townsend (the owner of extension
manager).
Nickolay
We are in the process of significantly overhauling these interfaces to
give more access to more of the information without having to go through
all the XPCOM chaff. Hopefully we'll have something far better in place
in Firefox 3.7.