Reland bug 121341.
[wine-gecko.git] / chrome / src / nsChromeRegistry.h
blob0fa15c93812560990dd41439a7cc4a7d13a576d5
1 /* -*- Mode: C++; tab-width: 2; 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 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Original Author: David W. Hyatt (hyatt@netscape.com)
24 * Benjamin Smedberg <benjamin@smedbergs.us>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsIChromeRegistry.h"
41 #include "nsIToolkitChromeRegistry.h"
42 #include "nsIObserver.h"
43 #include "nsWeakReference.h"
45 #ifdef MOZ_XUL
46 #include "nsIXULOverlayProvider.h"
47 #endif
49 #include "pldhash.h"
51 #include "nsCOMArray.h"
52 #include "nsString.h"
53 #include "nsTHashtable.h"
54 #include "nsURIHashKey.h"
55 #include "nsVoidArray.h"
56 #include "nsInterfaceHashtable.h"
58 struct PRFileDesc;
59 class nsIAtom;
60 class nsICSSLoader;
61 class nsICSSStyleSheet;
62 class nsIDOMWindowInternal;
63 class nsILocalFile;
64 class nsIRDFDataSource;
65 class nsIRDFResource;
66 class nsIRDFService;
67 class nsISimpleEnumerator;
68 class nsIURL;
70 // for component registration
71 // {47049e42-1d87-482a-984d-56ae185e367a}
72 #define NS_CHROMEREGISTRY_CID \
73 { 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
75 class nsChromeRegistry : public nsIToolkitChromeRegistry,
76 #ifdef MOZ_XUL
77 public nsIXULOverlayProvider,
78 #endif
79 public nsIObserver,
80 public nsSupportsWeakReference
82 public:
83 NS_DECL_ISUPPORTS
85 // nsIChromeRegistry methods:
86 NS_DECL_NSICHROMEREGISTRY
87 NS_DECL_NSIXULCHROMEREGISTRY
88 NS_DECL_NSITOOLKITCHROMEREGISTRY
90 #ifdef MOZ_XUL
91 NS_DECL_NSIXULOVERLAYPROVIDER
92 #endif
94 NS_DECL_NSIOBSERVER
96 // nsChromeRegistry methods:
97 nsChromeRegistry() : mInitialized(PR_FALSE) {
98 mPackagesHash.ops = nsnull;
100 ~nsChromeRegistry();
102 nsresult Init();
104 static nsChromeRegistry* gChromeRegistry;
106 static nsresult Canonify(nsIURL* aChromeURL);
108 protected:
109 nsresult GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult);
111 nsresult LoadInstallDataSource();
112 nsresult LoadProfileDataSource();
114 void FlushSkinCaches();
115 void FlushAllCaches();
117 private:
118 static nsresult RefreshWindow(nsIDOMWindowInternal* aWindow,
119 nsICSSLoader* aCSSLoader);
120 static nsresult GetProviderAndPath(nsIURL* aChromeURL,
121 nsACString& aProvider, nsACString& aPath);
123 #ifdef MOZ_XUL
124 NS_HIDDEN_(void) ProcessProvider(PRFileDesc *fd, nsIRDFService* aRDFs,
125 nsIRDFDataSource* ds, nsIRDFResource* aRoot,
126 PRBool aIsLocale, const nsACString& aBaseURL);
127 NS_HIDDEN_(void) ProcessOverlays(PRFileDesc *fd, nsIRDFDataSource* ds,
128 nsIRDFResource* aRoot,
129 const nsCSubstring& aType);
130 #endif
132 NS_HIDDEN_(nsresult) ProcessManifest(nsILocalFile* aManifest, PRBool aSkinOnly);
133 NS_HIDDEN_(nsresult) ProcessManifestBuffer(char *aBuffer, PRInt32 aLength, nsILocalFile* aManifest, PRBool aSkinOnly);
134 NS_HIDDEN_(nsresult) ProcessNewChromeFile(nsILocalFile *aListFile, nsIURI* aManifest);
135 NS_HIDDEN_(nsresult) ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength, nsIURI* aManifest);
137 public:
138 struct ProviderEntry
140 ProviderEntry(const nsACString& aProvider, nsIURI* aBase) :
141 provider(aProvider),
142 baseURI(aBase) { }
144 nsCString provider;
145 nsCOMPtr<nsIURI> baseURI;
148 class nsProviderArray
150 public:
151 nsProviderArray() :
152 mArray(1) { }
153 ~nsProviderArray()
154 { Clear(); }
156 // When looking up locales and skins, the "selected" locale is not always
157 // available. This enum identifies what kind of match is desired/found.
158 enum MatchType {
159 EXACT = 0,
160 LOCALE = 1, // "en-GB" is selected, we found "en-US"
161 ANY = 2
164 nsIURI* GetBase(const nsACString& aPreferred, MatchType aType);
165 const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType);
166 void SetBase(const nsACString& aProvider, nsIURI* base);
167 void EnumerateToArray(nsCStringArray *a);
168 void Clear();
170 private:
171 ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
173 nsVoidArray mArray;
176 struct PackageEntry : public PLDHashEntryHdr
178 PackageEntry(const nsACString& package);
179 ~PackageEntry() { }
181 // Available flags
182 enum {
183 // This is a "platform" package (e.g. chrome://global-platform/).
184 // Appends one of win/ unix/ mac/ to the base URI.
185 PLATFORM_PACKAGE = 1 << 0,
187 // This package should use the new XPCNativeWrappers to separate
188 // content from chrome. This flag is currently unused (because we call
189 // into xpconnect at registration time).
190 XPCNATIVEWRAPPERS = 1 << 1,
192 // Content script may access files in this package
193 CONTENT_ACCESSIBLE = 1 << 2
196 nsCString package;
197 nsCOMPtr<nsIURI> baseURI;
198 PRUint32 flags;
199 nsProviderArray locales;
200 nsProviderArray skins;
203 private:
204 static PLDHashNumber HashKey(PLDHashTable *table, const void *key);
205 static PRBool MatchKey(PLDHashTable *table, const PLDHashEntryHdr *entry,
206 const void *key);
207 static void ClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry);
208 static PRBool InitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
209 const void *key);
211 static const PLDHashTableOps kTableOps;
213 public:
214 class OverlayListEntry : public nsURIHashKey
216 public:
217 typedef nsURIHashKey::KeyType KeyType;
218 typedef nsURIHashKey::KeyTypePointer KeyTypePointer;
220 OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { }
221 OverlayListEntry(OverlayListEntry& toCopy) : nsURIHashKey(toCopy),
222 mArray(toCopy.mArray) { }
223 ~OverlayListEntry() { }
225 void AddURI(nsIURI* aURI);
227 nsCOMArray<nsIURI> mArray;
230 class OverlayListHash
232 public:
233 OverlayListHash() { }
234 ~OverlayListHash() { }
236 PRBool Init() { return mTable.Init(); }
237 void Add(nsIURI* aBase, nsIURI* aOverlay);
238 void Clear() { mTable.Clear(); }
239 const nsCOMArray<nsIURI>* GetArray(nsIURI* aBase);
241 private:
242 nsTHashtable<OverlayListEntry> mTable;
245 private:
246 PRBool mInitialized;
248 // Hash of package names ("global") to PackageEntry objects
249 PLDHashTable mPackagesHash;
251 // Hashes on the file to be overlaid (chrome://browser/content/browser.xul)
252 // to a list of overlays/stylesheets
253 OverlayListHash mOverlayHash;
254 OverlayListHash mStyleHash;
256 // "Override" table (chrome URI string -> real URI)
257 nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
259 nsCString mSelectedLocale;
260 nsCString mSelectedSkin;