2010-03-11 08:33:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2014-07-26 00:17:36 +04:00
|
|
|
/* vim: set ts=2 sts=2 sw=2 et tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2014-07-26 00:17:36 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2010-03-11 08:33:00 +03:00
|
|
|
#include "RegistryMessageUtils.h"
|
|
|
|
#include "nsResProtocolHandler.h"
|
|
|
|
|
|
|
|
#include "nsChromeRegistryChrome.h"
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
# include <windows.h>
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
# include <CoreServices/CoreServices.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nsArrayEnumerator.h"
|
2010-07-01 19:55:57 +04:00
|
|
|
#include "nsComponentManager.h"
|
2010-03-11 08:33:00 +03:00
|
|
|
#include "nsEnumeratorUtils.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsStringEnumerator.h"
|
|
|
|
#include "nsTextFormatter.h"
|
|
|
|
#include "nsXPCOMCIDInternal.h"
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2011-09-09 06:27:12 +04:00
|
|
|
|
2019-03-22 17:19:59 +03:00
|
|
|
#include "nsIAppStartup.h"
|
2010-03-11 08:33:00 +03:00
|
|
|
#include "nsIObserverService.h"
|
2021-02-18 16:26:32 +03:00
|
|
|
#include "mozilla/Components.h"
|
2013-04-26 19:11:47 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2010-03-23 08:18:53 +03:00
|
|
|
#include "nsIResProtocolHandler.h"
|
2010-03-11 08:33:00 +03:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIXULRuntime.h"
|
|
|
|
|
2013-04-26 19:11:47 +04:00
|
|
|
#define PACKAGE_OVERRIDE_BRANCH "chrome.override_package."
|
2019-04-24 14:18:50 +03:00
|
|
|
#define SKIN "classic/1.0"_ns
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
using namespace mozilla;
|
2014-07-26 00:17:36 +04:00
|
|
|
using mozilla::dom::ContentParent;
|
|
|
|
using mozilla::dom::PContentParent;
|
2017-03-15 01:28:47 +03:00
|
|
|
using mozilla::intl::LocaleService;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2014-08-11 22:13:36 +04:00
|
|
|
// We use a "best-fit" algorithm for matching locales and themes.
|
2010-03-11 08:33:00 +03:00
|
|
|
// 1) the exact selected locale/theme
|
|
|
|
// 2) (locales only) same language, different country
|
|
|
|
// e.g. en-GB is the selected locale, only en-US is available
|
|
|
|
// 3) any available locale/theme
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Match the language-part of two lang-COUNTRY codes, hopefully but
|
|
|
|
* not guaranteed to be in the form ab-CD or abz-CD. "ab" should also
|
|
|
|
* work, any other garbage-in will produce undefined results as long
|
|
|
|
* as it does not crash.
|
|
|
|
*/
|
|
|
|
static bool LanguagesMatch(const nsACString& a, const nsACString& b) {
|
|
|
|
if (a.Length() < 2 || b.Length() < 2) return false;
|
|
|
|
|
|
|
|
nsACString::const_iterator as, ae, bs, be;
|
|
|
|
a.BeginReading(as);
|
|
|
|
a.EndReading(ae);
|
|
|
|
b.BeginReading(bs);
|
|
|
|
b.EndReading(be);
|
|
|
|
|
|
|
|
while (*as == *bs) {
|
|
|
|
if (*as == '-') return true;
|
2014-08-11 22:13:36 +04:00
|
|
|
|
2010-03-11 08:33:00 +03:00
|
|
|
++as;
|
|
|
|
++bs;
|
|
|
|
|
|
|
|
// reached the end
|
|
|
|
if (as == ae && bs == be) return true;
|
|
|
|
|
|
|
|
// "a" is short
|
|
|
|
if (as == ae) return (*bs == '-');
|
|
|
|
|
|
|
|
// "b" is short
|
|
|
|
if (bs == be) return (*as == '-');
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsChromeRegistryChrome::nsChromeRegistryChrome()
|
2014-07-26 00:17:36 +04:00
|
|
|
: mProfileLoaded(false), mDynamicRegistration(true) {}
|
2010-03-11 08:33:00 +03:00
|
|
|
|
|
|
|
nsChromeRegistryChrome::~nsChromeRegistryChrome() {}
|
|
|
|
|
|
|
|
nsresult nsChromeRegistryChrome::Init() {
|
|
|
|
nsresult rv = nsChromeRegistry::Init();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool safeMode = false;
|
2010-03-11 08:33:00 +03:00
|
|
|
nsCOMPtr<nsIXULRuntime> xulrun(do_GetService(XULAPPINFO_SERVICE_CONTRACTID));
|
|
|
|
if (xulrun) xulrun->GetInSafeMode(&safeMode);
|
2014-02-27 22:04:09 +04:00
|
|
|
|
2010-05-14 10:41:14 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
2010-03-11 08:33:00 +03:00
|
|
|
if (obsService) {
|
2011-10-17 18:59:28 +04:00
|
|
|
obsService->AddObserver(this, "profile-initial-state", true);
|
2017-03-15 01:28:47 +03:00
|
|
|
obsService->AddObserver(this, "intl:app-locales-changed", true);
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistryChrome::GetLocalesForPackage(
|
|
|
|
const nsACString& aPackage, nsIUTF8StringEnumerator** aResult) {
|
2013-04-26 19:11:47 +04:00
|
|
|
nsCString realpackage;
|
|
|
|
nsresult rv = OverrideLocalePackage(aPackage, realpackage);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2010-03-11 08:33:00 +03:00
|
|
|
nsTArray<nsCString>* a = new nsTArray<nsCString>;
|
|
|
|
if (!a) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2014-08-11 22:13:36 +04:00
|
|
|
PackageEntry* entry;
|
|
|
|
if (mPackagesHash.Get(realpackage, &entry)) {
|
2010-03-11 08:33:00 +03:00
|
|
|
entry->locales.EnumerateToArray(a);
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:11:47 +04:00
|
|
|
rv = NS_NewAdoptingUTF8StringEnumerator(aResult, a);
|
2010-03-11 08:33:00 +03:00
|
|
|
if (NS_FAILED(rv)) delete a;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsChromeRegistryChrome::IsLocaleRTL(const nsACString& package, bool* aResult) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aResult = false;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString locale;
|
2020-02-22 03:20:03 +03:00
|
|
|
GetSelectedLocale(package, locale);
|
2010-03-11 08:33:00 +03:00
|
|
|
if (locale.Length() < 2) return NS_OK;
|
|
|
|
|
2019-11-26 19:41:55 +03:00
|
|
|
*aResult = LocaleService::IsLocaleRTL(locale);
|
2010-03-11 08:33:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:28:47 +03:00
|
|
|
/**
|
|
|
|
* This method negotiates only between the app locale and the available
|
|
|
|
* chrome packages.
|
|
|
|
*
|
|
|
|
* If you want to get the current application's UI locale, please use
|
2020-01-17 22:29:09 +03:00
|
|
|
* LocaleService::GetAppLocaleAsBCP47.
|
2017-03-15 01:28:47 +03:00
|
|
|
*/
|
2010-03-11 08:33:00 +03:00
|
|
|
nsresult nsChromeRegistryChrome::GetSelectedLocale(const nsACString& aPackage,
|
|
|
|
nsACString& aLocale) {
|
2017-03-15 01:28:47 +03:00
|
|
|
nsAutoCString reqLocale;
|
2017-09-06 11:13:45 +03:00
|
|
|
if (aPackage.EqualsLiteral("global")) {
|
2020-01-17 22:29:09 +03:00
|
|
|
LocaleService::GetInstance()->GetAppLocaleAsBCP47(reqLocale);
|
2017-03-15 01:28:47 +03:00
|
|
|
} else {
|
|
|
|
AutoTArray<nsCString, 10> requestedLocales;
|
|
|
|
LocaleService::GetInstance()->GetRequestedLocales(requestedLocales);
|
|
|
|
reqLocale.Assign(requestedLocales[0]);
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:11:47 +04:00
|
|
|
nsCString realpackage;
|
|
|
|
nsresult rv = OverrideLocalePackage(aPackage, realpackage);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2014-08-11 22:13:36 +04:00
|
|
|
PackageEntry* entry;
|
|
|
|
if (!mPackagesHash.Get(realpackage, &entry)) return NS_ERROR_FILE_NOT_FOUND;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2017-03-15 01:28:47 +03:00
|
|
|
aLocale = entry->locales.GetSelected(reqLocale, nsProviderArray::LOCALE);
|
2010-03-11 08:33:00 +03:00
|
|
|
if (aLocale.IsEmpty()) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-26 19:11:47 +04:00
|
|
|
nsresult nsChromeRegistryChrome::OverrideLocalePackage(
|
|
|
|
const nsACString& aPackage, nsACString& aOverride) {
|
|
|
|
const nsACString& pref = nsLiteralCString(PACKAGE_OVERRIDE_BRANCH) + aPackage;
|
2017-07-31 07:28:48 +03:00
|
|
|
nsAutoCString override;
|
|
|
|
nsresult rv = mozilla::Preferences::GetCString(PromiseFlatCString(pref).get(),
|
|
|
|
override);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2013-04-26 19:11:47 +04:00
|
|
|
aOverride = override;
|
2017-07-31 07:28:48 +03:00
|
|
|
} else {
|
2013-04-26 19:11:47 +04:00
|
|
|
aOverride = aPackage;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-11 08:33:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistryChrome::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* someData) {
|
2010-03-11 08:33:00 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2019-04-24 14:18:50 +03:00
|
|
|
if (!strcmp("profile-initial-state", aTopic)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mProfileLoaded = true;
|
2017-03-15 01:28:47 +03:00
|
|
|
} else if (!strcmp("intl:app-locales-changed", aTopic)) {
|
|
|
|
if (mProfileLoaded) {
|
|
|
|
FlushAllCaches();
|
|
|
|
}
|
2010-03-11 08:33:00 +03:00
|
|
|
} else {
|
|
|
|
NS_ERROR("Unexpected observer topic!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistryChrome::CheckForNewChrome() {
|
2019-03-22 17:19:59 +03:00
|
|
|
nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
|
|
|
|
if (appStartup->GetShuttingDown()) {
|
|
|
|
MOZ_ASSERT(false, "checking for new chrome during shutdown");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:13:36 +04:00
|
|
|
mPackagesHash.Clear();
|
2010-03-11 08:33:00 +03:00
|
|
|
mOverrideTable.Clear();
|
|
|
|
|
2014-07-26 00:17:36 +04:00
|
|
|
mDynamicRegistration = false;
|
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
nsComponentManagerImpl::gComponentManager->RereadChromeManifests();
|
2014-07-26 00:17:36 +04:00
|
|
|
|
|
|
|
mDynamicRegistration = true;
|
|
|
|
|
|
|
|
SendRegisteredChrome(nullptr);
|
2010-03-11 08:33:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SerializeURI(nsIURI* aURI, SerializedURI& aSerializedURI) {
|
|
|
|
if (!aURI) return;
|
|
|
|
|
|
|
|
aURI->GetSpec(aSerializedURI.spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsChromeRegistryChrome::SendRegisteredChrome(
|
2010-07-19 22:33:33 +04:00
|
|
|
mozilla::dom::PContentParent* aParent) {
|
2019-07-10 06:58:10 +03:00
|
|
|
nsTArray<ChromePackage> packages;
|
|
|
|
nsTArray<SubstitutionMapping> resources;
|
|
|
|
nsTArray<OverrideMapping> overrides;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2021-03-17 18:49:46 +03:00
|
|
|
for (const auto& entry : mPackagesHash) {
|
2015-11-18 04:58:34 +03:00
|
|
|
ChromePackage chromePackage;
|
2021-03-17 18:49:46 +03:00
|
|
|
ChromePackageFromPackageEntry(entry.GetKey(), entry.GetWeak(),
|
|
|
|
&chromePackage, SKIN);
|
2015-11-18 04:58:34 +03:00
|
|
|
packages.AppendElement(chromePackage);
|
|
|
|
}
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2014-10-07 21:29:40 +04:00
|
|
|
// If we were passed a parent then a new child process has been created and
|
|
|
|
// has requested all of the chrome so send it the resources too. Otherwise
|
|
|
|
// resource mappings are sent by the resource protocol handler dynamically.
|
|
|
|
if (aParent) {
|
|
|
|
nsCOMPtr<nsIIOService> io(do_GetIOService());
|
|
|
|
NS_ENSURE_TRUE_VOID(io);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProtocolHandler> ph;
|
|
|
|
nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph));
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIResProtocolHandler> irph(do_QueryInterface(ph));
|
|
|
|
nsResProtocolHandler* rph = static_cast<nsResProtocolHandler*>(irph.get());
|
2016-08-26 09:40:57 +03:00
|
|
|
rv = rph->CollectSubstitutions(resources);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2014-10-07 21:29:40 +04:00
|
|
|
}
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2021-03-17 18:49:46 +03:00
|
|
|
for (const auto& entry : mOverrideTable) {
|
2015-11-18 04:58:36 +03:00
|
|
|
SerializedURI chromeURI, overrideURI;
|
|
|
|
|
2021-03-17 18:49:46 +03:00
|
|
|
SerializeURI(entry.GetKey(), chromeURI);
|
|
|
|
SerializeURI(entry.GetWeak(), overrideURI);
|
2015-11-18 04:58:36 +03:00
|
|
|
|
2021-03-17 18:49:46 +03:00
|
|
|
overrides.AppendElement(
|
|
|
|
OverrideMapping{std::move(chromeURI), std::move(overrideURI)});
|
2015-11-18 04:58:36 +03:00
|
|
|
}
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2017-03-15 01:28:47 +03:00
|
|
|
nsAutoCString appLocale;
|
2020-01-17 22:29:09 +03:00
|
|
|
LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale);
|
2017-03-15 01:28:47 +03:00
|
|
|
|
2014-07-26 00:17:36 +04:00
|
|
|
if (aParent) {
|
|
|
|
bool success = aParent->SendRegisterChrome(packages, resources, overrides,
|
2017-03-15 01:28:47 +03:00
|
|
|
appLocale, false);
|
2014-07-26 00:17:36 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(success);
|
|
|
|
} else {
|
|
|
|
nsTArray<ContentParent*> parents;
|
|
|
|
ContentParent::GetAll(parents);
|
|
|
|
if (!parents.Length()) return;
|
|
|
|
|
2014-08-08 16:39:07 +04:00
|
|
|
for (uint32_t i = 0; i < parents.Length(); i++) {
|
2014-07-26 00:17:36 +04:00
|
|
|
DebugOnly<bool> success = parents[i]->SendRegisterChrome(
|
|
|
|
packages, resources, overrides, appLocale, true);
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(success,
|
|
|
|
"couldn't reset a child's registered chrome");
|
2014-07-26 00:17:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:04:01 +03:00
|
|
|
/* static */
|
|
|
|
void nsChromeRegistryChrome::ChromePackageFromPackageEntry(
|
2014-08-11 22:13:36 +04:00
|
|
|
const nsACString& aPackageName, PackageEntry* aPackage,
|
2014-07-26 00:17:36 +04:00
|
|
|
ChromePackage* aChromePackage, const nsCString& aSelectedSkin) {
|
2017-03-15 01:28:47 +03:00
|
|
|
nsAutoCString appLocale;
|
2020-01-17 22:29:09 +03:00
|
|
|
LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale);
|
2017-03-15 01:28:47 +03:00
|
|
|
|
2014-07-26 00:17:36 +04:00
|
|
|
SerializeURI(aPackage->baseURI, aChromePackage->contentBaseURI);
|
2017-03-15 01:28:47 +03:00
|
|
|
SerializeURI(aPackage->locales.GetBase(appLocale, nsProviderArray::LOCALE),
|
2014-07-26 00:17:36 +04:00
|
|
|
aChromePackage->localeBaseURI);
|
|
|
|
SerializeURI(aPackage->skins.GetBase(aSelectedSkin, nsProviderArray::ANY),
|
|
|
|
aChromePackage->skinBaseURI);
|
2014-08-11 22:13:36 +04:00
|
|
|
aChromePackage->package = aPackageName;
|
2014-07-26 00:17:36 +04:00
|
|
|
aChromePackage->flags = aPackage->flags;
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool CanLoadResource(nsIURI* aResourceURI) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isLocalResource = false;
|
2010-03-11 08:33:00 +03:00
|
|
|
(void)NS_URIChainHasFlags(aResourceURI,
|
|
|
|
nsIProtocolHandler::URI_IS_LOCAL_RESOURCE,
|
|
|
|
&isLocalResource);
|
|
|
|
return isLocalResource;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI* nsChromeRegistryChrome::GetBaseURIFromPackage(
|
|
|
|
const nsCString& aPackage, const nsCString& aProvider,
|
2010-10-13 23:46:05 +04:00
|
|
|
const nsCString& aPath) {
|
2014-08-11 22:13:36 +04:00
|
|
|
PackageEntry* entry;
|
|
|
|
if (!mPackagesHash.Get(aPackage, &entry)) {
|
2010-03-11 08:33:00 +03:00
|
|
|
if (!mInitialized) return nullptr;
|
|
|
|
|
|
|
|
LogMessage("No chrome package registered for chrome://%s/%s/%s",
|
|
|
|
aPackage.get(), aProvider.get(), aPath.get());
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aProvider.EqualsLiteral("locale")) {
|
2017-03-15 01:28:47 +03:00
|
|
|
nsAutoCString appLocale;
|
|
|
|
LocaleService::GetInstance()->GetAppLocaleAsLangTag(appLocale);
|
|
|
|
return entry->locales.GetBase(appLocale, nsProviderArray::LOCALE);
|
2010-03-11 08:33:00 +03:00
|
|
|
} else if (aProvider.EqualsLiteral("skin")) {
|
2019-04-24 14:18:50 +03:00
|
|
|
return entry->skins.GetBase(SKIN, nsProviderArray::ANY);
|
2010-03-11 08:33:00 +03:00
|
|
|
} else if (aProvider.EqualsLiteral("content")) {
|
2010-10-13 23:46:05 +04:00
|
|
|
return entry->baseURI;
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsChromeRegistryChrome::GetFlagsFromPackage(const nsCString& aPackage,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t* aFlags) {
|
2014-08-11 22:13:36 +04:00
|
|
|
PackageEntry* entry;
|
|
|
|
if (!mPackagesHash.Get(aPackage, &entry)) return NS_ERROR_FILE_NOT_FOUND;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
|
|
|
*aFlags = entry->flags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChromeRegistryChrome::ProviderEntry*
|
|
|
|
nsChromeRegistryChrome::nsProviderArray::GetProvider(
|
|
|
|
const nsACString& aPreferred, MatchType aType) {
|
2014-06-09 19:38:13 +04:00
|
|
|
size_t i = mArray.Length();
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!i) return nullptr;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
ProviderEntry* found = nullptr; // Only set if we find a partial-match locale
|
2014-06-09 19:38:13 +04:00
|
|
|
ProviderEntry* entry = nullptr;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
|
|
|
while (i--) {
|
2014-05-02 12:01:11 +04:00
|
|
|
entry = &mArray[i];
|
2010-03-11 08:33:00 +03:00
|
|
|
if (aPreferred.Equals(entry->provider)) return entry;
|
|
|
|
|
|
|
|
if (aType != LOCALE) continue;
|
|
|
|
|
|
|
|
if (LanguagesMatch(aPreferred, entry->provider)) {
|
|
|
|
found = entry;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found && entry->provider.EqualsLiteral("en-US")) found = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found && aType != EXACT) return entry;
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI* nsChromeRegistryChrome::nsProviderArray::GetBase(
|
|
|
|
const nsACString& aPreferred, MatchType aType) {
|
|
|
|
ProviderEntry* provider = GetProvider(aPreferred, aType);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!provider) return nullptr;
|
2010-03-11 08:33:00 +03:00
|
|
|
|
|
|
|
return provider->baseURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsACString& nsChromeRegistryChrome::nsProviderArray::GetSelected(
|
|
|
|
const nsACString& aPreferred, MatchType aType) {
|
|
|
|
ProviderEntry* entry = GetProvider(aPreferred, aType);
|
|
|
|
|
|
|
|
if (entry) return entry->provider;
|
|
|
|
|
|
|
|
return EmptyCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsChromeRegistryChrome::nsProviderArray::SetBase(
|
|
|
|
const nsACString& aProvider, nsIURI* aBaseURL) {
|
|
|
|
ProviderEntry* provider = GetProvider(aProvider, EXACT);
|
|
|
|
|
|
|
|
if (provider) {
|
|
|
|
provider->baseURI = aBaseURL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no existing entries, add a new one
|
2014-05-02 12:01:11 +04:00
|
|
|
mArray.AppendElement(ProviderEntry(aProvider, aBaseURL));
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsChromeRegistryChrome::nsProviderArray::EnumerateToArray(
|
|
|
|
nsTArray<nsCString>* a) {
|
2014-05-02 12:01:11 +04:00
|
|
|
int32_t i = mArray.Length();
|
2010-03-11 08:33:00 +03:00
|
|
|
while (i--) {
|
2014-05-02 12:01:11 +04:00
|
|
|
a->AppendElement(mArray[i].provider);
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
nsIURI* nsChromeRegistry::ManifestProcessingContext::GetManifestURI() {
|
|
|
|
if (!mManifestURI) {
|
2011-11-08 21:10:51 +04:00
|
|
|
nsCString uri;
|
|
|
|
mFile.GetURIString(uri);
|
|
|
|
NS_NewURI(getter_AddRefs(mManifestURI), uri);
|
2010-07-01 19:55:57 +04:00
|
|
|
}
|
|
|
|
return mManifestURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsChromeRegistry::ManifestProcessingContext::ResolveURI(const char* uri) {
|
|
|
|
nsIURI* baseuri = GetManifestURI();
|
2013-04-03 04:15:07 +04:00
|
|
|
if (!baseuri) return nullptr;
|
2010-07-01 19:55:57 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> resolved;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(resolved), uri, baseuri);
|
|
|
|
if (NS_FAILED(rv)) return nullptr;
|
|
|
|
|
|
|
|
return resolved.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void EnsureLowerCase(char* aBuf) {
|
|
|
|
for (; *aBuf; ++aBuf) {
|
|
|
|
char ch = *aBuf;
|
|
|
|
if (ch >= 'A' && ch <= 'Z') *aBuf = ch + 'a' - 'A';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 00:17:36 +04:00
|
|
|
static void SendManifestEntry(const ChromeRegistryItem& aItem) {
|
|
|
|
nsTArray<ContentParent*> parents;
|
|
|
|
ContentParent::GetAll(parents);
|
|
|
|
if (!parents.Length()) return;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < parents.Length(); i++) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << parents[i]->SendRegisterChromeItem(aItem);
|
2014-07-26 00:17:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
void nsChromeRegistryChrome::ManifestContent(ManifestProcessingContext& cx,
|
2015-02-05 19:09:15 +03:00
|
|
|
int lineno, char* const* argv,
|
|
|
|
int flags) {
|
2010-07-01 19:55:57 +04:00
|
|
|
char* package = argv[0];
|
|
|
|
char* uri = argv[1];
|
|
|
|
|
|
|
|
EnsureLowerCase(package);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> resolved = cx.ResolveURI(uri);
|
|
|
|
if (!resolved) {
|
|
|
|
LogMessageWithContext(
|
|
|
|
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, unable to create URI '%s'.", uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CanLoadResource(resolved)) {
|
|
|
|
LogMessageWithContext(resolved, lineno, nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, cannot register "
|
|
|
|
"non-local URI '%s' as content.",
|
|
|
|
uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:13:36 +04:00
|
|
|
nsDependentCString packageName(package);
|
2021-02-22 15:07:47 +03:00
|
|
|
PackageEntry* entry = mPackagesHash.GetOrInsertNew(packageName);
|
2010-07-01 19:55:57 +04:00
|
|
|
entry->baseURI = resolved;
|
2015-02-05 19:09:15 +03:00
|
|
|
entry->flags = flags;
|
2014-07-26 00:17:36 +04:00
|
|
|
|
|
|
|
if (mDynamicRegistration) {
|
|
|
|
ChromePackage chromePackage;
|
2019-04-24 14:18:50 +03:00
|
|
|
ChromePackageFromPackageEntry(packageName, entry, &chromePackage, SKIN);
|
2014-07-26 00:17:36 +04:00
|
|
|
SendManifestEntry(chromePackage);
|
|
|
|
}
|
2010-07-01 19:55:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsChromeRegistryChrome::ManifestLocale(ManifestProcessingContext& cx,
|
2015-02-05 19:09:15 +03:00
|
|
|
int lineno, char* const* argv,
|
|
|
|
int flags) {
|
2010-07-01 19:55:57 +04:00
|
|
|
char* package = argv[0];
|
|
|
|
char* provider = argv[1];
|
|
|
|
char* uri = argv[2];
|
|
|
|
|
|
|
|
EnsureLowerCase(package);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> resolved = cx.ResolveURI(uri);
|
|
|
|
if (!resolved) {
|
|
|
|
LogMessageWithContext(
|
|
|
|
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, unable to create URI '%s'.", uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CanLoadResource(resolved)) {
|
|
|
|
LogMessageWithContext(resolved, lineno, nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, cannot register "
|
|
|
|
"non-local URI '%s' as content.",
|
|
|
|
uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:13:36 +04:00
|
|
|
nsDependentCString packageName(package);
|
2021-02-22 15:07:47 +03:00
|
|
|
PackageEntry* entry = mPackagesHash.GetOrInsertNew(packageName);
|
2010-07-01 19:55:57 +04:00
|
|
|
entry->locales.SetBase(nsDependentCString(provider), resolved);
|
2014-07-26 00:17:36 +04:00
|
|
|
|
|
|
|
if (mDynamicRegistration) {
|
|
|
|
ChromePackage chromePackage;
|
2019-04-24 14:18:50 +03:00
|
|
|
ChromePackageFromPackageEntry(packageName, entry, &chromePackage, SKIN);
|
2014-07-26 00:17:36 +04:00
|
|
|
SendManifestEntry(chromePackage);
|
|
|
|
}
|
2017-03-15 01:28:47 +03:00
|
|
|
|
2017-05-04 20:38:53 +03:00
|
|
|
// We use mainPackage as the package we track for reporting new locales being
|
|
|
|
// registered. For most cases it will be "global", but for Fennec it will be
|
|
|
|
// "browser".
|
|
|
|
nsAutoCString mainPackage;
|
|
|
|
nsresult rv = OverrideLocalePackage("global"_ns, mainPackage);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
2010-07-01 19:55:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsChromeRegistryChrome::ManifestSkin(ManifestProcessingContext& cx,
|
2015-02-05 19:09:15 +03:00
|
|
|
int lineno, char* const* argv,
|
|
|
|
int flags) {
|
2010-07-01 19:55:57 +04:00
|
|
|
char* package = argv[0];
|
|
|
|
char* provider = argv[1];
|
|
|
|
char* uri = argv[2];
|
|
|
|
|
|
|
|
EnsureLowerCase(package);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> resolved = cx.ResolveURI(uri);
|
|
|
|
if (!resolved) {
|
|
|
|
LogMessageWithContext(
|
|
|
|
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, unable to create URI '%s'.", uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CanLoadResource(resolved)) {
|
|
|
|
LogMessageWithContext(resolved, lineno, nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, cannot register "
|
|
|
|
"non-local URI '%s' as content.",
|
|
|
|
uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:13:36 +04:00
|
|
|
nsDependentCString packageName(package);
|
2021-02-22 15:07:47 +03:00
|
|
|
PackageEntry* entry = mPackagesHash.GetOrInsertNew(packageName);
|
2010-07-01 19:55:57 +04:00
|
|
|
entry->skins.SetBase(nsDependentCString(provider), resolved);
|
2014-07-26 00:17:36 +04:00
|
|
|
|
|
|
|
if (mDynamicRegistration) {
|
|
|
|
ChromePackage chromePackage;
|
2019-04-24 14:18:50 +03:00
|
|
|
ChromePackageFromPackageEntry(packageName, entry, &chromePackage, SKIN);
|
2014-07-26 00:17:36 +04:00
|
|
|
SendManifestEntry(chromePackage);
|
|
|
|
}
|
2010-07-01 19:55:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsChromeRegistryChrome::ManifestOverride(ManifestProcessingContext& cx,
|
2015-02-05 19:09:15 +03:00
|
|
|
int lineno, char* const* argv,
|
|
|
|
int flags) {
|
2010-07-01 19:55:57 +04:00
|
|
|
char* chrome = argv[0];
|
|
|
|
char* resolved = argv[1];
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> chromeuri = cx.ResolveURI(chrome);
|
|
|
|
nsCOMPtr<nsIURI> resolveduri = cx.ResolveURI(resolved);
|
|
|
|
if (!chromeuri || !resolveduri) {
|
|
|
|
LogMessageWithContext(cx.GetManifestURI(), lineno,
|
|
|
|
nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, unable to create URI.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-01 19:05:39 +03:00
|
|
|
if (cx.mType == NS_SKIN_LOCATION) {
|
2019-08-07 22:49:40 +03:00
|
|
|
bool chromeSkinOnly =
|
|
|
|
chromeuri->SchemeIs("chrome") && resolveduri->SchemeIs("chrome");
|
2015-06-01 19:05:39 +03:00
|
|
|
if (chromeSkinOnly) {
|
|
|
|
nsAutoCString chromePath, resolvedPath;
|
2017-07-29 14:50:21 +03:00
|
|
|
chromeuri->GetPathQueryRef(chromePath);
|
|
|
|
resolveduri->GetPathQueryRef(resolvedPath);
|
2015-06-01 19:05:39 +03:00
|
|
|
chromeSkinOnly = StringBeginsWith(chromePath, "/skin/"_ns) &&
|
|
|
|
StringBeginsWith(resolvedPath, "/skin/"_ns);
|
|
|
|
}
|
|
|
|
if (!chromeSkinOnly) {
|
|
|
|
LogMessageWithContext(
|
|
|
|
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
|
|
|
|
"Cannot register non-chrome://.../skin/ URIs '%s' and '%s' as "
|
|
|
|
"overrides and/or to be overridden from a skin manifest.",
|
|
|
|
chrome, resolved);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
if (!CanLoadResource(resolveduri)) {
|
|
|
|
LogMessageWithContext(
|
|
|
|
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
|
|
|
|
"Cannot register non-local URI '%s' for an override.", resolved);
|
|
|
|
return;
|
|
|
|
}
|
2021-02-26 12:11:46 +03:00
|
|
|
mOverrideTable.InsertOrUpdate(chromeuri, resolveduri);
|
2014-07-26 00:17:36 +04:00
|
|
|
|
|
|
|
if (mDynamicRegistration) {
|
|
|
|
SerializedURI serializedChrome;
|
|
|
|
SerializedURI serializedOverride;
|
|
|
|
|
|
|
|
SerializeURI(chromeuri, serializedChrome);
|
|
|
|
SerializeURI(resolveduri, serializedOverride);
|
|
|
|
|
|
|
|
OverrideMapping override = {serializedChrome, serializedOverride};
|
|
|
|
SendManifestEntry(override);
|
|
|
|
}
|
2010-07-01 19:55:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsChromeRegistryChrome::ManifestResource(ManifestProcessingContext& cx,
|
2015-02-05 19:09:15 +03:00
|
|
|
int lineno, char* const* argv,
|
|
|
|
int flags) {
|
2010-07-01 19:55:57 +04:00
|
|
|
char* package = argv[0];
|
|
|
|
char* uri = argv[1];
|
|
|
|
|
|
|
|
EnsureLowerCase(package);
|
|
|
|
nsDependentCString host(package);
|
|
|
|
|
2021-02-18 16:26:32 +03:00
|
|
|
nsCOMPtr<nsIIOService> io = mozilla::components::IO::Service();
|
2010-07-01 19:55:57 +04:00
|
|
|
if (!io) {
|
|
|
|
NS_WARNING("No IO service trying to process chrome manifests");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProtocolHandler> ph;
|
|
|
|
nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph));
|
|
|
|
if (NS_FAILED(rv)) return;
|
2014-08-11 22:13:36 +04:00
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
nsCOMPtr<nsIResProtocolHandler> rph = do_QueryInterface(ph);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> resolved = cx.ResolveURI(uri);
|
|
|
|
if (!resolved) {
|
|
|
|
LogMessageWithContext(
|
|
|
|
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
|
|
|
|
"During chrome registration, unable to create URI '%s'.", uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CanLoadResource(resolved)) {
|
|
|
|
LogMessageWithContext(
|
|
|
|
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag,
|
|
|
|
"Warning: cannot register non-local URI '%s' as a resource.", uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-08 12:44:09 +03:00
|
|
|
// By default, Firefox resources are not content-accessible unless the
|
|
|
|
// manifests opts in.
|
|
|
|
bool contentAccessible = (flags & nsChromeRegistry::CONTENT_ACCESSIBLE);
|
|
|
|
|
|
|
|
uint32_t substitutionFlags = 0;
|
|
|
|
if (contentAccessible) {
|
|
|
|
substitutionFlags |= nsIResProtocolHandler::ALLOW_CONTENT_ACCESS;
|
|
|
|
}
|
|
|
|
rv = rph->SetSubstitutionWithFlags(host, resolved, substitutionFlags);
|
2016-11-04 13:13:13 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LogMessageWithContext(cx.GetManifestURI(), lineno,
|
|
|
|
nsIScriptError::warningFlag,
|
|
|
|
"Warning: cannot set substitution for '%s'.", uri);
|
|
|
|
}
|
2010-07-01 19:55:57 +04:00
|
|
|
}
|