1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla Set Default Mail.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corp.
18 * Portions created by the Initial Developer are Copyright (C) 2002
19 * the Initial Developer. All Rights Reserved.
22 * Bill Law <law@netscape.com>
23 * Sean Su <ssu@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 /* This file implements the nsICmdLineHandler interface. See nsICmdLineHandler.idl
40 * at http://lxr.mozilla.org/seamonkey/source/xpfe/appshell/public/nsICmdLineHandler.idl.
42 * This component handles the startup command line argument of the form:
44 * by making the current executable the "default mail client."
46 * The module is registered under the contractid
47 * "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultMail"
49 * The implementation consists of a JavaScript "class" named nsSetDefaultMail,
51 * - a JS constructor function
52 * - a prototype providing all the interface methods and implementation stuff
54 * In addition, this file implements an nsIModule object that registers the
55 * nsSetDefaultMail component.
60 function nsSetDefaultMail() {
63 nsSetDefaultMail.prototype = {
65 // nsICmdLineHandler interface
66 get commandLineArgument() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
67 get prefNameForStartup() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
69 get chromeUrlForTask() {
73 var mapiRegistryProgID = "@mozilla.org/mapiregistry;1"
74 // make sure mail is installed
75 if (mapiRegistryProgID in Components.classes) {
76 mapiRegistry = Components.classes[mapiRegistryProgID].getService(Components.interfaces.nsIMapiRegistry);
86 // Set mailnews as the default mail handler here
88 mapiRegistry.isDefaultMailClient = true;
90 // Now, get the cmd line service.
91 var cmdLineService = Components.classes[ "@mozilla.org/app-startup/commandLineService;1" ]
92 .getService( Components.interfaces.nsICmdLineService );
94 // See if "-setDefaultMail" was specified. The value will be "1" if
95 // -setDefaultMail is in the service's list of cmd line arguments, and
96 // null otherwise. -setDefaultMail will only be in the service's
97 // arg list if the application was not already running. That's because
98 // if it was already running, then the service reflects the arguments
99 // that were specified when *that* process was started, *not* the ones
100 // passed via IPC from the second instance.
101 var option = cmdLineService.getCmdLineValue( "-setDefaultMail" );
103 // Already running, so we don't have to worry about opening
104 // another window, etc.
105 throw Components.results.NS_ERROR_NOT_AVAILABLE;
108 // Return URL for dummy window that will auto-close. We do this rather
109 // than throw NS_ERROR_NOT_AVAILABLE, which *should* work, because it
110 // seems that if we don't open a window, we get a crash when trying to
111 // release this (or some other) JS component during XPCOM shutdown.
112 return "chrome://global/content/dummyWindow.xul";
115 get helpText() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
116 get handlesArgs() { return false; },
117 get defaultArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
118 get openWindowWithArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
120 // nsISupports interface
122 // This "class" supports nsICmdLineHandler and nsISupports.
123 QueryInterface: function (iid) {
124 if (iid.equals(Components.interfaces.nsICmdLineHandler) ||
125 iid.equals(Components.interfaces.nsISupports))
128 Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
132 // This Component's module implementation. All the code below is used to get this
133 // component registered and accessible via XPCOM.
135 // registerSelf: Register this component.
136 registerSelf: function (compMgr, fileSpec, location, type) {
137 var compReg = compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
138 compReg.registerFactoryLocation( this.cid,
139 "Set Mailnews as Default mail handler",
146 // getClassObject: Return this component's factory object.
147 getClassObject: function (compMgr, cid, iid) {
148 if (!cid.equals(this.cid))
149 throw Components.results.NS_ERROR_NO_INTERFACE;
151 if (!iid.equals(Components.interfaces.nsIFactory))
152 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
157 /* CID for this class */
158 cid: Components.ID("{8b26281d-c3b2-4b57-9653-419fc705a02d}"),
160 /* Contract ID for this class */
161 contractId: "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultMail",
165 // createInstance: Return a new nsSetDefaultMail object.
166 createInstance: function (outer, iid) {
168 throw Components.results.NS_ERROR_NO_AGGREGATION;
170 return (new nsSetDefaultMail()).QueryInterface(iid);
174 // canUnload: n/a (returns true)
175 canUnload: function(compMgr) {
181 // NSGetModule: Return the nsIModule object.
182 function NSGetModule(compMgr, fileSpec) {
183 return nsSetDefaultMail.prototype.module;