javascript - Firefox Restartless Addon: What information are available to the addon from AddonManager? -
javascript - Firefox Restartless Addon: What information are available to the addon from AddonManager? -
certain info passed restartless add-on
function startup(data, reason) { } info = { id: "***********", version: "1.0", installpath: xpcwrappednative_nohelper, // nsifile resourceuri: xpcwrappednative_nohelper, // nsiuri oldversion: "1.0" };
are above available data? possible addon name without accessing addonmanager?
my experience addonmanager.jsm has proved bulky , slow.[1]
in case above available data, best way nsiuri install.rdf in restartless addons (to accessed xhr)?
in overlay addons, add together resource
link pointing install.rdf. however, resource
not available in restartless addons , setting next not desirable
content addon ./
[1] update: clarification/correction: the timed xhr fetch did not include xml parsing , info extraction. hence overall operation (xhr, callback, responsexml, grab data) take much longer.
are above available data?
yes, apparently. documentation, btw.
is possible addon name without accessing addonmanager?
no. (well, talk parsing install.rdf
yourself, possibility, imho crappy one. addonmanager
supported , recommended way; e.g. consider corner cases meta-data, e.g. meta-data incl. name might have been refreshed online source).
my experience addonmanager.jsm has proved bulky , slow. example, asynchronously parsing install.rdf xhr takes 1ms while getting same info through addonmanager.jsm took 160-170ms. 160-170 times slower.
i uncertainty numbers. 1ms
xhr?! xhr setup takes longer that, , if xpi (or flat install.rdf
) internally cached or @ to the lowest degree in os disk cache, i/o take longer, if didn't parse xml , regexp out need text contents.
also, please note addonmanager
has not initialized meta info database when calling startup()
method. calling addonmanager
query method @ point forcefulness initialization once, means first phone call can bit slow.
in general, shouldn't request data, e.g. add-on name, until need it, in particular during startup.
in case above available data, best way nsiuri install.rdf in restartless addons (to accessed xhr)?
using __script_uri_spec__
or data.resourceuri
:
const {classes: cc, interfaces: ci, utils: cu} = components; cu.import("resource://gre/modules/services.jsm"); // using proper uri parsing allow selfuri = services.io.newuri(__script_uri_spec__, null, null); allow installrdf = services.io.newuri("install.rdf", null, selfuri).spec; cu.reporterror(installrdf); // or using string manipulation allow baseurispec = __script_uri_spec__.substr( 0, __script_uri_spec__.length - "bootstrap.js".length ); allow installrdf2 = baseurispec + "install.rdf"; cu.reporterror(installrdf2); cu.reporterror((installrdf == installrdf2).tostring()); // true allow installrdf = services.io.newuri("install.rdf", null, selfuri).spec; cu.reporterror(installrdf); function startup(data) { // or using bootstrap info allow installrdf3 = services.io.newuri("install.rdf", null, data.resourceuri).spec; cu.reporterror(installrdf3); cu.reporterror((installrdf == installrdf3).tostring()); // true }
__script_uri_spec__
has advantage available immediately, not in entry point methods.
edit got curious, , time stuff.
[log] am: 177, 18, 1, 1, 0, 0, 0, 0, 0, 1 [log] am: avg 0.4 [log] am: 168, 18, 1, 0, 0, 1, 0, 0, 0, 0 [log] am: avg 0.3 [log] am: 169, 21, 1, 0, 1, 0, 0, 0, 0, 0 [log] am: avg 0.3 [log] xx: 160, 25, 25, 4, 1, 2, 2, 3, 1, 1 [log] xx: avg 30.9 [log] xx: 137, 20, 19, 4, 1, 2, 3, 2, 0, 1 [log] xx: avg 26.0 [log] xx: 145, 22, 25, 3, 2, 2, 2, 2, 1, 1 [log] xx: avg 25.1
so turns out xhr isn't faster. tiny bit on first access, little worse on subsequent runs (can explained because costly , runs during startup lot of other stuff consumes resources well), , after difference negligible. xhr still need name dom, while addon.name
.
here stupid micro benchmark:
const {classes: cc, interfaces: ci, utils: cu, constructor: cc} = components; cu.import("resource://gre/modules/services.jsm"); // using proper uri parsing allow selfuri = services.io.newuri(__script_uri_spec__, null, null); allow installrdf = services.io.newuri("install.rdf", null, selfuri).spec; cu.reporterror(installrdf); const xmlhttprequest = cc("@mozilla.org/xmlextras/xmlhttprequest;1", "nsixmlhttprequest"); function log(s) { dump("[log] " + s + "\n"); } function print(name, diffs) { log(name + ": " + diffs.join(", ")); // average, disregarding single best, , 2 worst diffs.sort(); diffs.shift(); diffs.pop(); diffs.pop(); allow avg = diffs.reduce((c,p) => c + p, 0) / diffs.length; log(name + ": avg " + avg.tofixed(1)); } function timeam(id) { cu.import("resource://gre/modules/addonmanager.jsm"); allow diffs = []; var run = function(x) { x = x || 0; allow start = date.now(); addonmanager.getaddonbyid(id, function(addon) { allow d = date.now() - start; diffs.push(d); if (++x == 10) { print("am", diffs); return; } run(x); }); }; run(); } function timexhrxml() { cu.import("resource://gre/modules/addonmanager.jsm"); allow diffs = []; allow run = function(x) { x = x || 0; allow start = date.now(); allow r = new xmlhttprequest(); r.overridemimetype("text/xml"); r.open("get", installrdf); r.onloadend = function() { allow d = date.now() - start; diffs.push(d); if (++x == 10) { print("xx", diffs); return; } run(x); }; r.send(); }; run(); } function startup(data) { cu.reporterror("in"); //timeam(data.id); timexhrxml(data.id); }
javascript firefox firefox-addon firefox-addon-restartless
Comments
Post a Comment