chrome/src/nsChromeRegistryContent.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/chrome/src/nsChromeRegistryContent.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,308 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "RegistryMessageUtils.h"
    1.10 +#include "nsChromeRegistryContent.h"
    1.11 +#include "nsString.h"
    1.12 +#include "nsNetUtil.h"
    1.13 +#include "nsIResProtocolHandler.h"
    1.14 +
    1.15 +nsChromeRegistryContent::nsChromeRegistryContent()
    1.16 +{
    1.17 +}
    1.18 +
    1.19 +void
    1.20 +nsChromeRegistryContent::RegisterRemoteChrome(
    1.21 +    const InfallibleTArray<ChromePackage>& aPackages,
    1.22 +    const InfallibleTArray<ResourceMapping>& aResources,
    1.23 +    const InfallibleTArray<OverrideMapping>& aOverrides,
    1.24 +    const nsACString& aLocale)
    1.25 +{
    1.26 +  NS_ABORT_IF_FALSE(mLocale == nsDependentCString(""),
    1.27 +                    "RegisterChrome twice?");
    1.28 +
    1.29 +  for (uint32_t i = aPackages.Length(); i > 0; ) {
    1.30 +    --i;
    1.31 +    RegisterPackage(aPackages[i]);
    1.32 +  }
    1.33 +
    1.34 +  for (uint32_t i = aResources.Length(); i > 0; ) {
    1.35 +    --i;
    1.36 +    RegisterResource(aResources[i]);
    1.37 +  }
    1.38 +
    1.39 +  for (uint32_t i = aOverrides.Length(); i > 0; ) {
    1.40 +    --i;
    1.41 +    RegisterOverride(aOverrides[i]);
    1.42 +  }
    1.43 +
    1.44 +  mLocale = aLocale;
    1.45 +}
    1.46 +
    1.47 +void
    1.48 +nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage)
    1.49 +{
    1.50 +  nsCOMPtr<nsIIOService> io (do_GetIOService());
    1.51 +  if (!io)
    1.52 +    return;
    1.53 +
    1.54 +  nsCOMPtr<nsIURI> content, locale, skin;
    1.55 +
    1.56 +  if (aPackage.contentBaseURI.spec.Length()) {
    1.57 +    nsresult rv = NS_NewURI(getter_AddRefs(content),
    1.58 +                            aPackage.contentBaseURI.spec,
    1.59 +                            aPackage.contentBaseURI.charset.get(),
    1.60 +                            nullptr, io);
    1.61 +    if (NS_FAILED(rv))
    1.62 +      return;
    1.63 +  }
    1.64 +  if (aPackage.localeBaseURI.spec.Length()) {
    1.65 +    nsresult rv = NS_NewURI(getter_AddRefs(locale),
    1.66 +                            aPackage.localeBaseURI.spec,
    1.67 +                            aPackage.localeBaseURI.charset.get(),
    1.68 +                            nullptr, io);
    1.69 +    if (NS_FAILED(rv))
    1.70 +      return;
    1.71 +  }
    1.72 +  if (aPackage.skinBaseURI.spec.Length()) {
    1.73 +    nsCOMPtr<nsIURI> skinBaseURI;
    1.74 +    nsresult rv = NS_NewURI(getter_AddRefs(skin),
    1.75 +                            aPackage.skinBaseURI.spec,
    1.76 +                            aPackage.skinBaseURI.charset.get(),
    1.77 +                            nullptr, io);
    1.78 +    if (NS_FAILED(rv))
    1.79 +      return;
    1.80 +  }
    1.81 +
    1.82 +  PackageEntry* entry = new PackageEntry;
    1.83 +  entry->flags = aPackage.flags;
    1.84 +  entry->contentBaseURI = content;
    1.85 +  entry->localeBaseURI = locale;
    1.86 +  entry->skinBaseURI = skin;
    1.87 +
    1.88 +  mPackagesHash.Put(aPackage.package, entry);
    1.89 +}
    1.90 +
    1.91 +void
    1.92 +nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource)
    1.93 +{
    1.94 +  nsCOMPtr<nsIIOService> io (do_GetIOService());
    1.95 +  if (!io)
    1.96 +    return;
    1.97 +
    1.98 +  nsCOMPtr<nsIProtocolHandler> ph;
    1.99 +  nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph));
   1.100 +  if (NS_FAILED(rv))
   1.101 +    return;
   1.102 +  
   1.103 +  nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph));
   1.104 +  if (!rph)
   1.105 +    return;
   1.106 +
   1.107 +  nsCOMPtr<nsIURI> resolvedURI;
   1.108 +  if (aResource.resolvedURI.spec.Length()) {
   1.109 +    nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI),
   1.110 +                            aResource.resolvedURI.spec,
   1.111 +                            aResource.resolvedURI.charset.get(),
   1.112 +                            nullptr, io);                 
   1.113 +    if (NS_FAILED(rv))
   1.114 +      return;
   1.115 +  }
   1.116 +
   1.117 +  rv = rph->SetSubstitution(aResource.resource, resolvedURI);
   1.118 +  if (NS_FAILED(rv))
   1.119 +    return;
   1.120 +}
   1.121 +
   1.122 +void
   1.123 +nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride)
   1.124 +{
   1.125 +  nsCOMPtr<nsIIOService> io (do_GetIOService());
   1.126 +  if (!io)
   1.127 +    return;
   1.128 +
   1.129 +  nsCOMPtr<nsIURI> chromeURI, overrideURI;
   1.130 +  nsresult rv = NS_NewURI(getter_AddRefs(chromeURI),
   1.131 +                          aOverride.originalURI.spec,
   1.132 +                          aOverride.originalURI.charset.get(),
   1.133 +                          nullptr, io);
   1.134 +  if (NS_FAILED(rv))
   1.135 +    return;
   1.136 +
   1.137 +  rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec,
   1.138 +                 aOverride.overrideURI.charset.get(), nullptr, io);
   1.139 +  if (NS_FAILED(rv))
   1.140 +    return;
   1.141 +  
   1.142 +  mOverrideTable.Put(chromeURI, overrideURI);
   1.143 +}
   1.144 +
   1.145 +nsIURI*
   1.146 +nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage,
   1.147 +                                               const nsCString& aProvider,
   1.148 +                                               const nsCString& aPath)
   1.149 +{
   1.150 +  PackageEntry* entry;
   1.151 +  if (!mPackagesHash.Get(aPackage, &entry)) {
   1.152 +    return nullptr;
   1.153 +  }
   1.154 +
   1.155 +  if (aProvider.EqualsLiteral("locale")) {
   1.156 +    return entry->localeBaseURI;
   1.157 +  }
   1.158 +  else if (aProvider.EqualsLiteral("skin")) {
   1.159 +    return entry->skinBaseURI;
   1.160 +  }
   1.161 +  else if (aProvider.EqualsLiteral("content")) {
   1.162 +    return entry->contentBaseURI;
   1.163 +  }
   1.164 +  return nullptr;
   1.165 +}
   1.166 +
   1.167 +nsresult
   1.168 +nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage,
   1.169 +                                             uint32_t* aFlags)
   1.170 +{
   1.171 +  PackageEntry* entry;
   1.172 +  if (!mPackagesHash.Get(aPackage, &entry)) {
   1.173 +    return NS_ERROR_FAILURE;
   1.174 +  }
   1.175 +  *aFlags = entry->flags;
   1.176 +  return NS_OK;
   1.177 +}
   1.178 +
   1.179 +// All functions following only make sense in chrome, and therefore assert
   1.180 +
   1.181 +#define CONTENT_NOTREACHED() \
   1.182 +  NS_NOTREACHED("Content should not be calling this")
   1.183 +
   1.184 +#define CONTENT_NOT_IMPLEMENTED() \
   1.185 +  CONTENT_NOTREACHED();           \
   1.186 +  return NS_ERROR_NOT_IMPLEMENTED;
   1.187 +
   1.188 +NS_IMETHODIMP
   1.189 +nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage,
   1.190 +                                              nsIUTF8StringEnumerator* *aResult)
   1.191 +{
   1.192 +  CONTENT_NOT_IMPLEMENTED();
   1.193 +}
   1.194 +
   1.195 +NS_IMETHODIMP
   1.196 +nsChromeRegistryContent::CheckForOSAccessibility()
   1.197 +{
   1.198 +  CONTENT_NOT_IMPLEMENTED();
   1.199 +}
   1.200 +
   1.201 +NS_IMETHODIMP
   1.202 +nsChromeRegistryContent::CheckForNewChrome()
   1.203 +{
   1.204 +  CONTENT_NOT_IMPLEMENTED();
   1.205 +}
   1.206 +
   1.207 +NS_IMETHODIMP
   1.208 +nsChromeRegistryContent::IsLocaleRTL(const nsACString& package,
   1.209 +                                     bool *aResult)
   1.210 +{
   1.211 +  CONTENT_NOT_IMPLEMENTED();
   1.212 +}
   1.213 +
   1.214 +NS_IMETHODIMP
   1.215 +nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
   1.216 +                                           nsACString& aLocale)
   1.217 +{
   1.218 +  if (aPackage != nsDependentCString("global")) {
   1.219 +    NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
   1.220 +    return NS_ERROR_NOT_AVAILABLE;
   1.221 +  }
   1.222 +  aLocale = mLocale;
   1.223 +  return NS_OK;
   1.224 +}
   1.225 +  
   1.226 +NS_IMETHODIMP
   1.227 +nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
   1.228 +                                 const char16_t* aData)
   1.229 +{
   1.230 +  CONTENT_NOT_IMPLEMENTED();
   1.231 +}
   1.232 +
   1.233 +NS_IMETHODIMP
   1.234 +nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL,
   1.235 +                                          nsISimpleEnumerator **aResult)
   1.236 +{
   1.237 +  CONTENT_NOT_IMPLEMENTED();
   1.238 +}
   1.239 +
   1.240 +NS_IMETHODIMP
   1.241 +nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL,
   1.242 +                                        nsISimpleEnumerator **aResult)
   1.243 +{
   1.244 +  CONTENT_NOT_IMPLEMENTED();
   1.245 +}
   1.246 +
   1.247 +nsresult nsChromeRegistryContent::UpdateSelectedLocale()
   1.248 +{
   1.249 +  CONTENT_NOT_IMPLEMENTED();
   1.250 +}
   1.251 +
   1.252 +void
   1.253 +nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
   1.254 +                                         int lineno, char *const * argv,
   1.255 +                                         bool platform, bool contentaccessible)
   1.256 +{
   1.257 +  CONTENT_NOTREACHED();
   1.258 +}
   1.259 +
   1.260 +void
   1.261 +nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx,
   1.262 +                                        int lineno,
   1.263 +                                        char *const * argv, bool platform,
   1.264 +                                        bool contentaccessible)
   1.265 +{
   1.266 +  CONTENT_NOTREACHED();
   1.267 +}
   1.268 +
   1.269 +void
   1.270 +nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx,
   1.271 +                                      int lineno,
   1.272 +                                      char *const * argv, bool platform,
   1.273 +                                      bool contentaccessible)
   1.274 +{
   1.275 +  CONTENT_NOTREACHED();
   1.276 +}
   1.277 +
   1.278 +void
   1.279 +nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno,
   1.280 +                                         char *const * argv, bool platform,
   1.281 +                                         bool contentaccessible)
   1.282 +{
   1.283 +  CONTENT_NOTREACHED();
   1.284 +}
   1.285 +
   1.286 +void
   1.287 +nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx,
   1.288 +                                       int lineno,
   1.289 +                                       char *const * argv, bool platform,
   1.290 +                                       bool contentaccessible)
   1.291 +{
   1.292 +  CONTENT_NOTREACHED();
   1.293 +}
   1.294 +
   1.295 +void
   1.296 +nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx,
   1.297 +                                          int lineno,
   1.298 +                                          char *const * argv, bool platform,
   1.299 +                                          bool contentaccessible)
   1.300 +{
   1.301 +  CONTENT_NOTREACHED();
   1.302 +}
   1.303 +
   1.304 +void
   1.305 +nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx,
   1.306 +                                          int lineno,
   1.307 +                                          char *const * argv, bool platform,
   1.308 +                                          bool contentaccessible)
   1.309 +{
   1.310 +  CONTENT_NOTREACHED();
   1.311 +}

mercurial