chrome/src/nsChromeRegistryContent.cpp

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:a8b846ae60dd
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "RegistryMessageUtils.h"
7 #include "nsChromeRegistryContent.h"
8 #include "nsString.h"
9 #include "nsNetUtil.h"
10 #include "nsIResProtocolHandler.h"
11
12 nsChromeRegistryContent::nsChromeRegistryContent()
13 {
14 }
15
16 void
17 nsChromeRegistryContent::RegisterRemoteChrome(
18 const InfallibleTArray<ChromePackage>& aPackages,
19 const InfallibleTArray<ResourceMapping>& aResources,
20 const InfallibleTArray<OverrideMapping>& aOverrides,
21 const nsACString& aLocale)
22 {
23 NS_ABORT_IF_FALSE(mLocale == nsDependentCString(""),
24 "RegisterChrome twice?");
25
26 for (uint32_t i = aPackages.Length(); i > 0; ) {
27 --i;
28 RegisterPackage(aPackages[i]);
29 }
30
31 for (uint32_t i = aResources.Length(); i > 0; ) {
32 --i;
33 RegisterResource(aResources[i]);
34 }
35
36 for (uint32_t i = aOverrides.Length(); i > 0; ) {
37 --i;
38 RegisterOverride(aOverrides[i]);
39 }
40
41 mLocale = aLocale;
42 }
43
44 void
45 nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage)
46 {
47 nsCOMPtr<nsIIOService> io (do_GetIOService());
48 if (!io)
49 return;
50
51 nsCOMPtr<nsIURI> content, locale, skin;
52
53 if (aPackage.contentBaseURI.spec.Length()) {
54 nsresult rv = NS_NewURI(getter_AddRefs(content),
55 aPackage.contentBaseURI.spec,
56 aPackage.contentBaseURI.charset.get(),
57 nullptr, io);
58 if (NS_FAILED(rv))
59 return;
60 }
61 if (aPackage.localeBaseURI.spec.Length()) {
62 nsresult rv = NS_NewURI(getter_AddRefs(locale),
63 aPackage.localeBaseURI.spec,
64 aPackage.localeBaseURI.charset.get(),
65 nullptr, io);
66 if (NS_FAILED(rv))
67 return;
68 }
69 if (aPackage.skinBaseURI.spec.Length()) {
70 nsCOMPtr<nsIURI> skinBaseURI;
71 nsresult rv = NS_NewURI(getter_AddRefs(skin),
72 aPackage.skinBaseURI.spec,
73 aPackage.skinBaseURI.charset.get(),
74 nullptr, io);
75 if (NS_FAILED(rv))
76 return;
77 }
78
79 PackageEntry* entry = new PackageEntry;
80 entry->flags = aPackage.flags;
81 entry->contentBaseURI = content;
82 entry->localeBaseURI = locale;
83 entry->skinBaseURI = skin;
84
85 mPackagesHash.Put(aPackage.package, entry);
86 }
87
88 void
89 nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource)
90 {
91 nsCOMPtr<nsIIOService> io (do_GetIOService());
92 if (!io)
93 return;
94
95 nsCOMPtr<nsIProtocolHandler> ph;
96 nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph));
97 if (NS_FAILED(rv))
98 return;
99
100 nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph));
101 if (!rph)
102 return;
103
104 nsCOMPtr<nsIURI> resolvedURI;
105 if (aResource.resolvedURI.spec.Length()) {
106 nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI),
107 aResource.resolvedURI.spec,
108 aResource.resolvedURI.charset.get(),
109 nullptr, io);
110 if (NS_FAILED(rv))
111 return;
112 }
113
114 rv = rph->SetSubstitution(aResource.resource, resolvedURI);
115 if (NS_FAILED(rv))
116 return;
117 }
118
119 void
120 nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride)
121 {
122 nsCOMPtr<nsIIOService> io (do_GetIOService());
123 if (!io)
124 return;
125
126 nsCOMPtr<nsIURI> chromeURI, overrideURI;
127 nsresult rv = NS_NewURI(getter_AddRefs(chromeURI),
128 aOverride.originalURI.spec,
129 aOverride.originalURI.charset.get(),
130 nullptr, io);
131 if (NS_FAILED(rv))
132 return;
133
134 rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
135 aOverride.overrideURI.charset.get(), nullptr, io);
136 if (NS_FAILED(rv))
137 return;
138
139 mOverrideTable.Put(chromeURI, overrideURI);
140 }
141
142 nsIURI*
143 nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage,
144 const nsCString& aProvider,
145 const nsCString& aPath)
146 {
147 PackageEntry* entry;
148 if (!mPackagesHash.Get(aPackage, &entry)) {
149 return nullptr;
150 }
151
152 if (aProvider.EqualsLiteral("locale")) {
153 return entry->localeBaseURI;
154 }
155 else if (aProvider.EqualsLiteral("skin")) {
156 return entry->skinBaseURI;
157 }
158 else if (aProvider.EqualsLiteral("content")) {
159 return entry->contentBaseURI;
160 }
161 return nullptr;
162 }
163
164 nsresult
165 nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
166 uint32_t* aFlags)
167 {
168 PackageEntry* entry;
169 if (!mPackagesHash.Get(aPackage, &entry)) {
170 return NS_ERROR_FAILURE;
171 }
172 *aFlags = entry->flags;
173 return NS_OK;
174 }
175
176 // All functions following only make sense in chrome, and therefore assert
177
178 #define CONTENT_NOTREACHED() \
179 NS_NOTREACHED("Content should not be calling this")
180
181 #define CONTENT_NOT_IMPLEMENTED() \
182 CONTENT_NOTREACHED(); \
183 return NS_ERROR_NOT_IMPLEMENTED;
184
185 NS_IMETHODIMP
186 nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage,
187 nsIUTF8StringEnumerator* *aResult)
188 {
189 CONTENT_NOT_IMPLEMENTED();
190 }
191
192 NS_IMETHODIMP
193 nsChromeRegistryContent::CheckForOSAccessibility()
194 {
195 CONTENT_NOT_IMPLEMENTED();
196 }
197
198 NS_IMETHODIMP
199 nsChromeRegistryContent::CheckForNewChrome()
200 {
201 CONTENT_NOT_IMPLEMENTED();
202 }
203
204 NS_IMETHODIMP
205 nsChromeRegistryContent::IsLocaleRTL(const nsACString& package,
206 bool *aResult)
207 {
208 CONTENT_NOT_IMPLEMENTED();
209 }
210
211 NS_IMETHODIMP
212 nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
213 nsACString& aLocale)
214 {
215 if (aPackage != nsDependentCString("global")) {
216 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
217 return NS_ERROR_NOT_AVAILABLE;
218 }
219 aLocale = mLocale;
220 return NS_OK;
221 }
222
223 NS_IMETHODIMP
224 nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
225 const char16_t* aData)
226 {
227 CONTENT_NOT_IMPLEMENTED();
228 }
229
230 NS_IMETHODIMP
231 nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL,
232 nsISimpleEnumerator **aResult)
233 {
234 CONTENT_NOT_IMPLEMENTED();
235 }
236
237 NS_IMETHODIMP
238 nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL,
239 nsISimpleEnumerator **aResult)
240 {
241 CONTENT_NOT_IMPLEMENTED();
242 }
243
244 nsresult nsChromeRegistryContent::UpdateSelectedLocale()
245 {
246 CONTENT_NOT_IMPLEMENTED();
247 }
248
249 void
250 nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
251 int lineno, char *const * argv,
252 bool platform, bool contentaccessible)
253 {
254 CONTENT_NOTREACHED();
255 }
256
257 void
258 nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
259 int lineno,
260 char *const * argv, bool platform,
261 bool contentaccessible)
262 {
263 CONTENT_NOTREACHED();
264 }
265
266 void
267 nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
268 int lineno,
269 char *const * argv, bool platform,
270 bool contentaccessible)
271 {
272 CONTENT_NOTREACHED();
273 }
274
275 void
276 nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno,
277 char *const * argv, bool platform,
278 bool contentaccessible)
279 {
280 CONTENT_NOTREACHED();
281 }
282
283 void
284 nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx,
285 int lineno,
286 char *const * argv, bool platform,
287 bool contentaccessible)
288 {
289 CONTENT_NOTREACHED();
290 }
291
292 void
293 nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
294 int lineno,
295 char *const * argv, bool platform,
296 bool contentaccessible)
297 {
298 CONTENT_NOTREACHED();
299 }
300
301 void
302 nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
303 int lineno,
304 char *const * argv, bool platform,
305 bool contentaccessible)
306 {
307 CONTENT_NOTREACHED();
308 }

mercurial