Bumping manifests a=b2g-bump
[gecko.git] / chrome / nsChromeRegistryContent.cpp
blob3ea6f42ffcb52b998cf7f868427327960f19a6d5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sts=2 sw=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "RegistryMessageUtils.h"
8 #include "nsChromeRegistryContent.h"
9 #include "nsString.h"
10 #include "nsNetUtil.h"
11 #include "nsIResProtocolHandler.h"
13 nsChromeRegistryContent::nsChromeRegistryContent()
17 void
18 nsChromeRegistryContent::RegisterRemoteChrome(
19 const InfallibleTArray<ChromePackage>& aPackages,
20 const InfallibleTArray<ResourceMapping>& aResources,
21 const InfallibleTArray<OverrideMapping>& aOverrides,
22 const nsACString& aLocale,
23 bool aReset)
25 NS_ABORT_IF_FALSE(aReset || mLocale.IsEmpty(),
26 "RegisterChrome twice?");
28 if (aReset) {
29 mPackagesHash.Clear();
30 mOverrideTable.Clear();
31 // XXX Can't clear resources.
34 for (uint32_t i = aPackages.Length(); i > 0; ) {
35 --i;
36 RegisterPackage(aPackages[i]);
39 for (uint32_t i = aResources.Length(); i > 0; ) {
40 --i;
41 RegisterResource(aResources[i]);
44 for (uint32_t i = aOverrides.Length(); i > 0; ) {
45 --i;
46 RegisterOverride(aOverrides[i]);
49 mLocale = aLocale;
52 void
53 nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage)
55 nsCOMPtr<nsIIOService> io (do_GetIOService());
56 if (!io)
57 return;
59 nsCOMPtr<nsIURI> content, locale, skin;
61 if (aPackage.contentBaseURI.spec.Length()) {
62 nsresult rv = NS_NewURI(getter_AddRefs(content),
63 aPackage.contentBaseURI.spec,
64 aPackage.contentBaseURI.charset.get(),
65 nullptr, io);
66 if (NS_FAILED(rv))
67 return;
69 if (aPackage.localeBaseURI.spec.Length()) {
70 nsresult rv = NS_NewURI(getter_AddRefs(locale),
71 aPackage.localeBaseURI.spec,
72 aPackage.localeBaseURI.charset.get(),
73 nullptr, io);
74 if (NS_FAILED(rv))
75 return;
77 if (aPackage.skinBaseURI.spec.Length()) {
78 nsCOMPtr<nsIURI> skinBaseURI;
79 nsresult rv = NS_NewURI(getter_AddRefs(skin),
80 aPackage.skinBaseURI.spec,
81 aPackage.skinBaseURI.charset.get(),
82 nullptr, io);
83 if (NS_FAILED(rv))
84 return;
87 PackageEntry* entry = new PackageEntry;
88 entry->flags = aPackage.flags;
89 entry->contentBaseURI = content;
90 entry->localeBaseURI = locale;
91 entry->skinBaseURI = skin;
93 mPackagesHash.Put(aPackage.package, entry);
96 void
97 nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource)
99 nsCOMPtr<nsIIOService> io (do_GetIOService());
100 if (!io)
101 return;
103 nsCOMPtr<nsIProtocolHandler> ph;
104 nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph));
105 if (NS_FAILED(rv))
106 return;
108 nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph));
109 if (!rph)
110 return;
112 nsCOMPtr<nsIURI> resolvedURI;
113 if (aResource.resolvedURI.spec.Length()) {
114 nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI),
115 aResource.resolvedURI.spec,
116 aResource.resolvedURI.charset.get(),
117 nullptr, io);
118 if (NS_FAILED(rv))
119 return;
122 rv = rph->SetSubstitution(aResource.resource, resolvedURI);
123 if (NS_FAILED(rv))
124 return;
127 void
128 nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride)
130 nsCOMPtr<nsIIOService> io (do_GetIOService());
131 if (!io)
132 return;
134 nsCOMPtr<nsIURI> chromeURI, overrideURI;
135 nsresult rv = NS_NewURI(getter_AddRefs(chromeURI),
136 aOverride.originalURI.spec,
137 aOverride.originalURI.charset.get(),
138 nullptr, io);
139 if (NS_FAILED(rv))
140 return;
142 rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
143 aOverride.overrideURI.charset.get(), nullptr, io);
144 if (NS_FAILED(rv))
145 return;
147 mOverrideTable.Put(chromeURI, overrideURI);
150 nsIURI*
151 nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage,
152 const nsCString& aProvider,
153 const nsCString& aPath)
155 PackageEntry* entry;
156 if (!mPackagesHash.Get(aPackage, &entry)) {
157 return nullptr;
160 if (aProvider.EqualsLiteral("locale")) {
161 return entry->localeBaseURI;
163 else if (aProvider.EqualsLiteral("skin")) {
164 return entry->skinBaseURI;
166 else if (aProvider.EqualsLiteral("content")) {
167 return entry->contentBaseURI;
169 return nullptr;
172 nsresult
173 nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
174 uint32_t* aFlags)
176 PackageEntry* entry;
177 if (!mPackagesHash.Get(aPackage, &entry)) {
178 return NS_ERROR_FAILURE;
180 *aFlags = entry->flags;
181 return NS_OK;
184 // All functions following only make sense in chrome, and therefore assert
186 #define CONTENT_NOTREACHED() \
187 NS_NOTREACHED("Content should not be calling this")
189 #define CONTENT_NOT_IMPLEMENTED() \
190 CONTENT_NOTREACHED(); \
191 return NS_ERROR_NOT_IMPLEMENTED;
193 NS_IMETHODIMP
194 nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage,
195 nsIUTF8StringEnumerator* *aResult)
197 CONTENT_NOT_IMPLEMENTED();
200 NS_IMETHODIMP
201 nsChromeRegistryContent::CheckForOSAccessibility()
203 CONTENT_NOT_IMPLEMENTED();
206 NS_IMETHODIMP
207 nsChromeRegistryContent::CheckForNewChrome()
209 CONTENT_NOT_IMPLEMENTED();
212 NS_IMETHODIMP
213 nsChromeRegistryContent::IsLocaleRTL(const nsACString& package,
214 bool *aResult)
216 CONTENT_NOT_IMPLEMENTED();
219 NS_IMETHODIMP
220 nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
221 nsACString& aLocale)
223 if (aPackage != nsDependentCString("global")) {
224 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
225 return NS_ERROR_NOT_AVAILABLE;
227 aLocale = mLocale;
228 return NS_OK;
231 NS_IMETHODIMP
232 nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
233 const char16_t* aData)
235 CONTENT_NOT_IMPLEMENTED();
238 NS_IMETHODIMP
239 nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL,
240 nsISimpleEnumerator **aResult)
242 CONTENT_NOT_IMPLEMENTED();
245 NS_IMETHODIMP
246 nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL,
247 nsISimpleEnumerator **aResult)
249 CONTENT_NOT_IMPLEMENTED();
252 nsresult nsChromeRegistryContent::UpdateSelectedLocale()
254 CONTENT_NOT_IMPLEMENTED();
257 void
258 nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
259 int lineno, char *const * argv,
260 bool platform, bool contentaccessible)
262 CONTENT_NOTREACHED();
265 void
266 nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
267 int lineno,
268 char *const * argv, bool platform,
269 bool contentaccessible)
271 CONTENT_NOTREACHED();
274 void
275 nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
276 int lineno,
277 char *const * argv, bool platform,
278 bool contentaccessible)
280 CONTENT_NOTREACHED();
283 void
284 nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno,
285 char *const * argv, bool platform,
286 bool contentaccessible)
288 CONTENT_NOTREACHED();
291 void
292 nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx,
293 int lineno,
294 char *const * argv, bool platform,
295 bool contentaccessible)
297 CONTENT_NOTREACHED();
300 void
301 nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
302 int lineno,
303 char *const * argv, bool platform,
304 bool contentaccessible)
306 CONTENT_NOTREACHED();
309 void
310 nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
311 int lineno,
312 char *const * argv, bool platform,
313 bool contentaccessible)
315 CONTENT_NOTREACHED();