Bug 547353 - [OOPP] Mouse pointer coordinates misaligned with winless Silverlight...
[mozilla-central.git] / chrome / src / nsChromeRegistry.h
blob2216cd010cc14760a9f42b80ad4778066c99091e
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 "nsTArray.h"
57 #include "nsInterfaceHashtable.h"
59 struct PRFileDesc;
60 class nsIAtom;
61 class nsICSSLoader;
62 class nsICSSStyleSheet;
63 class nsIDOMWindowInternal;
64 class nsILocalFile;
65 class nsIPrefBranch;
66 class nsIRDFDataSource;
67 class nsIRDFResource;
68 class nsIRDFService;
69 class nsISimpleEnumerator;
70 class nsIURL;
72 // for component registration
73 // {47049e42-1d87-482a-984d-56ae185e367a}
74 #define NS_CHROMEREGISTRY_CID \
75 { 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
77 class nsChromeRegistry : public nsIToolkitChromeRegistry,
78 #ifdef MOZ_XUL
79 public nsIXULOverlayProvider,
80 #endif
81 public nsIObserver,
82 public nsSupportsWeakReference
84 public:
85 NS_DECL_ISUPPORTS
87 // nsIChromeRegistry methods:
88 NS_DECL_NSICHROMEREGISTRY
89 NS_DECL_NSIXULCHROMEREGISTRY
90 NS_DECL_NSITOOLKITCHROMEREGISTRY
92 #ifdef MOZ_XUL
93 NS_DECL_NSIXULOVERLAYPROVIDER
94 #endif
96 NS_DECL_NSIOBSERVER
98 // nsChromeRegistry methods:
99 nsChromeRegistry() : mInitialized(PR_FALSE), mProfileLoaded(PR_FALSE) {
100 mPackagesHash.ops = nsnull;
102 ~nsChromeRegistry();
104 nsresult Init();
106 static nsChromeRegistry* gChromeRegistry;
108 static nsresult Canonify(nsIURL* aChromeURL);
110 protected:
111 nsresult GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult);
113 nsresult LoadInstallDataSource();
114 nsresult LoadProfileDataSource();
116 void FlushSkinCaches();
117 void FlushAllCaches();
119 private:
120 nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
122 static nsresult RefreshWindow(nsIDOMWindowInternal* aWindow,
123 nsICSSLoader* aCSSLoader);
124 static nsresult GetProviderAndPath(nsIURL* aChromeURL,
125 nsACString& aProvider, nsACString& aPath);
127 #ifdef MOZ_XUL
128 NS_HIDDEN_(void) ProcessProvider(PRFileDesc *fd, nsIRDFService* aRDFs,
129 nsIRDFDataSource* ds, nsIRDFResource* aRoot,
130 PRBool aIsLocale, const nsACString& aBaseURL);
131 NS_HIDDEN_(void) ProcessOverlays(PRFileDesc *fd, nsIRDFDataSource* ds,
132 nsIRDFResource* aRoot,
133 const nsCSubstring& aType);
134 #endif
136 NS_HIDDEN_(nsresult) ProcessManifest(nsILocalFile* aManifest, PRBool aSkinOnly);
137 NS_HIDDEN_(nsresult) ProcessManifestBuffer(char *aBuffer, PRInt32 aLength, nsILocalFile* aManifest, PRBool aSkinOnly);
138 NS_HIDDEN_(nsresult) ProcessNewChromeFile(nsILocalFile *aListFile, nsIURI* aManifest);
139 NS_HIDDEN_(nsresult) ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength, nsIURI* aManifest);
141 public:
142 struct ProviderEntry
144 ProviderEntry(const nsACString& aProvider, nsIURI* aBase) :
145 provider(aProvider),
146 baseURI(aBase) { }
148 nsCString provider;
149 nsCOMPtr<nsIURI> baseURI;
152 class nsProviderArray
154 public:
155 nsProviderArray() :
156 mArray(1) { }
157 ~nsProviderArray()
158 { Clear(); }
160 // When looking up locales and skins, the "selected" locale is not always
161 // available. This enum identifies what kind of match is desired/found.
162 enum MatchType {
163 EXACT = 0,
164 LOCALE = 1, // "en-GB" is selected, we found "en-US"
165 ANY = 2
168 nsIURI* GetBase(const nsACString& aPreferred, MatchType aType);
169 const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType);
170 void SetBase(const nsACString& aProvider, nsIURI* base);
171 void EnumerateToArray(nsTArray<nsCString> *a);
172 void Clear();
174 private:
175 ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
177 nsVoidArray mArray;
180 struct PackageEntry : public PLDHashEntryHdr
182 PackageEntry(const nsACString& package);
183 ~PackageEntry() { }
185 // Available flags
186 enum {
187 // This is a "platform" package (e.g. chrome://global-platform/).
188 // Appends one of win/ unix/ mac/ to the base URI.
189 PLATFORM_PACKAGE = 1 << 0,
191 // This package should use the new XPCNativeWrappers to separate
192 // content from chrome. This flag is currently unused (because we call
193 // into xpconnect at registration time).
194 XPCNATIVEWRAPPERS = 1 << 1,
196 // Content script may access files in this package
197 CONTENT_ACCESSIBLE = 1 << 2
200 nsCString package;
201 nsCOMPtr<nsIURI> baseURI;
202 PRUint32 flags;
203 nsProviderArray locales;
204 nsProviderArray skins;
207 private:
208 static PLDHashNumber HashKey(PLDHashTable *table, const void *key);
209 static PRBool MatchKey(PLDHashTable *table, const PLDHashEntryHdr *entry,
210 const void *key);
211 static void ClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry);
212 static PRBool InitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
213 const void *key);
215 static const PLDHashTableOps kTableOps;
217 public:
218 class OverlayListEntry : public nsURIHashKey
220 public:
221 typedef nsURIHashKey::KeyType KeyType;
222 typedef nsURIHashKey::KeyTypePointer KeyTypePointer;
224 OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { }
225 OverlayListEntry(OverlayListEntry& toCopy) : nsURIHashKey(toCopy),
226 mArray(toCopy.mArray) { }
227 ~OverlayListEntry() { }
229 void AddURI(nsIURI* aURI);
231 nsCOMArray<nsIURI> mArray;
234 class OverlayListHash
236 public:
237 OverlayListHash() { }
238 ~OverlayListHash() { }
240 PRBool Init() { return mTable.Init(); }
241 void Add(nsIURI* aBase, nsIURI* aOverlay);
242 void Clear() { mTable.Clear(); }
243 const nsCOMArray<nsIURI>* GetArray(nsIURI* aBase);
245 private:
246 nsTHashtable<OverlayListEntry> mTable;
249 private:
250 PRBool mInitialized;
251 PRBool mProfileLoaded;
253 // Hash of package names ("global") to PackageEntry objects
254 PLDHashTable mPackagesHash;
256 // Hashes on the file to be overlaid (chrome://browser/content/browser.xul)
257 // to a list of overlays/stylesheets
258 OverlayListHash mOverlayHash;
259 OverlayListHash mStyleHash;
261 // "Override" table (chrome URI string -> real URI)
262 nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
264 nsCString mSelectedLocale;
265 nsCString mSelectedSkin;