Bug 1322869: Part 1 - Apply window filters per-window rather than per-tab. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 19 Dec 2016 12:34:09 -0800
changeset 451169 3249d06fb4fb7946011625c34247168239aabbd9
parent 451168 8de88776f656609009d371e9b71ccea8c2fe7615
child 451170 1043ce2112365fe1ed10a4ee2e52153c6f98bb05
push id39073
push usermaglione.k@gmail.com
push dateMon, 19 Dec 2016 20:35:35 +0000
reviewersaswan
bugs1322869
milestone53.0a1
Bug 1322869: Part 1 - Apply window filters per-window rather than per-tab. r?aswan 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) {