Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting add-on version

14 views
Skip to first unread message

dzen

unread,
Oct 7, 2009, 1:48:56 PM10/7/09
to dev-ext...@lists.mozilla.org
Does anybody know how to get <em:version>XXX</em:version> from
install.rdf in javascript.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4463 (20090928) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru


white...@fastmail.us

unread,
Oct 7, 2009, 6:59:09 PM10/7/09
to
Here is how I do it (note this is generalized to permit getting other
metadata info for your addon):

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");

Nickolay Ponomarev

unread,
Oct 8, 2009, 4:51:25 AM10/8/09
to dev-extensions
On Thu, Oct 8, 2009 at 2:59 AM, <white...@fastmail.us> wrote:

> 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

white...@fastmail.us

unread,
Oct 8, 2009, 11:48:56 AM10/8/09
to
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?

Nickolay Ponomarev

unread,
Oct 8, 2009, 5:09:13 PM10/8/09
to white...@fastmail.us, dev-ext...@lists.mozilla.org
On Thu, Oct 8, 2009 at 7:48 PM, <white...@fastmail.us> wrote:

> 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

white...@fastmail.us

unread,
Oct 8, 2009, 6:04:56 PM10/8/09
to
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.

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

Nickolay Ponomarev

unread,
Oct 9, 2009, 4:28:45 AM10/9/09
to white...@fastmail.us, dev-extensions
On Fri, Oct 9, 2009 at 2:04 AM, <white...@fastmail.us> wrote:

> 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

Dave Townsend

unread,
Oct 12, 2009, 3:31:56 PM10/12/09
to
On 09/10/2009 01:28, Nickolay Ponomarev wrote:
> 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).

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.

0 new messages