2016-05-10 15:29:21 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
2017-06-28 21:04:14 +03:00
|
|
|
/* global frame */
|
2016-05-10 15:29:21 +03:00
|
|
|
|
2017-01-04 22:37:13 +03:00
|
|
|
const {utils: Cu} = Components;
|
2016-05-10 15:29:21 +03:00
|
|
|
|
|
|
|
Cu.import("chrome://marionette/content/element.js");
|
2017-06-28 21:01:49 +03:00
|
|
|
const {
|
|
|
|
NoSuchWindowError,
|
|
|
|
UnsupportedOperationError,
|
|
|
|
} = Cu.import("chrome://marionette/content/error.js", {});
|
2016-05-10 15:29:21 +03:00
|
|
|
Cu.import("chrome://marionette/content/frame.js");
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["browser"];
|
|
|
|
|
|
|
|
this.browser = {};
|
|
|
|
|
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
2017-01-26 18:42:35 +03:00
|
|
|
/**
|
|
|
|
* Get the <xul:browser> for the specified tab.
|
|
|
|
*
|
|
|
|
* @param {<xul:tab>} tab
|
|
|
|
* The tab whose browser needs to be returned.
|
|
|
|
*
|
|
|
|
* @return {<xul:browser>}
|
2017-01-30 17:35:16 +03:00
|
|
|
* The linked browser for the tab or null if no browser can be found.
|
2017-01-26 18:42:35 +03:00
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
browser.getBrowserForTab = function(tab) {
|
|
|
|
// Fennec
|
2017-01-30 17:35:16 +03:00
|
|
|
if ("browser" in tab) {
|
2017-01-26 18:42:35 +03:00
|
|
|
return tab.browser;
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// Firefox
|
2017-01-30 17:35:16 +03:00
|
|
|
} else if ("linkedBrowser" in tab) {
|
2017-01-26 18:42:35 +03:00
|
|
|
return tab.linkedBrowser;
|
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
|
|
|
|
return null;
|
2017-01-26 18:42:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the tab browser for the specified chrome window.
|
|
|
|
*
|
|
|
|
* @param {nsIDOMWindow} win
|
|
|
|
* The window whose tabbrowser needs to be accessed.
|
|
|
|
*
|
|
|
|
* @return {<xul:tabbrowser>}
|
|
|
|
* Tab browser or null if it's not a browser window.
|
|
|
|
*/
|
2017-06-30 02:40:24 +03:00
|
|
|
browser.getTabBrowser = function(win) {
|
|
|
|
// Fennec
|
2017-01-30 17:35:16 +03:00
|
|
|
if ("BrowserApp" in win) {
|
2017-01-26 18:42:35 +03:00
|
|
|
return win.BrowserApp;
|
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// Firefox
|
2017-01-30 17:35:16 +03:00
|
|
|
} else if ("gBrowser" in win) {
|
2017-01-26 18:42:35 +03:00
|
|
|
return win.gBrowser;
|
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
|
|
|
|
return null;
|
2017-01-26 18:42:35 +03:00
|
|
|
};
|
|
|
|
|
2016-05-10 15:29:21 +03:00
|
|
|
/**
|
|
|
|
* Creates a browsing context wrapper.
|
|
|
|
*
|
|
|
|
* Browsing contexts handle interactions with the browser, according to
|
2017-05-04 12:45:08 +03:00
|
|
|
* the current environment (Firefox, Fennec).
|
2016-05-10 15:29:21 +03:00
|
|
|
*
|
|
|
|
* @param {nsIDOMWindow} win
|
|
|
|
* The window whose browser needs to be accessed.
|
|
|
|
* @param {GeckoDriver} driver
|
|
|
|
* Reference to the driver the browser is attached to.
|
|
|
|
*/
|
|
|
|
browser.Context = class {
|
|
|
|
|
2017-01-04 22:37:13 +03:00
|
|
|
/**
|
2017-07-06 19:02:19 +03:00
|
|
|
* @param {ChromeWindow} win
|
|
|
|
* ChromeWindow that contains the top-level browsing context.
|
2017-01-04 22:37:13 +03:00
|
|
|
* @param {GeckoDriver} driver
|
|
|
|
* Reference to driver instance.
|
|
|
|
*/
|
2016-05-10 15:29:21 +03:00
|
|
|
constructor(win, driver) {
|
|
|
|
this.window = win;
|
|
|
|
this.driver = driver;
|
2017-01-04 22:37:13 +03:00
|
|
|
|
|
|
|
// In Firefox this is <xul:tabbrowser> (not <xul:browser>!)
|
|
|
|
// and BrowserApp in Fennec
|
2017-01-26 18:42:35 +03:00
|
|
|
this.tabBrowser = browser.getTabBrowser(win);
|
2017-01-04 22:37:13 +03:00
|
|
|
|
2016-05-10 15:29:21 +03:00
|
|
|
this.knownFrames = [];
|
2017-01-04 22:37:13 +03:00
|
|
|
|
|
|
|
// Used to set curFrameId upon new session
|
2016-05-10 15:29:21 +03:00
|
|
|
this.newSession = true;
|
2017-01-04 22:37:13 +03:00
|
|
|
|
2016-05-20 18:49:19 +03:00
|
|
|
this.seenEls = new element.Store();
|
2016-05-10 15:29:21 +03:00
|
|
|
|
2017-06-30 02:40:24 +03:00
|
|
|
// A reference to the tab corresponding to the current window handle,
|
|
|
|
// if any. Specifically, this.tab refers to the last tab that Marionette
|
|
|
|
// switched to in this browser window. Note that this may not equal the
|
|
|
|
// currently selected tab. For example, if Marionette switches to tab
|
|
|
|
// A, and then clicks on a button that opens a new tab B in the same
|
|
|
|
// browser window, this.tab will still point to tab A, despite tab B
|
|
|
|
// being the currently selected tab.
|
2016-05-10 15:29:21 +03:00
|
|
|
this.tab = null;
|
2017-07-06 19:02:19 +03:00
|
|
|
|
|
|
|
// Commands which trigger a page load can cause the frame script to be
|
|
|
|
// reloaded. To not loose the currently active command, or any other
|
|
|
|
// already pushed following command, store them as long as they haven't
|
|
|
|
// been fully processed. The commands get flushed after a new browser
|
|
|
|
// has been registered.
|
2016-05-10 15:29:21 +03:00
|
|
|
this.pendingCommands = [];
|
2017-07-06 19:02:19 +03:00
|
|
|
this._needsFlushPendingCommands = false;
|
2016-05-10 15:29:21 +03:00
|
|
|
|
2017-01-04 22:37:13 +03:00
|
|
|
// We should have one frame.Manager per browser.Context so that we
|
|
|
|
// can handle modals in each <xul:browser>.
|
2016-05-10 15:29:21 +03:00
|
|
|
this.frameManager = new frame.Manager(driver);
|
|
|
|
this.frameRegsPending = 0;
|
|
|
|
|
|
|
|
// register all message listeners
|
|
|
|
this.frameManager.addMessageManagerListeners(driver.mm);
|
|
|
|
this.getIdForBrowser = driver.getIdForBrowser.bind(driver);
|
|
|
|
this.updateIdForBrowser = driver.updateIdForBrowser.bind(driver);
|
|
|
|
}
|
|
|
|
|
2017-03-27 12:02:36 +03:00
|
|
|
/**
|
|
|
|
* Returns the content browser for the currently selected tab.
|
|
|
|
* If there is no tab selected, null will be returned.
|
|
|
|
*/
|
|
|
|
get contentBrowser() {
|
|
|
|
if (this.tab) {
|
|
|
|
return browser.getBrowserForTab(this.tab);
|
2017-06-30 02:40:24 +03:00
|
|
|
} else if (this.tabBrowser &&
|
|
|
|
this.driver.isReftestBrowser(this.tabBrowser)) {
|
2017-05-09 21:05:49 +03:00
|
|
|
return this.tabBrowser;
|
2017-03-27 12:02:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-05-10 15:29:21 +03:00
|
|
|
/**
|
|
|
|
* The current frame ID is managed per browser element on desktop in
|
|
|
|
* case the ID needs to be refreshed. The currently selected window is
|
|
|
|
* identified by a tab.
|
|
|
|
*/
|
|
|
|
get curFrameId() {
|
|
|
|
let rv = null;
|
2017-06-30 02:40:24 +03:00
|
|
|
if (this.tab || this.driver.isReftestBrowser(this.contentBrowser)) {
|
2017-03-27 12:02:36 +03:00
|
|
|
rv = this.getIdForBrowser(this.contentBrowser);
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-07-02 14:31:18 +03:00
|
|
|
/**
|
|
|
|
* Returns the current title of the content browser.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
* Read-only property containing the current title.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* If the current ChromeWindow does not have a content browser.
|
|
|
|
*/
|
|
|
|
get currentTitle() {
|
|
|
|
// Bug 1363368 - contentBrowser could be null until we wait for its
|
|
|
|
// initialization been finished
|
|
|
|
if (this.contentBrowser) {
|
|
|
|
return this.contentBrowser.contentTitle;
|
|
|
|
}
|
|
|
|
throw new NoSuchWindowError(
|
|
|
|
"Current window does not have a content browser");
|
|
|
|
}
|
|
|
|
|
2017-05-31 17:49:56 +03:00
|
|
|
/**
|
2017-06-13 16:46:59 +03:00
|
|
|
* Returns the current URI of the content browser.
|
|
|
|
*
|
|
|
|
* @return {nsIURI}
|
|
|
|
* Read-only property containing the currently loaded URL.
|
|
|
|
*
|
|
|
|
* @throws {NoSuchWindowError}
|
|
|
|
* If the current ChromeWindow does not have a content browser.
|
2017-05-31 17:49:56 +03:00
|
|
|
*/
|
2017-06-13 16:46:59 +03:00
|
|
|
get currentURI() {
|
2017-05-31 17:49:56 +03:00
|
|
|
// Bug 1363368 - contentBrowser could be null until we wait for its
|
|
|
|
// initialization been finished
|
|
|
|
if (this.contentBrowser) {
|
2017-06-13 16:46:59 +03:00
|
|
|
return this.contentBrowser.currentURI;
|
2017-05-31 17:49:56 +03:00
|
|
|
}
|
2017-06-30 02:40:24 +03:00
|
|
|
throw new NoSuchWindowError(
|
|
|
|
"Current window does not have a content browser");
|
2017-05-31 17:49:56 +03:00
|
|
|
}
|
|
|
|
|
Bug 1364319 - Make setWindowRect deterministic; r=automatedtester,maja_zf
The Marionette setWindowRect command is meant to provide a blocking API
for resizing and moving the window. This currently has an intermittent
rate of ~0.254 with the WPT conformance test.
The main issue in providing a blocking API is that the DOM resize
event fires at a high rate and needs to be throttled. We are able to
throttle this successfully with requestAnimationFrame, and before that,
a hard-coded 60 fps setTimeout delay. To the naked eye, this appears to
synchronise window resizing before returning the resposne to the client.
However, occasionally the response contains the wrong window size.
window.outerWidth and window.outerHeight do not appear to be
deterministic as DOM properties are not synchronously populated.
Calls to ChromeWindow.outerWidth and ChromeWindow.outerHeight sometimes
also returns inconsistent values. Tests, document in the bug, have
shown that somtimes, the returned window size from the setWindowRect
command is correct, and that the size from the subsequent getWindowRect
command is not.
By using a combination of Services.tm.mainThread.idleDispatch and a
blocking promise on not returning a response until the window size has
changed, we are able to reduce the intermittent rate significantly (by
over an order of magnitude).
As one would expect, delaying computation allows DOM property values to
populate, and as such does not address the underlying problem or make it
inconceivable that the race described above could re-appear, but it does
seem to be more reliable than the current approach.
MozReview-Commit-ID: Lf2yeeXH082
--HG--
extra : rebase_source : e27912fdcb6edbf825bf3168f3542ff2b4551b8b
2017-06-21 19:13:51 +03:00
|
|
|
/**
|
|
|
|
* Gets the position and dimensions of the top-level browsing context.
|
|
|
|
*
|
|
|
|
* @return {Map.<string, number>}
|
|
|
|
* Object with |x|, |y|, |width|, and |height| properties.
|
|
|
|
*/
|
|
|
|
get rect() {
|
|
|
|
return {
|
|
|
|
x: this.window.screenX,
|
|
|
|
y: this.window.screenY,
|
|
|
|
width: this.window.outerWidth,
|
|
|
|
height: this.window.outerHeight,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-05-10 15:29:21 +03:00
|
|
|
/**
|
|
|
|
* Retrieves the current tabmodal UI object. According to the browser
|
|
|
|
* associated with the currently selected tab.
|
|
|
|
*/
|
|
|
|
getTabModalUI() {
|
2017-03-27 12:02:36 +03:00
|
|
|
let br = this.contentBrowser;
|
2016-05-10 15:29:21 +03:00
|
|
|
if (!br.hasAttribute("tabmodalPromptShowing")) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The modal is a direct sibling of the browser element.
|
|
|
|
// See tabbrowser.xml's getTabModalPromptBox.
|
|
|
|
let modals = br.parentNode.getElementsByTagNameNS(
|
|
|
|
XUL_NS, "tabmodalprompt");
|
|
|
|
return modals[0].ui;
|
|
|
|
}
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
/**
|
|
|
|
* Close the current window.
|
|
|
|
*
|
|
|
|
* @return {Promise}
|
|
|
|
* A promise which is resolved when the current window has been closed.
|
|
|
|
*/
|
|
|
|
closeWindow() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.window.addEventListener("unload", ev => {
|
|
|
|
resolve();
|
|
|
|
}, {once: true});
|
|
|
|
this.window.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the current tab.
|
|
|
|
*
|
|
|
|
* @return {Promise}
|
|
|
|
* A promise which is resolved when the current tab has been closed.
|
2017-01-26 18:42:35 +03:00
|
|
|
*
|
|
|
|
* @throws UnsupportedOperationError
|
|
|
|
* If tab handling for the current application isn't supported.
|
2017-01-10 18:36:49 +03:00
|
|
|
*/
|
2016-05-10 15:29:21 +03:00
|
|
|
closeTab() {
|
2017-01-10 18:36:49 +03:00
|
|
|
// If the current window is not a browser then close it directly. Do the
|
|
|
|
// same if only one remaining tab is open, or no tab selected at all.
|
2017-06-30 02:40:24 +03:00
|
|
|
if (!this.tabBrowser ||
|
|
|
|
!this.tabBrowser.tabs ||
|
|
|
|
this.tabBrowser.tabs.length === 1 ||
|
|
|
|
!this.tab) {
|
2017-01-10 18:36:49 +03:00
|
|
|
return this.closeWindow();
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
2017-01-10 18:36:49 +03:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2017-01-26 18:42:35 +03:00
|
|
|
if (this.tabBrowser.closeTab) {
|
|
|
|
// Fennec
|
|
|
|
this.tabBrowser.deck.addEventListener("TabClose", ev => {
|
|
|
|
resolve();
|
|
|
|
}, {once: true});
|
|
|
|
this.tabBrowser.closeTab(this.tab);
|
|
|
|
|
|
|
|
} else if (this.tabBrowser.removeTab) {
|
|
|
|
// Firefox
|
2017-01-10 18:36:49 +03:00
|
|
|
this.tab.addEventListener("TabClose", ev => {
|
|
|
|
resolve();
|
|
|
|
}, {once: true});
|
2017-01-26 18:42:35 +03:00
|
|
|
this.tabBrowser.removeTab(this.tab);
|
|
|
|
|
2017-01-10 18:36:49 +03:00
|
|
|
} else {
|
|
|
|
reject(new UnsupportedOperationError(
|
|
|
|
`closeTab() not supported in ${this.driver.appName}`));
|
|
|
|
}
|
|
|
|
});
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a tab with given URI.
|
|
|
|
*
|
|
|
|
* @param {string} uri
|
|
|
|
* URI to open.
|
|
|
|
*/
|
|
|
|
addTab(uri) {
|
2017-01-26 18:42:35 +03:00
|
|
|
return this.tabBrowser.addTab(uri, true);
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-06 19:02:19 +03:00
|
|
|
* Set the current tab.
|
2016-05-10 15:29:21 +03:00
|
|
|
*
|
2017-01-26 18:42:35 +03:00
|
|
|
* @param {number=} index
|
|
|
|
* Tab index to switch to. If the parameter is undefined,
|
|
|
|
* the currently selected tab will be used.
|
|
|
|
* @param {nsIDOMWindow=} win
|
|
|
|
* Switch to this window before selecting the tab.
|
2017-01-30 17:35:16 +03:00
|
|
|
* @param {boolean=} focus
|
|
|
|
* A boolean value which determins whether to focus
|
|
|
|
* the window. Defaults to true.
|
|
|
|
*
|
|
|
|
* @throws UnsupportedOperationError
|
|
|
|
* If tab handling for the current application isn't supported.
|
2016-05-10 15:29:21 +03:00
|
|
|
*/
|
2017-01-30 17:35:16 +03:00
|
|
|
switchToTab(index, win, focus = true) {
|
2016-05-10 15:29:21 +03:00
|
|
|
if (win) {
|
|
|
|
this.window = win;
|
2017-01-26 18:42:35 +03:00
|
|
|
this.tabBrowser = browser.getTabBrowser(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.tabBrowser) {
|
|
|
|
return;
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
2017-01-26 18:42:35 +03:00
|
|
|
|
|
|
|
if (typeof index == "undefined") {
|
|
|
|
this.tab = this.tabBrowser.selectedTab;
|
|
|
|
} else {
|
|
|
|
this.tab = this.tabBrowser.tabs[index];
|
|
|
|
|
2017-01-30 17:35:16 +03:00
|
|
|
if (focus) {
|
|
|
|
if (this.tabBrowser.selectTab) {
|
|
|
|
// Fennec
|
|
|
|
this.tabBrowser.selectTab(this.tab);
|
2017-01-26 18:42:35 +03:00
|
|
|
|
2017-01-30 17:35:16 +03:00
|
|
|
} else if ("selectedTab" in this.tabBrowser) {
|
|
|
|
// Firefox
|
|
|
|
this.tabBrowser.selectedTab = this.tab;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
throw new UnsupportedOperationError("switchToTab() not supported");
|
|
|
|
}
|
2017-01-26 18:42:35 +03:00
|
|
|
}
|
2016-07-01 00:03:41 +03:00
|
|
|
}
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a new frame, and sets its current frame id to this frame
|
|
|
|
* if it is not already assigned, and if a) we already have a session
|
|
|
|
* or b) we're starting a new session and it is the right start frame.
|
|
|
|
*
|
|
|
|
* @param {string} uid
|
|
|
|
* Frame uid for use by Marionette.
|
2017-07-06 19:02:19 +03:00
|
|
|
* @param {xul:browser} target
|
|
|
|
* The <xul:browser> that was the target of the originating message.
|
2016-05-10 15:29:21 +03:00
|
|
|
*/
|
|
|
|
register(uid, target) {
|
2017-07-06 19:02:19 +03:00
|
|
|
if (this.tabBrowser) {
|
|
|
|
// If we're setting up a new session on Firefox, we only process the
|
|
|
|
// registration for this frame if it belongs to the current tab.
|
|
|
|
if (!this.tab) {
|
|
|
|
this.switchToTab();
|
|
|
|
}
|
2016-05-10 15:29:21 +03:00
|
|
|
|
2017-07-06 19:02:19 +03:00
|
|
|
if (target === this.contentBrowser) {
|
|
|
|
this.updateIdForBrowser(this.contentBrowser, uid);
|
|
|
|
this._needsFlushPendingCommands = true;
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// used to delete sessions
|
|
|
|
this.knownFrames.push(uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-06 19:02:19 +03:00
|
|
|
* Flushes any queued pending commands after a reload of the frame script.
|
2016-05-10 15:29:21 +03:00
|
|
|
*/
|
|
|
|
flushPendingCommands() {
|
2017-07-06 19:02:19 +03:00
|
|
|
if (!this._needsFlushPendingCommands) {
|
2016-05-10 15:29:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pendingCommands.forEach(cb => cb());
|
|
|
|
this.pendingCommands = [];
|
2017-07-06 19:02:19 +03:00
|
|
|
this._needsFlushPendingCommands = false;
|
2016-05-10 15:29:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function intercepts commands interacting with content and queues
|
|
|
|
* or executes them as needed.
|
|
|
|
*
|
|
|
|
* No commands interacting with content are safe to process until
|
|
|
|
* the new listener script is loaded and registers itself.
|
|
|
|
* This occurs when a command whose effect is asynchronous (such
|
2017-07-06 19:02:19 +03:00
|
|
|
* as goBack) results in a reload of the frame script and new commands
|
2016-05-10 15:29:21 +03:00
|
|
|
* are subsequently posted to the server.
|
|
|
|
*/
|
|
|
|
executeWhenReady(cb) {
|
2017-07-06 19:02:19 +03:00
|
|
|
if (this._needsFlushPendingCommands) {
|
2016-05-10 15:29:21 +03:00
|
|
|
this.pendingCommands.push(cb);
|
|
|
|
} else {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2016-05-23 12:21:15 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The window storage is used to save outer window IDs mapped to weak
|
|
|
|
* references of Window objects.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* let wins = new browser.Windows();
|
|
|
|
* wins.set(browser.outerWindowID, window);
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* let win = wins.get(browser.outerWindowID);
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
browser.Windows = class extends Map {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a weak reference to the Window object.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Outer window ID.
|
|
|
|
* @param {Window} win
|
|
|
|
* Window object to save.
|
|
|
|
*
|
|
|
|
* @return {browser.Windows}
|
|
|
|
* Instance of self.
|
|
|
|
*/
|
|
|
|
set(id, win) {
|
|
|
|
let wref = Cu.getWeakReference(win);
|
|
|
|
super.set(id, wref);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the window object stored by provided |id|.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* Outer window ID.
|
|
|
|
*
|
|
|
|
* @return {Window}
|
2017-06-28 21:12:33 +03:00
|
|
|
* Saved window object.
|
|
|
|
*
|
|
|
|
* @throws {RangeError}
|
|
|
|
* If |id| is not in the store.
|
2016-05-23 12:21:15 +03:00
|
|
|
*/
|
|
|
|
get(id) {
|
|
|
|
let wref = super.get(id);
|
2017-06-28 21:12:33 +03:00
|
|
|
if (!wref) {
|
|
|
|
throw new RangeError();
|
2016-05-23 12:21:15 +03:00
|
|
|
}
|
2017-06-28 21:12:33 +03:00
|
|
|
return wref.get();
|
2016-05-23 12:21:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|