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"
|
2018-11-04 23:12:41 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
mozilla::StaticRefPtr<nsErrorService> gSingleton;
|
|
|
|
|
|
|
|
}
|
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
|
|
|
|
2018-11-04 23:12:41 +03:00
|
|
|
// static
|
|
|
|
already_AddRefed<nsIErrorService> nsErrorService::GetOrCreate() {
|
|
|
|
// Be careful to not recreate the service for a second time if GetOrCreate is
|
|
|
|
// called super late during shutdown.
|
|
|
|
static bool serviceCreated = false;
|
|
|
|
RefPtr<nsErrorService> svc;
|
|
|
|
if (gSingleton) {
|
|
|
|
svc = gSingleton;
|
|
|
|
} else if (!serviceCreated) {
|
|
|
|
gSingleton = new nsErrorService();
|
|
|
|
mozilla::ClearOnShutdown(&gSingleton);
|
|
|
|
svc = gSingleton;
|
|
|
|
serviceCreated = true;
|
2014-05-13 21:41:38 +04:00
|
|
|
}
|
2018-11-04 23:12:41 +03:00
|
|
|
|
|
|
|
return svc.forget();
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-08-25 23:17:15 +04:00
|
|
|
nsErrorService::RegisterErrorStringBundle(int16_t aErrorModule,
|
|
|
|
const char* aStringBundleURL) {
|
2014-05-10 00:47:37 +04:00
|
|
|
mErrorStringBundleURLMap.Put(aErrorModule, new nsCString(aStringBundleURL));
|
2014-05-10 00:47:36 +04:00
|
|
|
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) {
|
2014-05-10 00:47:37 +04:00
|
|
|
mErrorStringBundleURLMap.Remove(aErrorModule);
|
2014-05-10 00:47:36 +04:00
|
|
|
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) {
|
2014-05-10 00:47:37 +04:00
|
|
|
nsCString* bundleURL = mErrorStringBundleURLMap.Get(aErrorModule);
|
2014-07-26 03:41:24 +04:00
|
|
|
if (!bundleURL) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-05-10 00:47:37 +04:00
|
|
|
*aResult = ToNewCString(*bundleURL);
|
2014-05-05 21:30:39 +04:00
|
|
|
return NS_OK;
|
2000-07-22 09:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|