Verified Commit fb2aa139 authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Optimize web request listener-related logic

parent 6ea540fd
......@@ -137,25 +137,11 @@ stateManager.removeDomainFromWhitelist = function (domain) {
stateManager._createTab = function (tab) {
let tabIdentifier, requestFilters;
tabIdentifier = tab.id;
let tabIdentifier = tab.id;
stateManager.tabs[tabIdentifier] = {
'injections': {}
};
requestFilters = {
'tabId': tabIdentifier,
'urls': stateManager.validHosts
};
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
let tab = stateManager.tabs[tabIdentifier].details || {};
return interceptor.handleRequest(requestDetails, tabIdentifier, tab);
}, requestFilters, [WebRequest.BLOCKING]);
};
stateManager._removeTab = function (tabIdentifier) {
......@@ -302,6 +288,17 @@ for (let mapping in mappings) {
stateManager.validHosts.push(supportedHost);
}
stateManager.requestFilters = {
'urls': stateManager.validHosts
};
chrome.webRequest.onBeforeRequest.addListener(function (requestDetails) {
let tab = stateManager.tabs[requestDetails.tabId].details || {};
return interceptor.handleRequest(requestDetails, requestDetails.tabId, tab);
}, stateManager.requestFilters, [WebRequest.BLOCKING]);
chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._createTab);
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment