~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpfe/components/winhooks/nsSetDefaultMail.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
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/
 
8
 *
 
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
 
12
 * License.
 
13
 *
 
14
 * The Original Code is Mozilla Set Default Mail.
 
15
 *
 
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.
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Bill Law  <law@netscape.com>
 
23
 *   Sean Su <ssu@netscape.com>
 
24
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
/* This file implements the nsICmdLineHandler interface.  See nsICmdLineHandler.idl
 
40
 * at http://lxr.mozilla.org/seamonkey/source/xpfe/appshell/public/nsICmdLineHandler.idl.
 
41
 *
 
42
 * This component handles the startup command line argument of the form:
 
43
 *   -setDefaultMail
 
44
 * by making the current executable the "default mail client."
 
45
 *
 
46
 * The module is registered under the contractid
 
47
 *   "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultMail"
 
48
 *
 
49
 * The implementation consists of a JavaScript "class" named nsSetDefaultMail,
 
50
 * comprised of:
 
51
 *   - a JS constructor function
 
52
 *   - a prototype providing all the interface methods and implementation stuff
 
53
 *
 
54
 * In addition, this file implements an nsIModule object that registers the
 
55
 * nsSetDefaultMail component.
 
56
 */
 
57
 
 
58
/* ctor
 
59
 */
 
60
function nsSetDefaultMail() {
 
61
}
 
62
 
 
63
nsSetDefaultMail.prototype = {
 
64
 
 
65
    // nsICmdLineHandler interface
 
66
    get commandLineArgument() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
 
67
    get prefNameForStartup()  { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
 
68
 
 
69
    get chromeUrlForTask()    { 
 
70
 
 
71
      var mapiRegistry;
 
72
      try {
 
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);
 
77
          }
 
78
          else {
 
79
            mapiRegistry = null;
 
80
          }
 
81
      }
 
82
      catch (ex) { 
 
83
          mapiRegistry = null;
 
84
      }
 
85
 
 
86
      // Set mailnews as the default mail handler here
 
87
      if(mapiRegistry)
 
88
          mapiRegistry.isDefaultMailClient = true;
 
89
 
 
90
      // Now, get the cmd line service.
 
91
      var cmdLineService = Components.classes[ "@mozilla.org/appshell/commandLineService;1" ]
 
92
                              .getService( Components.interfaces.nsICmdLineService );
 
93
 
 
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" );
 
102
      if (!option) {
 
103
        // Already running, so we don't have to worry about opening
 
104
        // another window, etc.
 
105
        throw Components.results.NS_ERROR_NOT_AVAILABLE;
 
106
      }
 
107
 
 
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";
 
113
    },
 
114
 
 
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; }, 
 
119
 
 
120
    // nsISupports interface
 
121
 
 
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;
 
127
        }
 
128
        return this;
 
129
    },
 
130
 
 
131
    // This Component's module implementation.  All the code below is used to get this
 
132
    // component registered and accessible via XPCOM.
 
133
    module: {
 
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",
 
139
                                             this.contractId,
 
140
                                             fileSpec,
 
141
                                             location,
 
142
                                             type );
 
143
        },
 
144
    
 
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;
 
149
    
 
150
            if (!iid.equals(Components.interfaces.nsIFactory))
 
151
                throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
 
152
    
 
153
            return this.factory;
 
154
        },
 
155
    
 
156
        /* CID for this class */
 
157
        cid: Components.ID("{8b26281d-c3b2-4b57-9653-419fc705a02d}"),
 
158
    
 
159
        /* Contract ID for this class */
 
160
        contractId: "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultMail",
 
161
    
 
162
        /* factory object */
 
163
        factory: {
 
164
            // createInstance: Return a new nsSetDefaultMail object.
 
165
            createInstance: function (outer, iid) {
 
166
                if (outer != null)
 
167
                    throw Components.results.NS_ERROR_NO_AGGREGATION;
 
168
    
 
169
                return (new nsSetDefaultMail()).QueryInterface(iid);
 
170
            }
 
171
        },
 
172
    
 
173
        // canUnload: n/a (returns true)
 
174
        canUnload: function(compMgr) {
 
175
            return true;
 
176
        }
 
177
    }
 
178
}
 
179
 
 
180
// NSGetModule: Return the nsIModule object.
 
181
function NSGetModule(compMgr, fileSpec) {
 
182
    return nsSetDefaultMail.prototype.module;
 
183
}