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 "nsISubstitutingProtocolHandler.h"
11 #include "nsNetUtil.h"
12 #include "mozilla/UniquePtr.h"
14 nsChromeRegistryContent::nsChromeRegistryContent() {}
16 void nsChromeRegistryContent::RegisterRemoteChrome(
17 const nsTArray
<ChromePackage
>& aPackages
,
18 const nsTArray
<SubstitutionMapping
>& aSubstitutions
,
19 const nsTArray
<OverrideMapping
>& aOverrides
, const nsACString
& aLocale
,
21 MOZ_ASSERT(aReset
|| mLocale
.IsEmpty(), "RegisterChrome twice?");
24 mPackagesHash
.Clear();
25 mOverrideTable
.Clear();
26 // XXX Can't clear resources.
29 for (uint32_t i
= aPackages
.Length(); i
> 0;) {
31 RegisterPackage(aPackages
[i
]);
34 for (uint32_t i
= aSubstitutions
.Length(); i
> 0;) {
36 RegisterSubstitution(aSubstitutions
[i
]);
39 for (uint32_t i
= aOverrides
.Length(); i
> 0;) {
41 RegisterOverride(aOverrides
[i
]);
47 void nsChromeRegistryContent::RegisterPackage(const ChromePackage
& aPackage
) {
48 nsCOMPtr
<nsIURI
> content
, locale
, skin
;
50 if (aPackage
.contentBaseURI
.spec
.Length()) {
52 NS_NewURI(getter_AddRefs(content
), aPackage
.contentBaseURI
.spec
);
53 if (NS_FAILED(rv
)) return;
55 if (aPackage
.localeBaseURI
.spec
.Length()) {
57 NS_NewURI(getter_AddRefs(locale
), aPackage
.localeBaseURI
.spec
);
58 if (NS_FAILED(rv
)) return;
60 if (aPackage
.skinBaseURI
.spec
.Length()) {
61 nsresult rv
= NS_NewURI(getter_AddRefs(skin
), aPackage
.skinBaseURI
.spec
);
62 if (NS_FAILED(rv
)) return;
65 mozilla::UniquePtr
<PackageEntry
> entry
= mozilla::MakeUnique
<PackageEntry
>();
66 entry
->flags
= aPackage
.flags
;
67 entry
->contentBaseURI
= content
;
68 entry
->localeBaseURI
= locale
;
69 entry
->skinBaseURI
= skin
;
71 mPackagesHash
.InsertOrUpdate(aPackage
.package
, std::move(entry
));
74 void nsChromeRegistryContent::RegisterSubstitution(
75 const SubstitutionMapping
& aSubstitution
) {
76 nsCOMPtr
<nsIIOService
> io(do_GetIOService());
79 nsCOMPtr
<nsIProtocolHandler
> ph
;
81 io
->GetProtocolHandler(aSubstitution
.scheme
.get(), getter_AddRefs(ph
));
82 if (NS_FAILED(rv
)) return;
84 nsCOMPtr
<nsISubstitutingProtocolHandler
> sph(do_QueryInterface(ph
));
87 nsCOMPtr
<nsIURI
> resolvedURI
;
88 if (aSubstitution
.resolvedURI
.spec
.Length()) {
89 rv
= NS_NewURI(getter_AddRefs(resolvedURI
), aSubstitution
.resolvedURI
.spec
);
90 if (NS_FAILED(rv
)) return;
93 rv
= sph
->SetSubstitutionWithFlags(aSubstitution
.path
, resolvedURI
,
95 if (NS_FAILED(rv
)) return;
98 void nsChromeRegistryContent::RegisterOverride(
99 const OverrideMapping
& aOverride
) {
100 nsCOMPtr
<nsIURI
> chromeURI
, overrideURI
;
102 NS_NewURI(getter_AddRefs(chromeURI
), aOverride
.originalURI
.spec
);
103 if (NS_FAILED(rv
)) return;
105 rv
= NS_NewURI(getter_AddRefs(overrideURI
), aOverride
.overrideURI
.spec
);
106 if (NS_FAILED(rv
)) return;
108 mOverrideTable
.InsertOrUpdate(chromeURI
, overrideURI
);
111 nsIURI
* nsChromeRegistryContent::GetBaseURIFromPackage(
112 const nsCString
& aPackage
, const nsCString
& aProvider
,
113 const nsCString
& aPath
) {
115 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
119 if (aProvider
.EqualsLiteral("locale")) {
120 return entry
->localeBaseURI
;
123 if (aProvider
.EqualsLiteral("skin")) {
124 return entry
->skinBaseURI
;
127 if (aProvider
.EqualsLiteral("content")) {
128 return entry
->contentBaseURI
;
134 nsresult
nsChromeRegistryContent::GetFlagsFromPackage(const nsCString
& aPackage
,
137 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
138 return NS_ERROR_FAILURE
;
140 *aFlags
= entry
->flags
;
144 // All functions following only make sense in chrome, and therefore assert
146 #define CONTENT_NOTREACHED() \
147 MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
149 #define CONTENT_NOT_IMPLEMENTED() \
150 CONTENT_NOTREACHED(); \
151 return NS_ERROR_NOT_IMPLEMENTED;
154 nsChromeRegistryContent::GetLocalesForPackage(
155 const nsACString
& aPackage
, nsIUTF8StringEnumerator
** aResult
) {
156 CONTENT_NOT_IMPLEMENTED();
160 nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
163 nsChromeRegistryContent::IsLocaleRTL(const nsACString
& aPackage
,
165 *aResult
= mozilla::intl::LocaleService::IsLocaleRTL(mLocale
);
170 nsChromeRegistryContent::Observe(nsISupports
* aSubject
, const char* aTopic
,
171 const char16_t
* aData
) {
172 CONTENT_NOT_IMPLEMENTED();
175 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext
& cx
,
176 int lineno
, char* const* argv
,
178 CONTENT_NOTREACHED();
181 void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext
& cx
,
182 int lineno
, char* const* argv
,
184 CONTENT_NOTREACHED();
187 void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext
& cx
,
188 int lineno
, char* const* argv
,
190 CONTENT_NOTREACHED();
193 void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext
& cx
,
194 int lineno
, char* const* argv
,
196 CONTENT_NOTREACHED();
199 void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext
& cx
,
200 int lineno
, char* const* argv
,
202 CONTENT_NOTREACHED();