2

I have a firefox extension xpcom component that listens to http-on-modify-request and gets the location of the page making the request:

getLocationOfOriginatingWindow: function (httpChannel) {
    try {  
        var notificationCallbacks;

        if (httpChannel.notificationCallbacks) {
            notificationCallbacks = httpChannel.notificationCallbacks;
        }
        else if (httpChannel.loadGroup && httpChannel.loadGroup.notificationCallbacks) {
            notificationCallbacks = httpChannel.loadGroup.notificationCallbacks;        
        }
        else {
            return null;
        }

        return notificationCallbacks.getInterface(Components.interfaces.nsIDOMWindow).top.location;  
    }  
    catch (e) {
        DEBUG("Exception getting Window Location: " + e + "\nChannel URI: " + httpChannel.URI.spec); 
        return null;  
    }  
},

I would also like to get the page element that made the request (img, script etc.). Is there a way to do the from the httpChannel?

Anthony Bak
  • 1,123
  • 3
  • 10
  • 16

1 Answers1

0

There's no specific way to tell what made the request from the HTTP observer, since there are so many different ways of triggering requests, such as a CSS background image rollover. You could try attacking the problem from the content policy end, which I believe gives you more information.

Neil
  • 54,642
  • 8
  • 60
  • 72
  • I'm not sure what you mean by content policy end. If you mean by looking at the page and searching for elements that fire get requests the problem is that some objects (scripts, flash) can be quite opaque. Maybe you could elaborate? – Anthony Bak Jan 28 '11 at 06:29
  • There is a system for detecting resource loads by web pages called content policy. When you register for content policy, you get to watch all resource loads that have not already been blocked by some other content policy. See http://mxr.mozilla.org/mozilla-central/source/content/base/public/nsIContentPolicy.idl for the types of loads that you can watch. – Neil Jan 28 '11 at 21:44