4

I have an observer on "http-on-modify-request" and I need to get the DOMWindow that request is associated with.

The following code was taken from AdBlock Plus and is based on this article.

function getRequestWindow(/**nsIChannel*/ channel) /**nsIDOMWindow*/
  {
    try
    {
      if (channel.notificationCallbacks)
        return channel.notificationCallbacks.getInterface(Ci.nsILoadContext).associatedWindow;
    } catch(e) {}

    try
    {
      if (channel.loadGroup && channel.loadGroup.notificationCallbacks)
        return channel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext).associatedWindow;
    } catch(e) {}

 return null;
}

However, this code is no longer working on multiprocess Firefox (v36+, right now on Firefox Nightly).

Any ideas?

erikvold
  • 15,988
  • 11
  • 54
  • 98
josesigna
  • 488
  • 3
  • 16

2 Answers2

1

I haven't tried that myself, so take with a grain of salt:

Instead of getting the nsIDOMWindow itself from the channel you can get the innerWindowId from the nsIChannel.loadInfo. The window id can then be resolved inside a frame script by QueryInterfaceing to nsIDOMWindowUtils.

the8472
  • 40,999
  • 5
  • 70
  • 122
0

To talk to content, the recommended path for this sort of use case is probably Frame Scripts, see this documentation on MDN for more.

therealjeffg
  • 5,790
  • 1
  • 23
  • 24
  • 2
    I'm not sure how to use this, could you please provide an example? I don't need to actually access the DOM content, I just need to get the tab so I know which page made HTTP request. – josesigna Dec 19 '14 at 20:47