Source code

Revision control

Other Tools

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/. */
6
7
#include "RegistryMessageUtils.h"
8
#include "nsChromeRegistryContent.h"
9
#include "nsString.h"
10
#include "nsNetUtil.h"
11
12
nsChromeRegistryContent::nsChromeRegistryContent() {}
13
14
void nsChromeRegistryContent::RegisterRemoteChrome(
15
const nsTArray<ChromePackage>& aPackages,
16
const nsTArray<SubstitutionMapping>& aSubstitutions,
17
const nsTArray<OverrideMapping>& aOverrides, const nsACString& aLocale,
18
bool aReset) {
19
MOZ_ASSERT(aReset || mLocale.IsEmpty(), "RegisterChrome twice?");
20
21
if (aReset) {
22
mPackagesHash.Clear();
23
mOverrideTable.Clear();
24
// XXX Can't clear resources.
25
}
26
27
for (uint32_t i = aPackages.Length(); i > 0;) {
28
--i;
29
RegisterPackage(aPackages[i]);
30
}
31
32
for (uint32_t i = aSubstitutions.Length(); i > 0;) {
33
--i;
34
RegisterSubstitution(aSubstitutions[i]);
35
}
36
37
for (uint32_t i = aOverrides.Length(); i > 0;) {
38
--i;
39
RegisterOverride(aOverrides[i]);
40
}
41
42
mLocale = aLocale;
43
}
44
45
void nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) {
46
nsCOMPtr<nsIURI> content, locale, skin;
47
48
if (aPackage.contentBaseURI.spec.Length()) {
49
nsresult rv =
50
NS_NewURI(getter_AddRefs(content), aPackage.contentBaseURI.spec);
51
if (NS_FAILED(rv)) return;
52
}
53
if (aPackage.localeBaseURI.spec.Length()) {
54
nsresult rv =
55
NS_NewURI(getter_AddRefs(locale), aPackage.localeBaseURI.spec);
56
if (NS_FAILED(rv)) return;
57
}
58
if (aPackage.skinBaseURI.spec.Length()) {
59
nsresult rv = NS_NewURI(getter_AddRefs(skin), aPackage.skinBaseURI.spec);
60
if (NS_FAILED(rv)) return;
61
}
62
63
PackageEntry* entry = new PackageEntry;
64
entry->flags = aPackage.flags;
65
entry->contentBaseURI = content;
66
entry->localeBaseURI = locale;
67
entry->skinBaseURI = skin;
68
69
mPackagesHash.Put(aPackage.package, entry);
70
}
71
72
void nsChromeRegistryContent::RegisterSubstitution(
73
const SubstitutionMapping& aSubstitution) {
74
nsCOMPtr<nsIIOService> io(do_GetIOService());
75
if (!io) return;
76
77
nsCOMPtr<nsIProtocolHandler> ph;
78
nsresult rv =
79
io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph));
80
if (NS_FAILED(rv)) return;
81
82
nsCOMPtr<nsISubstitutingProtocolHandler> sph(do_QueryInterface(ph));
83
if (!sph) return;
84
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;
89
}
90
91
rv = sph->SetSubstitutionWithFlags(aSubstitution.path, resolvedURI,
92
aSubstitution.flags);
93
if (NS_FAILED(rv)) return;
94
}
95
96
void nsChromeRegistryContent::RegisterOverride(
97
const OverrideMapping& aOverride) {
98
nsCOMPtr<nsIURI> chromeURI, overrideURI;
99
nsresult rv =
100
NS_NewURI(getter_AddRefs(chromeURI), aOverride.originalURI.spec);
101
if (NS_FAILED(rv)) return;
102
103
rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec);
104
if (NS_FAILED(rv)) return;
105
106
mOverrideTable.Put(chromeURI, overrideURI);
107
}
108
109
nsIURI* nsChromeRegistryContent::GetBaseURIFromPackage(
110
const nsCString& aPackage, const nsCString& aProvider,
111
const nsCString& aPath) {
112
PackageEntry* entry;
113
if (!mPackagesHash.Get(aPackage, &entry)) {
114
return nullptr;
115
}
116
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;
123
}
124
return nullptr;
125
}
126
127
nsresult nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
128
uint32_t* aFlags) {
129
PackageEntry* entry;
130
if (!mPackagesHash.Get(aPackage, &entry)) {
131
return NS_ERROR_FAILURE;
132
}
133
*aFlags = entry->flags;
134
return NS_OK;
135
}
136
137
// All functions following only make sense in chrome, and therefore assert
138
139
#define CONTENT_NOTREACHED() \
140
MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
141
142
#define CONTENT_NOT_IMPLEMENTED() \
143
CONTENT_NOTREACHED(); \
144
return NS_ERROR_NOT_IMPLEMENTED;
145
146
NS_IMETHODIMP
147
nsChromeRegistryContent::GetLocalesForPackage(
148
const nsACString& aPackage, nsIUTF8StringEnumerator** aResult) {
149
CONTENT_NOT_IMPLEMENTED();
150
}
151
152
NS_IMETHODIMP
153
nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
154
155
NS_IMETHODIMP
156
nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage,
157
bool* aResult) {
158
*aResult = mozilla::intl::LocaleService::IsLocaleRTL(mLocale);
159
return NS_OK;
160
}
161
162
NS_IMETHODIMP
163
nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
164
const char16_t* aData) {
165
CONTENT_NOT_IMPLEMENTED();
166
}
167
168
void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
169
int lineno, char* const* argv,
170
int flags) {
171
CONTENT_NOTREACHED();
172
}
173
174
void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
175
int lineno, char* const* argv,
176
int flags) {
177
CONTENT_NOTREACHED();
178
}
179
180
void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
181
int lineno, char* const* argv,
182
int flags) {
183
CONTENT_NOTREACHED();
184
}
185
186
void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
187
int lineno, char* const* argv,
188
int flags) {
189
CONTENT_NOTREACHED();
190
}
191
192
void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
193
int lineno, char* const* argv,
194
int flags) {
195
CONTENT_NOTREACHED();
196
}