Bug 1850904 - Expand media.allow-audio-non-utility to early beta r=alwu
[gecko.git] / chrome / nsChromeRegistryContent.cpp
blob9b213a3ab95f2f828c1b91b993575872dbfc33a2
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 "nsISubstitutingProtocolHandler.h"
10 #include "nsString.h"
11 #include "nsNetUtil.h"
12 #include "mozilla/UniquePtr.h"
14 nsChromeRegistryContent::nsChromeRegistryContent() {}
16 void nsChromeRegistryContent::RegisterRemoteChrome(
17 const nsTArray<ChromePackage>& aPackages,
18 const nsTArray<SubstitutionMapping>& aSubstitutions,
19 const nsTArray<OverrideMapping>& aOverrides, const nsACString& aLocale,
20 bool aReset) {
21 MOZ_ASSERT(aReset || mLocale.IsEmpty(), "RegisterChrome twice?");
23 if (aReset) {
24 mPackagesHash.Clear();
25 mOverrideTable.Clear();
26 // XXX Can't clear resources.
29 for (uint32_t i = aPackages.Length(); i > 0;) {
30 --i;
31 RegisterPackage(aPackages[i]);
34 for (uint32_t i = aSubstitutions.Length(); i > 0;) {
35 --i;
36 RegisterSubstitution(aSubstitutions[i]);
39 for (uint32_t i = aOverrides.Length(); i > 0;) {
40 --i;
41 RegisterOverride(aOverrides[i]);
44 mLocale = aLocale;
47 void nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) {
48 nsCOMPtr<nsIURI> content, locale, skin;
50 if (aPackage.contentBaseURI.spec.Length()) {
51 nsresult rv =
52 NS_NewURI(getter_AddRefs(content), aPackage.contentBaseURI.spec);
53 if (NS_FAILED(rv)) return;
55 if (aPackage.localeBaseURI.spec.Length()) {
56 nsresult rv =
57 NS_NewURI(getter_AddRefs(locale), aPackage.localeBaseURI.spec);
58 if (NS_FAILED(rv)) return;
60 if (aPackage.skinBaseURI.spec.Length()) {
61 nsresult rv = NS_NewURI(getter_AddRefs(skin), aPackage.skinBaseURI.spec);
62 if (NS_FAILED(rv)) return;
65 mozilla::UniquePtr<PackageEntry> entry = mozilla::MakeUnique<PackageEntry>();
66 entry->flags = aPackage.flags;
67 entry->contentBaseURI = content;
68 entry->localeBaseURI = locale;
69 entry->skinBaseURI = skin;
71 mPackagesHash.InsertOrUpdate(aPackage.package, std::move(entry));
74 void nsChromeRegistryContent::RegisterSubstitution(
75 const SubstitutionMapping& aSubstitution) {
76 nsCOMPtr<nsIIOService> io(do_GetIOService());
77 if (!io) return;
79 nsCOMPtr<nsIProtocolHandler> ph;
80 nsresult rv =
81 io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph));
82 if (NS_FAILED(rv)) return;
84 nsCOMPtr<nsISubstitutingProtocolHandler> sph(do_QueryInterface(ph));
85 if (!sph) return;
87 nsCOMPtr<nsIURI> resolvedURI;
88 if (aSubstitution.resolvedURI.spec.Length()) {
89 rv = NS_NewURI(getter_AddRefs(resolvedURI), aSubstitution.resolvedURI.spec);
90 if (NS_FAILED(rv)) return;
93 rv = sph->SetSubstitutionWithFlags(aSubstitution.path, resolvedURI,
94 aSubstitution.flags);
95 if (NS_FAILED(rv)) return;
98 void nsChromeRegistryContent::RegisterOverride(
99 const OverrideMapping& aOverride) {
100 nsCOMPtr<nsIURI> chromeURI, overrideURI;
101 nsresult rv =
102 NS_NewURI(getter_AddRefs(chromeURI), aOverride.originalURI.spec);
103 if (NS_FAILED(rv)) return;
105 rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec);
106 if (NS_FAILED(rv)) return;
108 mOverrideTable.InsertOrUpdate(chromeURI, overrideURI);
111 nsIURI* nsChromeRegistryContent::GetBaseURIFromPackage(
112 const nsCString& aPackage, const nsCString& aProvider,
113 const nsCString& aPath) {
114 PackageEntry* entry;
115 if (!mPackagesHash.Get(aPackage, &entry)) {
116 return nullptr;
119 if (aProvider.EqualsLiteral("locale")) {
120 return entry->localeBaseURI;
123 if (aProvider.EqualsLiteral("skin")) {
124 return entry->skinBaseURI;
127 if (aProvider.EqualsLiteral("content")) {
128 return entry->contentBaseURI;
131 return nullptr;
134 nsresult nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
135 uint32_t* aFlags) {
136 PackageEntry* entry;
137 if (!mPackagesHash.Get(aPackage, &entry)) {
138 return NS_ERROR_FAILURE;
140 *aFlags = entry->flags;
141 return NS_OK;
144 // All functions following only make sense in chrome, and therefore assert
146 #define CONTENT_NOTREACHED() \
147 MOZ_ASSERT_UNREACHABLE("Content should not be calling this")
149 #define CONTENT_NOT_IMPLEMENTED() \
150 CONTENT_NOTREACHED(); \
151 return NS_ERROR_NOT_IMPLEMENTED;
153 NS_IMETHODIMP
154 nsChromeRegistryContent::GetLocalesForPackage(
155 const nsACString& aPackage, nsIUTF8StringEnumerator** aResult) {
156 CONTENT_NOT_IMPLEMENTED();
159 NS_IMETHODIMP
160 nsChromeRegistryContent::CheckForNewChrome() { CONTENT_NOT_IMPLEMENTED(); }
162 NS_IMETHODIMP
163 nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage,
164 bool* aResult) {
165 *aResult = mozilla::intl::LocaleService::IsLocaleRTL(mLocale);
166 return NS_OK;
169 NS_IMETHODIMP
170 nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
171 const char16_t* aData) {
172 CONTENT_NOT_IMPLEMENTED();
175 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
176 int lineno, char* const* argv,
177 int flags) {
178 CONTENT_NOTREACHED();
181 void nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
182 int lineno, char* const* argv,
183 int flags) {
184 CONTENT_NOTREACHED();
187 void nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
188 int lineno, char* const* argv,
189 int flags) {
190 CONTENT_NOTREACHED();
193 void nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
194 int lineno, char* const* argv,
195 int flags) {
196 CONTENT_NOTREACHED();
199 void nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
200 int lineno, char* const* argv,
201 int flags) {
202 CONTENT_NOTREACHED();