Bug 634734 - Fennec ASSERTION: mFUnitsConvFactor not valid: mFUnitsConvFactor > 0...
[mozilla-central.git] / chrome / src / nsChromeRegistry.h
blob3f82b2367c81d024b64a643265587eccbceef0b2
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 #ifndef nsChromeRegistry_h
41 #define nsChromeRegistry_h
43 #include "nsIChromeRegistry.h"
44 #include "nsIToolkitChromeRegistry.h"
45 #include "nsIObserver.h"
46 #include "nsWeakReference.h"
47 #include "nsIPrefBranch.h"
49 #ifdef MOZ_XUL
50 #include "nsIXULOverlayProvider.h"
51 #endif
53 #include "pldhash.h"
55 #include "nsCOMArray.h"
56 #include "nsString.h"
57 #include "nsTHashtable.h"
58 #include "nsURIHashKey.h"
59 #include "nsInterfaceHashtable.h"
60 #include "nsXULAppAPI.h"
61 #include "nsIResProtocolHandler.h"
62 #include "nsIXPConnect.h"
64 #include "mozilla/Omnijar.h"
66 class nsIDOMWindowInternal;
67 class nsIURL;
69 // The chrome registry is actually split between nsChromeRegistryChrome and
70 // nsChromeRegistryContent. The work/data that is common to both resides in
71 // the shared nsChromeRegistry implementation, with operations that only make
72 // sense for one side erroring out in the other.
74 // for component registration
75 // {47049e42-1d87-482a-984d-56ae185e367a}
76 #define NS_CHROMEREGISTRY_CID \
77 { 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
79 class nsChromeRegistry : public nsIToolkitChromeRegistry,
80 #ifdef MOZ_XUL
81 public nsIXULOverlayProvider,
82 #endif
83 public nsIObserver,
84 public nsSupportsWeakReference
86 public:
87 NS_DECL_ISUPPORTS
89 // nsIXULChromeRegistry methods:
90 NS_IMETHOD ReloadChrome();
91 NS_IMETHOD RefreshSkins();
92 NS_IMETHOD AllowScriptsForPackage(nsIURI* url,
93 PRBool* _retval NS_OUTPARAM);
94 NS_IMETHOD AllowContentToAccess(nsIURI* url,
95 PRBool* _retval NS_OUTPARAM);
97 // nsIChromeRegistry methods:
98 NS_IMETHOD_(PRBool) WrappersEnabled(nsIURI *aURI);
99 NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult);
101 // nsChromeRegistry methods:
102 nsChromeRegistry() : mInitialized(PR_FALSE) { }
103 virtual ~nsChromeRegistry();
105 virtual nsresult Init();
107 static already_AddRefed<nsIChromeRegistry> GetService();
109 static nsChromeRegistry* gChromeRegistry;
111 static nsresult Canonify(nsIURL* aChromeURL);
113 protected:
114 void FlushSkinCaches();
115 void FlushAllCaches();
117 // Update the selected locale used by the chrome registry, and fire a
118 // notification about this change
119 virtual void UpdateSelectedLocale() = 0;
121 static void LogMessage(const char* aMsg, ...);
122 static void LogMessageWithContext(nsIURI* aURL, PRUint32 aLineNumber, PRUint32 flags,
123 const char* aMsg, ...);
125 virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
126 const nsCString& aProvider,
127 const nsCString& aPath) = 0;
128 virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
129 PRUint32* aFlags) = 0;
131 nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
133 static nsresult RefreshWindow(nsIDOMWindowInternal* aWindow);
134 static nsresult GetProviderAndPath(nsIURL* aChromeURL,
135 nsACString& aProvider, nsACString& aPath);
137 public:
138 static already_AddRefed<nsChromeRegistry> GetSingleton();
140 struct ManifestProcessingContext
142 ManifestProcessingContext(NSLocationType aType, nsILocalFile* aFile)
143 : mType(aType)
144 , mFile(aFile)
145 , mPath(NULL)
148 ManifestProcessingContext(NSLocationType aType, nsILocalFile* aFile, const char* aPath)
149 : mType(aType)
150 , mFile(aFile)
151 , mPath(aPath)
154 ~ManifestProcessingContext()
157 nsIURI* GetManifestURI();
158 nsIXPConnect* GetXPConnect();
160 already_AddRefed<nsIURI> ResolveURI(const char* uri);
162 NSLocationType mType;
163 nsILocalFile* mFile;
164 const char* mPath;
165 nsCOMPtr<nsIURI> mManifestURI;
166 nsCOMPtr<nsIXPConnect> mXPConnect;
169 virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
170 char *const * argv, bool platform,
171 bool contentaccessible) = 0;
172 virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
173 char *const * argv, bool platform,
174 bool contentaccessible) = 0;
175 virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
176 char *const * argv, bool platform,
177 bool contentaccessible) = 0;
178 virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno,
179 char *const * argv, bool platform,
180 bool contentaccessible) = 0;
181 virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno,
182 char *const * argv, bool platform,
183 bool contentaccessible) = 0;
184 virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
185 char *const * argv, bool platform,
186 bool contentaccessible) = 0;
187 virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
188 char *const * argv, bool platform,
189 bool contentaccessible) = 0;
191 // Available flags
192 enum {
193 // This is a "platform" package (e.g. chrome://global-platform/).
194 // Appends one of win/ unix/ mac/ to the base URI.
195 PLATFORM_PACKAGE = 1 << 0,
197 // This package should use the new XPCNativeWrappers to separate
198 // content from chrome. This flag is currently unused (because we call
199 // into xpconnect at registration time).
200 XPCNATIVEWRAPPERS = 1 << 1,
202 // Content script may access files in this package
203 CONTENT_ACCESSIBLE = 1 << 2
206 PRBool mInitialized;
208 // "Override" table (chrome URI string -> real URI)
209 nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
212 #endif // nsChromeRegistry_h