Bug 1391099: Avoid using checkLoadURIStrWithPrincipal. r?mixedpuppy draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 16 Aug 2017 16:29:06 -0700
changeset 647814 f6ac5827fc4745be237436316d6c4c9945e607a4
parent 647801 6bcfdc51bdd5b8695c2718b960d1fda9c133398f
child 726641 85a099709362331411dbc98cce97ee5156064e87
push id74549
push usermaglione.k@gmail.com
push dateWed, 16 Aug 2017 23:58:03 +0000
reviewersmixedpuppy
bugs1391099
milestone57.0a1
Bug 1391099: Avoid using checkLoadURIStrWithPrincipal. r?mixedpuppy checkLoadURIStrWithPrincipal runs URLs through the URI fixup services and checks against each of the results. This is both expensive and unnecessary for our purposes. MozReview-Commit-ID: 4L2Z4KuMZhQ
toolkit/components/extensions/ExtensionCommon.jsm
toolkit/components/extensions/ExtensionParent.jsm
toolkit/components/extensions/Schemas.jsm
--- a/toolkit/components/extensions/ExtensionCommon.jsm
+++ b/toolkit/components/extensions/ExtensionCommon.jsm
@@ -280,17 +280,19 @@ class BaseContext {
     if (!options.allowInheritsPrincipal) {
       flags |= ssm.DISALLOW_INHERIT_PRINCIPAL;
     }
     if (options.dontReportErrors) {
       flags |= ssm.DONT_REPORT_ERRORS;
     }
 
     try {
-      ssm.checkLoadURIStrWithPrincipal(this.principal, url, flags);
+      ssm.checkLoadURIWithPrincipal(this.principal,
+                                    Services.io.newURI(url),
+                                    flags);
     } catch (e) {
       return false;
     }
     return true;
   }
 
   /**
    * Safely call JSON.stringify() on an object that comes from an
--- a/toolkit/components/extensions/ExtensionParent.jsm
+++ b/toolkit/components/extensions/ExtensionParent.jsm
@@ -1321,18 +1321,18 @@ let IconDetails = {
 
     return result;
   },
 
   // Checks if the extension is allowed to load the given URL with the specified principal.
   // This will throw an error if the URL is not allowed.
   _checkURL(url, principal) {
     try {
-      Services.scriptSecurityManager.checkLoadURIStrWithPrincipal(
-        principal, url,
+      Services.scriptSecurityManager.checkLoadURIWithPrincipal(
+        principal, Services.io.newURI(url),
         Services.scriptSecurityManager.DISALLOW_SCRIPT);
     } catch (e) {
       throw new ExtensionError(`Illegal URL ${url}`);
     }
   },
 
   // Returns the appropriate icon URL for the given icons object and the
   // screen resolution of the given window.
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -341,18 +341,19 @@ class Context {
    * Checks whether `url` may be loaded by the extension in this context.
    *
    * @param {string} url The URL that the extension wished to load.
    * @returns {boolean} Whether the context may load `url`.
    */
   checkLoadURL(url) {
     let ssm = Services.scriptSecurityManager;
     try {
-      ssm.checkLoadURIStrWithPrincipal(this.principal, url,
-                                       ssm.DISALLOW_INHERIT_PRINCIPAL);
+      ssm.checkLoadURIWithPrincipal(this.principal,
+                                    Services.io.newURI(url),
+                                    ssm.DISALLOW_INHERIT_PRINCIPAL);
     } catch (e) {
       return false;
     }
     return true;
   }
 
   /**
    * Checks whether this context has the given permission.