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"
12 nsChromeRegistryContent::nsChromeRegistryContent() {}
14 void nsChromeRegistryContent::RegisterRemoteChrome(
15 const nsTArray
<ChromePackage
>& aPackages
,
16 const nsTArray
<SubstitutionMapping
>& aSubstitutions
,
17 const nsTArray
<OverrideMapping
>& aOverrides
, const nsACString
& aLocale
,
19 MOZ_ASSERT(aReset
|| mLocale
.IsEmpty(), "RegisterChrome twice?");
22 mPackagesHash
.Clear();
23 mOverrideTable
.Clear();
24 // XXX Can't clear resources.
27 for (uint32_t i
= aPackages
.Length(); i
> 0;) {
29 RegisterPackage(aPackages
[i
]);
32 for (uint32_t i
= aSubstitutions
.Length(); i
> 0;) {
34 RegisterSubstitution(aSubstitutions
[i
]);
37 for (uint32_t i
= aOverrides
.Length(); i
> 0;) {
39 RegisterOverride(aOverrides
[i
]);
45 void nsChromeRegistryContent::RegisterPackage(const ChromePackage
& aPackage
) {
46 nsCOMPtr
<nsIURI
> content
, locale
, skin
;
48 if (aPackage
.contentBaseURI
.spec
.Length()) {
50 NS_NewURI(getter_AddRefs(content
), aPackage
.contentBaseURI
.spec
);
51 if (NS_FAILED(rv
)) return;
53 if (aPackage
.localeBaseURI
.spec
.Length()) {
55 NS_NewURI(getter_AddRefs(locale
), aPackage
.localeBaseURI
.spec
);
56 if (NS_FAILED(rv
)) return;
58 if (aPackage
.skinBaseURI
.spec
.Length()) {
59 nsresult rv
= NS_NewURI(getter_AddRefs(skin
), aPackage
.skinBaseURI
.spec
);
60 if (NS_FAILED(rv
)) return;
63 UniquePtr
<PackageEntry
> entry
= MakeUnique
<PackageEntry
>();
64 entry
->flags
= aPackage
.flags
;
65 entry
->contentBaseURI
= content
;
66 entry
->localeBaseURI
= locale
;
67 entry
->skinBaseURI
= skin
;
69 mPackagesHash
.InsertOrUpdate(aPackage
.package
, std::move(entry
));
72 void nsChromeRegistryContent::RegisterSubstitution(
73 const SubstitutionMapping
& aSubstitution
) {
74 nsCOMPtr
<nsIIOService
> io(do_GetIOService());
77 nsCOMPtr
<nsIProtocolHandler
> ph
;
79 io
->GetProtocolHandler(aSubstitution
.scheme
.get(), getter_AddRefs(ph
));
80 if (NS_FAILED(rv
)) return;
82 nsCOMPtr
<nsISubstitutingProtocolHandler
> sph(do_QueryInterface(ph
));
85 nsCOMPtr
<nsIURI
> resolvedURI
;
86 if (aSubstitution
.resolvedURI
.spec
.Length()) {
87 rv
= NS_NewURI(getter_AddRefs(resolvedURI
), aSubstitution
.resolvedURI
.spec
);
88 if (NS_FAILED(rv
)) return;
91 rv
= sph
->SetSubstitutionWithFlags(aSubstitution
.path
, resolvedURI
,
93 if (NS_FAILED(rv
)) return;
96 void nsChromeRegistryContent::RegisterOverride(
97 const OverrideMapping
& aOverride
) {
98 nsCOMPtr
<nsIURI
> chromeURI
, overrideURI
;
100 NS_NewURI(getter_AddRefs(chromeURI
), aOverride
.originalURI
.spec
);
101 if (NS_FAILED(rv
)) return;
103 rv
= NS_NewURI(getter_AddRefs(overrideURI
), aOverride
.overrideURI
.spec
);
104 if (NS_FAILED(rv
)) return;
106 mOverrideTable
.InsertOrUpdate(chromeURI
, overrideURI
);
109 nsIURI
* nsChromeRegistryContent::GetBaseURIFromPackage(
110 const nsCString
& aPackage
, const nsCString
& aProvider
,
111 const nsCString
& aPath
) {
113 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
117 if (aProvider
.EqualsLiteral("locale")) {
118 return entry
->localeBaseURI
;
119 } else if (aProvider
.EqualsLiteral("skin")) {
120 return entry
->skinBaseURI
;
121 } else if (aProvider
.EqualsLiteral("content")) {
122 return entry
->contentBaseURI
;
127 nsresult
nsChromeRegistryContent::GetFlagsFromPackage(const nsCString
& aPackage
,
130 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
131 return NS_ERROR_FAILURE
;
133 *aFlags
= entry
->flags
;
137 // All functions following only make sense in chrome, and therefore assert
139 #define CONTENT_NOTREACHED() \
140 MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
142 #define CONTENT_NOT_IMPLEMENTED() \
143 CONTENT_NOTREACHED(); \
144 return NS_ERROR_NOT_IMPLEMENTED;
147 nsChromeRegistryContent::GetLocalesForPackage(
148 const nsACString
& aPackage
, nsIUTF8StringEnumerator
** aResult
) {
149 CONTENT_NOT_IMPLEMENTED();
153 nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
156 nsChromeRegistryContent::IsLocaleRTL(const nsACString
& aPackage
,
158 *aResult
= mozilla::intl::LocaleService::IsLocaleRTL(mLocale
);
163 nsChromeRegistryContent::Observe(nsISupports
* aSubject
, const char* aTopic
,
164 const char16_t
* aData
) {
165 CONTENT_NOT_IMPLEMENTED();
168 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext
& cx
,
169 int lineno
, char* const* argv
,
171 CONTENT_NOTREACHED();
174 void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext
& cx
,
175 int lineno
, char* const* argv
,
177 CONTENT_NOTREACHED();
180 void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext
& cx
,
181 int lineno
, char* const* argv
,
183 CONTENT_NOTREACHED();
186 void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext
& cx
,
187 int lineno
, char* const* argv
,
189 CONTENT_NOTREACHED();
192 void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext
& cx
,
193 int lineno
, char* const* argv
,
195 CONTENT_NOTREACHED();