Bug 579497 - Add error console logging for missing/incorrect command-line handlers, r=Mossop a=beltzner for landing in a CLOSED TREE

This commit is contained in:
Benjamin Smedberg 2010-07-20 09:29:38 -04:00
parent 5ce2f52c66
commit 571cd9b161

View File

@ -40,6 +40,7 @@
#include "nsICategoryManager.h"
#include "nsICommandLineHandler.h"
#include "nsICommandLineValidator.h"
#include "nsIConsoleService.h"
#include "nsIClassInfoImpl.h"
#include "nsIDOMWindow.h"
#include "nsIFile.h"
@ -53,6 +54,7 @@
#include "nsNetUtil.h"
#include "nsUnicharUtils.h"
#include "nsTArray.h"
#include "nsTextFormatter.h"
#include "nsXPCOMCID.h"
#include "plstr.h"
@ -571,6 +573,21 @@ nsCommandLine::Init(PRInt32 argc, char** argv, nsIFile* aWorkingDir,
return NS_OK;
}
static void
LogConsoleMessage(const nsString& fmt, ...)
{
va_list args;
va_start(args, fmt);
PRUnichar* msg = nsTextFormatter::vsmprintf(fmt.get(), args);
va_end(args);
nsCOMPtr<nsIConsoleService> cs = do_GetService("@mozilla.org/consoleservice;1");
if (cs)
cs->LogStringMessage(msg);
NS_Free(msg);
}
nsresult
nsCommandLine::EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClosure)
{
@ -601,8 +618,12 @@ nsCommandLine::EnumerateHandlers(EnumerateHandlersCallback aCallback, void *aClo
continue;
nsCOMPtr<nsICommandLineHandler> clh(do_GetService(contractID.get()));
if (!clh)
if (!clh) {
LogConsoleMessage(NS_LITERAL_STRING("Contract ID '%s' was registered as a command line handler for entry '%s', but could not be created."),
contractID.get(),
entry.get());
continue;
}
rv = (aCallback)(clh, this, aClosure);
if (rv == NS_ERROR_ABORT)