Bug 386477 - XPCOMUtilify nsSetDefaultBrowser. r=mano
authorrflint@ryanflint.com
Tue, 28 Aug 2007 08:41:33 -0700
changeset 5381 3b2b4ab739c8181b18ddd2a56dbc42426c58f287
parent 5380 2a4cb3a7f070b4176db83365d80d34a698370c0e
child 5382 4a2906ecb4c44c20886efe0683fd408f80de31ed
push idunknown
push userunknown
push dateunknown
reviewersmano
bugs386477
milestone1.9a8pre
Bug 386477 - XPCOMUtilify nsSetDefaultBrowser. r=mano
browser/components/shell/src/Makefile.in
browser/components/shell/src/nsSetDefaultBrowser.js
--- a/browser/components/shell/src/Makefile.in
+++ b/browser/components/shell/src/Makefile.in
@@ -78,22 +78,18 @@ REQUIRES += mozgnome
 endif
 endif
 endif
 
 ifdef CPPSRCS
 LIBRARY_NAME = shellservice_s
 endif
 
+EXTRA_COMPONENTS = nsSetDefaultBrowser.js
+
 include $(topsrcdir)/config/rules.mk
 
 DEFINES += -DMOZ_APP_NAME=\"$(MOZ_APP_NAME)\"
 
-JS_SET_BROWSER_COMPONENT = nsSetDefaultBrowser.js
-
 CXXFLAGS += $(TK_CFLAGS)
 
-libs::
-	$(INSTALL) $(srcdir)/$(JS_SET_BROWSER_COMPONENT) $(DIST)/bin/components
-
 clobber::
 	rm -f $(DIST)/lib/$(LIBRARY_NAME).lib
-	rm -f $(DIST)/bin/components/$(JS_SET_BROWSER_COMPONENT)
--- a/browser/components/shell/src/nsSetDefaultBrowser.js
+++ b/browser/components/shell/src/nsSetDefaultBrowser.js
@@ -30,112 +30,43 @@
  * 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 ***** */
 
-/* This file implements the nsICommandLineHandler interface.
- *
- * This component handles the startup command line argument of the form:
- *   -setDefaultBrowser
- * by making the current executable the "default browser."
+/* 
+ * -setDefaultBrowser commandline handler
+ * Makes the current executable the "default browser".
  */
 
-function nsSetDefaultBrowser() {
-}
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function nsSetDefaultBrowser() {}
 
 nsSetDefaultBrowser.prototype = {
-  /* nsISupports */
-  QueryInterface: function nsSetDefault_QI(iid) {
-    if (!iid.equals(Components.interfaces.nsICommandLineHandler) &&
-        !iid.equals(Components.interfaces.nsISupports))
-      throw Components.results.NS_ERROR_NO_INTERFACE;
-
-    return this;
-  },
-
-  /* nsICommandLineHandler */
-  handle : function nsSetDefault_handle(cmdline) {
-    if (cmdline.handleFlag("setDefaultBrowser", false)) {
-      var shell = Components.classes["@mozilla.org/browser/shell-service;1"]
-                            .getService(Components.interfaces.nsIShellService);
+  handle: function nsSetDefault_handle(aCmdline) {
+    if (aCmdline.handleFlag("setDefaultBrowser", false)) {
+      var shell = Cc["@mozilla.org/browser/shell-service;1"].
+                  getService(Ci.nsIShellService);
       shell.setDefaultBrowser(true, true);
     }
   },
 
-  helpInfo : "  -setDefaultBrowser   Set this app as the default browser.\n"
+  helpInfo: "  -setDefaultBrowser   Set this app as the default browser.\n",
+
+  classDescription: "Default Browser Cmdline Handler",
+  contractID: "@mozilla.org/browser/default-browser-clh;1",
+  classID: Components.ID("{F57899D0-4E2C-4ac6-9E29-50C736103B0C}"),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
+  _xpcom_categories: [{
+    category: "command-line-handler",
+    entry: "m-setdefaultbrowser"
+  }]
 }
 
-// This Component's module and factory implementation.
-
-const contractID = "@mozilla.org/browser/default-browser-clh;1";
-const CID = Components.ID("{F57899D0-4E2C-4ac6-9E29-50C736103B0C}");
-
-var ModuleAndFactory = {
-  /* nsISupports */
-  QueryInterface: function nsSetDefault_QI(iid) {
-    if (!iid.equals(Components.interfaces.nsIModule) &&
-        !iid.equals(Components.interfaces.nsIFactory) &&
-        !iid.equals(Components.interfaces.nsISupports))
-      throw Components.results.NS_ERROR_NO_INTERFACE;
-
-    return this;
-  },
-
-  /* nsIModule */
-  getClassObject: function (compMgr, cid, iid) {
-    if (!cid.equals(CID))
-      throw Components.results.NS_ERROR_NO_INTERFACE;
-    
-    return this.QueryInterface(iid);
-  },
-    
-  registerSelf: function mod_regself(compMgr, fileSpec, location, type) {
-    var compReg =
-      compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
-
-    compReg.registerFactoryLocation( CID,
-                                     "Default Browser Cmdline Handler",
-                                     contractID,
-                                     fileSpec,
-                                     location,
-                                     type );
-
-    var catMan = Components.classes["@mozilla.org/categorymanager;1"]
-                           .getService(Components.interfaces.nsICategoryManager);
-
-    catMan.addCategoryEntry("command-line-handler",
-                            "m-setdefaultbrowser",
-                            contractID, true, true);
-  },
-    
-  unregisterSelf : function mod_unregself(compMgr, location, type) {
-    var catMan = Components.classes["@mozilla.org/categorymanager;1"]
-                           .getService(Components.interfaces.nsICategoryManager);
-
-    catMan.deleteCategoryEntry("command-line-handler",
-                               "m-setdefaultbrowser", true);
-  },
-
-  canUnload: function(compMgr) {
-    return true;
-  },
-
-  /* nsIFactory */
-  createInstance: function mod_CI(outer, iid) {
-    if (outer != null)
-      throw Components.results.NS_ERROR_NO_AGGREGATION;
-  
-    return new nsSetDefaultBrowser().QueryInterface(iid);
-  },
-    
-  lockFactory : function mod_lock(lock) {
-    /* no-op */
-  }
+function NSGetModule(compMgr, fileSpec) {
+  return XPCOMUtils.generateModule([nsSetDefaultBrowser]);
 }
-
-// NSGetModule: Return the nsIModule object.
-function NSGetModule(compMgr, fileSpec) {
-  return ModuleAndFactory;
-}