1 //http://developer.mozilla.org/en/docs/Chrome:_Command_Line
3 //const nsIAppShellService = Components.interfaces.nsIAppShellService;
4 const nsISupports = Components.interfaces.nsISupports;
5 const nsICategoryManager = Components.interfaces.nsICategoryManager;
6 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
7 const nsICommandLine = Components.interfaces.nsICommandLine;
8 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
9 const nsIFactory = Components.interfaces.nsIFactory;
10 const nsIModule = Components.interfaces.nsIModule;
11 //const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
14 * The XPCOM component that implements nsICommandLineHandler.
15 * It also implements nsIFactory to serve as its own singleton factory.
20 QueryInterface : function clh_QI(iid) {
21 if (iid.equals(nsICommandLineHandler) ||
22 iid.equals(nsIFactory) ||
23 iid.equals(nsISupports))
26 throw Components.results.NS_ERROR_NO_INTERFACE;
29 /* nsICommandLineHandler */
31 handle : function clh_handle(cmdLine) {
35 var argCount = cmdLine.length;
37 // Components.utils.reportError(cmdLine.state);
38 for (var i = 0; i < argCount; ++i) {
39 currentArg = cmdLine.getArgument(i);
41 /*var mConsoleService = Components.classes["@mozilla.org/consoleservice;1"]
42 .getService(Components.interfaces.nsIConsoleService)
43 mConsoleService.logStringMessage("eMusic_protocol: " + currentArg + "\n");*/
45 if (currentArg == "emusic://quit/") {
46 var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
47 getService(Components.interfaces.nsIAppStartup);
49 var quitSeverity = false ? Components.interfaces.nsIAppStartup.eForceQuit :
50 Components.interfaces.nsIAppStartup.eAttemptQuit;
51 appStartup.quit(quitSeverity);
54 //Components.utils.reportError("eMusic: " + currentArg + " - " + i);
55 if (currentArg && (/\.emp$/i.test(currentArg) || /\.emx$/i.test(currentArg))) {
56 // Components.utils.reportError(currentArg);
57 currentArg = cmdLine.resolveFile(currentArg).path
58 // Components.utils.reportError(currentArg);
60 prefs = Components.classes["@mozilla.org/preferences-service;1"]
61 .getService(Components.interfaces.nsIPrefService)
62 .getBranch("eMusic.");
64 prefs.setCharPref("cmdLineValue", currentArg);
69 Components.utils.reportError(e);
75 helpInfo : " just the emp path please\n",
79 createInstance : function clh_CI(outer, iid) {
81 throw Components.results.NS_ERROR_NO_AGGREGATION;
83 return this.QueryInterface(iid);
86 lockFactory : function clh_lock(lock) {
91 // CHANGEME: change the contract id, CID, and category to be unique
92 // to your application.
93 //const clh_contractID = "@mozilla.org/commandlinehandler/general-startup;1?type=emhandler";
94 const clh_contractID = "@mozilla.org/toolkit/default-clh;1?type=emhandler";
95 const clh_CID = Components.ID("{EA8CD2F1-920F-48b1-8C5E-84BB23139C73}");
97 // category names are sorted alphabetically. Typical command-line handlers use a
98 // category that begins with the letter "m".
99 const clh_category = "m-emhandler";
102 * The XPCOM glue that implements nsIModule
104 const myEMHandlerModule = {
106 QueryInterface : function mod_QI(iid) {
107 if (iid.equals(nsIModule) ||
108 iid.equals(nsISupports))
111 throw Components.results.NS_ERROR_NO_INTERFACE;
115 getClassObject : function mod_gch(compMgr, cid, iid) {
116 if (cid.equals(clh_CID))
117 return myEMHandler.QueryInterface(iid);
119 throw Components.results.NS_ERROR_NOT_REGISTERED;
122 registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
123 var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
124 compReg.registerFactoryLocation(clh_CID,
131 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
132 getService(nsICategoryManager);
133 catMan.addCategoryEntry("command-line-handler",
135 clh_contractID, true, true);
138 unregisterSelf : function mod_unreg(compMgr, location, type) {
139 var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
140 compReg.unregisterFactoryLocation(clh_CID, location);
142 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
143 getService(nsICategoryManager);
144 catMan.deleteCategoryEntry("command-line-handler", clh_category);
147 canUnload : function (compMgr) {
152 /* The NSGetModule function is the magic entry point that XPCOM uses to find what XPCOM objects
153 * this component provides
155 function NSGetModule(comMgr, fileSpec) {
156 return myEMHandlerModule;