]> git.donarmstrong.com Git - dactyl.git/blob - common/components/commandline-handler.js
Import r6948 from upstream hg supporting Firefox up to 24.*
[dactyl.git] / common / components / commandline-handler.js
1 // Copyright (c) 2009 by Doug Kearns
2 //
3 // This work is licensed for reuse under an MIT license. Details are
4 // given in the LICENSE.txt file included with this file.
5 "use strict";
6
7 function reportError(e) {
8     dump("dactyl: command-line-handler: " + e + "\n" + (e.stack || Error().stack));
9     Cu.reportError(e);
10 }
11
12 var global = this;
13 var NAME = "command-line-handler";
14 var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
15
16 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
17
18 function init() {
19     Cu.import("resource://dactyl/bootstrap.jsm");
20     require("config", global);
21     require("util", global);
22 }
23
24 function CommandLineHandler() {
25     this.wrappedJSObject = this;
26 }
27 CommandLineHandler.prototype = {
28
29     classDescription: "Dactyl command line Handler",
30
31     classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"),
32
33     contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl",
34
35     _xpcom_categories: [
36         {
37             category: "command-line-handler",
38             entry: "m-dactyl"
39         },
40
41         // FIXME: Belongs elsewhere
42          {
43             category: "profile-after-change",
44             entry: "m-dactyl"
45         }
46     ],
47
48     observe: function observe(subject, topic, data) {
49         if (topic === "profile-after-change") {
50             init();
51             require(global, "main");
52         }
53     },
54
55     QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsICommandLineHandler]),
56
57     handle: function (commandLine) {
58         init();
59         try {
60             var remote = commandLine.handleFlagWithParam(config.name + "-remote", false);
61         }
62         catch (e) {
63             util.dump("option '-" + config.name + "-remote' requires an argument\n");
64         }
65
66         try {
67             if (remote) {
68                 commandLine.preventDefault = true;
69                 require(global, "services");
70                 util.dactyl.execute(remote);
71             }
72         }
73         catch (e) {
74             util.reportError(e);
75         }
76
77         try {
78             this.optionValue = commandLine.handleFlagWithParam(config.name, false);
79         }
80         catch (e) {
81             util.dump("option '-" + config.name + "' requires an argument\n");
82         }
83     },
84
85     get helpInfo() "  -" + config.name + " <opts>" + "             Additional options for " + config.appName + " startup\n".substr(config.name.length)
86 };
87
88 if (XPCOMUtils.generateNSGetFactory)
89     var NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]);
90 else
91     var NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]);
92 var EXPORTED_SYMBOLS = ["NSGetFactory", "global"];
93
94 // vim: set fdm=marker sw=4 sts=4 ts=8 et: