LCOV - code coverage report
Current view: top level - chrome - nsChromeRegistryContent.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 76 140 54.3 %
Date: 2017-07-14 16:53:18 Functions: 7 22 31.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13