Reputation: 57
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
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
Reputation: 33192
Yes, but it is quite nasty. The AddonManager
will replace a bunch of predefined and dynamic properties in the URL:
nsIPropertyBag2
(or use an existing implementation, such as ["@mozilla.org/hash-property-bag;1"]
).nsICategoryManager
under the "extension-update-params"
category.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