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-p开发者_如何转开发arent-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).
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.
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
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.
精彩评论