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 @@ + + + + Test for simple WebExtension + + + + + + + + + + + + + diff --git a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_background_events.html b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_background_events.html new file mode 100644 index 000000000000..2799679fcb4c --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_background_events.html @@ -0,0 +1,109 @@ + + + + Test for simple WebExtension + + + + + + + + + + + + diff --git a/toolkit/components/extensions/test/mochitest/webrequest_chromeworker.js b/toolkit/components/extensions/test/mochitest/webrequest_chromeworker.js new file mode 100644 index 000000000000..ccfb2ac1fc13 --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/webrequest_chromeworker.js @@ -0,0 +1,8 @@ +"use strict"; + +onmessage = function(event) { + fetch("https://example.com/example.txt").then(() => { + postMessage("Done!"); + }); +}; + diff --git a/toolkit/components/extensions/test/mochitest/webrequest_test.jsm b/toolkit/components/extensions/test/mochitest/webrequest_test.jsm new file mode 100644 index 000000000000..bfb1483018ed --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/webrequest_test.jsm @@ -0,0 +1,22 @@ +"use strict"; + +this.EXPORTED_SYMBOLS = ["webrequest_test"]; + +Components.utils.importGlobalProperties(["fetch", "XMLHttpRequest"]); + +this.webrequest_test = { + testFetch(url) { + return fetch(url); + }, + + testXHR(url) { + return new Promise(resolve => { + let xhr = new XMLHttpRequest(); + xhr.open("HEAD", url); + xhr.onload = () => { + resolve(); + }; + xhr.send(); + }); + }, +}; diff --git a/toolkit/components/extensions/test/mochitest/webrequest_worker.js b/toolkit/components/extensions/test/mochitest/webrequest_worker.js new file mode 100644 index 000000000000..dcffd08578b5 --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/webrequest_worker.js @@ -0,0 +1,3 @@ +"use strict"; + +fetch("https://example.com/example.txt"); diff --git a/toolkit/modules/addons/WebRequest.jsm b/toolkit/modules/addons/WebRequest.jsm index b7c413ca04e8..89deefbae8c0 100644 --- a/toolkit/modules/addons/WebRequest.jsm +++ b/toolkit/modules/addons/WebRequest.jsm @@ -545,7 +545,7 @@ HttpObserverManager = { if (loadInfo) { let originPrincipal = loadInfo.triggeringPrincipal || loadInfo.loadingPrincipal; - if (originPrincipal && originPrincipal.URI) { + if (originPrincipal.URI) { commonData.originUrl = originPrincipal.URI.spec; } Object.assign(commonData, { @@ -553,6 +553,10 @@ HttpObserverManager = { loadInfo.frameOuterWindowID : loadInfo.outerWindowID, parentWindowId: loadInfo.frameOuterWindowID ? loadInfo.outerWindowID : loadInfo.parentOuterWindowID, + isSystemPrincipal: Services.scriptSecurityManager + .isSystemPrincipal(loadInfo.triggeringPrincipal) || + Services.scriptSecurityManager + .isSystemPrincipal(loadInfo.loadingPrincipal), }); } else { Object.assign(commonData, {