1 : /* -*- Mode: C++; tab-width: 8; 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 : * the Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2010
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Josh Matthews <josh@joshmatthews.net> (Initial Developer)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "RegistryMessageUtils.h"
40 : #include "nsChromeRegistry.h"
41 : #include "nsChromeRegistryContent.h"
42 : #include "nsString.h"
43 : #include "nsNetUtil.h"
44 : #include "nsResProtocolHandler.h"
45 :
46 0 : nsChromeRegistryContent::nsChromeRegistryContent()
47 : {
48 0 : mPackagesHash.Init();
49 0 : }
50 :
51 : void
52 0 : nsChromeRegistryContent::RegisterRemoteChrome(
53 : const nsTArray<ChromePackage>& aPackages,
54 : const nsTArray<ResourceMapping>& aResources,
55 : const nsTArray<OverrideMapping>& aOverrides,
56 : const nsACString& aLocale)
57 : {
58 0 : NS_ABORT_IF_FALSE(mLocale == nsDependentCString(""),
59 : "RegisterChrome twice?");
60 :
61 0 : for (PRUint32 i = aPackages.Length(); i > 0; ) {
62 0 : --i;
63 0 : RegisterPackage(aPackages[i]);
64 : }
65 :
66 0 : for (PRUint32 i = aResources.Length(); i > 0; ) {
67 0 : --i;
68 0 : RegisterResource(aResources[i]);
69 : }
70 :
71 0 : for (PRUint32 i = aOverrides.Length(); i > 0; ) {
72 0 : --i;
73 0 : RegisterOverride(aOverrides[i]);
74 : }
75 :
76 0 : mLocale = aLocale;
77 0 : }
78 :
79 : void
80 0 : nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage)
81 : {
82 0 : nsCOMPtr<nsIIOService> io (do_GetIOService());
83 0 : if (!io)
84 : return;
85 :
86 0 : nsCOMPtr<nsIURI> content, locale, skin;
87 :
88 0 : if (aPackage.contentBaseURI.spec.Length()) {
89 0 : nsresult rv = NS_NewURI(getter_AddRefs(content),
90 : aPackage.contentBaseURI.spec,
91 : aPackage.contentBaseURI.charset.get(),
92 0 : nsnull, io);
93 0 : if (NS_FAILED(rv))
94 : return;
95 : }
96 0 : if (aPackage.localeBaseURI.spec.Length()) {
97 0 : nsresult rv = NS_NewURI(getter_AddRefs(locale),
98 : aPackage.localeBaseURI.spec,
99 : aPackage.localeBaseURI.charset.get(),
100 0 : nsnull, io);
101 0 : if (NS_FAILED(rv))
102 : return;
103 : }
104 0 : if (aPackage.skinBaseURI.spec.Length()) {
105 0 : nsCOMPtr<nsIURI> skinBaseURI;
106 0 : nsresult rv = NS_NewURI(getter_AddRefs(skin),
107 : aPackage.skinBaseURI.spec,
108 : aPackage.skinBaseURI.charset.get(),
109 0 : nsnull, io);
110 0 : if (NS_FAILED(rv))
111 : return;
112 : }
113 :
114 0 : PackageEntry* entry = new PackageEntry;
115 0 : entry->flags = aPackage.flags;
116 0 : entry->contentBaseURI = content;
117 0 : entry->localeBaseURI = locale;
118 0 : entry->skinBaseURI = skin;
119 :
120 0 : nsresult rv = mPackagesHash.Put(aPackage.package, entry);
121 0 : if (NS_FAILED(rv))
122 : return;
123 : }
124 :
125 : void
126 0 : nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource)
127 : {
128 0 : nsCOMPtr<nsIIOService> io (do_GetIOService());
129 0 : if (!io)
130 : return;
131 :
132 0 : nsCOMPtr<nsIProtocolHandler> ph;
133 0 : nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph));
134 0 : if (NS_FAILED(rv))
135 : return;
136 :
137 0 : nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph));
138 0 : if (!rph)
139 : return;
140 :
141 0 : nsCOMPtr<nsIURI> resolvedURI;
142 0 : if (aResource.resolvedURI.spec.Length()) {
143 0 : nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI),
144 : aResource.resolvedURI.spec,
145 : aResource.resolvedURI.charset.get(),
146 0 : nsnull, io);
147 0 : if (NS_FAILED(rv))
148 : return;
149 : }
150 :
151 0 : rv = rph->SetSubstitution(aResource.resource, resolvedURI);
152 0 : if (NS_FAILED(rv))
153 : return;
154 : }
155 :
156 : void
157 0 : nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride)
158 : {
159 0 : nsCOMPtr<nsIIOService> io (do_GetIOService());
160 0 : if (!io)
161 : return;
162 :
163 0 : nsCOMPtr<nsIURI> chromeURI, overrideURI;
164 0 : nsresult rv = NS_NewURI(getter_AddRefs(chromeURI),
165 : aOverride.originalURI.spec,
166 : aOverride.originalURI.charset.get(),
167 0 : nsnull, io);
168 0 : if (NS_FAILED(rv))
169 : return;
170 :
171 0 : rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
172 0 : aOverride.overrideURI.charset.get(), nsnull, io);
173 0 : if (NS_FAILED(rv))
174 : return;
175 :
176 0 : mOverrideTable.Put(chromeURI, overrideURI);
177 : }
178 :
179 : nsIURI*
180 0 : nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage,
181 : const nsCString& aProvider,
182 : const nsCString& aPath)
183 : {
184 : PackageEntry* entry;
185 0 : if (!mPackagesHash.Get(aPackage, &entry)) {
186 0 : return nsnull;
187 : }
188 :
189 0 : if (aProvider.EqualsLiteral("locale")) {
190 0 : return entry->localeBaseURI;
191 : }
192 0 : else if (aProvider.EqualsLiteral("skin")) {
193 0 : return entry->skinBaseURI;
194 : }
195 0 : else if (aProvider.EqualsLiteral("content")) {
196 0 : return entry->contentBaseURI;
197 : }
198 0 : return nsnull;
199 : }
200 :
201 : nsresult
202 0 : nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
203 : PRUint32* aFlags)
204 : {
205 : PackageEntry* entry;
206 0 : if (!mPackagesHash.Get(aPackage, &entry)) {
207 0 : return NS_ERROR_FAILURE;
208 : }
209 0 : *aFlags = entry->flags;
210 0 : return NS_OK;
211 : }
212 :
213 : // All functions following only make sense in chrome, and therefore assert
214 :
215 : #define CONTENT_NOTREACHED() \
216 : NS_NOTREACHED("Content should not be calling this")
217 :
218 : #define CONTENT_NOT_IMPLEMENTED() \
219 : CONTENT_NOTREACHED(); \
220 : return NS_ERROR_NOT_IMPLEMENTED;
221 :
222 : NS_IMETHODIMP
223 0 : nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage,
224 : nsIUTF8StringEnumerator* *aResult)
225 : {
226 0 : CONTENT_NOT_IMPLEMENTED();
227 : }
228 :
229 : NS_IMETHODIMP
230 0 : nsChromeRegistryContent::CheckForOSAccessibility()
231 : {
232 0 : CONTENT_NOT_IMPLEMENTED();
233 : }
234 :
235 : NS_IMETHODIMP
236 0 : nsChromeRegistryContent::CheckForNewChrome()
237 : {
238 0 : CONTENT_NOT_IMPLEMENTED();
239 : }
240 :
241 : NS_IMETHODIMP
242 0 : nsChromeRegistryContent::IsLocaleRTL(const nsACString& package,
243 : bool *aResult)
244 : {
245 0 : CONTENT_NOT_IMPLEMENTED();
246 : }
247 :
248 : NS_IMETHODIMP
249 0 : nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
250 : nsACString& aLocale)
251 : {
252 0 : if (aPackage != nsDependentCString("global")) {
253 0 : NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
254 0 : return NS_ERROR_NOT_AVAILABLE;
255 : }
256 0 : aLocale = mLocale;
257 0 : return NS_OK;
258 : }
259 :
260 : NS_IMETHODIMP
261 0 : nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
262 : const PRUnichar* aData)
263 : {
264 0 : CONTENT_NOT_IMPLEMENTED();
265 : }
266 :
267 : NS_IMETHODIMP
268 0 : nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL,
269 : nsISimpleEnumerator **aResult)
270 : {
271 0 : CONTENT_NOT_IMPLEMENTED();
272 : }
273 :
274 : NS_IMETHODIMP
275 0 : nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL,
276 : nsISimpleEnumerator **aResult)
277 : {
278 0 : CONTENT_NOT_IMPLEMENTED();
279 : }
280 :
281 0 : nsresult nsChromeRegistryContent::UpdateSelectedLocale()
282 : {
283 0 : CONTENT_NOT_IMPLEMENTED();
284 : }
285 :
286 : void
287 0 : nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
288 : int lineno, char *const * argv,
289 : bool platform, bool contentaccessible)
290 : {
291 0 : CONTENT_NOTREACHED();
292 0 : }
293 :
294 : void
295 0 : nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
296 : int lineno,
297 : char *const * argv, bool platform,
298 : bool contentaccessible)
299 : {
300 0 : CONTENT_NOTREACHED();
301 0 : }
302 :
303 : void
304 0 : nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
305 : int lineno,
306 : char *const * argv, bool platform,
307 : bool contentaccessible)
308 : {
309 0 : CONTENT_NOTREACHED();
310 0 : }
311 :
312 : void
313 0 : nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno,
314 : char *const * argv, bool platform,
315 : bool contentaccessible)
316 : {
317 0 : CONTENT_NOTREACHED();
318 0 : }
319 :
320 : void
321 0 : nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx,
322 : int lineno,
323 : char *const * argv, bool platform,
324 : bool contentaccessible)
325 : {
326 0 : CONTENT_NOTREACHED();
327 0 : }
328 :
329 : void
330 0 : nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
331 : int lineno,
332 : char *const * argv, bool platform,
333 : bool contentaccessible)
334 : {
335 0 : CONTENT_NOTREACHED();
336 0 : }
337 :
338 : void
339 0 : nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
340 : int lineno,
341 : char *const * argv, bool platform,
342 : bool contentaccessible)
343 : {
344 0 : CONTENT_NOTREACHED();
345 0 : }
|