diff --git a/mozilla/xpfe/appshell/public/nsICmdLineService.idl b/mozilla/xpfe/appshell/public/nsICmdLineService.idl index 85ac4db8a09..7ca09df6e47 100644 --- a/mozilla/xpfe/appshell/public/nsICmdLineService.idl +++ b/mozilla/xpfe/appshell/public/nsICmdLineService.idl @@ -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++ diff --git a/mozilla/xpfe/appshell/src/nsCommandLineService.cpp b/mozilla/xpfe/appshell/src/nsCommandLineService.cpp index e39d7548af8..27bb0099934 100644 --- a/mozilla/xpfe/appshell/src/nsCommandLineService.cpp +++ b/mozilla/xpfe/appshell/src/nsCommandLineService.cpp @@ -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 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 diff --git a/mozilla/xpfe/components/startup/public/nsICmdLineService.idl b/mozilla/xpfe/components/startup/public/nsICmdLineService.idl index 85ac4db8a09..7ca09df6e47 100644 --- a/mozilla/xpfe/components/startup/public/nsICmdLineService.idl +++ b/mozilla/xpfe/components/startup/public/nsICmdLineService.idl @@ -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++ diff --git a/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp b/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp index e39d7548af8..27bb0099934 100644 --- a/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp +++ b/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp @@ -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 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