michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_FallbackEncoding_h_ michael@0: #define mozilla_dom_FallbackEncoding_h_ michael@0: michael@0: #include "nsString.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class FallbackEncoding michael@0: { michael@0: public: michael@0: michael@0: /** michael@0: * Whether FromTopLevelDomain() should be used. michael@0: */ michael@0: static bool sGuessFallbackFromTopLevelDomain; michael@0: michael@0: /** michael@0: * Gets the locale-dependent fallback encoding for legacy HTML and plain michael@0: * text content. michael@0: * michael@0: * @param aFallback the outparam for the fallback encoding michael@0: */ michael@0: static void FromLocale(nsACString& aFallback); michael@0: michael@0: /** michael@0: * Checks if it is appropriate to call FromTopLevelDomain() for a given TLD. michael@0: * michael@0: * @param aTLD the top-level domain (in Punycode) michael@0: * @return true if OK to call FromTopLevelDomain() michael@0: */ michael@0: static bool IsParticipatingTopLevelDomain(const nsACString& aTLD); michael@0: michael@0: /** michael@0: * Gets a top-level domain-depedendent fallback encoding for legacy HTML michael@0: * and plain text content michael@0: * michael@0: * @param aTLD the top-level domain (in Punycode) michael@0: * @param aFallback the outparam for the fallback encoding michael@0: */ michael@0: static void FromTopLevelDomain(const nsACString& aTLD, nsACString& aFallback); michael@0: michael@0: // public API ends here! michael@0: michael@0: /** michael@0: * Allocate sInstance used by FromLocale(). michael@0: * To be called from nsLayoutStatics only. michael@0: */ michael@0: static void Initialize(); michael@0: michael@0: /** michael@0: * Delete sInstance used by FromLocale(). michael@0: * To be called from nsLayoutStatics only. michael@0: */ michael@0: static void Shutdown(); michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * The fallback cache. michael@0: */ michael@0: static FallbackEncoding* sInstance; michael@0: michael@0: FallbackEncoding(); michael@0: ~FallbackEncoding(); michael@0: michael@0: /** michael@0: * Invalidates the cache. michael@0: */ michael@0: void Invalidate() michael@0: { michael@0: mFallback.Truncate(); michael@0: } michael@0: michael@0: static void PrefChanged(const char*, void*); michael@0: michael@0: /** michael@0: * Gets the fallback encoding label. michael@0: * @param aFallback the fallback encoding michael@0: */ michael@0: void Get(nsACString& aFallback); michael@0: michael@0: nsCString mFallback; michael@0: }; michael@0: michael@0: } // dom michael@0: } // mozilla michael@0: michael@0: #endif // mozilla_dom_FallbackEncoding_h_ michael@0: