Bug 1450572 - Optimize windows.get(windowId) draft
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Mon, 26 Mar 2018 00:06:53 +0200
changeset 775898 b3d84766486243c89fda548d981d5a0ea45b6586
parent 775890 ef717c03ff54d10b2e30df7e63fc11172c69db44
push id104745
push userbmo:oriol-bugzilla@hotmail.com
push dateSun, 01 Apr 2018 17:45:44 +0000
bugs1450572
milestone61.0a1
Bug 1450572 - Optimize windows.get(windowId) MozReview-Commit-ID: EHfSbaNIX75
toolkit/components/extensions/parent/ext-tabs-base.js
--- 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}`);
     }
   }
 
   /**