Bug 1529445 [wpt PR 15111] - Fix #12696: make property_order default to empty list...
[gecko.git] / chrome / nsChromeRegistryContent.cpp
blob8d619ffa9558a550adcce21bc823e13bf2527afd
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"
9 #include "nsString.h"
10 #include "nsNetUtil.h"
11 #include "nsIResProtocolHandler.h"
13 nsChromeRegistryContent::nsChromeRegistryContent() {}
15 void nsChromeRegistryContent::RegisterRemoteChrome(
16 const InfallibleTArray<ChromePackage>& aPackages,
17 const InfallibleTArray<SubstitutionMapping>& aSubstitutions,
18 const InfallibleTArray<OverrideMapping>& aOverrides,
19 const nsACString& aLocale, bool aReset) {
20 MOZ_ASSERT(aReset || mLocale.IsEmpty(), "RegisterChrome twice?");
22 if (aReset) {
23 mPackagesHash.Clear();
24 mOverrideTable.Clear();
25 // XXX Can't clear resources.
28 for (uint32_t i = aPackages.Length(); i > 0;) {
29 --i;
30 RegisterPackage(aPackages[i]);
33 for (uint32_t i = aSubstitutions.Length(); i > 0;) {
34 --i;
35 RegisterSubstitution(aSubstitutions[i]);
38 for (uint32_t i = aOverrides.Length(); i > 0;) {
39 --i;
40 RegisterOverride(aOverrides[i]);
43 mLocale = aLocale;
46 void nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) {
47 nsCOMPtr<nsIIOService> io(do_GetIOService());
48 if (!io) return;
50 nsCOMPtr<nsIURI> content, locale, skin;
52 if (aPackage.contentBaseURI.spec.Length()) {
53 nsresult rv = NS_NewURI(getter_AddRefs(content),
54 aPackage.contentBaseURI.spec, nullptr, nullptr, io);
55 if (NS_FAILED(rv)) return;
57 if (aPackage.localeBaseURI.spec.Length()) {
58 nsresult rv = NS_NewURI(getter_AddRefs(locale), aPackage.localeBaseURI.spec,
59 nullptr, nullptr, io);
60 if (NS_FAILED(rv)) return;
62 if (aPackage.skinBaseURI.spec.Length()) {
63 nsresult rv = NS_NewURI(getter_AddRefs(skin), aPackage.skinBaseURI.spec,
64 nullptr, nullptr, io);
65 if (NS_FAILED(rv)) return;
68 PackageEntry* entry = new PackageEntry;
69 entry->flags = aPackage.flags;
70 entry->contentBaseURI = content;
71 entry->localeBaseURI = locale;
72 entry->skinBaseURI = skin;
74 mPackagesHash.Put(aPackage.package, entry);
77 void nsChromeRegistryContent::RegisterSubstitution(
78 const SubstitutionMapping& aSubstitution) {
79 nsCOMPtr<nsIIOService> io(do_GetIOService());
80 if (!io) return;
82 nsCOMPtr<nsIProtocolHandler> ph;
83 nsresult rv =
84 io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph));
85 if (NS_FAILED(rv)) return;
87 nsCOMPtr<nsISubstitutingProtocolHandler> sph(do_QueryInterface(ph));
88 if (!sph) return;
90 nsCOMPtr<nsIURI> resolvedURI;
91 if (aSubstitution.resolvedURI.spec.Length()) {
92 rv = NS_NewURI(getter_AddRefs(resolvedURI), aSubstitution.resolvedURI.spec,
93 nullptr, nullptr, io);
94 if (NS_FAILED(rv)) return;
97 rv = sph->SetSubstitutionWithFlags(aSubstitution.path, resolvedURI,
98 aSubstitution.flags);
99 if (NS_FAILED(rv)) return;
102 void nsChromeRegistryContent::RegisterOverride(
103 const OverrideMapping& aOverride) {
104 nsCOMPtr<nsIIOService> io(do_GetIOService());
105 if (!io) return;
107 nsCOMPtr<nsIURI> chromeURI, overrideURI;
108 nsresult rv = NS_NewURI(getter_AddRefs(chromeURI), aOverride.originalURI.spec,
109 nullptr, nullptr, io);
110 if (NS_FAILED(rv)) return;
112 rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
113 nullptr, nullptr, io);
114 if (NS_FAILED(rv)) return;
116 mOverrideTable.Put(chromeURI, overrideURI);
119 nsIURI* nsChromeRegistryContent::GetBaseURIFromPackage(
120 const nsCString& aPackage, const nsCString& aProvider,
121 const nsCString& aPath) {
122 PackageEntry* entry;
123 if (!mPackagesHash.Get(aPackage, &entry)) {
124 return nullptr;
127 if (aProvider.EqualsLiteral("locale")) {
128 return entry->localeBaseURI;
129 } else if (aProvider.EqualsLiteral("skin")) {
130 return entry->skinBaseURI;
131 } else if (aProvider.EqualsLiteral("content")) {
132 return entry->contentBaseURI;
134 return nullptr;
137 nsresult nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
138 uint32_t* aFlags) {
139 PackageEntry* entry;
140 if (!mPackagesHash.Get(aPackage, &entry)) {
141 return NS_ERROR_FAILURE;
143 *aFlags = entry->flags;
144 return NS_OK;
147 // All functions following only make sense in chrome, and therefore assert
149 #define CONTENT_NOTREACHED() \
150 MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
152 #define CONTENT_NOT_IMPLEMENTED() \
153 CONTENT_NOTREACHED(); \
154 return NS_ERROR_NOT_IMPLEMENTED;
156 NS_IMETHODIMP
157 nsChromeRegistryContent::GetLocalesForPackage(
158 const nsACString& aPackage, nsIUTF8StringEnumerator** aResult) {
159 CONTENT_NOT_IMPLEMENTED();
162 NS_IMETHODIMP
163 nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
165 NS_IMETHODIMP
166 nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage,
167 bool* aResult) {
168 *aResult = GetDirectionForLocale(mLocale);
169 return NS_OK;
172 NS_IMETHODIMP
173 nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
174 bool aAsBCP47, nsACString& aLocale) {
175 if (aPackage != nsDependentCString("global")) {
176 NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
177 return NS_ERROR_NOT_AVAILABLE;
179 aLocale = mLocale;
180 if (aAsBCP47) {
181 SanitizeForBCP47(aLocale);
183 return NS_OK;
186 NS_IMETHODIMP
187 nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
188 const char16_t* aData) {
189 CONTENT_NOT_IMPLEMENTED();
192 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
193 int lineno, char* const* argv,
194 int flags) {
195 CONTENT_NOTREACHED();
198 void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
199 int lineno, char* const* argv,
200 int flags) {
201 CONTENT_NOTREACHED();
204 void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
205 int lineno, char* const* argv,
206 int flags) {
207 CONTENT_NOTREACHED();
210 void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
211 int lineno, char* const* argv,
212 int flags) {
213 CONTENT_NOTREACHED();
216 void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
217 int lineno, char* const* argv,
218 int flags) {
219 CONTENT_NOTREACHED();