javascript - How to get an url from nsITraceableChannel? -


so, after reading nsitraceablechannel , nsitraceablechannel, intercept http traffic, , starring at

observe: function(asubject, atopic, adata) {     if (atopic == "http-on-examine-response") {         var newlistener = new tracinglistener();         asubject.queryinterface(ci.nsitraceablechannel);         newlistener.originallistener = asubject.setnewlistener(newlistener);     } } 

i wonder: how exact url asubject? says nsihttpchannel, don't know how either.

nsichannel has .uri member can query. you'll still need qi nsichannel or of true sub-interfaces (nsitraceablechannel not inherit nsichannel despite name).

asubject = asubject.queryinterface(ci.nsichannel); var uri = asubject.uri; // original uri requested before other resolver steps // and/or redirects. var ouri = asubject.originaluri; 

edit queryinterface() sure returns something. following contract returns reference this cast requested interface (if implemented). js-xpcom bridge picks on , therefore stores in js-wrapper object implements interface (same happens instanceof btw).

ch = services.io.newchannel("https://google.com/", null, null); console.log(ch.tostring()); // "[xpconnect wrapped nsichannel]"  ch.queryinterface(ci.nsitraceablechannel);  console.log(ch.tostring()); // "[xpconnect wrapped (nsisupports, nsichannel, nsitraceablechannel)]"  console.log(ch instanceof ci.nsiuploadchannel); // true console.log(ch.tostring()); // "[xpconnect wrapped (nsisupports, nsichannel, nsitraceablechannel, nsiuploadchannel)]" // variable "ch" known implement 4 given interfaces @ point. 

so, practically don't need store result of .queryinterface, common practice do. also, using result of call may come handy if object implements multiple interfaces define same (from point-of-view of js) methods.

you cannot query 2 interfaces 1 call. don't think there issue doing multiple .queryinterface() (and/or instanceof) calls.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -