Bug 1450572 - Optimize windows.get(windowId)
MozReview-Commit-ID: EHfSbaNIX75
--- a/toolkit/components/extensions/parent/ext-tabs-base.js
+++ b/toolkit/components/extensions/parent/ext-tabs-base.js
@@ -1409,20 +1409,22 @@ class WindowTrackerBase extends EventEmi
* @throws {ExtensionError}
* If no window exists with the given ID and `strict` is true.
*/
getWindow(id, context, strict = true) {
if (id === WINDOW_ID_CURRENT) {
return this.getCurrentWindow(context);
}
- for (let window of this.browserWindows(true)) {
- if (this.getId(window) === id) {
- return window;
- }
+ let window = Services.wm.getOuterWindowWithId(id);
+ if (window && !window.closed && (window.document.readyState !== "complete"
+ || this.isBrowserWindow(window))) {
+ // Tolerate incomplete windows because isBrowserWindow is only reliable
+ // once the window is fully loaded.
+ return window;
}
if (strict) {
throw new ExtensionError(`Invalid window ID: ${id}`);
}
}
/**