Bug 1356852: Avoid loading NetUtil just for newURI. r?rhelmer draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 15 Apr 2017 19:25:08 -0700
changeset 563278 86489b7f4ca3bc34a08674d7ae70c9f3ffd17805
parent 563277 bfef2c65c69dce82164bf3021ba160f4b93a094f
child 624433 d74e95dc48684680224a0e91c43aaf2924413237
push id54256
push usermaglione.k@gmail.com
push dateSun, 16 Apr 2017 02:40:19 +0000
reviewersrhelmer
bugs1356852
milestone55.0a1
Bug 1356852: Avoid loading NetUtil just for newURI. r?rhelmer MozReview-Commit-ID: CJl2Tw2fAAO
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -966,17 +966,17 @@ function getRDFProperty(aDs, aResource, 
  *         A |file:| or |jar:| URL for the manifest
  * @return an AddonInternal object
  * @throws if the install manifest in the stream is corrupt or could not
  *         be read
  */
 var loadManifestFromWebManifest = Task.async(function*(aUri) {
   // We're passed the URI for the manifest file. Get the URI for its
   // parent directory.
-  let uri = NetUtil.newURI("./", null, aUri);
+  let uri = Services.io.newURI("./", null, aUri);
 
   let extension = new ExtensionData(uri);
 
   let manifest = yield extension.loadManifest();
 
   // Read the list of available locales, and pre-load messages for
   // all locales.
   let locales = (extension.errors.length == 0) ?
@@ -1246,17 +1246,17 @@ let loadManifestFromRDF = Task.async(fun
         addon.optionsType != AddonManager.OPTIONS_TYPE_DIALOG &&
         addon.optionsType != AddonManager.OPTIONS_TYPE_INLINE &&
         addon.optionsType != AddonManager.OPTIONS_TYPE_TAB &&
         addon.optionsType != AddonManager.OPTIONS_TYPE_INLINE_INFO) {
       throw new Error("Install manifest specifies unknown type: " + addon.optionsType);
     }
 
     if (addon.hasEmbeddedWebExtension) {
-      let uri = NetUtil.newURI("webextension/manifest.json", null, aUri);
+      let uri = Services.io.newURI("webextension/manifest.json", null, aUri);
       let embeddedAddon = yield loadManifestFromWebManifest(uri);
       if (embeddedAddon.optionsURL) {
         if (addon.optionsType || addon.optionsURL)
           logger.warn(`Addon ${addon.id} specifies optionsType or optionsURL ` +
                       `in both install.rdf and manifest.json`);
 
         addon.optionsURL = embeddedAddon.optionsURL;
         addon.optionsType = embeddedAddon.optionsType;
@@ -1669,17 +1669,17 @@ function syncLoadManifestFromFile(aFile,
  * @return an nsIURI pointing at the resource
  */
 function getURIForResourceInFile(aFile, aPath) {
   if (aFile.isDirectory()) {
     let resource = aFile.clone();
     if (aPath)
       aPath.split("/").forEach(part => resource.append(part));
 
-    return NetUtil.newURI(resource);
+    return Services.io.newFileURI(resource);
   }
 
   return buildJarURI(aFile, aPath);
 }
 
 /**
  * Creates a jar: URI for a file inside a ZIP file.
  *
@@ -1687,17 +1687,17 @@ function getURIForResourceInFile(aFile, 
  *         The ZIP file as an nsIFile
  * @param  aPath
  *         The path inside the ZIP file
  * @return an nsIURI for the file
  */
 function buildJarURI(aJarfile, aPath) {
   let uri = Services.io.newFileURI(aJarfile);
   uri = "jar:" + uri.spec + "!/" + aPath;
-  return NetUtil.newURI(uri);
+  return Services.io.newURI(uri);
 }
 
 /**
  * Sends local and remote notifications to flush a JAR file cache entry
  *
  * @param aJarFile
  *        The ZIP/XPI/JAR file as a nsIFile
  */
@@ -4014,17 +4014,17 @@ this.XPIProvider = {
    * @param  aBrowser
    *         The browser performing the install
    * @param  aCallback
    *         A callback to pass the AddonInstall to
    */
   getInstallForURL(aUrl, aHash, aName, aIcons, aVersion, aBrowser,
                              aCallback) {
     let location = XPIProvider.installLocationsByName[KEY_APP_PROFILE];
-    let url = NetUtil.newURI(aUrl);
+    let url = Services.io.newURI(aUrl);
 
     let options = {
       hash: aHash,
       browser: aBrowser,
       name: aName,
       icons: aIcons,
       version: aVersion,
     };
@@ -6634,20 +6634,20 @@ class StagedAddonInstall extends AddonIn
   constructor(installLocation, dir, manifest) {
     super(installLocation, dir);
 
     this.name = manifest.name;
     this.type = manifest.type;
     this.version = manifest.version;
     this.icons = manifest.icons;
     this.releaseNotesURI = manifest.releaseNotesURI ?
-                           NetUtil.newURI(manifest.releaseNotesURI) :
+                           Services.io.newURI(manifest.releaseNotesURI) :
                            null;
     this.sourceURI = manifest.sourceURI ?
-                     NetUtil.newURI(manifest.sourceURI) :
+                     Services.io.newURI(manifest.sourceURI) :
                      null;
     this.file = null;
     this.addon = manifest;
 
     this.state = AddonManager.STATE_INSTALLED;
   }
 }
 
@@ -6683,17 +6683,17 @@ function createLocalInstall(file, locati
  * @param  aCallback
  *         The callback to pass the new AddonInstall to
  * @param  aAddon
  *         The add-on being updated
  * @param  aUpdate
  *         The metadata about the new version from the update manifest
  */
 function createUpdate(aCallback, aAddon, aUpdate) {
-  let url = NetUtil.newURI(aUpdate.updateURL);
+  let url = Services.io.newURI(aUpdate.updateURL);
 
   Task.spawn(function*() {
     let opts = {
       hash: aUpdate.updateHash,
       existingAddon: aAddon,
       name: aAddon.selectedLocale.name,
       type: aAddon.type,
       icons: aAddon.icons,
@@ -6703,17 +6703,17 @@ function createUpdate(aCallback, aAddon,
     if (url instanceof Ci.nsIFileURL) {
       install = new LocalAddonInstall(aAddon._installLocation, url, opts);
       yield install.init();
     } else {
       install = new DownloadAddonInstall(aAddon._installLocation, url, opts);
     }
     try {
       if (aUpdate.updateInfoURL)
-        install.releaseNotesURI = NetUtil.newURI(escapeAddonURI(aAddon, aUpdate.updateInfoURL));
+        install.releaseNotesURI = Services.io.newURI(escapeAddonURI(aAddon, aUpdate.updateInfoURL));
     } catch (e) {
       // If the releaseNotesURI cannot be parsed then just ignore it.
     }
 
     aCallback(install);
   });
 }
 
@@ -7820,17 +7820,17 @@ AddonWrapper.prototype = {
    * @param  aPath
    *         The path in the add-on to get the URI for or null to get a URI to
    *         the file or directory the add-on is installed as.
    * @return an nsIURI
    */
   getResourceURI(aPath) {
     let addon = addonFor(this);
     if (!aPath)
-      return NetUtil.newURI(addon._sourceBundle);
+      return Services.io.newFileURI(addon._sourceBundle);
 
     return getURIForResourceInFile(addon._sourceBundle, aPath);
   }
 };
 
 /**
  * The PrivateWrapper is used to expose certain functionality only when being
  * called with the add-on instanceID, disallowing other add-ons to access it.
@@ -7956,17 +7956,17 @@ function defineAddonWrapperProperty(name
       return Services.io.newFileURI(addon._sourceBundle);
     }
 
     let [target, fromRepo] = chooseValue(addon, addon, aProp);
     if (!target)
       return null;
     if (fromRepo)
       return target;
-    return NetUtil.newURI(target);
+    return Services.io.newURI(target);
   });
 });
 
 PROP_LOCALE_SINGLE.forEach(function(aProp) {
   defineAddonWrapperProperty(aProp, function() {
     let addon = addonFor(this);
     // Override XPI creator if repository creator is defined
     if (aProp == "creator" &&