2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-11-04 15:24:33 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_FallbackEncoding_h_
|
|
|
|
#define mozilla_dom_FallbackEncoding_h_
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2018-11-22 15:30:13 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2017-03-12 05:43:11 +03:00
|
|
|
#include "nsIObserver.h"
|
2013-11-04 15:24:33 +04:00
|
|
|
#include "nsString.h"
|
2018-11-22 15:30:13 +03:00
|
|
|
#include "nsWeakReference.h"
|
2013-11-04 15:24:33 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2017-06-18 14:37:50 +03:00
|
|
|
class Encoding;
|
2013-11-04 15:24:33 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2017-03-12 05:43:11 +03:00
|
|
|
class FallbackEncoding : public nsIObserver, nsSupportsWeakReference {
|
2013-11-04 15:24:33 +04:00
|
|
|
public:
|
2017-03-12 05:43:11 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
2013-11-04 15:24:33 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the locale-dependent fallback encoding for legacy HTML and plain
|
|
|
|
* text content.
|
|
|
|
*
|
|
|
|
* @param aFallback the outparam for the fallback encoding
|
|
|
|
*/
|
2017-06-18 14:37:50 +03:00
|
|
|
static NotNull<const Encoding*> FromLocale();
|
2013-11-04 15:24:33 +04:00
|
|
|
|
2014-02-06 13:08:01 +04:00
|
|
|
/**
|
|
|
|
* Checks if it is appropriate to call FromTopLevelDomain() for a given TLD.
|
|
|
|
*
|
|
|
|
* @param aTLD the top-level domain (in Punycode)
|
|
|
|
* @return true if OK to call FromTopLevelDomain()
|
|
|
|
*/
|
|
|
|
static bool IsParticipatingTopLevelDomain(const nsACString& aTLD);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a top-level domain-depedendent fallback encoding for legacy HTML
|
|
|
|
* and plain text content
|
|
|
|
*
|
|
|
|
* @param aTLD the top-level domain (in Punycode)
|
|
|
|
* @param aFallback the outparam for the fallback encoding
|
|
|
|
*/
|
2017-06-18 14:37:50 +03:00
|
|
|
static NotNull<const Encoding*> FromTopLevelDomain(const nsACString& aTLD);
|
2014-02-06 13:08:01 +04:00
|
|
|
|
2013-11-04 15:24:33 +04:00
|
|
|
// public API ends here!
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate sInstance used by FromLocale().
|
|
|
|
* To be called from nsLayoutStatics only.
|
|
|
|
*/
|
|
|
|
static void Initialize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete sInstance used by FromLocale().
|
|
|
|
* To be called from nsLayoutStatics only.
|
|
|
|
*/
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* The fallback cache.
|
|
|
|
*/
|
2018-11-22 15:30:13 +03:00
|
|
|
static StaticRefPtr<FallbackEncoding> sInstance;
|
2013-11-04 15:24:33 +04:00
|
|
|
|
|
|
|
FallbackEncoding();
|
2017-03-12 05:43:11 +03:00
|
|
|
virtual ~FallbackEncoding(){};
|
2013-11-04 15:24:33 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidates the cache.
|
|
|
|
*/
|
2017-06-18 14:37:50 +03:00
|
|
|
void Invalidate() { mFallback = nullptr; }
|
2013-11-04 15:24:33 +04:00
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void PrefChanged(const char*, void*);
|
2013-11-04 15:24:33 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the fallback encoding label.
|
|
|
|
* @param aFallback the fallback encoding
|
|
|
|
*/
|
2017-06-18 14:37:50 +03:00
|
|
|
NotNull<const Encoding*> Get();
|
2013-11-04 15:24:33 +04:00
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
const Encoding* mFallback;
|
2013-11-04 15:24:33 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-11-04 15:24:33 +04:00
|
|
|
|
|
|
|
#endif // mozilla_dom_FallbackEncoding_h_
|