Follow up fix for bug 623435. (r=brendan)
[mozilla-central.git] / chrome / src / nsChromeRegistryChrome.h
blobdaee848d5dc3d2ac0b850b1dd6529800437485ff
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * the Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Josh Matthews <josh@joshmatthews.net> (Initial Developer)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsChromeRegistryChrome_h
40 #define nsChromeRegistryChrome_h
42 #include "nsChromeRegistry.h"
44 namespace mozilla {
45 namespace dom {
46 class PContentParent;
50 class nsIPrefBranch;
52 class nsChromeRegistryChrome : public nsChromeRegistry
54 public:
55 nsChromeRegistryChrome();
56 ~nsChromeRegistryChrome();
58 NS_OVERRIDE nsresult Init();
60 NS_OVERRIDE NS_IMETHOD CheckForNewChrome();
61 NS_OVERRIDE NS_IMETHOD CheckForOSAccessibility();
62 NS_OVERRIDE NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage,
63 nsIUTF8StringEnumerator* *aResult);
64 NS_OVERRIDE NS_IMETHOD IsLocaleRTL(const nsACString& package,
65 PRBool *aResult);
66 NS_OVERRIDE NS_IMETHOD GetSelectedLocale(const nsACString& aPackage,
67 nsACString& aLocale);
68 NS_OVERRIDE NS_IMETHOD Observe(nsISupports *aSubject, const char *aTopic,
69 const PRUnichar *someData);
71 #ifdef MOZ_XUL
72 NS_OVERRIDE NS_IMETHOD GetXULOverlays(nsIURI *aURI,
73 nsISimpleEnumerator **_retval);
74 NS_OVERRIDE NS_IMETHOD GetStyleOverlays(nsIURI *aURI,
75 nsISimpleEnumerator **_retval);
76 #endif
78 #ifdef MOZ_IPC
79 void SendRegisteredChrome(mozilla::dom::PContentParent* aChild);
80 #endif
82 private:
83 #ifdef MOZ_IPC
84 static PLDHashOperator CollectPackages(PLDHashTable *table,
85 PLDHashEntryHdr *entry,
86 PRUint32 number, void *arg);
87 #endif
89 nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
90 NS_OVERRIDE void UpdateSelectedLocale();
91 NS_OVERRIDE nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
92 const nsCString& aProvider,
93 const nsCString& aPath);
94 NS_OVERRIDE nsresult GetFlagsFromPackage(const nsCString& aPackage,
95 PRUint32* aFlags);
97 static const PLDHashTableOps kTableOps;
98 static PLDHashNumber HashKey(PLDHashTable *table, const void *key);
99 static PRBool MatchKey(PLDHashTable *table, const PLDHashEntryHdr *entry,
100 const void *key);
101 static void ClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry);
102 static PRBool InitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
103 const void *key);
105 struct ProviderEntry
107 ProviderEntry(const nsACString& aProvider, nsIURI* aBase) :
108 provider(aProvider),
109 baseURI(aBase) { }
111 nsCString provider;
112 nsCOMPtr<nsIURI> baseURI;
115 class nsProviderArray
117 public:
118 nsProviderArray() :
119 mArray(1) { }
120 ~nsProviderArray()
121 { Clear(); }
123 // When looking up locales and skins, the "selected" locale is not always
124 // available. This enum identifies what kind of match is desired/found.
125 enum MatchType {
126 EXACT = 0,
127 LOCALE = 1, // "en-GB" is selected, we found "en-US"
128 ANY = 2
131 nsIURI* GetBase(const nsACString& aPreferred, MatchType aType);
132 const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType);
133 void SetBase(const nsACString& aProvider, nsIURI* base);
134 void EnumerateToArray(nsTArray<nsCString> *a);
135 void Clear();
137 private:
138 ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
140 nsVoidArray mArray;
143 struct PackageEntry : public PLDHashEntryHdr
145 PackageEntry(const nsACString& package)
146 : package(package), flags(0) { }
147 ~PackageEntry() { }
149 nsCString package;
150 nsCOMPtr<nsIURI> baseURI;
151 PRUint32 flags;
152 nsProviderArray locales;
153 nsProviderArray skins;
156 class OverlayListEntry : public nsURIHashKey
158 public:
159 typedef nsURIHashKey::KeyType KeyType;
160 typedef nsURIHashKey::KeyTypePointer KeyTypePointer;
162 OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { }
163 OverlayListEntry(OverlayListEntry& toCopy) : nsURIHashKey(toCopy),
164 mArray(toCopy.mArray) { }
165 ~OverlayListEntry() { }
167 void AddURI(nsIURI* aURI);
169 nsCOMArray<nsIURI> mArray;
172 class OverlayListHash
174 public:
175 OverlayListHash() { }
176 ~OverlayListHash() { }
178 PRBool Init() { return mTable.Init(); }
179 void Add(nsIURI* aBase, nsIURI* aOverlay);
180 void Clear() { mTable.Clear(); }
181 const nsCOMArray<nsIURI>* GetArray(nsIURI* aBase);
183 private:
184 nsTHashtable<OverlayListEntry> mTable;
187 // Hashes on the file to be overlaid (chrome://browser/content/browser.xul)
188 // to a list of overlays/stylesheets
189 OverlayListHash mOverlayHash;
190 OverlayListHash mStyleHash;
192 PRBool mProfileLoaded;
194 nsCString mSelectedLocale;
195 nsCString mSelectedSkin;
197 // Hash of package names ("global") to PackageEntry objects
198 PLDHashTable mPackagesHash;
200 virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
201 char *const * argv, bool platform,
202 bool contentaccessible);
203 virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
204 char *const * argv, bool platform,
205 bool contentaccessible);
206 virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
207 char *const * argv, bool platform,
208 bool contentaccessible);
209 virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno,
210 char *const * argv, bool platform,
211 bool contentaccessible);
212 virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno,
213 char *const * argv, bool platform,
214 bool contentaccessible);
215 virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
216 char *const * argv, bool platform,
217 bool contentaccessible);
218 virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
219 char *const * argv, bool platform,
220 bool contentaccessible);
223 #endif // nsChromeRegistryChrome_h