Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsErrorService.h" |
michael@0 | 7 | #include "nsCRTGlue.h" |
michael@0 | 8 | #include "nsAutoPtr.h" |
michael@0 | 9 | |
michael@0 | 10 | static void* |
michael@0 | 11 | CloneCString(nsHashKey *aKey, void *aData, void* closure) |
michael@0 | 12 | { |
michael@0 | 13 | return NS_strdup((const char*)aData); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | static bool |
michael@0 | 17 | DeleteCString(nsHashKey *aKey, void *aData, void* closure) |
michael@0 | 18 | { |
michael@0 | 19 | NS_Free(aData); |
michael@0 | 20 | return true; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | nsInt2StrHashtable::nsInt2StrHashtable() |
michael@0 | 24 | : mHashtable(CloneCString, nullptr, DeleteCString, nullptr, 16) |
michael@0 | 25 | { |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | nsresult |
michael@0 | 29 | nsInt2StrHashtable::Put(uint32_t key, const char* aData) |
michael@0 | 30 | { |
michael@0 | 31 | char* value = NS_strdup(aData); |
michael@0 | 32 | if (value == nullptr) |
michael@0 | 33 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 34 | nsPRUint32Key k(key); |
michael@0 | 35 | char* oldValue = (char*)mHashtable.Put(&k, value); |
michael@0 | 36 | if (oldValue) |
michael@0 | 37 | NS_Free(oldValue); |
michael@0 | 38 | return NS_OK; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | char* |
michael@0 | 42 | nsInt2StrHashtable::Get(uint32_t key) |
michael@0 | 43 | { |
michael@0 | 44 | nsPRUint32Key k(key); |
michael@0 | 45 | const char* value = (const char*)mHashtable.Get(&k); |
michael@0 | 46 | if (value == nullptr) |
michael@0 | 47 | return nullptr; |
michael@0 | 48 | return NS_strdup(value); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | nsresult |
michael@0 | 52 | nsInt2StrHashtable::Remove(uint32_t key) |
michael@0 | 53 | { |
michael@0 | 54 | nsPRUint32Key k(key); |
michael@0 | 55 | char* oldValue = (char*)mHashtable.Remove(&k); |
michael@0 | 56 | if (oldValue) |
michael@0 | 57 | NS_Free(oldValue); |
michael@0 | 58 | return NS_OK; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 62 | |
michael@0 | 63 | NS_IMPL_ISUPPORTS(nsErrorService, nsIErrorService) |
michael@0 | 64 | |
michael@0 | 65 | nsresult |
michael@0 | 66 | nsErrorService::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) |
michael@0 | 67 | { |
michael@0 | 68 | if (NS_WARN_IF(outer)) |
michael@0 | 69 | return NS_ERROR_NO_AGGREGATION; |
michael@0 | 70 | nsRefPtr<nsErrorService> serv = new nsErrorService(); |
michael@0 | 71 | return serv->QueryInterface(aIID, aInstancePtr); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | NS_IMETHODIMP |
michael@0 | 75 | nsErrorService::RegisterErrorStringBundle(int16_t errorModule, const char *stringBundleURL) |
michael@0 | 76 | { |
michael@0 | 77 | return mErrorStringBundleURLMap.Put(errorModule, stringBundleURL); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | NS_IMETHODIMP |
michael@0 | 81 | nsErrorService::UnregisterErrorStringBundle(int16_t errorModule) |
michael@0 | 82 | { |
michael@0 | 83 | return mErrorStringBundleURLMap.Remove(errorModule); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | NS_IMETHODIMP |
michael@0 | 87 | nsErrorService::GetErrorStringBundle(int16_t errorModule, char **result) |
michael@0 | 88 | { |
michael@0 | 89 | char* value = mErrorStringBundleURLMap.Get(errorModule); |
michael@0 | 90 | if (value == nullptr) |
michael@0 | 91 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 92 | *result = value; |
michael@0 | 93 | return NS_OK; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | //////////////////////////////////////////////////////////////////////////////// |