part of fix for bug 83366, r=blake, sr=sspitzer, suggestions=jag - add a new method to nsICmdLineService to get the handler for a given parameter a=asa
git-svn-id: svn://10.0.0.236/trunk@97178 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
84266e9891
commit
37ba40d160
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIFactory.idl"
|
||||
#include "nsICmdLineHandler.idl"
|
||||
|
||||
%{C++
|
||||
// e34783f5-ac08-11d2-8d19-00805fc2500c
|
||||
@ -34,13 +35,55 @@
|
||||
[scriptable, uuid(e34783f4-ac08-11d2-8d19-00805fc2500c)]
|
||||
interface nsICmdLineService : nsISupports
|
||||
{
|
||||
string Initialize(in long argc);
|
||||
string getCmdLineValue(in string argc);
|
||||
/**
|
||||
* initialize
|
||||
* Used to pass the original argv/argc from main()
|
||||
* Warning: This will hold a reference to the original argv
|
||||
* passed into Initialze();
|
||||
*/
|
||||
[noscript] void initialize(in long argc, out string argv);
|
||||
|
||||
/**
|
||||
* getCmdLineValue
|
||||
* returns the 2nd parameter, if any, to the parameter passed in
|
||||
* For example, getCmdLineValue "-edit" will return any url that
|
||||
* came after the -edit parameter
|
||||
*/
|
||||
string getCmdLineValue(in string argv);
|
||||
|
||||
/**
|
||||
* URLToLoad
|
||||
* The URL to load as passed to the command line
|
||||
*/
|
||||
readonly attribute string URLToLoad;
|
||||
|
||||
/**
|
||||
* programName
|
||||
*
|
||||
*/
|
||||
readonly attribute string programName;
|
||||
|
||||
/**
|
||||
* argc
|
||||
* The number of parameters passed in on the command line
|
||||
*/
|
||||
readonly attribute long argc;
|
||||
|
||||
/**
|
||||
* argv
|
||||
* returns a direct reference to the parameter array passed in
|
||||
* to initialize() - do NOT dereference this array!
|
||||
*/
|
||||
[noscript] readonly attribute charArray argv;
|
||||
|
||||
/**
|
||||
* Get the command line handler for the given parameter
|
||||
* @param param - can be any parameter, with or without leading
|
||||
* "-" such as "-mail" or "edit" - Pass in a null
|
||||
* string if you want the "default" handler
|
||||
*/
|
||||
nsICmdLineHandler getHandlerForParam(in string param);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
@ -154,7 +154,7 @@ nsCmdLineService::GetURLToLoad(char ** aResult)
|
||||
NS_IMETHODIMP
|
||||
nsCmdLineService::GetProgramName(char ** aResult)
|
||||
{
|
||||
nsresult rv=nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*aResult = (char *)mArgValueList.ElementAt(0);
|
||||
|
||||
@ -254,7 +254,53 @@ nsCmdLineService::~nsCmdLineService()
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCmdLineService::GetHandlerForParam(const char *aParam,
|
||||
nsICmdLineHandler** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// allocate temp on the stack
|
||||
nsAutoVoidArray oneParameter;
|
||||
|
||||
nsVoidArray *paramList;
|
||||
|
||||
// if user passed in "null", then we want to go through each one
|
||||
if (!aParam)
|
||||
paramList = &mArgList;
|
||||
else {
|
||||
oneParameter.AppendElement((void *)aParam);
|
||||
paramList = &oneParameter;
|
||||
}
|
||||
|
||||
PRUint32 i;
|
||||
for (i=0; i< paramList->Count(); i++) {
|
||||
const char *param = (const char*)paramList->ElementAt(i);
|
||||
|
||||
// skip past leading / and -
|
||||
if (*param == '-' || *param == '/') {
|
||||
++param;
|
||||
if (*param == *(param-1)) // skip "--" or "//"
|
||||
++param;
|
||||
}
|
||||
|
||||
nsCAutoString
|
||||
contractID("@mozilla.org/commandlinehandler/general-startup;1?type=");
|
||||
|
||||
contractID += param;
|
||||
|
||||
nsCOMPtr<nsICmdLineHandler> handler =
|
||||
do_GetService(contractID.get(), &rv);
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
*aResult = handler;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// went through all the parameters, didn't find one
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIFactory.idl"
|
||||
#include "nsICmdLineHandler.idl"
|
||||
|
||||
%{C++
|
||||
// e34783f5-ac08-11d2-8d19-00805fc2500c
|
||||
@ -34,13 +35,55 @@
|
||||
[scriptable, uuid(e34783f4-ac08-11d2-8d19-00805fc2500c)]
|
||||
interface nsICmdLineService : nsISupports
|
||||
{
|
||||
string Initialize(in long argc);
|
||||
string getCmdLineValue(in string argc);
|
||||
/**
|
||||
* initialize
|
||||
* Used to pass the original argv/argc from main()
|
||||
* Warning: This will hold a reference to the original argv
|
||||
* passed into Initialze();
|
||||
*/
|
||||
[noscript] void initialize(in long argc, out string argv);
|
||||
|
||||
/**
|
||||
* getCmdLineValue
|
||||
* returns the 2nd parameter, if any, to the parameter passed in
|
||||
* For example, getCmdLineValue "-edit" will return any url that
|
||||
* came after the -edit parameter
|
||||
*/
|
||||
string getCmdLineValue(in string argv);
|
||||
|
||||
/**
|
||||
* URLToLoad
|
||||
* The URL to load as passed to the command line
|
||||
*/
|
||||
readonly attribute string URLToLoad;
|
||||
|
||||
/**
|
||||
* programName
|
||||
*
|
||||
*/
|
||||
readonly attribute string programName;
|
||||
|
||||
/**
|
||||
* argc
|
||||
* The number of parameters passed in on the command line
|
||||
*/
|
||||
readonly attribute long argc;
|
||||
|
||||
/**
|
||||
* argv
|
||||
* returns a direct reference to the parameter array passed in
|
||||
* to initialize() - do NOT dereference this array!
|
||||
*/
|
||||
[noscript] readonly attribute charArray argv;
|
||||
|
||||
/**
|
||||
* Get the command line handler for the given parameter
|
||||
* @param param - can be any parameter, with or without leading
|
||||
* "-" such as "-mail" or "edit" - Pass in a null
|
||||
* string if you want the "default" handler
|
||||
*/
|
||||
nsICmdLineHandler getHandlerForParam(in string param);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
@ -154,7 +154,7 @@ nsCmdLineService::GetURLToLoad(char ** aResult)
|
||||
NS_IMETHODIMP
|
||||
nsCmdLineService::GetProgramName(char ** aResult)
|
||||
{
|
||||
nsresult rv=nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*aResult = (char *)mArgValueList.ElementAt(0);
|
||||
|
||||
@ -254,7 +254,53 @@ nsCmdLineService::~nsCmdLineService()
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCmdLineService::GetHandlerForParam(const char *aParam,
|
||||
nsICmdLineHandler** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// allocate temp on the stack
|
||||
nsAutoVoidArray oneParameter;
|
||||
|
||||
nsVoidArray *paramList;
|
||||
|
||||
// if user passed in "null", then we want to go through each one
|
||||
if (!aParam)
|
||||
paramList = &mArgList;
|
||||
else {
|
||||
oneParameter.AppendElement((void *)aParam);
|
||||
paramList = &oneParameter;
|
||||
}
|
||||
|
||||
PRUint32 i;
|
||||
for (i=0; i< paramList->Count(); i++) {
|
||||
const char *param = (const char*)paramList->ElementAt(i);
|
||||
|
||||
// skip past leading / and -
|
||||
if (*param == '-' || *param == '/') {
|
||||
++param;
|
||||
if (*param == *(param-1)) // skip "--" or "//"
|
||||
++param;
|
||||
}
|
||||
|
||||
nsCAutoString
|
||||
contractID("@mozilla.org/commandlinehandler/general-startup;1?type=");
|
||||
|
||||
contractID += param;
|
||||
|
||||
nsCOMPtr<nsICmdLineHandler> handler =
|
||||
do_GetService(contractID.get(), &rv);
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
*aResult = handler;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// went through all the parameters, didn't find one
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user