/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=2 sts=2 sw=2 et tw=80: */ /* 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/. */
usingnamespace mozilla; using mozilla::dom::ContentParent; using mozilla::dom::PContentParent; using mozilla::intl::LocaleService;
// We use a "best-fit" algorithm for matching locales and themes. // 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.
*/ staticbool LanguagesMatch(const nsACString& a, const nsACString& b) { if (a.Length() < 2 || b.Length() < 2) returnfalse;
/** * 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 * LocaleService::GetAppLocaleAsBCP47.
*/
nsresult nsChromeRegistryChrome::GetSelectedLocale(const nsACString& aPackage,
nsACString& aLocale) {
nsAutoCString reqLocale; if (aPackage.EqualsLiteral("global")) {
LocaleService::GetInstance()->GetAppLocaleAsBCP47(reqLocale);
} else {
AutoTArray<nsCString, 10> requestedLocales;
LocaleService::GetInstance()->GetRequestedLocales(requestedLocales);
reqLocale.Assign(requestedLocales[0]);
}
nsCString realpackage;
nsresult rv = OverrideLocalePackage(aPackage, realpackage); if (NS_FAILED(rv)) return rv;
PackageEntry* entry; if (!mPackagesHash.Get(realpackage, &entry)) return NS_ERROR_FILE_NOT_FOUND;
aLocale = entry->locales.GetSelected(reqLocale, nsProviderArray::LOCALE); if (aLocale.IsEmpty()) return NS_ERROR_FAILURE;
NS_IMETHODIMP
nsChromeRegistryChrome::CheckForNewChrome() { if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
MOZ_ASSERT(false, "checking for new chrome during shutdown"); return NS_ERROR_UNEXPECTED;
}
// 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);
if (provider) {
provider->baseURI = aBaseURL; return;
}
// no existing entries, add a new one
mArray.AppendElement(ProviderEntry(aProvider, aBaseURL));
}
void nsChromeRegistryChrome::nsProviderArray::EnumerateToArray(
nsTArray<nsCString>* a) {
int32_t i = mArray.Length(); while (i--) {
a->AppendElement(mArray[i].provider);
}
}
// 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;
}
}
void nsChromeRegistryChrome::ManifestSkin(ManifestProcessingContext& cx, int lineno, char* const* argv, int flags) { 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;
}
if (cx.mType == NS_SKIN_LOCATION) { bool chromeSkinOnly =
chromeuri->SchemeIs("chrome") && resolveduri->SchemeIs("chrome"); if (chromeSkinOnly) {
nsAutoCString chromePath, resolvedPath;
chromeuri->GetPathQueryRef(chromePath);
resolveduri->GetPathQueryRef(resolvedPath);
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;
}
}
if (!CanLoadResource(resolveduri)) {
LogMessageWithContext(
cx.GetManifestURI(), lineno, nsIScriptError::warningFlag, "Cannot register non-local URI '%s' for an override.", resolved); return;
}
mOverrideTable.InsertOrUpdate(chromeuri, resolveduri);
if (mDynamicRegistration) {
SerializedURI serializedChrome;
SerializedURI serializedOverride;
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;
}
// 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); if (NS_FAILED(rv)) {
LogMessageWithContext(cx.GetManifestURI(), lineno,
nsIScriptError::warningFlag, "Warning: cannot set substitution for '%s'.", uri);
}
}
¤ Dauer der Verarbeitung: 0.3 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.