I'm adding some new functionality in a Firefox extension, TryAgain, that traps HTTP error codes (e.g. 500) and automatically retries loading the page after some interval.
Trapping the codes works excellently, and I'm trying to tally the total number of retries and store this in the tab using Session Store. Unfortunately, right now I'm getting a reference to a DOM window (through interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow)
), but I need a reference to a tab, which is a nsIDOMNode
as per nsISessionStore docs on setTabValue().
What I have so far (I've snipped the actual retrying out of this example):
// This function implements the nsIObserverService interface and observes
// the status of all HTTP channels
observe : function(aSubject, aTopic, aData) {
var httpChannel = aSubject
.QueryInterface(Components.interfaces.nsIHttpChannel);
if (httpChannel.responseStatus == 500) {
var domWindow;
try {
var notificationCallbacks;
if (httpChannel.notificationCallbacks) {
notificationCallbacks = httpChannel.notificationCallbacks;
} else {
notificationCallbacks = aSubject.loadGroup
.notificationCallbacks;
}
var interfaceRequestor = notificationCallbacks
.QueryInterface(Components.interfaces
.nsIInterfaceRequestor);
domWindow = interfaceRequestor
.getInterface(Components.interfaces.nsIDOMWindow);
} catch (e) {
// No window associated with this channel
return;
}
var ss = Components.classes["@mozilla.org/browser/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
ss.setTabValue(domWindow, "foo", "bar");
}
},
This of course fails on setTabValue
with an invalid parameter. How can I get the tab associated with the DOM window?
As an alternative solution, can I store variables associated with a DOM window in some way such that I don't have to clean up the memory myself?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…