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 nsTArray
<ChromePackage
>& aPackages
,
17 const nsTArray
<SubstitutionMapping
>& aSubstitutions
,
18 const nsTArray
<OverrideMapping
>& aOverrides
, const nsACString
& aLocale
,
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
<nsIURI
> content
, locale
, skin
;
49 if (aPackage
.contentBaseURI
.spec
.Length()) {
51 NS_NewURI(getter_AddRefs(content
), aPackage
.contentBaseURI
.spec
);
52 if (NS_FAILED(rv
)) return;
54 if (aPackage
.localeBaseURI
.spec
.Length()) {
56 NS_NewURI(getter_AddRefs(locale
), aPackage
.localeBaseURI
.spec
);
57 if (NS_FAILED(rv
)) return;
59 if (aPackage
.skinBaseURI
.spec
.Length()) {
60 nsresult rv
= NS_NewURI(getter_AddRefs(skin
), aPackage
.skinBaseURI
.spec
);
61 if (NS_FAILED(rv
)) return;
64 PackageEntry
* entry
= new PackageEntry
;
65 entry
->flags
= aPackage
.flags
;
66 entry
->contentBaseURI
= content
;
67 entry
->localeBaseURI
= locale
;
68 entry
->skinBaseURI
= skin
;
70 mPackagesHash
.Put(aPackage
.package
, entry
);
73 void nsChromeRegistryContent::RegisterSubstitution(
74 const SubstitutionMapping
& aSubstitution
) {
75 nsCOMPtr
<nsIIOService
> io(do_GetIOService());
78 nsCOMPtr
<nsIProtocolHandler
> ph
;
80 io
->GetProtocolHandler(aSubstitution
.scheme
.get(), getter_AddRefs(ph
));
81 if (NS_FAILED(rv
)) return;
83 nsCOMPtr
<nsISubstitutingProtocolHandler
> sph(do_QueryInterface(ph
));
86 nsCOMPtr
<nsIURI
> resolvedURI
;
87 if (aSubstitution
.resolvedURI
.spec
.Length()) {
88 rv
= NS_NewURI(getter_AddRefs(resolvedURI
), aSubstitution
.resolvedURI
.spec
);
89 if (NS_FAILED(rv
)) return;
92 rv
= sph
->SetSubstitutionWithFlags(aSubstitution
.path
, resolvedURI
,
94 if (NS_FAILED(rv
)) return;
97 void nsChromeRegistryContent::RegisterOverride(
98 const OverrideMapping
& aOverride
) {
99 nsCOMPtr
<nsIURI
> chromeURI
, overrideURI
;
101 NS_NewURI(getter_AddRefs(chromeURI
), aOverride
.originalURI
.spec
);
102 if (NS_FAILED(rv
)) return;
104 rv
= NS_NewURI(getter_AddRefs(overrideURI
), aOverride
.overrideURI
.spec
);
105 if (NS_FAILED(rv
)) return;
107 mOverrideTable
.Put(chromeURI
, overrideURI
);
110 nsIURI
* nsChromeRegistryContent::GetBaseURIFromPackage(
111 const nsCString
& aPackage
, const nsCString
& aProvider
,
112 const nsCString
& aPath
) {
114 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
118 if (aProvider
.EqualsLiteral("locale")) {
119 return entry
->localeBaseURI
;
120 } else if (aProvider
.EqualsLiteral("skin")) {
121 return entry
->skinBaseURI
;
122 } else if (aProvider
.EqualsLiteral("content")) {
123 return entry
->contentBaseURI
;
128 nsresult
nsChromeRegistryContent::GetFlagsFromPackage(const nsCString
& aPackage
,
131 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
132 return NS_ERROR_FAILURE
;
134 *aFlags
= entry
->flags
;
138 // All functions following only make sense in chrome, and therefore assert
140 #define CONTENT_NOTREACHED() \
141 MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
143 #define CONTENT_NOT_IMPLEMENTED() \
144 CONTENT_NOTREACHED(); \
145 return NS_ERROR_NOT_IMPLEMENTED;
148 nsChromeRegistryContent::GetLocalesForPackage(
149 const nsACString
& aPackage
, nsIUTF8StringEnumerator
** aResult
) {
150 CONTENT_NOT_IMPLEMENTED();
154 nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
157 nsChromeRegistryContent::IsLocaleRTL(const nsACString
& aPackage
,
159 *aResult
= GetDirectionForLocale(mLocale
);
164 nsChromeRegistryContent::GetSelectedLocale(const nsACString
& aPackage
,
165 bool aAsBCP47
, nsACString
& aLocale
) {
166 if (aPackage
!= nsDependentCString("global")) {
167 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
168 return NS_ERROR_NOT_AVAILABLE
;
172 SanitizeForBCP47(aLocale
);
178 nsChromeRegistryContent::Observe(nsISupports
* aSubject
, const char* aTopic
,
179 const char16_t
* aData
) {
180 CONTENT_NOT_IMPLEMENTED();
183 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext
& cx
,
184 int lineno
, char* const* argv
,
186 CONTENT_NOTREACHED();
189 void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext
& cx
,
190 int lineno
, char* const* argv
,
192 CONTENT_NOTREACHED();
195 void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext
& cx
,
196 int lineno
, char* const* argv
,
198 CONTENT_NOTREACHED();
201 void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext
& cx
,
202 int lineno
, char* const* argv
,
204 CONTENT_NOTREACHED();
207 void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext
& cx
,
208 int lineno
, char* const* argv
,
210 CONTENT_NOTREACHED();