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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef mozilla_dom_FallbackEncoding_h_ |
michael@0 | 6 | #define mozilla_dom_FallbackEncoding_h_ |
michael@0 | 7 | |
michael@0 | 8 | #include "nsString.h" |
michael@0 | 9 | |
michael@0 | 10 | namespace mozilla { |
michael@0 | 11 | namespace dom { |
michael@0 | 12 | |
michael@0 | 13 | class FallbackEncoding |
michael@0 | 14 | { |
michael@0 | 15 | public: |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * Whether FromTopLevelDomain() should be used. |
michael@0 | 19 | */ |
michael@0 | 20 | static bool sGuessFallbackFromTopLevelDomain; |
michael@0 | 21 | |
michael@0 | 22 | /** |
michael@0 | 23 | * Gets the locale-dependent fallback encoding for legacy HTML and plain |
michael@0 | 24 | * text content. |
michael@0 | 25 | * |
michael@0 | 26 | * @param aFallback the outparam for the fallback encoding |
michael@0 | 27 | */ |
michael@0 | 28 | static void FromLocale(nsACString& aFallback); |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * Checks if it is appropriate to call FromTopLevelDomain() for a given TLD. |
michael@0 | 32 | * |
michael@0 | 33 | * @param aTLD the top-level domain (in Punycode) |
michael@0 | 34 | * @return true if OK to call FromTopLevelDomain() |
michael@0 | 35 | */ |
michael@0 | 36 | static bool IsParticipatingTopLevelDomain(const nsACString& aTLD); |
michael@0 | 37 | |
michael@0 | 38 | /** |
michael@0 | 39 | * Gets a top-level domain-depedendent fallback encoding for legacy HTML |
michael@0 | 40 | * and plain text content |
michael@0 | 41 | * |
michael@0 | 42 | * @param aTLD the top-level domain (in Punycode) |
michael@0 | 43 | * @param aFallback the outparam for the fallback encoding |
michael@0 | 44 | */ |
michael@0 | 45 | static void FromTopLevelDomain(const nsACString& aTLD, nsACString& aFallback); |
michael@0 | 46 | |
michael@0 | 47 | // public API ends here! |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * Allocate sInstance used by FromLocale(). |
michael@0 | 51 | * To be called from nsLayoutStatics only. |
michael@0 | 52 | */ |
michael@0 | 53 | static void Initialize(); |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Delete sInstance used by FromLocale(). |
michael@0 | 57 | * To be called from nsLayoutStatics only. |
michael@0 | 58 | */ |
michael@0 | 59 | static void Shutdown(); |
michael@0 | 60 | |
michael@0 | 61 | private: |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * The fallback cache. |
michael@0 | 65 | */ |
michael@0 | 66 | static FallbackEncoding* sInstance; |
michael@0 | 67 | |
michael@0 | 68 | FallbackEncoding(); |
michael@0 | 69 | ~FallbackEncoding(); |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Invalidates the cache. |
michael@0 | 73 | */ |
michael@0 | 74 | void Invalidate() |
michael@0 | 75 | { |
michael@0 | 76 | mFallback.Truncate(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | static void PrefChanged(const char*, void*); |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * Gets the fallback encoding label. |
michael@0 | 83 | * @param aFallback the fallback encoding |
michael@0 | 84 | */ |
michael@0 | 85 | void Get(nsACString& aFallback); |
michael@0 | 86 | |
michael@0 | 87 | nsCString mFallback; |
michael@0 | 88 | }; |
michael@0 | 89 | |
michael@0 | 90 | } // dom |
michael@0 | 91 | } // mozilla |
michael@0 | 92 | |
michael@0 | 93 | #endif // mozilla_dom_FallbackEncoding_h_ |
michael@0 | 94 |