dom/encoding/FallbackEncoding.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/encoding/FallbackEncoding.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozilla_dom_FallbackEncoding_h_
     1.9 +#define mozilla_dom_FallbackEncoding_h_
    1.10 +
    1.11 +#include "nsString.h"
    1.12 +
    1.13 +namespace mozilla {
    1.14 +namespace dom {
    1.15 +
    1.16 +class FallbackEncoding
    1.17 +{
    1.18 +public:
    1.19 +
    1.20 +  /**
    1.21 +   * Whether FromTopLevelDomain() should be used.
    1.22 +   */
    1.23 +  static bool sGuessFallbackFromTopLevelDomain;
    1.24 +
    1.25 +  /**
    1.26 +   * Gets the locale-dependent fallback encoding for legacy HTML and plain
    1.27 +   * text content.
    1.28 +   *
    1.29 +   * @param aFallback the outparam for the fallback encoding
    1.30 +   */
    1.31 +  static void FromLocale(nsACString& aFallback);
    1.32 +
    1.33 +  /**
    1.34 +   * Checks if it is appropriate to call FromTopLevelDomain() for a given TLD.
    1.35 +   *
    1.36 +   * @param aTLD the top-level domain (in Punycode)
    1.37 +   * @return true if OK to call FromTopLevelDomain()
    1.38 +   */
    1.39 +  static bool IsParticipatingTopLevelDomain(const nsACString& aTLD);
    1.40 +
    1.41 +  /**
    1.42 +   * Gets a top-level domain-depedendent fallback encoding for legacy HTML
    1.43 +   * and plain text content
    1.44 +   *
    1.45 +   * @param aTLD the top-level domain (in Punycode)
    1.46 +   * @param aFallback the outparam for the fallback encoding
    1.47 +   */
    1.48 +  static void FromTopLevelDomain(const nsACString& aTLD, nsACString& aFallback);
    1.49 +
    1.50 +  // public API ends here!
    1.51 +
    1.52 +  /**
    1.53 +   * Allocate sInstance used by FromLocale().
    1.54 +   * To be called from nsLayoutStatics only.
    1.55 +   */
    1.56 +  static void Initialize();
    1.57 +
    1.58 +  /**
    1.59 +   * Delete sInstance used by FromLocale().
    1.60 +   * To be called from nsLayoutStatics only.
    1.61 +   */
    1.62 +  static void Shutdown();
    1.63 +
    1.64 +private:
    1.65 +
    1.66 +  /**
    1.67 +   * The fallback cache.
    1.68 +   */
    1.69 +  static FallbackEncoding* sInstance;
    1.70 +
    1.71 +  FallbackEncoding();
    1.72 +  ~FallbackEncoding();
    1.73 +
    1.74 +  /**
    1.75 +   * Invalidates the cache.
    1.76 +   */
    1.77 +  void Invalidate()
    1.78 +  {
    1.79 +    mFallback.Truncate();
    1.80 +  }
    1.81 +
    1.82 +  static void PrefChanged(const char*, void*);
    1.83 +
    1.84 +  /**
    1.85 +   * Gets the fallback encoding label.
    1.86 +   * @param aFallback the fallback encoding
    1.87 +   */
    1.88 +  void Get(nsACString& aFallback);
    1.89 +
    1.90 +  nsCString mFallback;
    1.91 +};
    1.92 +
    1.93 +} // dom
    1.94 +} // mozilla
    1.95 +
    1.96 +#endif // mozilla_dom_FallbackEncoding_h_
    1.97 +

mercurial