Bug 1378727: Use the zip reader cache when reading extension locales. r=aswan
☠☠ backed out by 9c0a02ed5bad ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Sat, 08 Jul 2017 16:48:54 -0700
changeset 607767 a8809f15b58213f3292b9eaf7fa9583377d1fa30
parent 607742 63215af4995f74aae2a6b24ad148e83d47c732f9
child 607768 de7260da8e7acc006431c32492e1d6ac272a0e2c
child 607771 cf78c3e822fec439a7a568b5f6597dabd4c65ed5
child 607772 4cb6299806578650895c819750dfb1402c1191ab
child 607773 f7db6ee4ab4ca159b9dfb35358833daa814ff790
child 607775 671f6bdbb5517716dcead0431f073d6421d562bc
child 607777 f5687797261d69daf1a788d15275909be03c4c2f
child 607789 ba5aa96ab034edb8aa0c8a15ce3c386d4405bfe0
child 608438 90eee22eec6f166243bfe2a6d93638462507679f
push id68105
push userdholbert@mozilla.com
push dateWed, 12 Jul 2017 21:16:09 +0000
reviewersaswan
bugs1378727
milestone56.0a1
Bug 1378727: Use the zip reader cache when reading extension locales. r=aswan MozReview-Commit-ID: BOoVcyypdRN
toolkit/components/extensions/Extension.jsm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -88,16 +88,20 @@ XPCOMUtils.defineLazyGetter(
           .getService().wrappedJSObject);
 
 Cu.import("resource://gre/modules/ExtensionParent.jsm");
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "uuidGen",
                                    "@mozilla.org/uuid-generator;1",
                                    "nsIUUIDGenerator");
+XPCOMUtils.defineLazyServiceGetter(this, "zipCache",
+                                   "@mozilla.org/libjar/zip-reader-cache;1",
+                                   "nsIZipReaderCache");
+
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "useRemoteWebExtensions",
                                       "extensions.webextensions.remote", false);
 
 var {
   GlobalManager,
   ParentAPIManager,
   StartupCache,
@@ -385,56 +389,49 @@ this.ExtensionData = class {
         // not a directory) for symmetry with the ZipReader behavior.
         Cu.reportError(e);
       }
       iter.close();
 
       return results;
     }
 
-    // FIXME: We need a way to do this without main thread IO.
-
     let uri = this.rootURI.QueryInterface(Ci.nsIJARURI);
-
     let file = uri.JARFile.QueryInterface(Ci.nsIFileURL).file;
-    let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
-    zipReader.open(file);
-    try {
-      let results = [];
+    let zipReader = zipCache.getZip(file);
 
-      // Normalize the directory path.
-      path = `${uri.JAREntry}/${path}`;
-      path = path.replace(/\/\/+/g, "/").replace(/^\/|\/$/g, "") + "/";
-
-      // Escape pattern metacharacters.
-      let pattern = path.replace(/[[\]()?*~|$\\]/g, "\\$&");
+    let results = [];
 
-      let enumerator = zipReader.findEntries(pattern + "*");
-      while (enumerator.hasMore()) {
-        let name = enumerator.getNext();
-        if (!name.startsWith(path)) {
-          throw new Error("Unexpected ZipReader entry");
-        }
+    // Normalize the directory path.
+    path = `${uri.JAREntry}/${path}`;
+    path = path.replace(/\/\/+/g, "/").replace(/^\/|\/$/g, "") + "/";
 
-        // The enumerator returns the full path of all entries.
-        // Trim off the leading path, and filter out entries from
-        // subdirectories.
-        name = name.slice(path.length);
-        if (name && !/\/./.test(name)) {
-          results.push({
-            name: name.replace("/", ""),
-            isDir: name.endsWith("/"),
-          });
-        }
+    // Escape pattern metacharacters.
+    let pattern = path.replace(/[[\]()?*~|$\\]/g, "\\$&");
+
+    let enumerator = zipReader.findEntries(pattern + "*");
+    while (enumerator.hasMore()) {
+      let name = enumerator.getNext();
+      if (!name.startsWith(path)) {
+        throw new Error("Unexpected ZipReader entry");
       }
 
-      return results;
-    } finally {
-      zipReader.close();
+      // The enumerator returns the full path of all entries.
+      // Trim off the leading path, and filter out entries from
+      // subdirectories.
+      name = name.slice(path.length);
+      if (name && !/\/./.test(name)) {
+        results.push({
+          name: name.replace("/", ""),
+          isDir: name.endsWith("/"),
+        });
+      }
     }
+
+    return results;
   }
 
   readJSON(path) {
     return new Promise((resolve, reject) => {
       let uri = this.rootURI.resolve(`./${path}`);
 
       NetUtil.asyncFetch({uri, loadUsingSystemPrincipal: true}, (inputStream, status) => {
         if (!Components.isSuccessCode(status)) {