1

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

Community
  • 1
  • 1
studgeek
  • 14,272
  • 6
  • 84
  • 96

3 Answers3

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

Neil
  • 54,642
  • 8
  • 60
  • 72
  • Hi @Neil, I haven't had a chance to test this yet, but it look very promising. Will get back to here once I do. – studgeek Aug 17 '11 at 19:31
0

From an extension's point of view, "window" is the top level chrome window of Firefox, containing special <vbox> and <hbox> elements for the buttons, toolbars, etc. You can see these in the DOM Inspector if you go to File -> Inspect Chrome Document -> (Browser Window). To get the current page frame from extension's Javascript, use content.

To get the outer window, use window.parent, or window.parent.top. If the inner document is chrome-privileged, perhaps you could check for a special attribute or variable at the window level.

NoBugs
  • 9,310
  • 13
  • 80
  • 146
  • Thanks, I am looking to do the opposite. I have a "content" and I want to find out which XUL browser/iframe is holding it. I updated my question a bit more to hopefully make it clearer. – studgeek Jul 12 '11 at 01:21
0

In an extension your code is typically already executing in the main window, so you simply use gBrowser (see https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#From_main_window).

If your code runs in a different window then window mediator is your friend: https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#From_a_dialog

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Thanks, but I am looking to move up the tree from a content HTML window, not to get the current XUL window (gBrowser) or to find another XUL window. Unless the mediator does something I am missing? I updated my question a bit more to hopefully make it clearer. – studgeek Jul 12 '11 at 01:19
  • Looks like I misunderstood. See http://stackoverflow.com/questions/6484823/finding-the-tab-associated-with-a-dom-window/6489272#6489272 then. – Wladimir Palant Jul 12 '11 at 05:49