Line data Source code
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 : * Gets the locale-dependent fallback encoding for legacy HTML and plain
31 : * text content.
32 : *
33 : * @param aFallback the outparam for the fallback encoding
34 : */
35 : static NotNull<const Encoding*> FromLocale();
36 :
37 : /**
38 : * Checks if it is appropriate to call FromTopLevelDomain() for a given TLD.
39 : *
40 : * @param aTLD the top-level domain (in Punycode)
41 : * @return true if OK to call FromTopLevelDomain()
42 : */
43 : static bool IsParticipatingTopLevelDomain(const nsACString& aTLD);
44 :
45 : /**
46 : * Gets a top-level domain-depedendent fallback encoding for legacy HTML
47 : * and plain text content
48 : *
49 : * @param aTLD the top-level domain (in Punycode)
50 : * @param aFallback the outparam for the fallback encoding
51 : */
52 : static NotNull<const Encoding*> FromTopLevelDomain(const nsACString& aTLD);
53 :
54 : // public API ends here!
55 :
56 : /**
57 : * Allocate sInstance used by FromLocale().
58 : * To be called from nsLayoutStatics only.
59 : */
60 : static void Initialize();
61 :
62 : /**
63 : * Delete sInstance used by FromLocale().
64 : * To be called from nsLayoutStatics only.
65 : */
66 : static void Shutdown();
67 :
68 : private:
69 :
70 : /**
71 : * The fallback cache.
72 : */
73 : static FallbackEncoding* sInstance;
74 :
75 : FallbackEncoding();
76 0 : virtual ~FallbackEncoding() {};
77 :
78 : /**
79 : * Invalidates the cache.
80 : */
81 0 : void Invalidate()
82 : {
83 0 : mFallback = nullptr;
84 0 : }
85 :
86 : static void PrefChanged(const char*, void*);
87 :
88 : /**
89 : * Gets the fallback encoding label.
90 : * @param aFallback the fallback encoding
91 : */
92 : NotNull<const Encoding*> Get();
93 :
94 : const Encoding* mFallback;
95 : };
96 :
97 : } // namespace dom
98 : } // namespace mozilla
99 :
100 : #endif // mozilla_dom_FallbackEncoding_h_
101 :
|