Bug 1322869: Part 1 - Apply window filters per-window rather than per-tab. r?aswan
MozReview-Commit-ID: AAlyBJowMOm
--- 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) {