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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : * Original Author: David W. Hyatt (hyatt@netscape.com)
24 : * Benjamin Smedberg <benjamin@smedbergs.us>
25 : *
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.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsChromeRegistry_h
41 : #define nsChromeRegistry_h
42 :
43 : #include "nsIChromeRegistry.h"
44 : #include "nsIToolkitChromeRegistry.h"
45 : #include "nsIObserver.h"
46 : #include "nsWeakReference.h"
47 : #include "nsIPrefBranch.h"
48 :
49 : #ifdef MOZ_XUL
50 : #include "nsIXULOverlayProvider.h"
51 : #endif
52 :
53 : #include "pldhash.h"
54 :
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"
63 :
64 : #include "mozilla/Omnijar.h"
65 : #include "mozilla/FileLocation.h"
66 :
67 : class nsIDOMWindow;
68 : class nsIURL;
69 :
70 : // The chrome registry is actually split between nsChromeRegistryChrome and
71 : // nsChromeRegistryContent. The work/data that is common to both resides in
72 : // the shared nsChromeRegistry implementation, with operations that only make
73 : // sense for one side erroring out in the other.
74 :
75 : // for component registration
76 : // {47049e42-1d87-482a-984d-56ae185e367a}
77 : #define NS_CHROMEREGISTRY_CID \
78 : { 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
79 :
80 : class nsChromeRegistry : public nsIToolkitChromeRegistry,
81 : #ifdef MOZ_XUL
82 : public nsIXULOverlayProvider,
83 : #endif
84 : public nsIObserver,
85 : public nsSupportsWeakReference
86 : {
87 : public:
88 : NS_DECL_ISUPPORTS
89 :
90 : // nsIXULChromeRegistry methods:
91 : NS_IMETHOD ReloadChrome();
92 : NS_IMETHOD RefreshSkins();
93 : NS_IMETHOD AllowScriptsForPackage(nsIURI* url,
94 : bool* _retval NS_OUTPARAM);
95 : NS_IMETHOD AllowContentToAccess(nsIURI* url,
96 : bool* _retval NS_OUTPARAM);
97 :
98 : // nsIChromeRegistry methods:
99 : NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI);
100 : NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult);
101 :
102 : // nsChromeRegistry methods:
103 1419 : nsChromeRegistry() : mInitialized(false) { }
104 : virtual ~nsChromeRegistry();
105 :
106 : virtual nsresult Init();
107 :
108 : static already_AddRefed<nsIChromeRegistry> GetService();
109 :
110 : static nsChromeRegistry* gChromeRegistry;
111 :
112 : static nsresult Canonify(nsIURL* aChromeURL);
113 :
114 : protected:
115 : void FlushSkinCaches();
116 : void FlushAllCaches();
117 :
118 : // Update the selected locale used by the chrome registry, and fire a
119 : // notification about this change
120 : virtual nsresult UpdateSelectedLocale() = 0;
121 :
122 : static void LogMessage(const char* aMsg, ...);
123 : static void LogMessageWithContext(nsIURI* aURL, PRUint32 aLineNumber, PRUint32 flags,
124 : const char* aMsg, ...);
125 :
126 : virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
127 : const nsCString& aProvider,
128 : const nsCString& aPath) = 0;
129 : virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
130 : PRUint32* aFlags) = 0;
131 :
132 : nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
133 :
134 : static nsresult RefreshWindow(nsIDOMWindow* aWindow);
135 : static nsresult GetProviderAndPath(nsIURL* aChromeURL,
136 : nsACString& aProvider, nsACString& aPath);
137 :
138 : public:
139 : static already_AddRefed<nsChromeRegistry> GetSingleton();
140 :
141 : struct ManifestProcessingContext
142 : {
143 99082 : ManifestProcessingContext(NSLocationType aType, mozilla::FileLocation &aFile)
144 : : mType(aType)
145 99082 : , mFile(aFile)
146 99082 : { }
147 :
148 99082 : ~ManifestProcessingContext()
149 99082 : { }
150 :
151 : nsIURI* GetManifestURI();
152 : nsIXPConnect* GetXPConnect();
153 :
154 : already_AddRefed<nsIURI> ResolveURI(const char* uri);
155 :
156 : NSLocationType mType;
157 : mozilla::FileLocation mFile;
158 : nsCOMPtr<nsIURI> mManifestURI;
159 : nsCOMPtr<nsIXPConnect> mXPConnect;
160 : };
161 :
162 : virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
163 : char *const * argv, bool platform,
164 : bool contentaccessible) = 0;
165 : virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
166 : char *const * argv, bool platform,
167 : bool contentaccessible) = 0;
168 : virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
169 : char *const * argv, bool platform,
170 : bool contentaccessible) = 0;
171 : virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno,
172 : char *const * argv, bool platform,
173 : bool contentaccessible) = 0;
174 : virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno,
175 : char *const * argv, bool platform,
176 : bool contentaccessible) = 0;
177 : virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
178 : char *const * argv, bool platform,
179 : bool contentaccessible) = 0;
180 : virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
181 : char *const * argv, bool platform,
182 : bool contentaccessible) = 0;
183 :
184 : // Available flags
185 : enum {
186 : // This is a "platform" package (e.g. chrome://global-platform/).
187 : // Appends one of win/ unix/ mac/ to the base URI.
188 : PLATFORM_PACKAGE = 1 << 0,
189 :
190 : // This package should use the new XPCNativeWrappers to separate
191 : // content from chrome. This flag is currently unused (because we call
192 : // into xpconnect at registration time).
193 : XPCNATIVEWRAPPERS = 1 << 1,
194 :
195 : // Content script may access files in this package
196 : CONTENT_ACCESSIBLE = 1 << 2
197 : };
198 :
199 : bool mInitialized;
200 :
201 : // "Override" table (chrome URI string -> real URI)
202 : nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
203 : };
204 :
205 : #endif // nsChromeRegistry_h
|