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
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.
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"
46 #include "nsIXULOverlayProvider.h"
51 #include "nsCOMArray.h"
53 #include "nsTHashtable.h"
54 #include "nsURIHashKey.h"
55 #include "nsVoidArray.h"
57 #include "nsInterfaceHashtable.h"
62 class nsICSSStyleSheet
;
63 class nsIDOMWindowInternal
;
66 class nsIRDFDataSource
;
69 class nsISimpleEnumerator
;
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
,
79 public nsIXULOverlayProvider
,
82 public nsSupportsWeakReference
87 // nsIChromeRegistry methods:
88 NS_DECL_NSICHROMEREGISTRY
89 NS_DECL_NSIXULCHROMEREGISTRY
90 NS_DECL_NSITOOLKITCHROMEREGISTRY
93 NS_DECL_NSIXULOVERLAYPROVIDER
98 // nsChromeRegistry methods:
99 nsChromeRegistry() : mInitialized(PR_FALSE
), mProfileLoaded(PR_FALSE
) {
100 mPackagesHash
.ops
= nsnull
;
106 static nsChromeRegistry
* gChromeRegistry
;
108 static nsresult
Canonify(nsIURL
* aChromeURL
);
111 nsresult
GetDynamicInfo(nsIURI
*aChromeURL
, PRBool aIsOverlay
, nsISimpleEnumerator
**aResult
);
113 nsresult
LoadInstallDataSource();
114 nsresult
LoadProfileDataSource();
116 void FlushSkinCaches();
117 void FlushAllCaches();
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
);
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
);
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
);
144 ProviderEntry(const nsACString
& aProvider
, nsIURI
* aBase
) :
149 nsCOMPtr
<nsIURI
> baseURI
;
152 class nsProviderArray
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.
164 LOCALE
= 1, // "en-GB" is selected, we found "en-US"
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
);
175 ProviderEntry
* GetProvider(const nsACString
& aPreferred
, MatchType aType
);
180 struct PackageEntry
: public PLDHashEntryHdr
182 PackageEntry(const nsACString
& package
);
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
201 nsCOMPtr
<nsIURI
> baseURI
;
203 nsProviderArray locales
;
204 nsProviderArray skins
;
208 static PLDHashNumber
HashKey(PLDHashTable
*table
, const void *key
);
209 static PRBool
MatchKey(PLDHashTable
*table
, const PLDHashEntryHdr
*entry
,
211 static void ClearEntry(PLDHashTable
*table
, PLDHashEntryHdr
*entry
);
212 static PRBool
InitEntry(PLDHashTable
*table
, PLDHashEntryHdr
*entry
,
215 static const PLDHashTableOps kTableOps
;
218 class OverlayListEntry
: public nsURIHashKey
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
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
);
246 nsTHashtable
<OverlayListEntry
> mTable
;
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
;