Bug 1124604 - Move code for getting the outer window id into its own method. r=ato

There are several places which make use of DOMWindowUtils to determine the
outer window id. Lets centralize it to a single method to avoid duplication.

MozReview-Commit-ID: 1IRKMpBPFH

--HG--
extra : rebase_source : 98307ddf40a67e61910aa6391a37fca6081adaa5
This commit is contained in:
Henrik Skupin 2017-01-27 09:09:32 +01:00
parent ba8e2a22b0
commit c94676c778

View File

@ -201,11 +201,8 @@ Object.defineProperty(GeckoDriver.prototype, "windowHandles", {
}
});
} else {
// For other chrome windows beside the browser window, only count the window itself.
let winId = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
hs.push(winId.toString());
// For other chrome windows beside the browser window, only add the window itself.
hs.push(getOuterWindowId(win));
}
}
@ -219,11 +216,7 @@ Object.defineProperty(GeckoDriver.prototype, "chromeWindowHandles", {
let winEn = Services.wm.getEnumerator(null);
while (winEn.hasMoreElements()) {
let foundWin = winEn.getNext();
let winId = foundWin.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
hs.push(winId.toString());
hs.push(getOuterWindowId(winEn.getNext()));
}
return hs;
@ -359,9 +352,8 @@ GeckoDriver.prototype.addFrameCloseListener = function (action) {
*/
GeckoDriver.prototype.addBrowser = function (win) {
let bc = new browser.Context(win, this);
let winId = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
winId = winId + ((this.appName == "B2G") ? "-b2g" : "");
let winId = getOuterWindowId(win);
this.browsers[winId] = bc;
this.curBrowser = this.browsers[winId];
if (!this.wins.has(winId)) {
@ -1204,13 +1196,6 @@ GeckoDriver.prototype.switchToWindow = function* (cmd, resp) {
let switchTo = cmd.parameters.name;
let found;
let getOuterWindowId = function (win) {
let rv = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
return rv;
};
let byNameOrId = function (name, outerId, contentWindowId) {
return switchTo == name ||
switchTo == contentWindowId ||
@ -2856,3 +2841,20 @@ function copy (obj) {
}
return obj;
}
/**
* Get the outer window ID for the specified window.
*
* @param {nsIDOMWindow} win
* Window whose browser we need to access.
*
* @return {string}
* Returns the unique window ID.
*/
function getOuterWindowId(win) {
let id = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
return id.toString();
}