I am adding some new features to the Firefox extension, TryAgain , which intercepts HTTP error codes (e.g. 500) and automatically retries loading after some interval.
The code trap works fine, and I am trying to calculate the total number of attempts and store this in a tab using the session store . Unfortunately, right now I get a link to the DOM window (via interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow) ), but I need a link to the tab, which is nsIDOMNode by nsISessionStore docs to setTabValue () .
What I had so far (I disabled the actual retry from 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, does not work on setTabValue with an invalid parameter. How can I get the tab associated with the DOM window?
As an alternative solution, can I somehow store the variables associated with the DOM window, so that I do not need to clear the memory myself?
Paul lammertsma
source share