Bug 1124604 - Move code for getting the outer window id into its own method.
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
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -196,39 +196,32 @@ Object.defineProperty(GeckoDriver.protot
if (tabBrowser) {
tabBrowser.tabs.forEach(tab => {
let winId = this.getIdForBrowser(browser.getBrowserForTab(tab));
if (winId !== null) {
hs.push(winId);
}
});
} 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));
}
}
return hs;
},
});
Object.defineProperty(GeckoDriver.prototype, "chromeWindowHandles", {
get : function () {
let hs = [];
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;
},
});
GeckoDriver.prototype.QueryInterface = XPCOMUtils.generateQI([
Ci.nsIMessageListener,
@@ -354,19 +347,18 @@ GeckoDriver.prototype.addFrameCloseListe
* @param {nsIDOMWindow} win
* Window for which we will create a browsing context.
*
* @return {string}
* Returns the unique server-assigned ID of the window.
*/
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)) {
// add this to seenItems so we can guarantee
// the user will get winId as this window's id
this.wins.set(winId, win);
}
};
@@ -1199,23 +1191,16 @@ GeckoDriver.prototype.setWindowPosition
*
* @param {string} name
* Target name or ID of the window to switch to.
*/
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 ||
switchTo == outerId;
};
let winEn = Services.wm.getEnumerator(null);
while (winEn.hasMoreElements()) {
@@ -2851,8 +2836,25 @@ GeckoDriver.prototype.commands = {
function copy (obj) {
if (Array.isArray(obj)) {
return obj.slice();
} else if (typeof obj == "object") {
return Object.assign({}, 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();
+}