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 | |
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 "mozilla/ArrayUtils.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIPlatformCharset.h" |
michael@0 | 9 | #include "nsUConvPropertySearch.h" |
michael@0 | 10 | #include <windows.h> |
michael@0 | 11 | #include "nsWin32Locale.h" |
michael@0 | 12 | #include "nsCOMPtr.h" |
michael@0 | 13 | #include "nsReadableUtils.h" |
michael@0 | 14 | #include "nsServiceManagerUtils.h" |
michael@0 | 15 | #include "nsPlatformCharset.h" |
michael@0 | 16 | #include "nsEncoderDecoderUtils.h" |
michael@0 | 17 | |
michael@0 | 18 | using namespace mozilla; |
michael@0 | 19 | |
michael@0 | 20 | static const char* kWinCharsets[][3] = { |
michael@0 | 21 | #include "wincharset.properties.h" |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | NS_IMPL_ISUPPORTS(nsPlatformCharset, nsIPlatformCharset) |
michael@0 | 25 | |
michael@0 | 26 | nsPlatformCharset::nsPlatformCharset() |
michael@0 | 27 | { |
michael@0 | 28 | nsAutoString acpKey(NS_LITERAL_STRING("acp.")); |
michael@0 | 29 | acpKey.AppendInt(int32_t(::GetACP() & 0x00FFFF), 10); |
michael@0 | 30 | MapToCharset(acpKey, mCharset); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | nsPlatformCharset::~nsPlatformCharset() |
michael@0 | 34 | { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | nsresult |
michael@0 | 38 | nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset) |
michael@0 | 39 | { |
michael@0 | 40 | nsAutoCString key; |
michael@0 | 41 | LossyCopyUTF16toASCII(inANSICodePage, key); |
michael@0 | 42 | |
michael@0 | 43 | nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kWinCharsets, |
michael@0 | 44 | ArrayLength(kWinCharsets), key, outCharset); |
michael@0 | 45 | if (NS_FAILED(rv)) { |
michael@0 | 46 | outCharset.AssignLiteral("windows-1252"); |
michael@0 | 47 | return NS_SUCCESS_USING_FALLBACK_LOCALE; |
michael@0 | 48 | } |
michael@0 | 49 | return rv; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | NS_IMETHODIMP |
michael@0 | 53 | nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, |
michael@0 | 54 | nsACString& oResult) |
michael@0 | 55 | { |
michael@0 | 56 | oResult = mCharset; |
michael@0 | 57 | return NS_OK; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | NS_IMETHODIMP |
michael@0 | 61 | nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult) |
michael@0 | 62 | { |
michael@0 | 63 | LCID localeAsLCID; |
michael@0 | 64 | |
michael@0 | 65 | // |
michael@0 | 66 | // convert locale name to a code page (through the LCID) |
michael@0 | 67 | // |
michael@0 | 68 | nsresult rv; |
michael@0 | 69 | oResult.Truncate(); |
michael@0 | 70 | |
michael@0 | 71 | rv = nsWin32Locale::GetPlatformLocale(localeName, &localeAsLCID); |
michael@0 | 72 | if (NS_FAILED(rv)) { return rv; } |
michael@0 | 73 | |
michael@0 | 74 | wchar_t acp_name[6]; |
michael@0 | 75 | if (GetLocaleInfoW(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name, |
michael@0 | 76 | ArrayLength(acp_name))==0) { |
michael@0 | 77 | return NS_ERROR_FAILURE; |
michael@0 | 78 | } |
michael@0 | 79 | nsAutoString acp_key(NS_LITERAL_STRING("acp.")); |
michael@0 | 80 | acp_key.Append(acp_name); |
michael@0 | 81 | |
michael@0 | 82 | return MapToCharset(acp_key, oResult); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | NS_IMETHODIMP |
michael@0 | 86 | nsPlatformCharset::Init() |
michael@0 | 87 | { |
michael@0 | 88 | return NS_OK; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | nsresult |
michael@0 | 92 | nsPlatformCharset::InitGetCharset(nsACString &oString) |
michael@0 | 93 | { |
michael@0 | 94 | return NS_OK; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | nsresult |
michael@0 | 98 | nsPlatformCharset::VerifyCharset(nsCString &aCharset) |
michael@0 | 99 | { |
michael@0 | 100 | return NS_OK; |
michael@0 | 101 | } |