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"
10 #include "nsNetUtil.h"
11 #include "nsIResProtocolHandler.h"
13 nsChromeRegistryContent::nsChromeRegistryContent()
18 nsChromeRegistryContent::RegisterRemoteChrome(
19 const InfallibleTArray
<ChromePackage
>& aPackages
,
20 const InfallibleTArray
<ResourceMapping
>& aResources
,
21 const InfallibleTArray
<OverrideMapping
>& aOverrides
,
22 const nsACString
& aLocale
,
25 NS_ABORT_IF_FALSE(aReset
|| mLocale
.IsEmpty(),
26 "RegisterChrome twice?");
29 mPackagesHash
.Clear();
30 mOverrideTable
.Clear();
31 // XXX Can't clear resources.
34 for (uint32_t i
= aPackages
.Length(); i
> 0; ) {
36 RegisterPackage(aPackages
[i
]);
39 for (uint32_t i
= aResources
.Length(); i
> 0; ) {
41 RegisterResource(aResources
[i
]);
44 for (uint32_t i
= aOverrides
.Length(); i
> 0; ) {
46 RegisterOverride(aOverrides
[i
]);
53 nsChromeRegistryContent::RegisterPackage(const ChromePackage
& aPackage
)
55 nsCOMPtr
<nsIIOService
> io (do_GetIOService());
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(),
69 if (aPackage
.localeBaseURI
.spec
.Length()) {
70 nsresult rv
= NS_NewURI(getter_AddRefs(locale
),
71 aPackage
.localeBaseURI
.spec
,
72 aPackage
.localeBaseURI
.charset
.get(),
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(),
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
);
97 nsChromeRegistryContent::RegisterResource(const ResourceMapping
& aResource
)
99 nsCOMPtr
<nsIIOService
> io (do_GetIOService());
103 nsCOMPtr
<nsIProtocolHandler
> ph
;
104 nsresult rv
= io
->GetProtocolHandler("resource", getter_AddRefs(ph
));
108 nsCOMPtr
<nsIResProtocolHandler
> rph (do_QueryInterface(ph
));
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(),
122 rv
= rph
->SetSubstitution(aResource
.resource
, resolvedURI
);
128 nsChromeRegistryContent::RegisterOverride(const OverrideMapping
& aOverride
)
130 nsCOMPtr
<nsIIOService
> io (do_GetIOService());
134 nsCOMPtr
<nsIURI
> chromeURI
, overrideURI
;
135 nsresult rv
= NS_NewURI(getter_AddRefs(chromeURI
),
136 aOverride
.originalURI
.spec
,
137 aOverride
.originalURI
.charset
.get(),
142 rv
= NS_NewURI(getter_AddRefs(overrideURI
), aOverride
.overrideURI
.spec
,
143 aOverride
.overrideURI
.charset
.get(), nullptr, io
);
147 mOverrideTable
.Put(chromeURI
, overrideURI
);
151 nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString
& aPackage
,
152 const nsCString
& aProvider
,
153 const nsCString
& aPath
)
156 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
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
;
173 nsChromeRegistryContent::GetFlagsFromPackage(const nsCString
& aPackage
,
177 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
178 return NS_ERROR_FAILURE
;
180 *aFlags
= entry
->flags
;
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;
194 nsChromeRegistryContent::GetLocalesForPackage(const nsACString
& aPackage
,
195 nsIUTF8StringEnumerator
* *aResult
)
197 CONTENT_NOT_IMPLEMENTED();
201 nsChromeRegistryContent::CheckForOSAccessibility()
203 CONTENT_NOT_IMPLEMENTED();
207 nsChromeRegistryContent::CheckForNewChrome()
209 CONTENT_NOT_IMPLEMENTED();
213 nsChromeRegistryContent::IsLocaleRTL(const nsACString
& package
,
216 CONTENT_NOT_IMPLEMENTED();
220 nsChromeRegistryContent::GetSelectedLocale(const nsACString
& aPackage
,
223 if (aPackage
!= nsDependentCString("global")) {
224 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
225 return NS_ERROR_NOT_AVAILABLE
;
232 nsChromeRegistryContent::Observe(nsISupports
* aSubject
, const char* aTopic
,
233 const char16_t
* aData
)
235 CONTENT_NOT_IMPLEMENTED();
239 nsChromeRegistryContent::GetStyleOverlays(nsIURI
*aChromeURL
,
240 nsISimpleEnumerator
**aResult
)
242 CONTENT_NOT_IMPLEMENTED();
246 nsChromeRegistryContent::GetXULOverlays(nsIURI
*aChromeURL
,
247 nsISimpleEnumerator
**aResult
)
249 CONTENT_NOT_IMPLEMENTED();
252 nsresult
nsChromeRegistryContent::UpdateSelectedLocale()
254 CONTENT_NOT_IMPLEMENTED();
258 nsChromeRegistryContent::ManifestContent(ManifestProcessingContext
& cx
,
259 int lineno
, char *const * argv
,
260 bool platform
, bool contentaccessible
)
262 CONTENT_NOTREACHED();
266 nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext
& cx
,
268 char *const * argv
, bool platform
,
269 bool contentaccessible
)
271 CONTENT_NOTREACHED();
275 nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext
& cx
,
277 char *const * argv
, bool platform
,
278 bool contentaccessible
)
280 CONTENT_NOTREACHED();
284 nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext
& cx
, int lineno
,
285 char *const * argv
, bool platform
,
286 bool contentaccessible
)
288 CONTENT_NOTREACHED();
292 nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext
& cx
,
294 char *const * argv
, bool platform
,
295 bool contentaccessible
)
297 CONTENT_NOTREACHED();
301 nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext
& cx
,
303 char *const * argv
, bool platform
,
304 bool contentaccessible
)
306 CONTENT_NOTREACHED();
310 nsChromeRegistryContent::ManifestResource(ManifestProcessingContext
& cx
,
312 char *const * argv
, bool platform
,
313 bool contentaccessible
)
315 CONTENT_NOTREACHED();