summaryrefslogtreecommitdiff
path: root/common/components/commandline-handler.js
blob: e4362d970cb85abe1fed8b87cdbd8272028be4f1 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2009 by Doug Kearns
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";

function reportError(e) {
    dump("dactyl: command-line-handler: " + e + "\n" + (e.stack || Error().stack));
    Cu.reportError(e);
}

var global = this;
var NAME = "command-line-handler";
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function CommandLineHandler() {
    this.wrappedJSObject = this;

    Cu.import("resource://dactyl/base.jsm");
    require(global, "util");
    require(global, "config");
}
CommandLineHandler.prototype = {

    classDescription: "Dactyl Command-line Handler",

    classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"),

    contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl",

    _xpcom_categories: [{
        category: "command-line-handler",
        entry: "m-dactyl"
    }],

    QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]),

    handle: function (commandLine) {
        try {
            var remote = commandLine.handleFlagWithParam(config.name + "-remote", false);
        }
        catch (e) {
            util.dump("option '-" + config.name + "-remote' requires an argument\n");
        }

        try {
            if (remote) {
                commandLine.preventDefault = true;
                require(global, "services");
                let win = services.windowMediator.getMostRecentWindow("navigator:browser");
                if (win && win.dactyl)
                    win.dactyl.execute(remote);
            }
        }
        catch(e) {
            util.reportError(e)
        };

        try {
            this.optionValue = commandLine.handleFlagWithParam(config.name, false);
        }
        catch (e) {
            util.dump("option '-" + config.name + "' requires an argument\n");
        }
    },

    get helpInfo() "  -" + config.name + " <opts>" + "             Additional options for " + config.appName + " startup\n".substr(config.name.length)
};

if (XPCOMUtils.generateNSGetFactory)
    var NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]);
else
    var NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]);
var EXPORTED_SYMBOLS = ["NSGetFactory", "global"];

// vim: set fdm=marker sw=4 ts=4 et: