Bug 1464481 - fix and test crash when getting registered channelwrapper, r?kmag
MozReview-Commit-ID: LEGojHEb742
--- a/dom/chrome-webidl/ChannelWrapper.webidl
+++ b/dom/chrome-webidl/ChannelWrapper.webidl
@@ -48,17 +48,17 @@ interface ChannelWrapper : EventTarget {
* always returned for a given channel.
*/
static ChannelWrapper get(MozChannel channel);
/**
* Returns the wrapper instance for the given channel. The same wrapper is
* always returned for a given channel.
*/
- static ChannelWrapper getRegisteredChannel(unsigned long long aChannelId,
+ static ChannelWrapper? getRegisteredChannel(unsigned long long aChannelId,
WebExtensionPolicy extension,
TabParent? tabParent);
/**
* A unique ID for for the requests which remains constant throughout the
* redirect chain.
*/
[Constant, StoreInSlot]
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_hsts.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_hsts.html
@@ -180,14 +180,39 @@ add_task(async function test_hsts_header
["onBeforeRequest", "onBeforeRedirect", "onBeforeRequest",
"onBeforeSendHeaders", "onSendHeaders", "onHeadersReceived",
"onResponseStarted", "onCompleted"]);
is(await tabdone, `https://${testPath}/file_sample.html`, "hsts upgraded");
is(await completed, `https://${testPath}/file_sample.html`, "request upgraded");
await extension.unload();
});
+
+add_task(async function test_nonBlocking_securityInfo() {
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ "permissions": [
+ "webRequest",
+ "<all_urls>",
+ ],
+ },
+ async background() {
+ let tab;
+ browser.webRequest.onHeadersReceived.addListener(async (details) => {
+ let securityInfo = await browser.webRequest.getSecurityInfo(details.requestId, {});
+ browser.test.assertTrue(!securityInfo, "securityInfo undefined on http request");
+ browser.tabs.remove(tab.id);
+ browser.test.notifyPass("success");
+ }, {urls: ["<all_urls>"], types: ["main_frame"]});
+ tab = await browser.tabs.create({url: "https://example.org/tests/toolkit/components/extensions/test/mochitest/file_sample.html"});
+ },
+ });
+ await extension.startup();
+
+ await extension.awaitFinish("success");
+ await extension.unload();
+});
</script>
</head>
<body>
</body>
</html>
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -990,13 +990,15 @@ var WebRequest = {
// OnStopRequest channel listener.
onCompleted: onCompleted,
// nsIHttpActivityObserver.
onErrorOccurred: onErrorOccurred,
getSecurityInfo: (details) => {
let channel = ChannelWrapper.getRegisteredChannel(details.id, details.extension, details.tabParent);
- return SecurityInfo.getSecurityInfo(channel.channel, details.options);
+ if (channel) {
+ return SecurityInfo.getSecurityInfo(channel.channel, details.options);
+ }
},
};
Services.ppmm.loadProcessScript("resource://gre/modules/WebRequestContent.js", true);