Bug 459784 Fix Error: uncaught exception: 2147500034, and switch the default commandline handler to use XPCOMUtils.jsm. r=philor
authorMark Banner <bugzilla@standard8.plus.com>
Thu, 16 Oct 2008 08:37:50 +0100
changeset 621 5233061b8367afb8e71900ca96a5964e17326b60
parent 620 16a9fb5a46e45eb61d6ddf02bf06bcd450a110b1
child 622 5d69c7b6e83ce8039e202198ca209f75e326161b
push idunknown
push userunknown
push dateunknown
reviewersphilor
bugs459784
Bug 459784 Fix Error: uncaught exception: 2147500034, and switch the default commandline handler to use XPCOMUtils.jsm. r=philor
mail/components/Makefile.in
mail/components/nsMailDefaultHandler.js
--- a/mail/components/Makefile.in
+++ b/mail/components/Makefile.in
@@ -59,12 +59,12 @@ endif
 ifneq (,$(filter windows, $(MOZ_WIDGET_TOOLKIT)))
 ifndef MOZ_DISABLE_VISTA_SDK_REQUIREMENTS
 DIRS += search
 endif
 endif
 
 DIRS += build
 
-EXTRA_PP_COMPONENTS = nsMailDefaultHandler.js
+EXTRA_COMPONENTS = nsMailDefaultHandler.js
 
 include $(topsrcdir)/config/rules.mk
 
--- a/mail/components/nsMailDefaultHandler.js
+++ b/mail/components/nsMailDefaultHandler.js
@@ -31,16 +31,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
 const nsISupports              = Components.interfaces.nsISupports;
 
 const nsICommandLine           = Components.interfaces.nsICommandLine;
 const nsICommandLineHandler    = Components.interfaces.nsICommandLineHandler;
 const nsICommandLineValidator  = Components.interfaces.nsICommandLineValidator;
 const nsIDOMWindowInternal     = Components.interfaces.nsIDOMWindowInternal;
 const nsIFactory               = Components.interfaces.nsIFactory;
 const nsIFileURL               = Components.interfaces.nsIFileURL;
@@ -118,24 +120,18 @@ function openURI(uri)
     onStartRequest: function ll_start(aRequest, aContext) {
       appstartup.enterLastWindowClosingSurvivalArea();
     },
 
     onStopRequest: function ll_stop(aRequest, aContext, aStatusCode) {
       appstartup.exitLastWindowClosingSurvivalArea();
     },
 
-    QueryInterface: function ll_QI(iid) {
-      if (iid.equals(nsISupports) ||
-          iid.equals(Components.interfaces.nsIRequestObserver) ||
-          iid.equals(Components.interfaces.nsISupportsWeakReference))
-        return this;
-
-      throw Components.results.NS_ERROR_NO_INTERFACE;
-    }
+    QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIRequestObserver,
+                                           Components.interfaces.nsISupportsWeakReference])
   };
 
   loadgroup.groupObserver = loadlistener;
 
   var listener = {
     onStartURIOpen: function(uri) { return false; },
     doContent: function(ctype, preferred, request, handler) { return false; },
     isPreferred: function(ctype, desired) { return false; },
@@ -151,27 +147,19 @@ function openURI(uri)
 
       throw Components.results.NS_ERROR_NO_INTERFACE;
     }
   };
   loader.openURI(channel, true, listener);
 }
 
 var nsMailDefaultHandler = {
-  /* nsISupports */
-
-  QueryInterface : function mdh_QI(iid) {
-    if (iid.equals(nsICommandLineHandler) ||
-        iid.equals(nsICommandLineValidator) ||
-        iid.equals(nsIFactory) ||
-        iid.equals(nsISupports))
-      return this;
-
-    throw Components.results.NS_ERROR_NO_INTERFACE;
-  },
+  QueryInterface: XPCOMUtils.generateQI([nsICommandLineHandler,
+                                         nsICommandLineValidator,
+                                         nsIFactory]),
 
   /* nsICommandLineHandler */
 
   handle : function mdh_handle(cmdLine) {
     var uri;
 
     try {
       var remoteCommand = cmdLine.handleFlagWithParam("remote", true);
@@ -383,74 +371,30 @@ var nsMailDefaultHandler = {
     return this.QueryInterface(iid);
   },
 
   lockFactory : function mdh_lock(lock) {
     /* no-op */
   }
 };
 
-const mdh_contractID = "@mozilla.org/mail/clh;1";
-const mdh_CID = Components.ID("{44346520-c5d2-44e5-a1ec-034e04d7fac4}");
-
-var Module = {
-  /* nsISupports */
-
-  QueryInterface : function QI(iid) {
-    if (iid.equals(Components.interfaces.nsIModule) &&
-        iid.equals(Components.interfaces.nsISupports))
-      return this;
+function mailDefaultCommandLineHandler() {}
 
-    throw Components.results.NS_ERROR_NO_INTERFACE;
-  },
-
-  /* nsIModule */
-  getClassObject : function (compMgr, cid, iid) {
-    if (cid.equals(mdh_CID))
-      return nsMailDefaultHandler.QueryInterface(iid);
-
-    throw Components.results.NS_ERROR_FAILURE;
-  },
-    
-  registerSelf: function mod_regself(compMgr, fileSpec, location, type) {
-    var compReg =
-      compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
+mailDefaultCommandLineHandler.prototype = {
+  classDescription: "Mail default commandline handler",
+  classID: Components.ID("{44346520-c5d2-44e5-a1ec-034e04d7fac4}"),
+  contractID: "@mozilla.org/mail/clh;1",
 
-    compReg.registerFactoryLocation(mdh_CID,
-                                    "nsMailDefaultHandler",
-                                    mdh_contractID,
-                                    fileSpec,
-                                    location,
-                                    type );
-
-    var catMan = Components.classes["@mozilla.org/categorymanager;1"]
-                           .getService(Components.interfaces.nsICategoryManager);
+  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIModule]),
 
-    catMan.addCategoryEntry("command-line-handler",
-                            "x-default",
-                            mdh_contractID, true, true);
-    catMan.addCategoryEntry("command-line-validator",
-                            "b-default",
-                            mdh_contractID, true, true);
-  },
-    
-  unregisterSelf : function mod_unregself(compMgr, location, type) {
-    var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
-    compReg.unregisterFactoryLocation(mdh_CID, location);
+  _xpcom_categories:
+    [ { category: "command-line-handler",
+        entry: "x-default" },
+      { category: "command-line-validator",
+        entry: "b-default" } ],
 
-    var catMan = Components.classes["@mozilla.org/categorymanager;1"]
-                           .getService(Components.interfaces.nsICategoryManager);
-
-    catMan.deleteCategoryEntry("command-line-handler",
-                               "x-default", true);
-    catMan.deleteCategoryEntry("command-line-validator",
-                               "b-default", true);
-  },
-
-  canUnload: function(compMgr) {
-    return true;
-  }
+  _xpcom_factory: nsMailDefaultHandler
 }
 
 // NSGetModule: Return the nsIModule object.
 function NSGetModule(compMgr, fileSpec) {
-  return Module;
+  return XPCOMUtils.generateModule([mailDefaultCommandLineHandler]);
 }