1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/commandlines/nsICommandLine.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,141 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsISupports.idl" 1.9 + 1.10 +interface nsIFile; 1.11 +interface nsIURI; 1.12 +interface nsIDOMWindow; 1.13 + 1.14 +/** 1.15 + * Represents the command line used to invoke a XUL application. This may be the 1.16 + * original command-line of this instance, or a command line remoted from another 1.17 + * instance of the application. 1.18 + * 1.19 + * DEFINITIONS: 1.20 + * "arguments" are any values found on the command line. 1.21 + * "flags" are switches. In normalized form they are preceded by a single dash. 1.22 + * Some flags may take "parameters", e.g. "-url <param>" or "-install-xpi <param>" 1.23 + */ 1.24 + 1.25 +[scriptable, uuid(bc3173bd-aa46-46a0-9d25-d9867a9659b6)] 1.26 +interface nsICommandLine : nsISupports 1.27 +{ 1.28 + /** 1.29 + * Number of arguments in the command line. The application name is not 1.30 + * part of the command line. 1.31 + */ 1.32 + readonly attribute long length; 1.33 + 1.34 + /** 1.35 + * Get an argument from the array of command-line arguments. 1.36 + * 1.37 + * On windows, flags of the form /flag are normalized to -flag. /flag:param 1.38 + * are normalized to -flag param. 1.39 + * 1.40 + * On *nix and mac flags of the form --flag are normalized to -flag. --flag=param 1.41 + * are normalized to the form -flag param. 1.42 + * 1.43 + * @param aIndex The argument to retrieve. This index is 0-based, and does 1.44 + * not include the application name. 1.45 + * @return The indexth argument. 1.46 + * @throws NS_ERROR_INVALID_ARG if aIndex is out of bounds. 1.47 + */ 1.48 + AString getArgument(in long aIndex); 1.49 + 1.50 + /** 1.51 + * Find a command-line flag. 1.52 + * 1.53 + * @param aFlag The flag name to locate. Do not include the initial 1.54 + * hyphen. 1.55 + * @param aCaseSensitive Whether to do case-sensitive comparisons. 1.56 + * @return The position of the flag in the command line. 1.57 + */ 1.58 + long findFlag(in AString aFlag, in boolean aCaseSensitive); 1.59 + 1.60 + /** 1.61 + * Remove arguments from the command line. This normally occurs after 1.62 + * a handler has processed the arguments. 1.63 + * 1.64 + * @param aStart Index to begin removing. 1.65 + * @param aEnd Index to end removing, inclusive. 1.66 + */ 1.67 + void removeArguments(in long aStart, in long aEnd); 1.68 + 1.69 + /** 1.70 + * A helper method which will find a flag and remove it in one step. 1.71 + * 1.72 + * @param aFlag The flag name to find and remove. 1.73 + * @param aCaseSensitive Whether to do case-sensitive comparisons. 1.74 + * @return Whether the flag was found. 1.75 + */ 1.76 + boolean handleFlag(in AString aFlag, in boolean aCaseSensitive); 1.77 + 1.78 + /** 1.79 + * Find a flag with a parameter and remove both. This is a helper 1.80 + * method that combines "findFlag" and "removeArguments" in one step. 1.81 + * 1.82 + * @return null (a void astring) if the flag is not found. The parameter value 1.83 + * if found. Note that null and the empty string are not the same. 1.84 + * @throws NS_ERROR_INVALID_ARG if the flag exists without a parameter 1.85 + * 1.86 + * @param aFlag The flag name to find and remove. 1.87 + * @param aCaseSensitive Whether to do case-sensitive flag search. 1.88 + */ 1.89 + AString handleFlagWithParam(in AString aFlag, in boolean aCaseSensitive); 1.90 + 1.91 + /** 1.92 + * The type of command line being processed. 1.93 + * 1.94 + * STATE_INITIAL_LAUNCH is the first launch of the application instance. 1.95 + * STATE_REMOTE_AUTO is a remote command line automatically redirected to 1.96 + * this instance. 1.97 + * STATE_REMOTE_EXPLICIT is a remote command line explicitly redirected to 1.98 + * this instance using xremote/windde/appleevents. 1.99 + */ 1.100 + readonly attribute unsigned long state; 1.101 + 1.102 + const unsigned long STATE_INITIAL_LAUNCH = 0; 1.103 + const unsigned long STATE_REMOTE_AUTO = 1; 1.104 + const unsigned long STATE_REMOTE_EXPLICIT = 2; 1.105 + 1.106 + /** 1.107 + * There may be a command-line handler which performs a default action if 1.108 + * there was no explicit action on the command line (open a default browser 1.109 + * window, for example). This flag allows the default action to be prevented. 1.110 + */ 1.111 + attribute boolean preventDefault; 1.112 + 1.113 + /** 1.114 + * The working directory for this command line. Use this property instead 1.115 + * of the working directory for the current process, since a redirected 1.116 + * command line may have had a different working directory. 1.117 + */ 1.118 + readonly attribute nsIFile workingDirectory; 1.119 + 1.120 + /** 1.121 + * A window to be targeted by this command line. In most cases, this will 1.122 + * be null (xremote will sometimes set this attribute). 1.123 + */ 1.124 + readonly attribute nsIDOMWindow windowContext; 1.125 + 1.126 + /** 1.127 + * Resolve a file-path argument into an nsIFile. This method gracefully 1.128 + * handles relative or absolute file paths, according to the working 1.129 + * directory of this command line. 1.130 + * 1.131 + * @param aArgument The command-line argument to resolve. 1.132 + */ 1.133 + nsIFile resolveFile(in AString aArgument); 1.134 + 1.135 + /** 1.136 + * Resolves a URI argument into a URI. This method has platform-specific 1.137 + * logic for converting an absolute URI or a relative file-path into the 1.138 + * appropriate URI object; it gracefully handles win32 C:\ paths which would 1.139 + * confuse the ioservice if passed directly. 1.140 + * 1.141 + * @param aArgument The command-line argument to resolve. 1.142 + */ 1.143 + nsIURI resolveURI(in AString aArgument); 1.144 +};