Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes
nsCommandLine Class Reference
Inheritance diagram for nsCommandLine:
Inheritance graph
[legend]
Collaboration diagram for nsCommandLine:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSICOMMANDLINE
NS_DECL_NSICOMMANDLINERUNNER 
nsCommandLine ()
void init (in long argc, in nsCharPtrArray argv, in nsIFile workingDir, in unsigned long state)
 This method assumes a native character set, and is meant to be called with the argc/argv passed to main().
void setWindowContext (in nsIDOMWindow aWindow)
 Set the windowContext parameter.
void run ()
 Process the command-line handlers in the proper order, calling "handle()" on each.
AString getArgument (in long aIndex)
 Get an argument from the array of command-line arguments.
long findFlag (in AString aFlag, in boolean aCaseSensitive)
 Find a command-line flag.
void removeArguments (in long aStart, in long aEnd)
 Remove arguments from the command line.
boolean handleFlag (in AString aFlag, in boolean aCaseSensitive)
 A helper method which will find a flag and remove it in one step.
AString handleFlagWithParam (in AString aFlag, in boolean aCaseSensitive)
 Find a flag with a parameter and remove both.
nsIFile resolveFile (in AString aArgument)
 Resolve a file-path argument into an nsIFile.
nsIURI resolveURI (in AString aArgument)
 Resolves a URI argument into a URI.

Public Attributes

readonly attribute AUTF8String helpText
 Process and combine the help text provided by each command-line handler.
readonly attribute long length
 Number of arguments in the command line.
readonly attribute unsigned long state
 The type of command line being processed.
const unsigned long STATE_INITIAL_LAUNCH = 0
const unsigned long STATE_REMOTE_AUTO = 1
const unsigned long STATE_REMOTE_EXPLICIT = 2
attribute boolean preventDefault
 There may be a command-line handler which performs a default action if there was no explicit action on the command line (open a default browser window, for example).
readonly attribute nsIFile workingDirectory
 The working directory for this command line.
readonly attribute nsIDOMWindow windowContext
 A window to be targeted by this command line.

Protected Types

typedef nsresult(* EnumerateHandlersCallback )(nsICommandLineHandler *aHandler, nsICommandLine *aThis, void *aClosure)
typedef nsresult(* EnumerateValidatorsCallback )(nsICommandLineValidator *aValidator, nsICommandLine *aThis, void *aClosure)

Protected Member Functions

 ~nsCommandLine ()
void appendArg (const char *arg)
void resolveShortcutURL (nsILocalFile *aFile, nsACString &outURL)
nsresult EnumerateHandlers (EnumerateHandlersCallback aCallback, void *aClosure)
nsresult EnumerateValidators (EnumerateValidatorsCallback aCallback, void *aClosure)

Protected Attributes

nsStringArray mArgs
PRUint32 mState
nsCOMPtr< nsIFilemWorkingDir
nsCOMPtr< nsIDOMWindowmWindowContext
PRBool mPreventDefault

Detailed Description

Definition at line 77 of file nsCommandLine.cpp.


Member Typedef Documentation

Definition at line 89 of file nsCommandLine.cpp.

Definition at line 92 of file nsCommandLine.cpp.


Constructor & Destructor Documentation

nsCommandLine::~nsCommandLine ( ) [inline, protected]

Definition at line 87 of file nsCommandLine.cpp.

{ }

Member Function Documentation

void nsCommandLine::appendArg ( const char *  arg) [protected]

Definition at line 476 of file nsCommandLine.cpp.

{
#ifdef DEBUG_COMMANDLINE
  printf("Adding XP arg: %s\n", arg);
#endif

  nsAutoString warg;
  NS_CopyNativeToUnicode(nsDependentCString(arg), warg);

  mArgs.AppendString(warg);
}

Here is the call graph for this function:

nsresult nsCommandLine::EnumerateHandlers ( EnumerateHandlersCallback  aCallback,
void aClosure 
) [protected]

Definition at line 570 of file nsCommandLine.cpp.

{
  nsresult rv;

  nsCOMPtr<nsICategoryManager> catman
    (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
  NS_ENSURE_TRUE(catman, NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsISimpleEnumerator> entenum;
  rv = catman->EnumerateCategory("command-line-handler",
                                 getter_AddRefs(entenum));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUTF8StringEnumerator> strenum (do_QueryInterface(entenum));
  NS_ENSURE_TRUE(strenum, NS_ERROR_UNEXPECTED);

  nsCAutoString entry;
  PRBool hasMore;
  while (NS_SUCCEEDED(strenum->HasMore(&hasMore)) && hasMore) {
    strenum->GetNext(entry);

    nsXPIDLCString contractID;
    rv = catman->GetCategoryEntry("command-line-handler",
                              entry.get(),
                              getter_Copies(contractID));
    if (!contractID)
      continue;

    nsCOMPtr<nsICommandLineHandler> clh(do_GetService(contractID.get()));
    if (!clh)
      continue;

    rv = (aCallback)(clh, this, aClosure);
    if (rv == NS_ERROR_ABORT)
      break;

    rv = NS_OK;
  }

  return rv;
}

Here is the call graph for this function:

nsresult nsCommandLine::EnumerateValidators ( EnumerateValidatorsCallback  aCallback,
void aClosure 
) [protected]

Definition at line 613 of file nsCommandLine.cpp.

{
  nsresult rv;

  nsCOMPtr<nsICategoryManager> catman
    (do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
  NS_ENSURE_TRUE(catman, NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsISimpleEnumerator> entenum;
  rv = catman->EnumerateCategory("command-line-validator",
                                 getter_AddRefs(entenum));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUTF8StringEnumerator> strenum (do_QueryInterface(entenum));
  NS_ENSURE_TRUE(strenum, NS_ERROR_UNEXPECTED);

  nsCAutoString entry;
  PRBool hasMore;
  while (NS_SUCCEEDED(strenum->HasMore(&hasMore)) && hasMore) {
    strenum->GetNext(entry);

    nsXPIDLCString contractID;
    rv = catman->GetCategoryEntry("command-line-validator",
                              entry.get(),
                              getter_Copies(contractID));
    if (!contractID)
      continue;

    nsCOMPtr<nsICommandLineValidator> clv(do_GetService(contractID.get()));
    if (!clv)
      continue;

    rv = (aCallback)(clv, this, aClosure);
    if (rv == NS_ERROR_ABORT)
      break;

    rv = NS_OK;
  }

  return rv;
}

Here is the call graph for this function:

long nsICommandLine::findFlag ( in AString  aFlag,
in boolean  aCaseSensitive 
) [inherited]

Find a command-line flag.

Parameters:
aFlagThe flag name to locate. Do not include the initial hyphen.
aCaseSensitiveWhether to do case-sensitive comparisons.
Returns:
The position of the flag in the command line.
AString nsICommandLine::getArgument ( in long  aIndex) [inherited]

Get an argument from the array of command-line arguments.

On windows, flags of the form /flag are normalized to -flag. /flag:param are normalized to -flag param.

On *nix and mac flags of the form --flag are normalized to -flag. --flag=param are normalized to the form -flag param.

Parameters:
aIndexThe argument to retrieve. This index is 0-based, and does not include the application name.
Returns:
The indexth argument.
Exceptions:
NS_ERROR_INVALID_ARGif aIndex is out of bounds.
boolean nsICommandLine::handleFlag ( in AString  aFlag,
in boolean  aCaseSensitive 
) [inherited]

A helper method which will find a flag and remove it in one step.

Parameters:
aFlagThe flag name to find and remove.
aCaseSensitiveWhether to do case-sensitive comparisons.
Returns:
Whether the flag was found.
AString nsICommandLine::handleFlagWithParam ( in AString  aFlag,
in boolean  aCaseSensitive 
) [inherited]

Find a flag with a parameter and remove both.

This is a helper method that combines "findFlag" and "removeArguments" in one step.

Returns:
null (a void astring) if the flag is not found. The parameter value if found. Note that null and the empty string are not the same.
Exceptions:
NS_ERROR_INVALID_ARGif the flag exists without a parameter
Parameters:
aFlagThe flag name to find and remove.
aCaseSensitiveWhether to do case-sensitive flag search.
void nsICommandLineRunner::init ( in long  argc,
in nsCharPtrArray  argv,
in nsIFile  workingDir,
in unsigned long  state 
) [inherited]

This method assumes a native character set, and is meant to be called with the argc/argv passed to main().

Talk to bsmedberg if you need to create a command line using other data. argv will not be altered in any way.

Parameters:
workingDirThe working directory for resolving file and URI paths.
stateThe nsICommandLine.state flag.
void nsICommandLine::removeArguments ( in long  aStart,
in long  aEnd 
) [inherited]

Remove arguments from the command line.

This normally occurs after a handler has processed the arguments.

Parameters:
aStartIndex to begin removing.
aEndIndex to end removing, inclusive.
nsIFile nsICommandLine::resolveFile ( in AString  aArgument) [inherited]

Resolve a file-path argument into an nsIFile.

This method gracefully handles relative or absolute file paths, according to the working directory of this command line.

Parameters:
aArgumentThe command-line argument to resolve.
void nsCommandLine::resolveShortcutURL ( nsILocalFile aFile,
nsACString &  outURL 
) [protected]

Definition at line 489 of file nsCommandLine.cpp.

{
  nsCOMPtr<nsIFileProtocolHandler> fph;
  nsresult rv = NS_GetFileProtocolHandler(getter_AddRefs(fph));
  if (NS_FAILED(rv))
    return;

  nsCOMPtr<nsIURI> uri;
  rv = fph->ReadURLFile(aFile, getter_AddRefs(uri));
  if (NS_FAILED(rv))
    return;

  uri->GetSpec(outURL);
}

Here is the call graph for this function:

nsIURI nsICommandLine::resolveURI ( in AString  aArgument) [inherited]

Resolves a URI argument into a URI.

This method has platform-specific logic for converting an absolute URI or a relative file-path into the appropriate URI object; it gracefully handles win32 C:\ paths which would confuse the ioservice if passed directly.

Parameters:
aArgumentThe command-line argument to resolve.

Process the command-line handlers in the proper order, calling "handle()" on each.

Exceptions:
NS_ERROR_ABORTif any handler throws NS_ERROR_ABORT. All other errors thrown by handlers will be silently ignored.

Set the windowContext parameter.


Member Data Documentation

readonly attribute AUTF8String nsICommandLineRunner::helpText [inherited]

Process and combine the help text provided by each command-line handler.

Definition at line 85 of file nsICommandLineRunner.idl.

readonly attribute long nsICommandLine::length [inherited]

Number of arguments in the command line.

The application name is not part of the command line.

Definition at line 65 of file nsICommandLine.idl.

nsStringArray nsCommandLine::mArgs [protected]

Definition at line 101 of file nsCommandLine.cpp.

Definition at line 105 of file nsCommandLine.cpp.

Definition at line 102 of file nsCommandLine.cpp.

Definition at line 104 of file nsCommandLine.cpp.

Definition at line 103 of file nsCommandLine.cpp.

There may be a command-line handler which performs a default action if there was no explicit action on the command line (open a default browser window, for example).

This flag allows the default action to be prevented.

Definition at line 144 of file nsICommandLine.idl.

readonly attribute unsigned long nsICommandLine::state [inherited]

The type of command line being processed.

STATE_INITIAL_LAUNCH is the first launch of the application instance. STATE_REMOTE_AUTO is a remote command line automatically redirected to this instance. STATE_REMOTE_EXPLICIT is a remote command line explicitly redirected to this instance using xremote/windde/appleevents.

Definition at line 133 of file nsICommandLine.idl.

Definition at line 135 of file nsICommandLine.idl.

const unsigned long nsICommandLine::STATE_REMOTE_AUTO = 1 [inherited]

Definition at line 136 of file nsICommandLine.idl.

Definition at line 137 of file nsICommandLine.idl.

A window to be targeted by this command line.

In most cases, this will be null (xremote will sometimes set this attribute).

Definition at line 157 of file nsICommandLine.idl.

The working directory for this command line.

Use this property instead of the working directory for the current process, since a redirected command line may have had a different working directory.

Definition at line 151 of file nsICommandLine.idl.


The documentation for this class was generated from the following file: