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 the Mozilla toolkit.
15 *
16 * The Initial Developer of the Original Code is
17 * Benjamin Smedberg <benjamin@smedbergs.us>
18 *
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38 #include "nsISupports.idl"
39
40 interface nsIFile;
41 interface nsIURI;
42 interface nsIDOMWindow;
43
44 /**
45 * Represents the command line used to invoke a XUL application. This may be the
46 * original command-line of this instance, or a command line remoted from another
47 * instance of the application.
48 *
49 * DEFINITIONS:
50 * "arguments" are any values found on the command line.
51 * "flags" are switches. In normalized form they are preceded by a single dash.
52 * Some flags may take "parameters", e.g. "-url <param>" or "-install-xpi <param>"
53 *
54 * @status UNDER_REVIEW This interface is intended to be frozen, but isn't frozen
55 * yet. Please use with care.
56 */
57
58 [scriptable, uuid(bc3173bd-aa46-46a0-9d25-d9867a9659b6)]
59 interface nsICommandLine : nsISupports
60 {
61 /**
62 * Number of arguments in the command line. The application name is not
63 * part of the command line.
64 */
65 readonly attribute long length;
66
67 /**
68 * Get an argument from the array of command-line arguments.
69 *
70 * On windows, flags of the form /flag are normalized to -flag. /flag:param
71 * are normalized to -flag param.
72 *
73 * On *nix and mac flags of the form --flag are normalized to -flag. --flag=param
74 * are normalized to the form -flag param.
75 *
76 * @param aIndex The argument to retrieve. This index is 0-based, and does
77 * not include the application name.
78 * @return The indexth argument.
79 * @throws NS_ERROR_INVALID_ARG if aIndex is out of bounds.
80 */
81 AString getArgument(in long aIndex);
82
83 /**
84 * Find a command-line flag.
85 *
86 * @param aFlag The flag name to locate. Do not include the initial
87 * hyphen.
88 * @param aCaseSensitive Whether to do case-sensitive comparisons.
89 * @return The position of the flag in the command line.
90 */
91 long findFlag(in AString aFlag, in boolean aCaseSensitive);
92
93 /**
94 * Remove arguments from the command line. This normally occurs after
95 * a handler has processed the arguments.
96 *
97 * @param aStart Index to begin removing.
98 * @param aEnd Index to end removing, inclusive.
99 */
100 void removeArguments(in long aStart, in long aEnd);
101
102 /**
103 * A helper method which will find a flag and remove it in one step.
104 *
105 * @param aFlag The flag name to find and remove.
106 * @param aCaseSensitive Whether to do case-sensitive comparisons.
107 * @return Whether the flag was found.
108 */
109 boolean handleFlag(in AString aFlag, in boolean aCaseSensitive);
110
111 /**
112 * Find a flag with a parameter and remove both. This is a helper
113 * method that combines "findFlag" and "removeArguments" in one step.
114 *
115 * @return null (a void astring) if the flag is not found. The parameter value
116 * if found. Note that null and the empty string are not the same.
117 * @throws NS_ERROR_INVALID_ARG if the flag exists without a parameter
118 *
119 * @param aFlag The flag name to find and remove.
120 * @param aCaseSensitive Whether to do case-sensitive flag search.
121 */
122 AString handleFlagWithParam(in AString aFlag, in boolean aCaseSensitive);
123
124 /**
125 * The type of command line being processed.
126 *
127 * STATE_INITIAL_LAUNCH is the first launch of the application instance.
128 * STATE_REMOTE_AUTO is a remote command line automatically redirected to
129 * this instance.
130 * STATE_REMOTE_EXPLICIT is a remote command line explicitly redirected to
131 * this instance using xremote/windde/appleevents.
132 */
133 readonly attribute unsigned long state;
134
135 const unsigned long STATE_INITIAL_LAUNCH = 0;
136 const unsigned long STATE_REMOTE_AUTO = 1;
137 const unsigned long STATE_REMOTE_EXPLICIT = 2;
138
139 /**
140 * There may be a command-line handler which performs a default action if
141 * there was no explicit action on the command line (open a default browser
142 * window, for example). This flag allows the default action to be prevented.
143 */
144 attribute boolean preventDefault;
145
146 /**
147 * The working directory for this command line. Use this property instead
148 * of the working directory for the current process, since a redirected
149 * command line may have had a different working directory.
150 */
151 readonly attribute nsIFile workingDirectory;
152
153 /**
154 * A window to be targeted by this command line. In most cases, this will
155 * be null (xremote will sometimes set this attribute).
156 */
157 readonly attribute nsIDOMWindow windowContext;
158
159 /**
160 * Resolve a file-path argument into an nsIFile. This method gracefully
161 * handles relative or absolute file paths, according to the working
162 * directory of this command line.
163 *
164 * @param aArgument The command-line argument to resolve.
165 */
166 nsIFile resolveFile(in AString aArgument);
167
168 /**
169 * Resolves a URI argument into a URI. This method has platform-specific
170 * logic for converting an absolute URI or a relative file-path into the
171 * appropriate URI object; it gracefully handles win32 C:\ paths which would
172 * confuse the ioservice if passed directly.
173 *
174 * @param aArgument The command-line argument to resolve.
175 */
176 nsIURI resolveURI(in AString aArgument);
177 };