1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/src/nsChromeRegistryChrome.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,190 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsChromeRegistryChrome_h 1.10 +#define nsChromeRegistryChrome_h 1.11 + 1.12 +#include "nsCOMArray.h" 1.13 +#include "nsChromeRegistry.h" 1.14 +#include "nsVoidArray.h" 1.15 +#include "mozilla/Move.h" 1.16 + 1.17 +namespace mozilla { 1.18 +namespace dom { 1.19 +class PContentParent; 1.20 +} 1.21 +} 1.22 + 1.23 +class nsIPrefBranch; 1.24 + 1.25 +class nsChromeRegistryChrome : public nsChromeRegistry 1.26 +{ 1.27 + public: 1.28 + nsChromeRegistryChrome(); 1.29 + ~nsChromeRegistryChrome(); 1.30 + 1.31 + nsresult Init() MOZ_OVERRIDE; 1.32 + 1.33 + NS_IMETHOD CheckForNewChrome() MOZ_OVERRIDE; 1.34 + NS_IMETHOD CheckForOSAccessibility() MOZ_OVERRIDE; 1.35 + NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage, 1.36 + nsIUTF8StringEnumerator* *aResult) MOZ_OVERRIDE; 1.37 + NS_IMETHOD IsLocaleRTL(const nsACString& package, 1.38 + bool *aResult) MOZ_OVERRIDE; 1.39 + NS_IMETHOD GetSelectedLocale(const nsACString& aPackage, 1.40 + nsACString& aLocale) MOZ_OVERRIDE; 1.41 + NS_IMETHOD Observe(nsISupports *aSubject, const char *aTopic, 1.42 + const char16_t *someData) MOZ_OVERRIDE; 1.43 + 1.44 +#ifdef MOZ_XUL 1.45 + NS_IMETHOD GetXULOverlays(nsIURI *aURI, 1.46 + nsISimpleEnumerator **_retval) MOZ_OVERRIDE; 1.47 + NS_IMETHOD GetStyleOverlays(nsIURI *aURI, 1.48 + nsISimpleEnumerator **_retval) MOZ_OVERRIDE; 1.49 +#endif 1.50 + 1.51 + void SendRegisteredChrome(mozilla::dom::PContentParent* aChild); 1.52 + 1.53 + private: 1.54 + static PLDHashOperator CollectPackages(PLDHashTable *table, 1.55 + PLDHashEntryHdr *entry, 1.56 + uint32_t number, void *arg); 1.57 + 1.58 + nsresult OverrideLocalePackage(const nsACString& aPackage, 1.59 + nsACString& aOverride); 1.60 + nsresult SelectLocaleFromPref(nsIPrefBranch* prefs); 1.61 + nsresult UpdateSelectedLocale() MOZ_OVERRIDE; 1.62 + nsIURI* GetBaseURIFromPackage(const nsCString& aPackage, 1.63 + const nsCString& aProvider, 1.64 + const nsCString& aPath) MOZ_OVERRIDE; 1.65 + nsresult GetFlagsFromPackage(const nsCString& aPackage, 1.66 + uint32_t* aFlags) MOZ_OVERRIDE; 1.67 + 1.68 + static const PLDHashTableOps kTableOps; 1.69 + static PLDHashNumber HashKey(PLDHashTable *table, const void *key); 1.70 + static bool MatchKey(PLDHashTable *table, const PLDHashEntryHdr *entry, 1.71 + const void *key); 1.72 + static void ClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry); 1.73 + static bool InitEntry(PLDHashTable *table, PLDHashEntryHdr *entry, 1.74 + const void *key); 1.75 + 1.76 + struct ProviderEntry 1.77 + { 1.78 + ProviderEntry(const nsACString& aProvider, nsIURI* aBase) : 1.79 + provider(aProvider), 1.80 + baseURI(aBase) { } 1.81 + 1.82 + nsCString provider; 1.83 + nsCOMPtr<nsIURI> baseURI; 1.84 + }; 1.85 + 1.86 + class nsProviderArray 1.87 + { 1.88 + public: 1.89 + nsProviderArray() : 1.90 + mArray(1) { } 1.91 + ~nsProviderArray() 1.92 + { Clear(); } 1.93 + 1.94 + // When looking up locales and skins, the "selected" locale is not always 1.95 + // available. This enum identifies what kind of match is desired/found. 1.96 + enum MatchType { 1.97 + EXACT = 0, 1.98 + LOCALE = 1, // "en-GB" is selected, we found "en-US" 1.99 + ANY = 2 1.100 + }; 1.101 + 1.102 + nsIURI* GetBase(const nsACString& aPreferred, MatchType aType); 1.103 + const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType); 1.104 + void SetBase(const nsACString& aProvider, nsIURI* base); 1.105 + void EnumerateToArray(nsTArray<nsCString> *a); 1.106 + void Clear(); 1.107 + 1.108 + private: 1.109 + ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType); 1.110 + 1.111 + nsVoidArray mArray; 1.112 + }; 1.113 + 1.114 + struct PackageEntry : public PLDHashEntryHdr 1.115 + { 1.116 + PackageEntry(const nsACString& package) 1.117 + : package(package), flags(0) { } 1.118 + ~PackageEntry() { } 1.119 + 1.120 + nsCString package; 1.121 + nsCOMPtr<nsIURI> baseURI; 1.122 + uint32_t flags; 1.123 + nsProviderArray locales; 1.124 + nsProviderArray skins; 1.125 + }; 1.126 + 1.127 + class OverlayListEntry : public nsURIHashKey 1.128 + { 1.129 + public: 1.130 + typedef nsURIHashKey::KeyType KeyType; 1.131 + typedef nsURIHashKey::KeyTypePointer KeyTypePointer; 1.132 + 1.133 + OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { } 1.134 + OverlayListEntry(OverlayListEntry&& toMove) : nsURIHashKey(mozilla::Move(toMove)), 1.135 + mArray(mozilla::Move(toMove.mArray)) { } 1.136 + ~OverlayListEntry() { } 1.137 + 1.138 + void AddURI(nsIURI* aURI); 1.139 + 1.140 + nsCOMArray<nsIURI> mArray; 1.141 + }; 1.142 + 1.143 + class OverlayListHash 1.144 + { 1.145 + public: 1.146 + OverlayListHash() { } 1.147 + ~OverlayListHash() { } 1.148 + 1.149 + void Add(nsIURI* aBase, nsIURI* aOverlay); 1.150 + void Clear() { mTable.Clear(); } 1.151 + const nsCOMArray<nsIURI>* GetArray(nsIURI* aBase); 1.152 + 1.153 + private: 1.154 + nsTHashtable<OverlayListEntry> mTable; 1.155 + }; 1.156 + 1.157 + // Hashes on the file to be overlaid (chrome://browser/content/browser.xul) 1.158 + // to a list of overlays/stylesheets 1.159 + OverlayListHash mOverlayHash; 1.160 + OverlayListHash mStyleHash; 1.161 + 1.162 + bool mProfileLoaded; 1.163 + 1.164 + nsCString mSelectedLocale; 1.165 + nsCString mSelectedSkin; 1.166 + 1.167 + // Hash of package names ("global") to PackageEntry objects 1.168 + PLDHashTable mPackagesHash; 1.169 + 1.170 + virtual void ManifestContent(ManifestProcessingContext& cx, int lineno, 1.171 + char *const * argv, bool platform, 1.172 + bool contentaccessible); 1.173 + virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno, 1.174 + char *const * argv, bool platform, 1.175 + bool contentaccessible); 1.176 + virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno, 1.177 + char *const * argv, bool platform, 1.178 + bool contentaccessible); 1.179 + virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno, 1.180 + char *const * argv, bool platform, 1.181 + bool contentaccessible); 1.182 + virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno, 1.183 + char *const * argv, bool platform, 1.184 + bool contentaccessible); 1.185 + virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno, 1.186 + char *const * argv, bool platform, 1.187 + bool contentaccessible); 1.188 + virtual void ManifestResource(ManifestProcessingContext& cx, int lineno, 1.189 + char *const * argv, bool platform, 1.190 + bool contentaccessible); 1.191 +}; 1.192 + 1.193 +#endif // nsChromeRegistryChrome_h