1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * the Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
23 * Josh Matthews <josh@joshmatthews.net> (Initial Developer)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "RegistryMessageUtils.h"
40 #include "nsChromeRegistry.h"
41 #include "nsChromeRegistryContent.h"
43 #include "nsNetUtil.h"
44 #include "nsResProtocolHandler.h"
46 nsChromeRegistryContent::nsChromeRegistryContent()
52 nsChromeRegistryContent::RegisterRemoteChrome(
53 const nsTArray
<ChromePackage
>& aPackages
,
54 const nsTArray
<ResourceMapping
>& aResources
,
55 const nsTArray
<OverrideMapping
>& aOverrides
,
56 const nsACString
& aLocale
)
58 NS_ABORT_IF_FALSE(mLocale
== nsDependentCString(""),
59 "RegisterChrome twice?");
61 for (PRUint32 i
= aPackages
.Length(); i
> 0; ) {
63 RegisterPackage(aPackages
[i
]);
66 for (PRUint32 i
= aResources
.Length(); i
> 0; ) {
68 RegisterResource(aResources
[i
]);
71 for (PRUint32 i
= aOverrides
.Length(); i
> 0; ) {
73 RegisterOverride(aOverrides
[i
]);
80 nsChromeRegistryContent::RegisterPackage(const ChromePackage
& aPackage
)
82 nsCOMPtr
<nsIIOService
> io (do_GetIOService());
86 nsCOMPtr
<nsIURI
> content
, locale
, skin
;
88 if (aPackage
.contentBaseURI
.spec
.Length()) {
89 nsresult rv
= NS_NewURI(getter_AddRefs(content
),
90 aPackage
.contentBaseURI
.spec
,
91 aPackage
.contentBaseURI
.charset
.get(),
96 if (aPackage
.localeBaseURI
.spec
.Length()) {
97 nsresult rv
= NS_NewURI(getter_AddRefs(locale
),
98 aPackage
.localeBaseURI
.spec
,
99 aPackage
.localeBaseURI
.charset
.get(),
104 if (aPackage
.skinBaseURI
.spec
.Length()) {
105 nsCOMPtr
<nsIURI
> skinBaseURI
;
106 nsresult rv
= NS_NewURI(getter_AddRefs(skin
),
107 aPackage
.skinBaseURI
.spec
,
108 aPackage
.skinBaseURI
.charset
.get(),
114 PackageEntry
* entry
= new PackageEntry
;
115 entry
->flags
= aPackage
.flags
;
116 entry
->contentBaseURI
= content
;
117 entry
->localeBaseURI
= locale
;
118 entry
->skinBaseURI
= skin
;
120 nsresult rv
= mPackagesHash
.Put(aPackage
.package
, entry
);
126 nsChromeRegistryContent::RegisterResource(const ResourceMapping
& aResource
)
128 nsCOMPtr
<nsIIOService
> io (do_GetIOService());
132 nsCOMPtr
<nsIProtocolHandler
> ph
;
133 nsresult rv
= io
->GetProtocolHandler("resource", getter_AddRefs(ph
));
137 nsCOMPtr
<nsIResProtocolHandler
> rph (do_QueryInterface(ph
));
141 nsCOMPtr
<nsIURI
> resolvedURI
;
142 if (aResource
.resolvedURI
.spec
.Length()) {
143 nsresult rv
= NS_NewURI(getter_AddRefs(resolvedURI
),
144 aResource
.resolvedURI
.spec
,
145 aResource
.resolvedURI
.charset
.get(),
151 rv
= rph
->SetSubstitution(aResource
.resource
, resolvedURI
);
157 nsChromeRegistryContent::RegisterOverride(const OverrideMapping
& aOverride
)
159 nsCOMPtr
<nsIIOService
> io (do_GetIOService());
163 nsCOMPtr
<nsIURI
> chromeURI
, overrideURI
;
164 nsresult rv
= NS_NewURI(getter_AddRefs(chromeURI
),
165 aOverride
.originalURI
.spec
,
166 aOverride
.originalURI
.charset
.get(),
171 rv
= NS_NewURI(getter_AddRefs(overrideURI
), aOverride
.overrideURI
.spec
,
172 aOverride
.overrideURI
.charset
.get(), nsnull
, io
);
176 mOverrideTable
.Put(chromeURI
, overrideURI
);
180 nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString
& aPackage
,
181 const nsCString
& aProvider
,
182 const nsCString
& aPath
)
185 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
189 if (aProvider
.EqualsLiteral("locale")) {
190 return entry
->localeBaseURI
;
192 else if (aProvider
.EqualsLiteral("skin")) {
193 return entry
->skinBaseURI
;
195 else if (aProvider
.EqualsLiteral("content")) {
196 return entry
->contentBaseURI
;
202 nsChromeRegistryContent::GetFlagsFromPackage(const nsCString
& aPackage
,
206 if (!mPackagesHash
.Get(aPackage
, &entry
)) {
207 return NS_ERROR_FAILURE
;
209 *aFlags
= entry
->flags
;
213 // All functions following only make sense in chrome, and therefore assert
215 #define CONTENT_NOTREACHED() \
216 NS_NOTREACHED("Content should not be calling this")
218 #define CONTENT_NOT_IMPLEMENTED() \
219 CONTENT_NOTREACHED(); \
220 return NS_ERROR_NOT_IMPLEMENTED;
223 nsChromeRegistryContent::GetLocalesForPackage(const nsACString
& aPackage
,
224 nsIUTF8StringEnumerator
* *aResult
)
226 CONTENT_NOT_IMPLEMENTED();
230 nsChromeRegistryContent::CheckForOSAccessibility()
232 CONTENT_NOT_IMPLEMENTED();
236 nsChromeRegistryContent::CheckForNewChrome()
238 CONTENT_NOT_IMPLEMENTED();
242 nsChromeRegistryContent::IsLocaleRTL(const nsACString
& package
,
245 CONTENT_NOT_IMPLEMENTED();
249 nsChromeRegistryContent::GetSelectedLocale(const nsACString
& aPackage
,
252 if (aPackage
!= nsDependentCString("global")) {
253 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
254 return NS_ERROR_NOT_AVAILABLE
;
261 nsChromeRegistryContent::Observe(nsISupports
* aSubject
, const char* aTopic
,
262 const PRUnichar
* aData
)
264 CONTENT_NOT_IMPLEMENTED();
268 nsChromeRegistryContent::GetStyleOverlays(nsIURI
*aChromeURL
,
269 nsISimpleEnumerator
**aResult
)
271 CONTENT_NOT_IMPLEMENTED();
275 nsChromeRegistryContent::GetXULOverlays(nsIURI
*aChromeURL
,
276 nsISimpleEnumerator
**aResult
)
278 CONTENT_NOT_IMPLEMENTED();
281 void nsChromeRegistryContent::UpdateSelectedLocale()
283 CONTENT_NOTREACHED();
287 nsChromeRegistryContent::ManifestContent(ManifestProcessingContext
& cx
,
288 int lineno
, char *const * argv
,
289 bool platform
, bool contentaccessible
)
291 CONTENT_NOTREACHED();
295 nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext
& cx
,
297 char *const * argv
, bool platform
,
298 bool contentaccessible
)
300 CONTENT_NOTREACHED();
304 nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext
& cx
,
306 char *const * argv
, bool platform
,
307 bool contentaccessible
)
309 CONTENT_NOTREACHED();
313 nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext
& cx
, int lineno
,
314 char *const * argv
, bool platform
,
315 bool contentaccessible
)
317 CONTENT_NOTREACHED();
321 nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext
& cx
,
323 char *const * argv
, bool platform
,
324 bool contentaccessible
)
326 CONTENT_NOTREACHED();
330 nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext
& cx
,
332 char *const * argv
, bool platform
,
333 bool contentaccessible
)
335 CONTENT_NOTREACHED();
339 nsChromeRegistryContent::ManifestResource(ManifestProcessingContext
& cx
,
341 char *const * argv
, bool platform
,
342 bool contentaccessible
)
344 CONTENT_NOTREACHED();