Search code examples
firefoxgetxpcom

How to get the page element initiating a GET request from inside a firefox extension xpcom component?


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?


Solution

  • 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.