erosman
erosman

Reputation: 7771

How to get own Name & version without AddonManger?

Is it possible for an overlay add-on to get its own name & version without using the AddonManager?

In an overlay add-on, the add-on ID is not automatically provided (like a bootstrapped add-on) and thus has to be entered manually in order to use the AddonManager. At the moment, I parse install.rdf for the data.

Is there any alternative method of getting above data?

Upvotes: 0

Views: 50

Answers (2)

Noitidart
Noitidart

Reputation: 37328

Ok how about this?

Do you know the name of your addon?

Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAllAddons(function (addons) {
    var cnt = 0;
    console.log(addons)
    for (var i = 0; i < addons.length; i++) {
        if (addons[i].name == 'Adblock Plus') {
            console.log('addons', cnt, addons[i]);
            console.log(addons[i].name);
            console.log(addons[i].id)
            break;
        }
        cnt++
    }
})

You're going to have to hard code something, the name, the id, something.

Upvotes: 0

nmaier
nmaier

Reputation: 33202

The official API to query add-on information is the AddonManager. Anything else are just hacks or work-arounds.

Parsing install.rdf for the name is such a hack and has its own problems: The add-on manager may have retrieved e.g. an updated name from an online source, e.g. the addons.mozilla.org website, and as such the install.rdf-provided name would be outdated and disagree with the name about:addons would show.

I'd argue that normally and add-on should know it's own ID. But I recognize that there might be some code meant for reuse (like frameworks) where it would be bad to hard-code the id, i.e. edit the file meant for reuse.

In such cases, parsing install.rdf (or some other configuration file) to get the id to be used when querying AddonManager might be a viable alternative.

There is also the (undocumented on MDN) AddonManager.mapURIToAddonID API, which is used internally to map memory measurements to add-ons in about:memory, but which could also be used instead of parsing install.rdf, I guess.

Upvotes: 2

Related Questions