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