Bug 1317366: Handle blocking WebRequest listeners returning non-object values. r=mixedpuppy
authorKris Maglione <maglione.k@gmail.com>
Mon, 14 Nov 2016 21:34:23 -0800
changeset 322479 69cd55731647b0c8821645c7bcb315a84d720df5
parent 322478 f6ae2c26b11a8f52195cfec6368c8da59c106dd9
child 322480 e4636b63cd369040faf645417f512b814f8f7d2c
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersmixedpuppy
bugs1317366
milestone53.0a1
Bug 1317366: Handle blocking WebRequest listeners returning non-object values. r=mixedpuppy MozReview-Commit-ID: HMbgONPqsKU
toolkit/components/extensions/test/mochitest/test_ext_webrequest_suspend.html
toolkit/modules/addons/WebRequest.jsm
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_suspend.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_suspend.html
@@ -8,37 +8,53 @@
   <script type="text/javascript" src="head.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 
 <script type="text/javascript">
 "use strict";
 
-add_task(function* () {
+add_task(function* test_suspend() {
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: [
         "webRequest",
         "webRequestBlocking",
       ],
     },
 
     background() {
-      browser.webRequest.onBeforeSendHeaders.addListener(details => {
-        let requestHeaders = details.requestHeaders.concat({name: "Foo", value: "Bar"});
+      browser.webRequest.onBeforeSendHeaders.addListener(
+        details => {
+          // Make sure that returning undefined or a promise that resolves to
+          // undefined does not break later handlers.
+        },
+        {urls: ["<all_urls>"]},
+        ["blocking", "requestHeaders"]);
 
-        return new Promise(resolve => {
-          setTimeout(resolve, 500);
-        }).then(() => {
-          return {requestHeaders};
-        });
-      },
-      {urls: ["<all_urls>"]},
-      ["blocking", "requestHeaders"]);
+      browser.webRequest.onBeforeSendHeaders.addListener(
+        details => {
+          return Promise.resolve();
+        },
+        {urls: ["<all_urls>"]},
+        ["blocking", "requestHeaders"]);
+
+      browser.webRequest.onBeforeSendHeaders.addListener(
+        details => {
+          let requestHeaders = details.requestHeaders.concat({name: "Foo", value: "Bar"});
+
+          return new Promise(resolve => {
+            setTimeout(resolve, 500);
+          }).then(() => {
+            return {requestHeaders};
+          });
+        },
+        {urls: ["<all_urls>"]},
+        ["blocking", "requestHeaders"]);
     },
   });
 
   yield extension.startup();
 
   let result = yield fetch(SimpleTest.getTestFileURL("return_headers.sjs"));
 
   let headers = JSON.parse(yield result.text());
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -744,16 +744,20 @@ HttpObserverManager = {
           } catch (e) {
             Cu.reportError(e);
             value.result = {};
           }
         }
       }
 
       for (let {opts, result} of handlerResults) {
+        if (!result || typeof result !== "object") {
+          continue;
+        }
+
         if (result.cancel) {
           this.maybeResume(channel);
           channel.cancel(Cr.NS_ERROR_ABORT);
 
           this.errorCheck(channel, loadContext);
           return;
         }