Search code examples
javascriptfirefox-addonxul

How to get reference to XUL iframe that contains a window


From a Firefox extension is there a way to get the XUL iframe/browser that contains a content HTML window. Note I am not asking how to get the current browser (gBrowser) or the browser.xul window. I have target/content HTML window handle, I want to follow it up in the XUL tree (to the XUL element that contains it).

getting-a-reference-to-the-parent-iframe suggest that for HTML iframes you need to iterate through all iframes to find the right one, but I am wondering if there is some Firefox-specific way of accessing a containing XUL iframe (from privileged/extension code).


Solution

  • aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
           .getInterface(Components.interfaces.nsIWebNavigation)
           .QueryInterface(Components.interfaces.nsIDocShell)
           .chromeEventHandler
    

    Note that in Firefox 3.6 and previously this returns an XPCNativeWrapper which you then probably want to unwrap.