user1863881
user1863881

Reputation: 57

firefox addon install.rdf pass data to server on update

Is there any chance to pass some data to my server through install.rdf when my Firefox add-on check server for update?

Example:

...
<em:updateURL>http://www.site.com/update.php?var=myData</em:updateURL>
...

where "myData" is saved in options.xul or in another place like simple-storage.

Upvotes: 3

Views: 77

Answers (2)

user1863881
user1863881

Reputation: 57

I found one "simple solution" but I dont know if that is also good practice ...

var origLink = "http://www.site.net/update.php?var=myData";
var newsLink = "http://www.site.net/update.php?var=" + simplePref.prefs.myData;

const {Cc,Ci,Cu} = require("chrome");

var observer = {
    QueryInterface: function(iid) {
        if (iid.equals(Ci.nsIObserver) || iid.equals(Ci.nsISupports)) return this;
    },
    observe: function(subject, topic, data){
        if (topic == "http-on-modify-request"){
            var channel = subject.QueryInterface(Ci.nsIChannel);
            if (channel.originalURI.spec == origLink) {
                channel.originalURI.spec  = newsLink;
            }
         }
    }
};
var ObsService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
ObsService.addObserver(observer, "http-on-modify-request", false);

Upvotes: 0

nmaier
nmaier

Reputation: 33192

Yes, but it is quite nasty. The AddonManager will replace a bunch of predefined and dynamic properties in the URL:

  • Register a new component implementing nsIPropertyBag2 (or use an existing implementation, such as ["@mozilla.org/hash-property-bag;1"]).
  • Register your component in the nsICategoryManager under the "extension-update-params" category.
  • Since you mentioned simple-storage: restartless add-ons must also unregister their stuff when being unloaded.

There is a unit test demonstrating how this stuff works. You of course need to adapt it a bit (if alone for require("chrome").

Upvotes: 1

Related Questions