/src/mozilla-central/chrome/nsChromeRegistryContent.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "nsIResProtocolHandler.h" |
12 | | |
13 | | nsChromeRegistryContent::nsChromeRegistryContent() |
14 | 0 | { |
15 | 0 | } |
16 | | |
17 | | void |
18 | | nsChromeRegistryContent::RegisterRemoteChrome( |
19 | | const InfallibleTArray<ChromePackage>& aPackages, |
20 | | const InfallibleTArray<SubstitutionMapping>& aSubstitutions, |
21 | | const InfallibleTArray<OverrideMapping>& aOverrides, |
22 | | const nsACString& aLocale, |
23 | | bool aReset) |
24 | 0 | { |
25 | 0 | MOZ_ASSERT(aReset || mLocale.IsEmpty(), |
26 | 0 | "RegisterChrome twice?"); |
27 | 0 |
|
28 | 0 | if (aReset) { |
29 | 0 | mPackagesHash.Clear(); |
30 | 0 | mOverrideTable.Clear(); |
31 | 0 | // XXX Can't clear resources. |
32 | 0 | } |
33 | 0 |
|
34 | 0 | for (uint32_t i = aPackages.Length(); i > 0; ) { |
35 | 0 | --i; |
36 | 0 | RegisterPackage(aPackages[i]); |
37 | 0 | } |
38 | 0 |
|
39 | 0 | for (uint32_t i = aSubstitutions.Length(); i > 0; ) { |
40 | 0 | --i; |
41 | 0 | RegisterSubstitution(aSubstitutions[i]); |
42 | 0 | } |
43 | 0 |
|
44 | 0 | for (uint32_t i = aOverrides.Length(); i > 0; ) { |
45 | 0 | --i; |
46 | 0 | RegisterOverride(aOverrides[i]); |
47 | 0 | } |
48 | 0 |
|
49 | 0 | mLocale = aLocale; |
50 | 0 | } |
51 | | |
52 | | void |
53 | | nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) |
54 | 0 | { |
55 | 0 | nsCOMPtr<nsIIOService> io (do_GetIOService()); |
56 | 0 | if (!io) |
57 | 0 | return; |
58 | 0 | |
59 | 0 | nsCOMPtr<nsIURI> content, locale, skin; |
60 | 0 |
|
61 | 0 | if (aPackage.contentBaseURI.spec.Length()) { |
62 | 0 | nsresult rv = NS_NewURI(getter_AddRefs(content), |
63 | 0 | aPackage.contentBaseURI.spec, |
64 | 0 | nullptr, nullptr, io); |
65 | 0 | if (NS_FAILED(rv)) |
66 | 0 | return; |
67 | 0 | } |
68 | 0 | if (aPackage.localeBaseURI.spec.Length()) { |
69 | 0 | nsresult rv = NS_NewURI(getter_AddRefs(locale), |
70 | 0 | aPackage.localeBaseURI.spec, |
71 | 0 | nullptr, nullptr, io); |
72 | 0 | if (NS_FAILED(rv)) |
73 | 0 | return; |
74 | 0 | } |
75 | 0 | if (aPackage.skinBaseURI.spec.Length()) { |
76 | 0 | nsresult rv = NS_NewURI(getter_AddRefs(skin), |
77 | 0 | aPackage.skinBaseURI.spec, |
78 | 0 | nullptr, nullptr, io); |
79 | 0 | if (NS_FAILED(rv)) |
80 | 0 | return; |
81 | 0 | } |
82 | 0 | |
83 | 0 | PackageEntry* entry = new PackageEntry; |
84 | 0 | entry->flags = aPackage.flags; |
85 | 0 | entry->contentBaseURI = content; |
86 | 0 | entry->localeBaseURI = locale; |
87 | 0 | entry->skinBaseURI = skin; |
88 | 0 |
|
89 | 0 | mPackagesHash.Put(aPackage.package, entry); |
90 | 0 | } |
91 | | |
92 | | void |
93 | | nsChromeRegistryContent::RegisterSubstitution(const SubstitutionMapping& aSubstitution) |
94 | 0 | { |
95 | 0 | nsCOMPtr<nsIIOService> io (do_GetIOService()); |
96 | 0 | if (!io) |
97 | 0 | return; |
98 | 0 | |
99 | 0 | nsCOMPtr<nsIProtocolHandler> ph; |
100 | 0 | nsresult rv = io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph)); |
101 | 0 | if (NS_FAILED(rv)) |
102 | 0 | return; |
103 | 0 | |
104 | 0 | nsCOMPtr<nsISubstitutingProtocolHandler> sph (do_QueryInterface(ph)); |
105 | 0 | if (!sph) |
106 | 0 | return; |
107 | 0 | |
108 | 0 | nsCOMPtr<nsIURI> resolvedURI; |
109 | 0 | if (aSubstitution.resolvedURI.spec.Length()) { |
110 | 0 | rv = NS_NewURI(getter_AddRefs(resolvedURI), |
111 | 0 | aSubstitution.resolvedURI.spec, |
112 | 0 | nullptr, nullptr, io); |
113 | 0 | if (NS_FAILED(rv)) |
114 | 0 | return; |
115 | 0 | } |
116 | 0 | |
117 | 0 | rv = sph->SetSubstitutionWithFlags(aSubstitution.path, resolvedURI, aSubstitution.flags); |
118 | 0 | if (NS_FAILED(rv)) |
119 | 0 | return; |
120 | 0 | } |
121 | | |
122 | | void |
123 | | nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride) |
124 | 0 | { |
125 | 0 | nsCOMPtr<nsIIOService> io (do_GetIOService()); |
126 | 0 | if (!io) |
127 | 0 | return; |
128 | 0 | |
129 | 0 | nsCOMPtr<nsIURI> chromeURI, overrideURI; |
130 | 0 | nsresult rv = NS_NewURI(getter_AddRefs(chromeURI), |
131 | 0 | aOverride.originalURI.spec, |
132 | 0 | nullptr, nullptr, io); |
133 | 0 | if (NS_FAILED(rv)) |
134 | 0 | return; |
135 | 0 | |
136 | 0 | rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec, |
137 | 0 | nullptr, nullptr, io); |
138 | 0 | if (NS_FAILED(rv)) |
139 | 0 | return; |
140 | 0 | |
141 | 0 | mOverrideTable.Put(chromeURI, overrideURI); |
142 | 0 | } |
143 | | |
144 | | nsIURI* |
145 | | nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage, |
146 | | const nsCString& aProvider, |
147 | | const nsCString& aPath) |
148 | 0 | { |
149 | 0 | PackageEntry* entry; |
150 | 0 | if (!mPackagesHash.Get(aPackage, &entry)) { |
151 | 0 | return nullptr; |
152 | 0 | } |
153 | 0 | |
154 | 0 | if (aProvider.EqualsLiteral("locale")) { |
155 | 0 | return entry->localeBaseURI; |
156 | 0 | } |
157 | 0 | else if (aProvider.EqualsLiteral("skin")) { |
158 | 0 | return entry->skinBaseURI; |
159 | 0 | } |
160 | 0 | else if (aProvider.EqualsLiteral("content")) { |
161 | 0 | return entry->contentBaseURI; |
162 | 0 | } |
163 | 0 | return nullptr; |
164 | 0 | } |
165 | | |
166 | | nsresult |
167 | | nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage, |
168 | | uint32_t* aFlags) |
169 | 0 | { |
170 | 0 | PackageEntry* entry; |
171 | 0 | if (!mPackagesHash.Get(aPackage, &entry)) { |
172 | 0 | return NS_ERROR_FAILURE; |
173 | 0 | } |
174 | 0 | *aFlags = entry->flags; |
175 | 0 | return NS_OK; |
176 | 0 | } |
177 | | |
178 | | // All functions following only make sense in chrome, and therefore assert |
179 | | |
180 | | #define CONTENT_NOTREACHED() \ |
181 | 0 | MOZ_ASSERT_UNREACHABLE("Content should not be calling this") |
182 | | |
183 | | #define CONTENT_NOT_IMPLEMENTED() \ |
184 | 0 | CONTENT_NOTREACHED(); \ |
185 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
186 | | |
187 | | NS_IMETHODIMP |
188 | | nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage, |
189 | | nsIUTF8StringEnumerator* *aResult) |
190 | 0 | { |
191 | 0 | CONTENT_NOT_IMPLEMENTED(); |
192 | 0 | } |
193 | | |
194 | | NS_IMETHODIMP |
195 | | nsChromeRegistryContent::CheckForOSAccessibility() |
196 | 0 | { |
197 | 0 | CONTENT_NOT_IMPLEMENTED(); |
198 | 0 | } |
199 | | |
200 | | NS_IMETHODIMP |
201 | | nsChromeRegistryContent::CheckForNewChrome() |
202 | 0 | { |
203 | 0 | CONTENT_NOT_IMPLEMENTED(); |
204 | 0 | } |
205 | | |
206 | | NS_IMETHODIMP |
207 | | nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage, |
208 | | bool *aResult) |
209 | 0 | { |
210 | 0 | if (aPackage != nsDependentCString("global")) { |
211 | 0 | NS_ERROR("Packages other than global unavailable"); |
212 | 0 | return NS_ERROR_NOT_AVAILABLE; |
213 | 0 | } |
214 | 0 | *aResult = GetDirectionForLocale(mLocale); |
215 | 0 | return NS_OK; |
216 | 0 | } |
217 | | |
218 | | NS_IMETHODIMP |
219 | | nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage, |
220 | | bool aAsBCP47, |
221 | | nsACString& aLocale) |
222 | 0 | { |
223 | 0 | if (aPackage != nsDependentCString("global")) { |
224 | 0 | NS_ERROR("Uh-oh, caller wanted something other than 'some local'"); |
225 | 0 | return NS_ERROR_NOT_AVAILABLE; |
226 | 0 | } |
227 | 0 | aLocale = mLocale; |
228 | 0 | if (aAsBCP47) { |
229 | 0 | SanitizeForBCP47(aLocale); |
230 | 0 | } |
231 | 0 | return NS_OK; |
232 | 0 | } |
233 | | |
234 | | NS_IMETHODIMP |
235 | | nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic, |
236 | | const char16_t* aData) |
237 | 0 | { |
238 | 0 | CONTENT_NOT_IMPLEMENTED(); |
239 | 0 | } |
240 | | |
241 | | void |
242 | | nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx, |
243 | | int lineno, char *const * argv, |
244 | | int flags) |
245 | 0 | { |
246 | 0 | CONTENT_NOTREACHED(); |
247 | 0 | } |
248 | | |
249 | | void |
250 | | nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx, |
251 | | int lineno, |
252 | | char *const * argv, int flags) |
253 | 0 | { |
254 | 0 | CONTENT_NOTREACHED(); |
255 | 0 | } |
256 | | |
257 | | void |
258 | | nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx, |
259 | | int lineno, |
260 | | char *const * argv, int flags) |
261 | 0 | { |
262 | 0 | CONTENT_NOTREACHED(); |
263 | 0 | } |
264 | | |
265 | | void |
266 | | nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx, |
267 | | int lineno, |
268 | | char *const * argv, int flags) |
269 | 0 | { |
270 | 0 | CONTENT_NOTREACHED(); |
271 | 0 | } |
272 | | |
273 | | void |
274 | | nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx, |
275 | | int lineno, |
276 | | char *const * argv, int flags) |
277 | 0 | { |
278 | 0 | CONTENT_NOTREACHED(); |
279 | 0 | } |