michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "RegistryMessageUtils.h" michael@0: #include "nsChromeRegistryContent.h" michael@0: #include "nsString.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsIResProtocolHandler.h" michael@0: michael@0: nsChromeRegistryContent::nsChromeRegistryContent() michael@0: { michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::RegisterRemoteChrome( michael@0: const InfallibleTArray& aPackages, michael@0: const InfallibleTArray& aResources, michael@0: const InfallibleTArray& aOverrides, michael@0: const nsACString& aLocale) michael@0: { michael@0: NS_ABORT_IF_FALSE(mLocale == nsDependentCString(""), michael@0: "RegisterChrome twice?"); michael@0: michael@0: for (uint32_t i = aPackages.Length(); i > 0; ) { michael@0: --i; michael@0: RegisterPackage(aPackages[i]); michael@0: } michael@0: michael@0: for (uint32_t i = aResources.Length(); i > 0; ) { michael@0: --i; michael@0: RegisterResource(aResources[i]); michael@0: } michael@0: michael@0: for (uint32_t i = aOverrides.Length(); i > 0; ) { michael@0: --i; michael@0: RegisterOverride(aOverrides[i]); michael@0: } michael@0: michael@0: mLocale = aLocale; michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) michael@0: { michael@0: nsCOMPtr io (do_GetIOService()); michael@0: if (!io) michael@0: return; michael@0: michael@0: nsCOMPtr content, locale, skin; michael@0: michael@0: if (aPackage.contentBaseURI.spec.Length()) { michael@0: nsresult rv = NS_NewURI(getter_AddRefs(content), michael@0: aPackage.contentBaseURI.spec, michael@0: aPackage.contentBaseURI.charset.get(), michael@0: nullptr, io); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: } michael@0: if (aPackage.localeBaseURI.spec.Length()) { michael@0: nsresult rv = NS_NewURI(getter_AddRefs(locale), michael@0: aPackage.localeBaseURI.spec, michael@0: aPackage.localeBaseURI.charset.get(), michael@0: nullptr, io); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: } michael@0: if (aPackage.skinBaseURI.spec.Length()) { michael@0: nsCOMPtr skinBaseURI; michael@0: nsresult rv = NS_NewURI(getter_AddRefs(skin), michael@0: aPackage.skinBaseURI.spec, michael@0: aPackage.skinBaseURI.charset.get(), michael@0: nullptr, io); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: } michael@0: michael@0: PackageEntry* entry = new PackageEntry; michael@0: entry->flags = aPackage.flags; michael@0: entry->contentBaseURI = content; michael@0: entry->localeBaseURI = locale; michael@0: entry->skinBaseURI = skin; michael@0: michael@0: mPackagesHash.Put(aPackage.package, entry); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource) michael@0: { michael@0: nsCOMPtr io (do_GetIOService()); michael@0: if (!io) michael@0: return; michael@0: michael@0: nsCOMPtr ph; michael@0: nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph)); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: michael@0: nsCOMPtr rph (do_QueryInterface(ph)); michael@0: if (!rph) michael@0: return; michael@0: michael@0: nsCOMPtr resolvedURI; michael@0: if (aResource.resolvedURI.spec.Length()) { michael@0: nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), michael@0: aResource.resolvedURI.spec, michael@0: aResource.resolvedURI.charset.get(), michael@0: nullptr, io); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: } michael@0: michael@0: rv = rph->SetSubstitution(aResource.resource, resolvedURI); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride) michael@0: { michael@0: nsCOMPtr io (do_GetIOService()); michael@0: if (!io) michael@0: return; michael@0: michael@0: nsCOMPtr chromeURI, overrideURI; michael@0: nsresult rv = NS_NewURI(getter_AddRefs(chromeURI), michael@0: aOverride.originalURI.spec, michael@0: aOverride.originalURI.charset.get(), michael@0: nullptr, io); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: michael@0: rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec, michael@0: aOverride.overrideURI.charset.get(), nullptr, io); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: michael@0: mOverrideTable.Put(chromeURI, overrideURI); michael@0: } michael@0: michael@0: nsIURI* michael@0: nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage, michael@0: const nsCString& aProvider, michael@0: const nsCString& aPath) michael@0: { michael@0: PackageEntry* entry; michael@0: if (!mPackagesHash.Get(aPackage, &entry)) { michael@0: return nullptr; michael@0: } michael@0: michael@0: if (aProvider.EqualsLiteral("locale")) { michael@0: return entry->localeBaseURI; michael@0: } michael@0: else if (aProvider.EqualsLiteral("skin")) { michael@0: return entry->skinBaseURI; michael@0: } michael@0: else if (aProvider.EqualsLiteral("content")) { michael@0: return entry->contentBaseURI; michael@0: } michael@0: return nullptr; michael@0: } michael@0: michael@0: nsresult michael@0: nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage, michael@0: uint32_t* aFlags) michael@0: { michael@0: PackageEntry* entry; michael@0: if (!mPackagesHash.Get(aPackage, &entry)) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: *aFlags = entry->flags; michael@0: return NS_OK; michael@0: } michael@0: michael@0: // All functions following only make sense in chrome, and therefore assert michael@0: michael@0: #define CONTENT_NOTREACHED() \ michael@0: NS_NOTREACHED("Content should not be calling this") michael@0: michael@0: #define CONTENT_NOT_IMPLEMENTED() \ michael@0: CONTENT_NOTREACHED(); \ michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage, michael@0: nsIUTF8StringEnumerator* *aResult) michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::CheckForOSAccessibility() michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::CheckForNewChrome() michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::IsLocaleRTL(const nsACString& package, michael@0: bool *aResult) michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage, michael@0: nsACString& aLocale) michael@0: { michael@0: if (aPackage != nsDependentCString("global")) { michael@0: NS_ERROR("Uh-oh, caller wanted something other than 'some local'"); michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: aLocale = mLocale; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic, michael@0: const char16_t* aData) michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL, michael@0: nsISimpleEnumerator **aResult) michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL, michael@0: nsISimpleEnumerator **aResult) michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: nsresult nsChromeRegistryContent::UpdateSelectedLocale() michael@0: { michael@0: CONTENT_NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx, michael@0: int lineno, char *const * argv, michael@0: bool platform, bool contentaccessible) michael@0: { michael@0: CONTENT_NOTREACHED(); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx, michael@0: int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible) michael@0: { michael@0: CONTENT_NOTREACHED(); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx, michael@0: int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible) michael@0: { michael@0: CONTENT_NOTREACHED(); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible) michael@0: { michael@0: CONTENT_NOTREACHED(); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx, michael@0: int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible) michael@0: { michael@0: CONTENT_NOTREACHED(); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx, michael@0: int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible) michael@0: { michael@0: CONTENT_NOTREACHED(); michael@0: } michael@0: michael@0: void michael@0: nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx, michael@0: int lineno, michael@0: char *const * argv, bool platform, michael@0: bool contentaccessible) michael@0: { michael@0: CONTENT_NOTREACHED(); michael@0: }