michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsChromeRegistryChrome_h michael@0: #define nsChromeRegistryChrome_h michael@0: michael@0: #include "nsCOMArray.h" michael@0: #include "nsChromeRegistry.h" michael@0: #include "nsVoidArray.h" michael@0: #include "mozilla/Move.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class PContentParent; michael@0: } michael@0: } michael@0: michael@0: class nsIPrefBranch; michael@0: michael@0: class nsChromeRegistryChrome : public nsChromeRegistry michael@0: { michael@0: public: michael@0: nsChromeRegistryChrome(); michael@0: ~nsChromeRegistryChrome(); michael@0: michael@0: nsresult Init() MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD CheckForNewChrome() MOZ_OVERRIDE; michael@0: NS_IMETHOD CheckForOSAccessibility() MOZ_OVERRIDE; michael@0: NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage, michael@0: nsIUTF8StringEnumerator* *aResult) MOZ_OVERRIDE; michael@0: NS_IMETHOD IsLocaleRTL(const nsACString& package, michael@0: bool *aResult) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetSelectedLocale(const nsACString& aPackage, michael@0: nsACString& aLocale) MOZ_OVERRIDE; michael@0: NS_IMETHOD Observe(nsISupports *aSubject, const char *aTopic, michael@0: const char16_t *someData) MOZ_OVERRIDE; michael@0: michael@0: #ifdef MOZ_XUL michael@0: NS_IMETHOD GetXULOverlays(nsIURI *aURI, michael@0: nsISimpleEnumerator **_retval) MOZ_OVERRIDE; michael@0: NS_IMETHOD GetStyleOverlays(nsIURI *aURI, michael@0: nsISimpleEnumerator **_retval) MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: void SendRegisteredChrome(mozilla::dom::PContentParent* aChild); michael@0: michael@0: private: michael@0: static PLDHashOperator CollectPackages(PLDHashTable *table, michael@0: PLDHashEntryHdr *entry, michael@0: uint32_t number, void *arg); michael@0: michael@0: nsresult OverrideLocalePackage(const nsACString& aPackage, michael@0: nsACString& aOverride); michael@0: nsresult SelectLocaleFromPref(nsIPrefBranch* prefs); michael@0: nsresult UpdateSelectedLocale() MOZ_OVERRIDE; michael@0: nsIURI* GetBaseURIFromPackage(const nsCString& aPackage, michael@0: const nsCString& aProvider, michael@0: const nsCString& aPath) MOZ_OVERRIDE; michael@0: nsresult GetFlagsFromPackage(const nsCString& aPackage, michael@0: uint32_t* aFlags) MOZ_OVERRIDE; michael@0: michael@0: static const PLDHashTableOps kTableOps; michael@0: static PLDHashNumber HashKey(PLDHashTable *table, const void *key); michael@0: static bool MatchKey(PLDHashTable *table, const PLDHashEntryHdr *entry, michael@0: const void *key); michael@0: static void ClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry); michael@0: static bool InitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, michael@0: const void *key); michael@0: michael@0: struct ProviderEntry michael@0: { michael@0: ProviderEntry(const nsACString& aProvider, nsIURI* aBase) : michael@0: provider(aProvider), michael@0: baseURI(aBase) { } michael@0: michael@0: nsCString provider; michael@0: nsCOMPtr baseURI; michael@0: }; michael@0: michael@0: class nsProviderArray michael@0: { michael@0: public: michael@0: nsProviderArray() : michael@0: mArray(1) { } michael@0: ~nsProviderArray() michael@0: { Clear(); } michael@0: michael@0: // When looking up locales and skins, the "selected" locale is not always michael@0: // available. This enum identifies what kind of match is desired/found. michael@0: enum MatchType { michael@0: EXACT = 0, michael@0: LOCALE = 1, // "en-GB" is selected, we found "en-US" michael@0: ANY = 2 michael@0: }; michael@0: michael@0: nsIURI* GetBase(const nsACString& aPreferred, MatchType aType); michael@0: const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType); michael@0: void SetBase(const nsACString& aProvider, nsIURI* base); michael@0: void EnumerateToArray(nsTArray *a); michael@0: void Clear(); michael@0: michael@0: private: michael@0: ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType); michael@0: michael@0: nsVoidArray mArray; michael@0: }; michael@0: michael@0: struct PackageEntry : public PLDHashEntryHdr michael@0: { michael@0: PackageEntry(const nsACString& package) michael@0: : package(package), flags(0) { } michael@0: ~PackageEntry() { } michael@0: michael@0: nsCString package; michael@0: nsCOMPtr baseURI; michael@0: uint32_t flags; michael@0: nsProviderArray locales; michael@0: nsProviderArray skins; michael@0: }; michael@0: michael@0: class OverlayListEntry : public nsURIHashKey michael@0: { michael@0: public: michael@0: typedef nsURIHashKey::KeyType KeyType; michael@0: typedef nsURIHashKey::KeyTypePointer KeyTypePointer; michael@0: michael@0: OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { } michael@0: OverlayListEntry(OverlayListEntry&& toMove) : nsURIHashKey(mozilla::Move(toMove)), michael@0: mArray(mozilla::Move(toMove.mArray)) { } michael@0: ~OverlayListEntry() { } michael@0: michael@0: void AddURI(nsIURI* aURI); michael@0: michael@0: nsCOMArray mArray; michael@0: }; michael@0: michael@0: class OverlayListHash michael@0: { michael@0: public: michael@0: OverlayListHash() { } michael@0: ~OverlayListHash() { } michael@0: michael@0: void Add(nsIURI* aBase, nsIURI* aOverlay); michael@0: void Clear() { mTable.Clear(); } michael@0: const nsCOMArray* GetArray(nsIURI* aBase); michael@0: michael@0: private: michael@0: nsTHashtable mTable; michael@0: }; michael@0: michael@0: // Hashes on the file to be overlaid (chrome://browser/content/browser.xul) michael@0: // to a list of overlays/stylesheets michael@0: OverlayListHash mOverlayHash; michael@0: OverlayListHash mStyleHash; michael@0: michael@0: bool mProfileLoaded; michael@0: michael@0: nsCString mSelectedLocale; michael@0: nsCString mSelectedSkin; michael@0: michael@0: // Hash of package names ("global") to PackageEntry objects michael@0: PLDHashTable mPackagesHash; michael@0: michael@0: virtual void ManifestContent(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible); michael@0: virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible); michael@0: virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible); michael@0: virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible); michael@0: virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible); michael@0: virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible); michael@0: virtual void ManifestResource(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible); michael@0: }; michael@0: michael@0: #endif // nsChromeRegistryChrome_h