nsChromeRegistryContent.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. #include "RegistryMessageUtils.h"
  6. #include "nsChromeRegistryContent.h"
  7. #include "nsString.h"
  8. #include "nsNetUtil.h"
  9. #include "nsIResProtocolHandler.h"
  10. nsChromeRegistryContent::nsChromeRegistryContent()
  11. {
  12. }
  13. void
  14. nsChromeRegistryContent::RegisterRemoteChrome(
  15. const InfallibleTArray<ChromePackage>& aPackages,
  16. const InfallibleTArray<SubstitutionMapping>& aSubstitutions,
  17. const InfallibleTArray<OverrideMapping>& aOverrides,
  18. const nsACString& aLocale,
  19. bool aReset)
  20. {
  21. MOZ_ASSERT(aReset || mLocale.IsEmpty(),
  22. "RegisterChrome twice?");
  23. if (aReset) {
  24. mPackagesHash.Clear();
  25. mOverrideTable.Clear();
  26. // XXX Can't clear resources.
  27. }
  28. for (uint32_t i = aPackages.Length(); i > 0; ) {
  29. --i;
  30. RegisterPackage(aPackages[i]);
  31. }
  32. for (uint32_t i = aSubstitutions.Length(); i > 0; ) {
  33. --i;
  34. RegisterSubstitution(aSubstitutions[i]);
  35. }
  36. for (uint32_t i = aOverrides.Length(); i > 0; ) {
  37. --i;
  38. RegisterOverride(aOverrides[i]);
  39. }
  40. mLocale = aLocale;
  41. }
  42. void
  43. nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage)
  44. {
  45. nsCOMPtr<nsIIOService> io (do_GetIOService());
  46. if (!io)
  47. return;
  48. nsCOMPtr<nsIURI> content, locale, skin;
  49. if (aPackage.contentBaseURI.spec.Length()) {
  50. nsresult rv = NS_NewURI(getter_AddRefs(content),
  51. aPackage.contentBaseURI.spec,
  52. aPackage.contentBaseURI.charset.get(),
  53. nullptr, io);
  54. if (NS_FAILED(rv))
  55. return;
  56. }
  57. if (aPackage.localeBaseURI.spec.Length()) {
  58. nsresult rv = NS_NewURI(getter_AddRefs(locale),
  59. aPackage.localeBaseURI.spec,
  60. aPackage.localeBaseURI.charset.get(),
  61. nullptr, io);
  62. if (NS_FAILED(rv))
  63. return;
  64. }
  65. if (aPackage.skinBaseURI.spec.Length()) {
  66. nsresult rv = NS_NewURI(getter_AddRefs(skin),
  67. aPackage.skinBaseURI.spec,
  68. aPackage.skinBaseURI.charset.get(),
  69. nullptr, io);
  70. if (NS_FAILED(rv))
  71. return;
  72. }
  73. PackageEntry* entry = new PackageEntry;
  74. entry->flags = aPackage.flags;
  75. entry->contentBaseURI = content;
  76. entry->localeBaseURI = locale;
  77. entry->skinBaseURI = skin;
  78. mPackagesHash.Put(aPackage.package, entry);
  79. }
  80. void
  81. nsChromeRegistryContent::RegisterSubstitution(const SubstitutionMapping& aSubstitution)
  82. {
  83. nsCOMPtr<nsIIOService> io (do_GetIOService());
  84. if (!io)
  85. return;
  86. nsCOMPtr<nsIProtocolHandler> ph;
  87. nsresult rv = io->GetProtocolHandler(aSubstitution.scheme.get(), getter_AddRefs(ph));
  88. if (NS_FAILED(rv))
  89. return;
  90. nsCOMPtr<nsISubstitutingProtocolHandler> sph (do_QueryInterface(ph));
  91. if (!sph)
  92. return;
  93. nsCOMPtr<nsIURI> resolvedURI;
  94. if (aSubstitution.resolvedURI.spec.Length()) {
  95. rv = NS_NewURI(getter_AddRefs(resolvedURI),
  96. aSubstitution.resolvedURI.spec,
  97. aSubstitution.resolvedURI.charset.get(),
  98. nullptr, io);
  99. if (NS_FAILED(rv))
  100. return;
  101. }
  102. rv = sph->SetSubstitution(aSubstitution.path, resolvedURI);
  103. if (NS_FAILED(rv))
  104. return;
  105. }
  106. void
  107. nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride)
  108. {
  109. nsCOMPtr<nsIIOService> io (do_GetIOService());
  110. if (!io)
  111. return;
  112. nsCOMPtr<nsIURI> chromeURI, overrideURI;
  113. nsresult rv = NS_NewURI(getter_AddRefs(chromeURI),
  114. aOverride.originalURI.spec,
  115. aOverride.originalURI.charset.get(),
  116. nullptr, io);
  117. if (NS_FAILED(rv))
  118. return;
  119. rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
  120. aOverride.overrideURI.charset.get(), nullptr, io);
  121. if (NS_FAILED(rv))
  122. return;
  123. mOverrideTable.Put(chromeURI, overrideURI);
  124. }
  125. nsIURI*
  126. nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage,
  127. const nsCString& aProvider,
  128. const nsCString& aPath)
  129. {
  130. PackageEntry* entry;
  131. if (!mPackagesHash.Get(aPackage, &entry)) {
  132. return nullptr;
  133. }
  134. if (aProvider.EqualsLiteral("locale")) {
  135. return entry->localeBaseURI;
  136. }
  137. else if (aProvider.EqualsLiteral("skin")) {
  138. return entry->skinBaseURI;
  139. }
  140. else if (aProvider.EqualsLiteral("content")) {
  141. return entry->contentBaseURI;
  142. }
  143. return nullptr;
  144. }
  145. nsresult
  146. nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
  147. uint32_t* aFlags)
  148. {
  149. PackageEntry* entry;
  150. if (!mPackagesHash.Get(aPackage, &entry)) {
  151. return NS_ERROR_FAILURE;
  152. }
  153. *aFlags = entry->flags;
  154. return NS_OK;
  155. }
  156. // All functions following only make sense in chrome, and therefore assert
  157. #define CONTENT_NOTREACHED() \
  158. NS_NOTREACHED("Content should not be calling this")
  159. #define CONTENT_NOT_IMPLEMENTED() \
  160. CONTENT_NOTREACHED(); \
  161. return NS_ERROR_NOT_IMPLEMENTED;
  162. NS_IMETHODIMP
  163. nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage,
  164. nsIUTF8StringEnumerator* *aResult)
  165. {
  166. CONTENT_NOT_IMPLEMENTED();
  167. }
  168. NS_IMETHODIMP
  169. nsChromeRegistryContent::CheckForOSAccessibility()
  170. {
  171. CONTENT_NOT_IMPLEMENTED();
  172. }
  173. NS_IMETHODIMP
  174. nsChromeRegistryContent::CheckForNewChrome()
  175. {
  176. CONTENT_NOT_IMPLEMENTED();
  177. }
  178. NS_IMETHODIMP
  179. nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage,
  180. bool *aResult)
  181. {
  182. if (aPackage != nsDependentCString("global")) {
  183. NS_ERROR("Packages other than global unavailable");
  184. return NS_ERROR_NOT_AVAILABLE;
  185. }
  186. *aResult = GetDirectionForLocale(mLocale);
  187. return NS_OK;
  188. }
  189. NS_IMETHODIMP
  190. nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
  191. bool aAsBCP47,
  192. nsACString& aLocale)
  193. {
  194. if (aPackage != nsDependentCString("global")) {
  195. NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
  196. return NS_ERROR_NOT_AVAILABLE;
  197. }
  198. aLocale = mLocale;
  199. if (aAsBCP47) {
  200. SanitizeForBCP47(aLocale);
  201. }
  202. return NS_OK;
  203. }
  204. NS_IMETHODIMP
  205. nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
  206. const char16_t* aData)
  207. {
  208. CONTENT_NOT_IMPLEMENTED();
  209. }
  210. NS_IMETHODIMP
  211. nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL,
  212. nsISimpleEnumerator **aResult)
  213. {
  214. CONTENT_NOT_IMPLEMENTED();
  215. }
  216. NS_IMETHODIMP
  217. nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL,
  218. nsISimpleEnumerator **aResult)
  219. {
  220. CONTENT_NOT_IMPLEMENTED();
  221. }
  222. nsresult nsChromeRegistryContent::UpdateSelectedLocale()
  223. {
  224. CONTENT_NOT_IMPLEMENTED();
  225. }
  226. void
  227. nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
  228. int lineno, char *const * argv,
  229. int flags)
  230. {
  231. CONTENT_NOTREACHED();
  232. }
  233. void
  234. nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
  235. int lineno,
  236. char *const * argv, int flags)
  237. {
  238. CONTENT_NOTREACHED();
  239. }
  240. void
  241. nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
  242. int lineno,
  243. char *const * argv, int flags)
  244. {
  245. CONTENT_NOTREACHED();
  246. }
  247. void
  248. nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno,
  249. char *const * argv, int flags)
  250. {
  251. CONTENT_NOTREACHED();
  252. }
  253. void
  254. nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx,
  255. int lineno,
  256. char *const * argv, int flags)
  257. {
  258. CONTENT_NOTREACHED();
  259. }
  260. void
  261. nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
  262. int lineno,
  263. char *const * argv, int flags)
  264. {
  265. CONTENT_NOTREACHED();
  266. }
  267. void
  268. nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
  269. int lineno,
  270. char *const * argv, int flags)
  271. {
  272. CONTENT_NOTREACHED();
  273. }