Fix runChannelListener complexity warnings again, change severity to error. r=me (no bug)
authorKris Maglione <maglione.k@gmail.com>
Fri, 20 Jan 2017 18:07:45 -0800
changeset 375525 033dff7024f618a9a7014efa01eef3cd6a5d079e
parent 375524 c633650caea682de11142d5cb6d28f3effcadf55
child 375526 0d86f65852e6fc5d8816903dc63e151959185337
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix runChannelListener complexity warnings again, change severity to error. r=me (no bug) MozReview-Commit-ID: HMUPIOLR61Y
toolkit/components/extensions/.eslintrc.js
toolkit/modules/addons/WebRequest.jsm
--- a/toolkit/components/extensions/.eslintrc.js
+++ b/toolkit/components/extensions/.eslintrc.js
@@ -242,17 +242,17 @@ module.exports = { // eslint-disable-lin
     // since only let and const are used, see "no-var").
     "block-scoped-var": "error",
 
     // Allow trailing commas for easy list extension.  Having them does not
     // impair readability, but also not required either.
     "comma-dangle": ["error", "always-multiline"],
 
     // Warn about cyclomatic complexity in functions.
-    "complexity": "warn",
+    "complexity": "error",
 
     // Don't warn for inconsistent naming when capturing this (not so important
     // with auto-binding fat arrow functions).
     // "consistent-this": ["error", "self"],
 
     // Don't require a default case in switch statements. Avoid being forced to
     // add a bogus default when you know all possible cases are handled.
     "default-case": "off",
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -653,16 +653,33 @@ HttpObserverManager = {
         // The remoteAddress getter throws if the address is unavailable,
         // but ip is an optional property so just ignore the exception.
       }
     }
 
     return Object.assign(data, extraData);
   },
 
+  canModify(channel) {
+    let {isHostPermitted} = AddonManagerPermissions;
+
+    if (isHostPermitted(channel.URI.host)) {
+      return false;
+    }
+
+    let {loadInfo} = channel;
+    if (loadInfo && loadInfo.loadingPrincipal) {
+      let {loadingPrincipal} = loadInfo;
+
+      return loadingPrincipal.URI && !isHostPermitted(loadingPrincipal.URI.host);
+    }
+
+    return true;
+  },
+
   runChannelListener(channel, loadContext = null, kind, extraData = null) {
     let handlerResults = [];
     let requestHeaders;
     let responseHeaders;
 
     try {
       if (this.activityInitialized) {
         let channelData = getData(channel);
@@ -678,16 +695,17 @@ HttpObserverManager = {
 
       let {loadInfo} = channel;
       let policyType = (loadInfo ? loadInfo.externalContentPolicyType
                                  : Ci.nsIContentPolicy.TYPE_OTHER);
 
       let includeStatus = (["headersReceived", "onRedirect", "onStart", "onStop"].includes(kind) &&
                            channel instanceof Ci.nsIHttpChannel);
 
+      let canModify = this.canModify(channel);
       let commonData = null;
       let uri = channel.URI;
       let requestBody;
       for (let [callback, opts] of this.listeners[kind].entries()) {
         if (!this.shouldRunListener(policyType, uri, opts.filter)) {
           continue;
         }
 
@@ -713,21 +731,17 @@ HttpObserverManager = {
 
         if (includeStatus) {
           mergeStatus(data, channel, kind);
         }
 
         try {
           let result = callback(data);
 
-          if (result && typeof result === "object" && opts.blocking
-              && !AddonManagerPermissions.isHostPermitted(uri.host)
-              && (!loadInfo || !loadInfo.loadingPrincipal
-                  || !loadInfo.loadingPrincipal.URI
-                  || !AddonManagerPermissions.isHostPermitted(loadInfo.loadingPrincipal.URI.host))) {
+          if (canModify && result && typeof result === "object" && opts.blocking) {
             handlerResults.push({opts, result});
           }
         } catch (e) {
           Cu.reportError(e);
         }
       }
     } catch (e) {
       Cu.reportError(e);