Bug 1398622 fix ws handling in contentpolicymanager, and fix stupid error. r=kmag
authorShane Caraveo <scaraveo@mozilla.com>
Sun, 10 Sep 2017 21:37:27 -0700
changeset 662666 17b67958139223c2e2250b3f43a409ac06c0a756
parent 662665 b86983c73434cbe6705631c9bf76d0b33b6dc6aa
child 662667 ed8245718923a2b3470c4a1d4788c3282fa4ab3a
push id79159
push userhikezoe@mozilla.com
push dateMon, 11 Sep 2017 23:25:15 +0000
reviewerskmag
bugs1398622
milestone57.0a1
Bug 1398622 fix ws handling in contentpolicymanager, and fix stupid error. r=kmag 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
@@ -661,17 +661,17 @@ HttpObserverManager = {
                lastActivity !== nsIHttpActivityObserver.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE) {
       channel.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)}`);
     }
 
     if (filter.types && !filter.types.includes(policyType)) {
       return false;
     }
 
     return WebRequestCommon.urlMatches(uri, filter.urls);
   },
--- 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,