dom/encoding/FallbackEncoding.h
author Bobby Holley <bobbyholley@gmail.com>
Fri, 31 Jan 2014 14:51:41 -0800
changeset 166310 8c206e77eb64ed7671ced59ddf599c4af79351ed
parent 159791 98be0e9cbc152f4313ef9adbbc0b6925ef7d0123
child 167159 a4e9e8bead92c9d51d4e478a73e8e589263e92ae
permissions -rw-r--r--
Bug 962449 - Don't call initIteratorClasses directly, and use ensureConstructor. r=luke This isn't strictly necessary at this point. The basic issue is that there are a few new classes (iterator stuff, intl stuff, and typed objects) that use this kind of constructor bootstrap scheme, and each of them will need something like this to move to ClassSpecs. But that doesn't actually need to happen until we convert them. I wrote this patch before I realized this, and I believe it's correct, so I figured I'd get it landed along with everything. But I'm also ok to skip it for now.

/* 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_

#include "nsString.h"

namespace mozilla {
namespace dom {

class FallbackEncoding
{
public:

  /**
   * Gets the locale-dependent fallback encoding for legacy HTML and plain
   * text content.
   *
   * @param aFallback the outparam for the fallback encoding
   */
  static void FromLocale(nsACString& aFallback);

  // 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.
   */
  static FallbackEncoding* sInstance;

  FallbackEncoding();
  ~FallbackEncoding();

  /**
   * Invalidates the cache.
   */
  void Invalidate()
  {
    mFallback.Truncate();
  }

  static void PrefChanged(const char*, void*);

  /**
   * Gets the fallback encoding label.
   * @param aFallback the fallback encoding
   */
  void Get(nsACString& aFallback);

  nsCString mFallback;
};

} // dom
} // mozilla

#endif // mozilla_dom_FallbackEncoding_h_