Bug 634734 - Fennec ASSERTION: mFUnitsConvFactor not valid: mFUnitsConvFactor > 0...
[mozilla-central.git] / chrome / src / nsChromeRegistryContent.cpp
blobd5982833e9fe71cc5aee2a2572eebe7c695b938e
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
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 * the Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Josh Matthews <josh@joshmatthews.net> (Initial Developer)
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.
37 * ***** END LICENSE BLOCK ***** */
39 #include "RegistryMessageUtils.h"
40 #include "nsChromeRegistry.h"
41 #include "nsChromeRegistryContent.h"
42 #include "nsString.h"
43 #include "nsNetUtil.h"
44 #include "nsResProtocolHandler.h"
46 nsChromeRegistryContent::nsChromeRegistryContent()
48 mPackagesHash.Init();
51 void
52 nsChromeRegistryContent::RegisterRemoteChrome(
53 const nsTArray<ChromePackage>& aPackages,
54 const nsTArray<ResourceMapping>& aResources,
55 const nsTArray<OverrideMapping>& aOverrides,
56 const nsACString& aLocale)
58 NS_ABORT_IF_FALSE(mLocale == nsDependentCString(""),
59 "RegisterChrome twice?");
61 for (PRUint32 i = aPackages.Length(); i > 0; ) {
62 --i;
63 RegisterPackage(aPackages[i]);
66 for (PRUint32 i = aResources.Length(); i > 0; ) {
67 --i;
68 RegisterResource(aResources[i]);
71 for (PRUint32 i = aOverrides.Length(); i > 0; ) {
72 --i;
73 RegisterOverride(aOverrides[i]);
76 mLocale = aLocale;
79 void
80 nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage)
82 nsCOMPtr<nsIIOService> io (do_GetIOService());
83 if (!io)
84 return;
86 nsCOMPtr<nsIURI> content, locale, skin;
88 if (aPackage.contentBaseURI.spec.Length()) {
89 nsresult rv = NS_NewURI(getter_AddRefs(content),
90 aPackage.contentBaseURI.spec,
91 aPackage.contentBaseURI.charset.get(),
92 nsnull, io);
93 if (NS_FAILED(rv))
94 return;
96 if (aPackage.localeBaseURI.spec.Length()) {
97 nsresult rv = NS_NewURI(getter_AddRefs(locale),
98 aPackage.localeBaseURI.spec,
99 aPackage.localeBaseURI.charset.get(),
100 nsnull, io);
101 if (NS_FAILED(rv))
102 return;
104 if (aPackage.skinBaseURI.spec.Length()) {
105 nsCOMPtr<nsIURI> skinBaseURI;
106 nsresult rv = NS_NewURI(getter_AddRefs(skin),
107 aPackage.skinBaseURI.spec,
108 aPackage.skinBaseURI.charset.get(),
109 nsnull, io);
110 if (NS_FAILED(rv))
111 return;
114 PackageEntry* entry = new PackageEntry;
115 entry->flags = aPackage.flags;
116 entry->contentBaseURI = content;
117 entry->localeBaseURI = locale;
118 entry->skinBaseURI = skin;
120 nsresult rv = mPackagesHash.Put(aPackage.package, entry);
121 if (NS_FAILED(rv))
122 return;
125 void
126 nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource)
128 nsCOMPtr<nsIIOService> io (do_GetIOService());
129 if (!io)
130 return;
132 nsCOMPtr<nsIProtocolHandler> ph;
133 nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph));
134 if (NS_FAILED(rv))
135 return;
137 nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph));
138 if (!rph)
139 return;
141 nsCOMPtr<nsIURI> resolvedURI;
142 if (aResource.resolvedURI.spec.Length()) {
143 nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI),
144 aResource.resolvedURI.spec,
145 aResource.resolvedURI.charset.get(),
146 nsnull, io);
147 if (NS_FAILED(rv))
148 return;
151 rv = rph->SetSubstitution(aResource.resource, resolvedURI);
152 if (NS_FAILED(rv))
153 return;
156 void
157 nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride)
159 nsCOMPtr<nsIIOService> io (do_GetIOService());
160 if (!io)
161 return;
163 nsCOMPtr<nsIURI> chromeURI, overrideURI;
164 nsresult rv = NS_NewURI(getter_AddRefs(chromeURI),
165 aOverride.originalURI.spec,
166 aOverride.originalURI.charset.get(),
167 nsnull, io);
168 if (NS_FAILED(rv))
169 return;
171 rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
172 aOverride.overrideURI.charset.get(), nsnull, io);
173 if (NS_FAILED(rv))
174 return;
176 mOverrideTable.Put(chromeURI, overrideURI);
179 nsIURI*
180 nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage,
181 const nsCString& aProvider,
182 const nsCString& aPath)
184 PackageEntry* entry;
185 if (!mPackagesHash.Get(aPackage, &entry)) {
186 return nsnull;
189 if (aProvider.EqualsLiteral("locale")) {
190 return entry->localeBaseURI;
192 else if (aProvider.EqualsLiteral("skin")) {
193 return entry->skinBaseURI;
195 else if (aProvider.EqualsLiteral("content")) {
196 return entry->contentBaseURI;
198 return nsnull;
201 nsresult
202 nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
203 PRUint32* aFlags)
205 PackageEntry* entry;
206 if (!mPackagesHash.Get(aPackage, &entry)) {
207 return NS_ERROR_FAILURE;
209 *aFlags = entry->flags;
210 return NS_OK;
213 // All functions following only make sense in chrome, and therefore assert
215 #define CONTENT_NOTREACHED() \
216 NS_NOTREACHED("Content should not be calling this")
218 #define CONTENT_NOT_IMPLEMENTED() \
219 CONTENT_NOTREACHED(); \
220 return NS_ERROR_NOT_IMPLEMENTED;
222 NS_IMETHODIMP
223 nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage,
224 nsIUTF8StringEnumerator* *aResult)
226 CONTENT_NOT_IMPLEMENTED();
229 NS_IMETHODIMP
230 nsChromeRegistryContent::CheckForOSAccessibility()
232 CONTENT_NOT_IMPLEMENTED();
235 NS_IMETHODIMP
236 nsChromeRegistryContent::CheckForNewChrome()
238 CONTENT_NOT_IMPLEMENTED();
241 NS_IMETHODIMP
242 nsChromeRegistryContent::IsLocaleRTL(const nsACString& package,
243 PRBool *aResult)
245 CONTENT_NOT_IMPLEMENTED();
248 NS_IMETHODIMP
249 nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
250 nsACString& aLocale)
252 if (aPackage != nsDependentCString("global")) {
253 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
254 return NS_ERROR_NOT_AVAILABLE;
256 aLocale = mLocale;
257 return NS_OK;
260 NS_IMETHODIMP
261 nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
262 const PRUnichar* aData)
264 CONTENT_NOT_IMPLEMENTED();
267 NS_IMETHODIMP
268 nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL,
269 nsISimpleEnumerator **aResult)
271 CONTENT_NOT_IMPLEMENTED();
274 NS_IMETHODIMP
275 nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL,
276 nsISimpleEnumerator **aResult)
278 CONTENT_NOT_IMPLEMENTED();
281 void nsChromeRegistryContent::UpdateSelectedLocale()
283 CONTENT_NOTREACHED();
286 void
287 nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
288 int lineno, char *const * argv,
289 bool platform, bool contentaccessible)
291 CONTENT_NOTREACHED();
294 void
295 nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
296 int lineno,
297 char *const * argv, bool platform,
298 bool contentaccessible)
300 CONTENT_NOTREACHED();
303 void
304 nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
305 int lineno,
306 char *const * argv, bool platform,
307 bool contentaccessible)
309 CONTENT_NOTREACHED();
312 void
313 nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno,
314 char *const * argv, bool platform,
315 bool contentaccessible)
317 CONTENT_NOTREACHED();
320 void
321 nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx,
322 int lineno,
323 char *const * argv, bool platform,
324 bool contentaccessible)
326 CONTENT_NOTREACHED();
329 void
330 nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
331 int lineno,
332 char *const * argv, bool platform,
333 bool contentaccessible)
335 CONTENT_NOTREACHED();
338 void
339 nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
340 int lineno,
341 char *const * argv, bool platform,
342 bool contentaccessible)
344 CONTENT_NOTREACHED();