Bug 923166 - Use nsIDOMWindowUtils.containerElement inside of LayoutHelpers.getFrameElement. r=paul

This commit is contained in:
Brian Grinstead 2013-10-10 08:57:33 -05:00
parent ccc07d493f
commit aacef8c89a

View File

@ -368,37 +368,17 @@ LayoutHelpers.prototype = {
* like win.frameElement, but goes through mozbrowsers and mozapps iframes.
*
* @param DOMWindow win The window to get the frame for
* @return DOMElement The element(only <iframe> for now) in which the window
* is embedded. A null return from this function does not imply that it is a
* top level window. Use isTopLevelWindow(win) if needed.
* @return DOMElement The element in which the window is embedded.
*/
getFrameElement: function LH_getFrameElement(win) {
if (this.isTopLevelWindow(win)) {
return null;
}
// Get the docShell for that window
let docShell = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);
let winUtils = win.
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
if (docShell.isBrowserOrApp) {
// Get the docShell's same-type parent ignoring mozBrowser and mozApp
// boundaries
let parentDocShell = docShell.getSameTypeParentIgnoreBrowserAndAppBoundaries();
// Once we have a parent, get all its iframes and loop through them
// to find `win`. If we do, it means win is a nested iframe
let parentDoc = parentDocShell.contentViewer.DOMDocument;
let allIframes = parentDoc.querySelectorAll("iframe");
for (let f of allIframes) {
if (f.contentWindow === win) {
return f;
}
}
return null;
} else {
return win.frameElement;
}
return winUtils.containerElement;
},
};