Bug 1512612 - Don't try to create folders for unloaded extensions. r=aceman a=jorgk
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 07 Dec 2018 04:49:00 +0100
changeset 33881 f4713beacbe117a1a262e0fe5a1c1cc2af2a56ad
parent 33880 16ba8334367e9a1fd702163b5087d9796aeda43a
child 33882 6317b7048dcceb73c637a65e9c0d87c6acdd6182
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersaceman, jorgk
bugs1512612
Bug 1512612 - Don't try to create folders for unloaded extensions. r=aceman a=jorgk
mailnews/base/src/folderLookupService.js
--- a/mailnews/base/src/folderLookupService.js
+++ b/mailnews/base/src/folderLookupService.js
@@ -65,39 +65,40 @@ folderLookupService.prototype = {
 
     // If we get here, then the folder was not in our map. It could be that the
     // folder was created by somebody else, so try to find that folder.
     // For now, we use the RDF service, since it results in minimal changes. But
     // RDF has a tendency to create objects without checking to see if they
     // really exist---use the parent property to see if the folder is a real
     // folder.
     if (folder == null) {
-      let rdf = Cc["@mozilla.org/rdf/rdf-service;1"]
-                  .getService(Ci.nsIRDFService);
-      try {
-        folder = rdf.GetResource(aUrl)
-                    .QueryInterface(Ci.nsIMsgFolder);
-      } catch (e) {
-        // If the QI fails, then we somehow picked up an RDF resource that isn't
-        // a folder. Return null in this case.
+      folder = this.getOrCreateFolderForURL(aUrl);
+      if (!folder)
         return null;
-      }
     }
     // We don't want to return "dangling" (parentless) folders.
     if (!isValidFolder(folder))
       return null;
 
     // Add the new folder to our map. Store a weak reference instead, so that
     // the folder can be closed when necessary.
     let weakRef = folder.QueryInterface(Ci.nsISupportsWeakReference)
                         .GetWeakReference();
     this._map.set(aUrl, weakRef);
     return folder;
   },
   getOrCreateFolderForURL: function (aUrl) {
+    // Check that aUrl has an active scheme, in case this folder is from
+    // an extension that is currently disabled or hasn't started up yet.
+    // Extract the scheme in the same way that the RDF service does.
+    let scheme = aUrl.match(/\w*/)[0];
+    let contractID = "@mozilla.org/rdf/resource-factory;1?name=" + scheme;
+    if (!(contractID in Components.classes))
+      return null;
+
     // NOTE: this doesn't update _map, but it'll work fine and
     // it's a transitional function we want deleted anyway.
     let rdf = Cc["@mozilla.org/rdf/rdf-service;1"]
                 .getService(Ci.nsIRDFService);
     try {
       let folder = rdf.GetResource(aUrl)
                       .QueryInterface(Ci.nsIMsgFolder);
       return folder;