/work/obj-fuzz/dist/include/mozilla/dom/FallbackEncoding.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_FallbackEncoding_h_ |
8 | | #define mozilla_dom_FallbackEncoding_h_ |
9 | | |
10 | | #include "mozilla/NotNull.h" |
11 | | #include "nsIObserver.h" |
12 | | #include "nsString.h" |
13 | | |
14 | | namespace mozilla { |
15 | | class Encoding; |
16 | | namespace dom { |
17 | | |
18 | | class FallbackEncoding : public nsIObserver |
19 | | { |
20 | | public: |
21 | | NS_DECL_ISUPPORTS |
22 | | NS_DECL_NSIOBSERVER |
23 | | |
24 | | /** |
25 | | * Whether FromTopLevelDomain() should be used. |
26 | | */ |
27 | | static bool sGuessFallbackFromTopLevelDomain; |
28 | | |
29 | | /** |
30 | | * Whether UTF-8 should be used for file URLs. |
31 | | */ |
32 | | static bool sFallbackToUTF8ForFile; |
33 | | |
34 | | /** |
35 | | * Gets the locale-dependent fallback encoding for legacy HTML and plain |
36 | | * text content. |
37 | | * |
38 | | * @param aFallback the outparam for the fallback encoding |
39 | | */ |
40 | | static NotNull<const Encoding*> FromLocale(); |
41 | | |
42 | | /** |
43 | | * Checks if it is appropriate to call FromTopLevelDomain() for a given TLD. |
44 | | * |
45 | | * @param aTLD the top-level domain (in Punycode) |
46 | | * @return true if OK to call FromTopLevelDomain() |
47 | | */ |
48 | | static bool IsParticipatingTopLevelDomain(const nsACString& aTLD); |
49 | | |
50 | | /** |
51 | | * Gets a top-level domain-depedendent fallback encoding for legacy HTML |
52 | | * and plain text content |
53 | | * |
54 | | * @param aTLD the top-level domain (in Punycode) |
55 | | * @param aFallback the outparam for the fallback encoding |
56 | | */ |
57 | | static NotNull<const Encoding*> FromTopLevelDomain(const nsACString& aTLD); |
58 | | |
59 | | // public API ends here! |
60 | | |
61 | | /** |
62 | | * Allocate sInstance used by FromLocale(). |
63 | | * To be called from nsLayoutStatics only. |
64 | | */ |
65 | | static void Initialize(); |
66 | | |
67 | | /** |
68 | | * Delete sInstance used by FromLocale(). |
69 | | * To be called from nsLayoutStatics only. |
70 | | */ |
71 | | static void Shutdown(); |
72 | | |
73 | | private: |
74 | | |
75 | | /** |
76 | | * The fallback cache. |
77 | | */ |
78 | | static FallbackEncoding* sInstance; |
79 | | |
80 | | FallbackEncoding(); |
81 | 0 | virtual ~FallbackEncoding() {}; |
82 | | |
83 | | /** |
84 | | * Invalidates the cache. |
85 | | */ |
86 | | void Invalidate() |
87 | 0 | { |
88 | 0 | mFallback = nullptr; |
89 | 0 | } |
90 | | |
91 | | static void PrefChanged(const char*, void*); |
92 | | |
93 | | /** |
94 | | * Gets the fallback encoding label. |
95 | | * @param aFallback the fallback encoding |
96 | | */ |
97 | | NotNull<const Encoding*> Get(); |
98 | | |
99 | | const Encoding* mFallback; |
100 | | }; |
101 | | |
102 | | } // namespace dom |
103 | | } // namespace mozilla |
104 | | |
105 | | #endif // mozilla_dom_FallbackEncoding_h_ |
106 | | |