diff --git a/browser/components/extensions/ext-tabs.js b/browser/components/extensions/ext-tabs.js index 7a503abfc082..ad2f664b53cd 100644 --- a/browser/components/extensions/ext-tabs.js +++ b/browser/components/extensions/ext-tabs.js @@ -75,14 +75,8 @@ extensions.on("page-shutdown", (type, context) => { } }); -extensions.on("fill-browser-data", (type, browser, data, result) => { - let tabId = TabManager.getBrowserId(browser); - if (tabId == -1) { - result.cancel = true; - return; - } - - data.tabId = tabId; +extensions.on("fill-browser-data", (type, browser, data) => { + data.tabId = browser ? TabManager.getBrowserId(browser) : -1; }); /* eslint-enable mozilla/balanced-listeners */ diff --git a/toolkit/components/extensions/ext-webNavigation.js b/toolkit/components/extensions/ext-webNavigation.js index 4136a7f460f4..1ff30ad564a6 100644 --- a/toolkit/components/extensions/ext-webNavigation.js +++ b/toolkit/components/extensions/ext-webNavigation.js @@ -109,11 +109,6 @@ function WebNavigationEventManager(context, eventName) { return; } - let tabId = TabManager.getBrowserId(data.browser); - if (tabId == -1) { - return; - } - let data2 = { url: data.url, timeStamp: Date.now(), @@ -126,9 +121,8 @@ function WebNavigationEventManager(context, eventName) { } // Fills in tabId typically. - let result = {}; - extensions.emit("fill-browser-data", data.browser, data2, result); - if (result.cancel) { + extensions.emit("fill-browser-data", data.browser, data2); + if (data2.tabId < 0) { return; } diff --git a/toolkit/components/extensions/ext-webRequest.js b/toolkit/components/extensions/ext-webRequest.js index 5e1a45786102..907b7bf4836c 100644 --- a/toolkit/components/extensions/ext-webRequest.js +++ b/toolkit/components/extensions/ext-webRequest.js @@ -23,12 +23,9 @@ function WebRequestEventManager(context, eventName) { let name = `webRequest.${eventName}`; let register = (callback, filter, info) => { let listener = data => { - if (!data.browser) { - return; - } - - let tabId = TabManager.getBrowserId(data.browser); - if (tabId == -1) { + // Prevent listening in on requests originating from system principal to + // prevent tinkering with OCSP, app and addon updates, etc. + if (data.isSystemPrincipal) { return; } @@ -52,12 +49,7 @@ function WebRequestEventManager(context, eventName) { data2.ip = data.ip; } - // Fills in tabId typically. - let result = {}; - extensions.emit("fill-browser-data", data.browser, data2, result); - if (result.cancel) { - return; - } + extensions.emit("fill-browser-data", data.browser, data2); let optional = ["requestHeaders", "responseHeaders", "statusCode", "statusLine", "error", "redirectUrl", "requestBody"]; diff --git a/toolkit/components/extensions/test/mochitest/.eslintrc.js b/toolkit/components/extensions/test/mochitest/.eslintrc.js index 3a8cd46bcf61..53d74bbd1847 100644 --- a/toolkit/components/extensions/test/mochitest/.eslintrc.js +++ b/toolkit/components/extensions/test/mochitest/.eslintrc.js @@ -8,6 +8,8 @@ module.exports = { // eslint-disable-line no-undef }, "globals": { + "ChromeWorker": false, + "onmessage": true, "sendAsyncMessage": false, "waitForLoad": true, @@ -15,6 +17,7 @@ module.exports = { // eslint-disable-line no-undef "ExtensionTestUtils": false, "NetUtil": true, + "webrequest_test": false, "XPCOMUtils": true, }, }; diff --git a/toolkit/components/extensions/test/mochitest/chrome.ini b/toolkit/components/extensions/test/mochitest/chrome.ini index 2d8252810fae..b8b6e34b97a7 100644 --- a/toolkit/components/extensions/test/mochitest/chrome.ini +++ b/toolkit/components/extensions/test/mochitest/chrome.ini @@ -3,6 +3,8 @@ support-files = chrome_head.js head.js file_sample.html + webrequest_chromeworker.js + webrequest_test.jsm tags = webextensions [test_chrome_ext_background_debug_global.html] @@ -27,3 +29,5 @@ skip-if = os != "mac" && os != "linux" [test_chrome_ext_storage_cleanup.html] [test_chrome_ext_idle.html] [test_chrome_ext_downloads_saveAs.html] +[test_chrome_ext_webrequest_background_events.html] +skip-if = os == 'android' # webrequest api unsupported (bug 1258975). diff --git a/toolkit/components/extensions/test/mochitest/mochitest.ini b/toolkit/components/extensions/test/mochitest/mochitest.ini index aff1c595677a..3081f37666d8 100644 --- a/toolkit/components/extensions/test/mochitest/mochitest.ini +++ b/toolkit/components/extensions/test/mochitest/mochitest.ini @@ -35,6 +35,7 @@ support-files = file_ext_test_api_injection.js file_permission_xhr.html file_teardown_test.js + webrequest_worker.js tags = webextensions [test_clipboard.html] @@ -93,6 +94,8 @@ skip-if = (os == 'android') # Bug 1258975 on android. skip-if = (os == 'android') # Bug 1258975 on android. [test_ext_webrequest.html] skip-if = os == 'android' # webrequest api unsupported (bug 1258975). +[test_ext_webrequest_background_events.html] +skip-if = os == 'android' # webrequest api unsupported (bug 1258975). [test_ext_webrequest_upload.html] skip-if = os == 'android' # webrequest api unsupported (bug 1258975). [test_ext_webnavigation.html] diff --git a/toolkit/components/extensions/test/mochitest/test_chrome_ext_webrequest_background_events.html b/toolkit/components/extensions/test/mochitest/test_chrome_ext_webrequest_background_events.html new file mode 100644 index 000000000000..a13c4d475490 --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_webrequest_background_events.html @@ -0,0 +1,96 @@ + + +
+