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/appshell/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)) {
126
throw Components.results.NS_ERROR_NO_INTERFACE;
131
// This Component's module implementation. All the code below is used to get this
132
// component registered and accessible via XPCOM.
134
// registerSelf: Register this component.
135
registerSelf: function (compMgr, fileSpec, location, type) {
136
var compReg = compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
137
compReg.registerFactoryLocation( this.cid,
138
"Set Mailnews as Default mail handler",
145
// getClassObject: Return this component's factory object.
146
getClassObject: function (compMgr, cid, iid) {
147
if (!cid.equals(this.cid))
148
throw Components.results.NS_ERROR_NO_INTERFACE;
150
if (!iid.equals(Components.interfaces.nsIFactory))
151
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
156
/* CID for this class */
157
cid: Components.ID("{8b26281d-c3b2-4b57-9653-419fc705a02d}"),
159
/* Contract ID for this class */
160
contractId: "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultMail",
164
// createInstance: Return a new nsSetDefaultMail object.
165
createInstance: function (outer, iid) {
167
throw Components.results.NS_ERROR_NO_AGGREGATION;
169
return (new nsSetDefaultMail()).QueryInterface(iid);
173
// canUnload: n/a (returns true)
174
canUnload: function(compMgr) {
180
// NSGetModule: Return the nsIModule object.
181
function NSGetModule(compMgr, fileSpec) {
182
return nsSetDefaultMail.prototype.module;