Bug 1398622 - Fix ws handling in contentpolicymanager, and fix stupid error. r=kmag, a=lizzard
authorShane Caraveo <scaraveo@mozilla.com>
Sun, 10 Sep 2017 21:37:27 -0700
changeset 421722 1aadca44c4b72c06d18fc046b85444fc411d4980
parent 421721 776744d895c98d89764bca8018509a77a2127cab
child 421723 e8e660d7c455191c250bbb728e97e411c42a4338
push id7756
push userryanvm@gmail.com
push dateThu, 14 Sep 2017 00:25:28 +0000
treeherdermozilla-beta@faf98f63da30 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, lizzard
bugs1398622
milestone56.0
Bug 1398622 - Fix ws handling in contentpolicymanager, and fix stupid error. r=kmag, a=lizzard MozReview-Commit-ID: EmPvtRrnrnI
toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
toolkit/modules/addons/WebRequest.jsm
toolkit/modules/addons/WebRequestContent.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
@@ -40,17 +40,17 @@ add_task(async function test_webSocket()
         };
       });
       browser.test.sendMessage("ready");
     },
   });
   await extension.startup();
   await extension.awaitMessage("ready");
   extension.sendMessage("go");
-  await extension.awaitFinish();
+  await extension.awaitFinish("websocket");
   await extension.unload();
 });
 
 </script>
 </head>
 <body>
 </body>
 </html>
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -683,17 +683,17 @@ HttpObserverManager = {
                lastActivity !== nsIHttpActivityObserver.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE) {
       channelData.lastActivity = activitySubtype;
     }
   },
 
   shouldRunListener(policyType, uri, filter) {
     // force the protocol to be ws again.
     if (policyType == "websocket" && ["http", "https"].includes(uri.scheme)) {
-      uri = new Services.io.newURI(`ws${uri.spec.substring(4)}`);
+      uri = Services.io.newURI(`ws${uri.spec.substring(4)}`);
     }
     return WebRequestCommon.typeMatches(policyType, filter.types) &&
            WebRequestCommon.urlMatches(uri, filter.urls);
   },
 
   get resultsMap() {
     delete this.resultsMap;
     this.resultsMap = new Map(Object.keys(Cr).map(name => [Cr[name], name]));
--- a/toolkit/modules/addons/WebRequestContent.js
+++ b/toolkit/modules/addons/WebRequestContent.js
@@ -15,17 +15,19 @@ var Cr = Components.results;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "MatchPattern",
                                   "resource://gre/modules/MatchPattern.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "WebRequestCommon",
                                   "resource://gre/modules/WebRequestCommon.jsm");
 
-const IS_HTTP = /^https?:/;
+// Websockets will get handled via httpchannel notifications same as http
+// requests, treat them the same as http in ContentPolicy.
+const IS_HTTP = /^https?:|wss?:/;
 
 var ContentPolicy = {
   _classDescription: "WebRequest content policy",
   _classID: Components.ID("938e5d24-9ccc-4b55-883e-c252a41f7ce9"),
   _contractID: "@mozilla.org/webrequest/policy;1",
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy,
                                          Ci.nsIFactory,