summaryrefslogtreecommitdiffstats
path: root/comm/suite/components/shell/nsSetDefault.js
blob: 4d35dc45317edd393895e95a579fa78e5f22ec37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
 * This component handles the startup command line arguments of the form:
 *   -setDefaultBrowser
 *   -setDefaultMail
 *   -setDefaultNews
 *   -setDefaultFeed
 */

const nsICommandLineHandler = Ci.nsICommandLineHandler;
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");

function nsSetDefault() {
}

nsSetDefault.prototype = {
  handle: function nsSetDefault_handle(aCmdline) {
    if (aCmdline.handleFlag("setDefaultBrowser", false)) {
      var shell = Cc["@mozilla.org/suite/shell-service;1"]
                    .getService(Ci.nsIShellService);
      shell.setDefaultClient(true, true, Ci.nsIShellService.BROWSER);
    }
    else if (aCmdline.handleFlag("setDefaultMail", false)) {
      var shell = Cc["@mozilla.org/suite/shell-service;1"]
                    .getService(Ci.nsIShellService);
      shell.setDefaultClient(true, true, Ci.nsIShellService.MAIL);
    }
    else if (aCmdline.handleFlag("setDefaultNews", false)) {
      var shell = Cc["@mozilla.org/suite/shell-service;1"]
                    .getService(Ci.nsIShellService);
      shell.setDefaultClient(true, true, Ci.nsIShellService.NEWS);
    }
    else if (aCmdline.handleFlag("setDefaultFeed", false)) {
      var shell = Cc["@mozilla.org/suite/shell-service;1"]
                    .getService(Ci.nsIShellService);
      shell.setDefaultClient(true, true, Ci.nsIShellService.RSS);
    }
  },

  helpInfo: "  -setDefaultBrowser Set this app as the default browser client.\n" +
            "  -setDefaultMail    Set this app as the default mail client.\n" +
            "  -setDefaultNews    Set this app as the default newsreader.\n" +
            "  -setDefaultFeed    Set this app as the default feedreader.\n",

  classID: Components.ID("{a3d5b950-690a-491f-a881-2c2cdcd241cb}"),
  QueryInterface: XPCOMUtils.generateQI([nsICommandLineHandler])
}

var NSGetFactory = XPCOMUtils.generateNSGetFactory([nsSetDefault]);