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() {}
15 void nsChromeRegistryContent::RegisterRemoteChrome(
16 const InfallibleTArray
<ChromePackage
>& aPackages
,
17 const InfallibleTArray
<SubstitutionMapping
>& aSubstitutions
,
18 const InfallibleTArray
<OverrideMapping
>& aOverrides
,
19 const nsACString
& aLocale
, bool aReset
) {
20 MOZ_ASSERT(aReset
|| mLocale
.IsEmpty(), "RegisterChrome twice?");
23 mPackagesHash
.Clear();
24 mOverrideTable
.Clear();
25 // XXX Can't clear resources.
28 for (uint32_t i
= aPackages
.Length(); i
> 0;) {
30 RegisterPackage(aPackages
[i
]);
33 for (uint32_t i
= aSubstitutions
.Length(); i
> 0;) {
35 RegisterSubstitution(aSubstitutions
[i
]);
38 for (uint32_t i
= aOverrides
.Length(); i
> 0;) {
40 RegisterOverride(aOverrides
[i
]);
46 void nsChromeRegistryContent::RegisterPackage(const ChromePackage
& aPackage
) {
47 nsCOMPtr
<nsIIOService
> io(do_GetIOService());
50 nsCOMPtr
<nsIURI
> content
, locale
, skin
;
52 if (aPackage
.contentBaseURI
.spec
.Length()) {
53 nsresult rv
= NS_NewURI(getter_AddRefs(content
),
54 aPackage
.contentBaseURI
.spec
, nullptr, nullptr, io
);
55 if (NS_FAILED(rv
)) return;
57 if (aPackage
.localeBaseURI
.spec
.Length()) {
58 nsresult rv
= NS_NewURI(getter_AddRefs(locale
), aPackage
.localeBaseURI
.spec
,
59 nullptr, nullptr, io
);
60 if (NS_FAILED(rv
)) return;
62 if (aPackage
.skinBaseURI
.spec
.Length()) {
63 nsresult rv
= NS_NewURI(getter_AddRefs(skin
), aPackage
.skinBaseURI
.spec
,
64 nullptr, nullptr, io
);
65 if (NS_FAILED(rv
)) return;
68 PackageEntry
* entry
= new PackageEntry
;
69 entry
->flags
= aPackage
.flags
;
70 entry
->contentBaseURI
= content
;
71 entry
->localeBaseURI
= locale
;
72 entry
->skinBaseURI
= skin
;
74 mPackagesHash
.Put(aPackage
.package
, entry
);
77 void nsChromeRegistryContent::RegisterSubstitution(
78 const SubstitutionMapping
& aSubstitution
) {
79 nsCOMPtr
<nsIIOService
> io(do_GetIOService());
82 nsCOMPtr
<nsIProtocolHandler
> ph
;
84 io
->GetProtocolHandler(aSubstitution
.scheme
.get(), getter_AddRefs(ph
));
85 if (NS_FAILED(rv
)) return;
87 nsCOMPtr
<nsISubstitutingProtocolHandler
> sph(do_QueryInterface(ph
));
90 nsCOMPtr
<nsIURI
> resolvedURI
;
91 if (aSubstitution
.resolvedURI
.spec
.Length()) {
92 rv
= NS_NewURI(getter_AddRefs(resolvedURI
), aSubstitution
.resolvedURI
.spec
,
93 nullptr, nullptr, io
);
94 if (NS_FAILED(rv
)) return;
97 rv
= sph
->SetSubstitutionWithFlags(aSubstitution
.path
, resolvedURI
,
99 if (NS_FAILED(rv
)) return;
102 void nsChromeRegistryContent::RegisterOverride(
103 const OverrideMapping
& aOverride
) {
104 nsCOMPtr
<nsIIOService
> io(do_GetIOService());
107 nsCOMPtr
<nsIURI
> chromeURI
, overrideURI
;
108 nsresult rv
= NS_NewURI(getter_AddRefs(chromeURI
), aOverride
.originalURI
.spec
,
109 nullptr, nullptr, io
);
110 if (NS_FAILED(rv
)) return;
112 rv
= NS_NewURI(getter_AddRefs(overrideURI
), aOverride
.overrideURI
.spec
,
113 nullptr, nullptr, io
);
114 if (NS_FAILED(rv
)) return;
116 mOverrideTable
.Put(chromeURI
, overrideURI
);
119 nsIURI
* nsChromeRegistryContent::GetBaseURIFromPackage(
120 const nsCString
& aPackage
, const nsCString
& aProvider
,
121 const nsCString
& aPath
) {
123 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
127 if (aProvider
.EqualsLiteral("locale")) {
128 return entry
->localeBaseURI
;
129 } else if (aProvider
.EqualsLiteral("skin")) {
130 return entry
->skinBaseURI
;
131 } else if (aProvider
.EqualsLiteral("content")) {
132 return entry
->contentBaseURI
;
137 nsresult
nsChromeRegistryContent::GetFlagsFromPackage(const nsCString
& aPackage
,
140 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
141 return NS_ERROR_FAILURE
;
143 *aFlags
= entry
->flags
;
147 // All functions following only make sense in chrome, and therefore assert
149 #define CONTENT_NOTREACHED() \
150 MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
152 #define CONTENT_NOT_IMPLEMENTED() \
153 CONTENT_NOTREACHED(); \
154 return NS_ERROR_NOT_IMPLEMENTED;
157 nsChromeRegistryContent::GetLocalesForPackage(
158 const nsACString
& aPackage
, nsIUTF8StringEnumerator
** aResult
) {
159 CONTENT_NOT_IMPLEMENTED();
163 nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
166 nsChromeRegistryContent::IsLocaleRTL(const nsACString
& aPackage
,
168 *aResult
= GetDirectionForLocale(mLocale
);
173 nsChromeRegistryContent::GetSelectedLocale(const nsACString
& aPackage
,
174 bool aAsBCP47
, nsACString
& aLocale
) {
175 if (aPackage
!= nsDependentCString("global")) {
176 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
177 return NS_ERROR_NOT_AVAILABLE
;
181 SanitizeForBCP47(aLocale
);
187 nsChromeRegistryContent::Observe(nsISupports
* aSubject
, const char* aTopic
,
188 const char16_t
* aData
) {
189 CONTENT_NOT_IMPLEMENTED();
192 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext
& cx
,
193 int lineno
, char* const* argv
,
195 CONTENT_NOTREACHED();
198 void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext
& cx
,
199 int lineno
, char* const* argv
,
201 CONTENT_NOTREACHED();
204 void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext
& cx
,
205 int lineno
, char* const* argv
,
207 CONTENT_NOTREACHED();
210 void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext
& cx
,
211 int lineno
, char* const* argv
,
213 CONTENT_NOTREACHED();
216 void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext
& cx
,
217 int lineno
, char* const* argv
,
219 CONTENT_NOTREACHED();