views:

152

answers:

1

I'm using the nsIObserverService to monitor the responses, but it fires events for all tabs (browser in Mozilla terminology). I'd like to know which browser is getting the response in my observe method.

+1  A: 

This sample code snippet from DevMo should do the trick. It allows you to find a browser (tab) given an nsICHannel from an HTTP request/response.

It specifically references the http-on-modify-request event, but aSubject should still be an nsIChannel for http-on-examine-response event events.

Mike
I found that it works fine for events fired by the browser, but sometimes fail when the event was fired from a plugin (like Flash). In these cases, nsIChannel will have no notificationCallbacks, making impossible to find the tab that fired the event.
Fábio