Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
5 #ifndef mozilla_dom_FallbackEncoding_h_
6 #define mozilla_dom_FallbackEncoding_h_
8 #include "nsString.h"
10 namespace mozilla {
11 namespace dom {
13 class FallbackEncoding
14 {
15 public:
17 /**
18 * Whether FromTopLevelDomain() should be used.
19 */
20 static bool sGuessFallbackFromTopLevelDomain;
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);
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);
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);
47 // public API ends here!
49 /**
50 * Allocate sInstance used by FromLocale().
51 * To be called from nsLayoutStatics only.
52 */
53 static void Initialize();
55 /**
56 * Delete sInstance used by FromLocale().
57 * To be called from nsLayoutStatics only.
58 */
59 static void Shutdown();
61 private:
63 /**
64 * The fallback cache.
65 */
66 static FallbackEncoding* sInstance;
68 FallbackEncoding();
69 ~FallbackEncoding();
71 /**
72 * Invalidates the cache.
73 */
74 void Invalidate()
75 {
76 mFallback.Truncate();
77 }
79 static void PrefChanged(const char*, void*);
81 /**
82 * Gets the fallback encoding label.
83 * @param aFallback the fallback encoding
84 */
85 void Get(nsACString& aFallback);
87 nsCString mFallback;
88 };
90 } // dom
91 } // mozilla
93 #endif // mozilla_dom_FallbackEncoding_h_