Bug 1699062 - Flatten toolkit/themes/*/global/alerts/. r=desktop-theme-reviewers,dao
[gecko.git] / chrome / nsChromeRegistryContent.cpp
blob739dcba727b68daa93a86b43a2c5203ccfe56629
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"
12 nsChromeRegistryContent::nsChromeRegistryContent() {}
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?");
21 if (aReset) {
22 mPackagesHash.Clear();
23 mOverrideTable.Clear();
24 // XXX Can't clear resources.
27 for (uint32_t i = aPackages.Length(); i > 0;) {
28 --i;
29 RegisterPackage(aPackages[i]);
32 for (uint32_t i = aSubstitutions.Length(); i > 0;) {
33 --i;
34 RegisterSubstitution(aSubstitutions[i]);
37 for (uint32_t i = aOverrides.Length(); i > 0;) {
38 --i;
39 RegisterOverride(aOverrides[i]);
42 mLocale = aLocale;
45 void nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) {
46 nsCOMPtr<nsIURI> content, locale, skin;
48 if (aPackage.contentBaseURI.spec.Length()) {
49 nsresult rv =
50 NS_NewURI(getter_AddRefs(content), aPackage.contentBaseURI.spec);
51 if (NS_FAILED(rv)) return;
53 if (aPackage.localeBaseURI.spec.Length()) {
54 nsresult rv =
55 NS_NewURI(getter_AddRefs(locale), aPackage.localeBaseURI.spec);
56 if (NS_FAILED(rv)) return;
58 if (aPackage.skinBaseURI.spec.Length()) {
59 nsresult rv = NS_NewURI(getter_AddRefs(skin), aPackage.skinBaseURI.spec);
60 if (NS_FAILED(rv)) return;
63 UniquePtr<PackageEntry> entry = MakeUnique<PackageEntry>();
64 entry->flags = aPackage.flags;
65 entry->contentBaseURI = content;
66 entry->localeBaseURI = locale;
67 entry->skinBaseURI = skin;
69 mPackagesHash.InsertOrUpdate(aPackage.package, std::move(entry));
72 void nsChromeRegistryContent::RegisterSubstitution(
73 const SubstitutionMapping& aSubstitution) {
74 nsCOMPtr<nsIIOService> io(do_GetIOService());
75 if (!io) return;
77 nsCOMPtr<nsIProtocolHandler> ph;
78 nsresult rv =
79 io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph));
80 if (NS_FAILED(rv)) return;
82 nsCOMPtr<nsISubstitutingProtocolHandler> sph(do_QueryInterface(ph));
83 if (!sph) return;
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;
91 rv = sph->SetSubstitutionWithFlags(aSubstitution.path, resolvedURI,
92 aSubstitution.flags);
93 if (NS_FAILED(rv)) return;
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;
103 rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec);
104 if (NS_FAILED(rv)) return;
106 mOverrideTable.InsertOrUpdate(chromeURI, overrideURI);
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;
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;
124 return nullptr;
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;
133 *aFlags = entry->flags;
134 return NS_OK;
137 // All functions following only make sense in chrome, and therefore assert
139 #define CONTENT_NOTREACHED() \
140 MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
142 #define CONTENT_NOT_IMPLEMENTED() \
143 CONTENT_NOTREACHED(); \
144 return NS_ERROR_NOT_IMPLEMENTED;
146 NS_IMETHODIMP
147 nsChromeRegistryContent::GetLocalesForPackage(
148 const nsACString& aPackage, nsIUTF8StringEnumerator** aResult) {
149 CONTENT_NOT_IMPLEMENTED();
152 NS_IMETHODIMP
153 nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
155 NS_IMETHODIMP
156 nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage,
157 bool* aResult) {
158 *aResult = mozilla::intl::LocaleService::IsLocaleRTL(mLocale);
159 return NS_OK;
162 NS_IMETHODIMP
163 nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
164 const char16_t* aData) {
165 CONTENT_NOT_IMPLEMENTED();
168 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
169 int lineno, char* const* argv,
170 int flags) {
171 CONTENT_NOTREACHED();
174 void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
175 int lineno, char* const* argv,
176 int flags) {
177 CONTENT_NOTREACHED();
180 void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
181 int lineno, char* const* argv,
182 int flags) {
183 CONTENT_NOTREACHED();
186 void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
187 int lineno, char* const* argv,
188 int flags) {
189 CONTENT_NOTREACHED();
192 void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
193 int lineno, char* const* argv,
194 int flags) {
195 CONTENT_NOTREACHED();