Bug 1621385 - Account for unaccesible tabs in mobile's WindowTracker.getAll. r=mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D66310

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Agi Sferro 2020-03-13 18:12:08 +00:00
parent cf6ef6a24b
commit bf7b46f3d1
3 changed files with 25 additions and 9 deletions

View File

@ -1221,13 +1221,6 @@ class WindowManager extends WindowManagerBase {
return this.getWrapper(window);
}
canAccessWindow(window, context) {
return (
(context && context.canAccessWindow(window)) ||
this.extension.canAccessWindow(window)
);
}
*getAll(context) {
for (let window of windowTracker.browserWindows()) {
if (!this.canAccessWindow(window, context)) {

View File

@ -585,9 +585,15 @@ class WindowManager extends WindowManagerBase {
return this.getWrapper(window);
}
*getAll() {
*getAll(context) {
for (let window of windowTracker.browserWindows()) {
yield this.getWrapper(window);
if (!this.canAccessWindow(window, context)) {
continue;
}
let wrapped = this.getWrapper(window);
if (wrapped) {
yield wrapped;
}
}
}

View File

@ -2070,6 +2070,23 @@ class WindowManagerBase {
}
}
/**
* Returns whether this window can be accessed by the extension in the given
* context.
*
* @param {DOMWindow} window
* The browser window that is being tested
* @param {BaseContext|null} context
* The extension context for which this test is being performed.
* @returns {boolean}
*/
canAccessWindow(window, context) {
return (
(context && context.canAccessWindow(window)) ||
this.extension.canAccessWindow(window)
);
}
// The JSDoc validator does not support @returns tags in abstract functions or
// star functions without return statements.
/* eslint-disable valid-jsdoc */