Bug 1322869: Part 1 - Apply window filters per-window rather than per-tab. r=bsilverberg
authorKris Maglione <maglione.k@gmail.com>
Mon, 19 Dec 2016 12:34:09 -0800
changeset 326974 31943df12a3aafc9846b852da24a676fc18505fc
parent 326973 f374e4333d3a17f72d89063670115d71a9643a5f
child 326975 7f813afa9a8c9deda34b19cb31bedf433f8d8e3c
push id31116
push userkwierso@gmail.com
push dateFri, 23 Dec 2016 02:37:16 +0000
treeherdermozilla-central@2785aaf276ba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsilverberg
bugs1322869
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1322869: Part 1 - Apply window filters per-window rather than per-tab. r=bsilverberg MozReview-Commit-ID: AAlyBJowMOm
browser/components/extensions/ext-tabs.js
--- a/browser/components/extensions/ext-tabs.js
+++ b/browser/components/extensions/ext-tabs.js
@@ -668,80 +668,80 @@ extensions.registerSchemaAPI("tabs", "ad
         if (queryInfo.url !== null) {
           if (!extension.hasPermission("tabs")) {
             return Promise.reject({message: 'The "tabs" permission is required to use the query API with the "url" parameter'});
           }
 
           pattern = new MatchPattern(queryInfo.url);
         }
 
-        function matches(window, tab) {
+        function matches(tab) {
           let props = ["active", "pinned", "highlighted", "status", "title", "index"];
           for (let prop of props) {
             if (queryInfo[prop] !== null && queryInfo[prop] != tab[prop]) {
               return false;
             }
           }
 
-          let lastFocused = window == WindowManager.topWindow;
-          if (queryInfo.lastFocusedWindow !== null && queryInfo.lastFocusedWindow != lastFocused) {
-            return false;
-          }
-
-          let windowType = WindowManager.windowType(window);
-          if (queryInfo.windowType !== null && queryInfo.windowType != windowType) {
-            return false;
-          }
-
-          if (queryInfo.windowId !== null) {
-            if (queryInfo.windowId == WindowManager.WINDOW_ID_CURRENT) {
-              if (currentWindow(context) != window) {
-                return false;
-              }
-            } else if (queryInfo.windowId != tab.windowId) {
-              return false;
-            }
-          }
-
           if (queryInfo.audible !== null) {
             if (queryInfo.audible != tab.audible) {
               return false;
             }
           }
 
           if (queryInfo.muted !== null) {
             if (queryInfo.muted != tab.mutedInfo.muted) {
               return false;
             }
           }
 
-          if (queryInfo.currentWindow !== null) {
-            let eq = window == currentWindow(context);
-            if (queryInfo.currentWindow != eq) {
-              return false;
-            }
-          }
-
           if (queryInfo.cookieStoreId !== null &&
               tab.cookieStoreId != queryInfo.cookieStoreId) {
             return false;
           }
 
           if (pattern && !pattern.matches(Services.io.newURI(tab.url, null, null))) {
             return false;
           }
 
           return true;
         }
 
         let result = [];
         for (let window of WindowListManager.browserWindows()) {
+          let lastFocused = window === WindowManager.topWindow;
+          if (queryInfo.lastFocusedWindow !== null && queryInfo.lastFocusedWindow !== lastFocused) {
+            continue;
+          }
+
+          let windowType = WindowManager.windowType(window);
+          if (queryInfo.windowType !== null && queryInfo.windowType !== windowType) {
+            continue;
+          }
+
+          if (queryInfo.windowId !== null) {
+            if (queryInfo.windowId === WindowManager.WINDOW_ID_CURRENT) {
+              if (currentWindow(context) !== window) {
+                continue;
+              }
+            } else if (queryInfo.windowId !== WindowManager.getId(window)) {
+              continue;
+            }
+          }
+
+          if (queryInfo.currentWindow !== null) {
+            let eq = window === currentWindow(context);
+            if (queryInfo.currentWindow != eq) {
+              continue;
+            }
+          }
+
           let tabs = TabManager.for(extension).getTabs(window);
           for (let tab of tabs) {
-            if (matches(window, tab)) {
+            if (matches(tab)) {
               result.push(tab);
             }
           }
         }
         return Promise.resolve(result);
       },
 
       captureVisibleTab: function(windowId, options) {