1 var command_line_handlers = [];
3 define_variable("url_remoting_fn", load_url_in_new_window);
5 function load_url_in_new_window(url, ctx) {
6 make_window(buffer_creator(content_buffer, $load = url, $configuration = ctx.config));
9 function load_url_in_new_buffer(url, ctx) {
10 create_buffer_in_current_window(buffer_creator(content_buffer, $load = url, $configuration = ctx.config),
11 OPEN_NEW_BUFFER, true /* focus the new window */);
14 function command_line_handler(name, suppress_default, handler)
16 command_line_handlers[name] = { suppress_default: suppress_default, func: handler };
19 function command_line_param_handler(name, suppress_default, handler)
21 command_line_handlers[name] = { suppress_default: suppress_default,
26 command_line_handler("batch", true);
27 command_line_param_handler("e", false, function (expr, ctx) {
31 command_line_param_handler("E", false, function (expr, ctx) {});
33 command_line_param_handler("chrome", true, function (uri, ctx) {
35 make_chrome_window(uri);
36 } catch (e) { dump_error(e); }
38 command_line_param_handler("q", false, function () {
39 dumpln ("w: -q may only be used as the first argument.");
42 command_line_param_handler("cwd", false, function (dir, ctx) {
43 if (ctx.config == null)
49 function handle_command_line(cmdline)
52 var suppress_default = false;
53 var suppress_rc = false;
57 /* -q must be the first argument, if it is given */
58 if (cmdline.length > 0 && cmdline.getArgument(0) == "-q")
64 var initial_launch = (cmdline.state == cmdline.STATE_INITIAL_LAUNCH);
68 while (j + 1 < cmdline.length) {
69 if (cmdline.getArgument(j) == "-E") {
70 eval(cmdline.getArgument(j+1));
71 cmdline.removeArguments(j, j+1);
76 let load_default_modules = get_pref("conkeror.loadDefaultModules");
78 let branch = preferences.getBranch("conkeror.load.");
79 for each (let m in branch.getChildList("", {})) {
81 let val = branch.getBoolPref(m);
82 if (val && (load_default_modules || branch.prefHasUserValue(m)))
85 dumpln("Error: Preference 'conkeror.load." + m + "' has non-boolean value.");
88 } catch (e) {dump_error(e);}
91 if (! suppress_rc && initial_launch)
95 } catch (e) { dump (e + "\n"); }
96 } else if (suppress_rc && ! initial_launch) {
97 dumpln ("w: attempt to suppress load_rc in remote invocation");
99 var ctx = {}; // command-line processing context
101 for (; i < cmdline.length; ++i)
103 var arg = cmdline.getArgument(i);
105 var arg1 = arg.substring(1);
106 if (arg1 in command_line_handlers) {
107 var handler = command_line_handlers[arg1];
108 if (handler.suppress_default)
109 suppress_default = true;
112 i++; // increment the argument counter to skip the parameter
113 if (i >= cmdline.length) {
114 dump ("w: ignoring command switch `"+arg+"' because no argument was provided.\n");
117 var param = cmdline.getArgument (i);
118 handler.func(param, ctx);
127 // something other than a switch was passed on the command
128 // line. suppress the default window, and call the
129 // user-configurable remoting function on it.
131 suppress_default = true;
132 url_remoting_fn (arg, ctx);
135 // we are greedy and handle all command line arguments. remove
136 // everything from the command line object, so no other
137 // components can see them.
139 if (cmdline.length > 0) {
140 cmdline.removeArguments(0, cmdline.length - 1);
143 // no args were found for url_remoting_fn, and no switches
144 // explicitly suppressed the creation of a default window
145 // (e.g. -batch or -daemon)
147 if (! suppress_default) {
148 url_remoting_fn(homepage, ctx);
151 dumpln("Error processing command line.");