2014-05-05 21:30:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-07-22 09:38:43 +04:00
|
|
|
|
|
|
|
#include "nsErrorService.h"
|
2013-09-19 22:29:31 +04:00
|
|
|
#include "nsCRTGlue.h"
|
2013-08-05 19:16:53 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2000-07-22 09:38:43 +04:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void*
|
2014-05-10 00:47:36 +04:00
|
|
|
CloneCString(nsHashKey *aKey, void *aData, void* aClosure)
|
2000-07-22 09:38:43 +04:00
|
|
|
{
|
2009-03-25 16:19:08 +03:00
|
|
|
return NS_strdup((const char*)aData);
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2014-05-10 00:47:36 +04:00
|
|
|
DeleteCString(nsHashKey *aKey, void *aData, void* aClosure)
|
2000-07-22 09:38:43 +04:00
|
|
|
{
|
2009-03-25 16:19:08 +03:00
|
|
|
NS_Free(aData);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-05-10 00:47:36 +04:00
|
|
|
nsErrorService::nsErrorService()
|
|
|
|
: mErrorStringBundleURLMap(CloneCString, nullptr, DeleteCString, nullptr, 16)
|
2000-07-22 09:38:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsErrorService, nsIErrorService)
|
2000-07-22 09:38:43 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
nsresult
|
2014-05-10 00:47:36 +04:00
|
|
|
nsErrorService::Create(nsISupports* aOuter, const nsIID& aIID, void** aInstancePtr)
|
2000-07-22 09:38:43 +04:00
|
|
|
{
|
2014-05-10 00:47:36 +04:00
|
|
|
if (NS_WARN_IF(aOuter))
|
2014-05-05 21:30:39 +04:00
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
nsRefPtr<nsErrorService> serv = new nsErrorService();
|
|
|
|
return serv->QueryInterface(aIID, aInstancePtr);
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-10 00:47:36 +04:00
|
|
|
nsErrorService::RegisterErrorStringBundle(int16_t aErrorModule, const char* aStringBundleURL)
|
2000-07-22 09:38:43 +04:00
|
|
|
{
|
2014-05-10 00:47:36 +04:00
|
|
|
char* value = NS_strdup(aStringBundleURL);
|
|
|
|
if (!value) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsPRUint32Key k(aErrorModule);
|
|
|
|
char* oldValue = (char*)mErrorStringBundleURLMap.Put(&k, value);
|
|
|
|
if (oldValue) {
|
|
|
|
NS_Free(oldValue);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-10 00:47:36 +04:00
|
|
|
nsErrorService::UnregisterErrorStringBundle(int16_t aErrorModule)
|
2000-07-22 09:38:43 +04:00
|
|
|
{
|
2014-05-10 00:47:36 +04:00
|
|
|
nsPRUint32Key k(aErrorModule);
|
|
|
|
char* oldValue = (char*)mErrorStringBundleURLMap.Remove(&k);
|
|
|
|
if (oldValue) {
|
|
|
|
NS_Free(oldValue);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-10 00:47:36 +04:00
|
|
|
nsErrorService::GetErrorStringBundle(int16_t aErrorModule, char** aResult)
|
2000-07-22 09:38:43 +04:00
|
|
|
{
|
2014-05-10 00:47:36 +04:00
|
|
|
nsPRUint32Key k(aErrorModule);
|
|
|
|
char* value = (char*)mErrorStringBundleURLMap.Get(&k);
|
|
|
|
if (!value) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
value = NS_strdup(value);
|
|
|
|
if (!value) {
|
2014-05-05 21:30:39 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-05-10 00:47:36 +04:00
|
|
|
}
|
2014-05-10 00:47:36 +04:00
|
|
|
*aResult = value;
|
2014-05-05 21:30:39 +04:00
|
|
|
return NS_OK;
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|