From 8fdbb6d26b5ba5a492e2c4cdddb0b52e319ac542 Mon Sep 17 00:00:00 2001 From: Zibi Braniecki Date: Fri, 21 Sep 2018 15:30:24 +0000 Subject: [PATCH 01/18] Bug 1491394 - Migrate mozILocaleService to use Array<> interface. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D5924 --HG-- extra : moz-landing-system : lando --- intl/locale/LocaleService.cpp | 414 ++++++------------ intl/locale/LocaleService.h | 122 +----- intl/locale/mozILocaleService.idl | 79 +--- .../gtest/TestLocaleServiceNegotiate.cpp | 8 +- intl/locale/tests/unit/test_localeService.js | 66 +-- .../test_localeService_negotiateLanguages.js | 38 +- 6 files changed, 201 insertions(+), 526 deletions(-) diff --git a/intl/locale/LocaleService.cpp b/intl/locale/LocaleService.cpp index 8ec8f8a8c497..dae1a85aaa90 100644 --- a/intl/locale/LocaleService.cpp +++ b/intl/locale/LocaleService.cpp @@ -97,7 +97,7 @@ SplitLocaleListStringIntoArray(nsACString& str, nsTArray& aRetVal) } } -static bool +static void ReadRequestedLocales(nsTArray& aRetVal) { nsAutoCString str; @@ -116,13 +116,16 @@ ReadRequestedLocales(nsTArray& aRetVal) } else { SplitLocaleListStringIntoArray(str, aRetVal); } - } else { + } + + // This will happen when either the pref is not set, + // or parsing of the pref didn't produce any usable + // result. + if (aRetVal.IsEmpty()) { nsAutoCString defaultLocale; LocaleService::GetInstance()->GetDefaultLocale(defaultLocale); aRetVal.AppendElement(defaultLocale); } - - return true; } LocaleService::LocaleService(bool aIsServer) @@ -148,7 +151,7 @@ LocaleService::NegotiateAppLocales(nsTArray& aRetVal) GetRequestedLocales(requestedLocales); NegotiateLanguages(requestedLocales, availableLocales, defaultLocale, - LangNegStrategy::Filtering, aRetVal); + kLangNegStrategyFiltering, aRetVal); } nsAutoCString lastFallbackLocale; @@ -202,72 +205,6 @@ LocaleService::~LocaleService() } } -void -LocaleService::GetAppLocalesAsLangTags(nsTArray& aRetVal) -{ - if (mAppLocales.IsEmpty()) { - NegotiateAppLocales(mAppLocales); - } - for (uint32_t i = 0; i < mAppLocales.Length(); i++) { - nsAutoCString locale(mAppLocales[i]); - if (locale.LowerCaseEqualsASCII("ja-jp-macos")) { - aRetVal.AppendElement("ja-JP-mac"); - } else { - aRetVal.AppendElement(locale); - } - } -} - -void -LocaleService::GetAppLocalesAsBCP47(nsTArray& aRetVal) -{ - if (mAppLocales.IsEmpty()) { - NegotiateAppLocales(mAppLocales); - } - aRetVal = mAppLocales; -} - -void -LocaleService::GetRegionalPrefsLocales(nsTArray& aRetVal) -{ - bool useOSLocales = Preferences::GetBool("intl.regional_prefs.use_os_locales", false); - - // If the user specified that they want to use OS Regional Preferences locales, - // try to retrieve them and use. - if (useOSLocales) { - if (OSPreferences::GetInstance()->GetRegionalPrefsLocales(aRetVal)) { - return; - } - - // If we fail to retrieve them, return the app locales. - GetAppLocalesAsBCP47(aRetVal); - return; - } - - // Otherwise, fetch OS Regional Preferences locales and compare the first one - // to the app locale. If the language subtag matches, we can safely use - // the OS Regional Preferences locale. - // - // This facilitates scenarios such as Firefox in "en-US" and User sets - // regional prefs to "en-GB". - nsAutoCString appLocale; - AutoTArray regionalPrefsLocales; - LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale); - - if (!OSPreferences::GetInstance()->GetRegionalPrefsLocales(regionalPrefsLocales)) { - GetAppLocalesAsBCP47(aRetVal); - return; - } - - if (LocaleService::LanguagesMatch(appLocale, regionalPrefsLocales[0])) { - aRetVal = regionalPrefsLocales; - return; - } - - // Otherwise use the app locales. - GetAppLocalesAsBCP47(aRetVal); -} - void LocaleService::AssignAppLocales(const nsTArray& aAppLocales) { @@ -292,36 +229,6 @@ LocaleService::AssignRequestedLocales(const nsTArray& aRequestedLocal } } -bool -LocaleService::GetRequestedLocales(nsTArray& aRetVal) -{ - if (mRequestedLocales.IsEmpty()) { - ReadRequestedLocales(mRequestedLocales); - } - - aRetVal = mRequestedLocales; - return true; -} - -bool -LocaleService::GetAvailableLocales(nsTArray& aRetVal) -{ - MOZ_ASSERT(mIsServer, "This should only be called in the server mode."); - if (!mIsServer) { - return false; - } - - if (mAvailableLocales.IsEmpty()) { - // If there are no available locales set, it means that L10nRegistry - // did not register its locale pool yet. The best course of action - // is to use packaged locales until that happens. - GetPackagedLocales(mAvailableLocales); - } - - aRetVal = mAvailableLocales; - return true; -} - void LocaleService::RequestedLocalesChanged() { @@ -368,11 +275,11 @@ LocaleService::LocalesChanged() // according to the desired negotiation strategy. #define HANDLE_STRATEGY \ switch (aStrategy) { \ - case LangNegStrategy::Lookup: \ + case kLangNegStrategyLookup: \ return; \ - case LangNegStrategy::Matching: \ + case kLangNegStrategyMatching: \ continue; \ - case LangNegStrategy::Filtering: \ + case kLangNegStrategyFiltering: \ break; \ } @@ -420,7 +327,7 @@ LocaleService::LocalesChanged() void LocaleService::FilterMatches(const nsTArray& aRequested, const nsTArray& aAvailable, - LangNegStrategy aStrategy, + int32_t aStrategy, nsTArray& aRetVal) { // Local copy of the list of available locales, in Locale form for flexible @@ -434,7 +341,6 @@ LocaleService::FilterMatches(const nsTArray& aRequested, for (auto& requested : aRequested) { if (requested.IsEmpty()) { - MOZ_ASSERT(!requested.IsEmpty(), "Locale string cannot be empty."); continue; } @@ -466,7 +372,7 @@ LocaleService::FilterMatches(const nsTArray& aRequested, aRetVal.AppendElement(aAvailable[match - availLocales.begin()]); match->Invalidate(); foundMatch = true; - if (aStrategy != LangNegStrategy::Filtering) { + if (aStrategy != kLangNegStrategyFiltering) { return true; // we only want the first match } } @@ -507,43 +413,6 @@ LocaleService::FilterMatches(const nsTArray& aRequested, } } -void -LocaleService::NegotiateLanguages(const nsTArray& aRequested, - const nsTArray& aAvailable, - const nsACString& aDefaultLocale, - LangNegStrategy aStrategy, - nsTArray& aRetVal) -{ - MOZ_ASSERT(aDefaultLocale.IsEmpty() || Locale(aDefaultLocale).IsWellFormed(), - "If specified, default locale must be a well-formed BCP47 language tag."); - - if (aStrategy == LangNegStrategy::Lookup && aDefaultLocale.IsEmpty()) { - NS_WARNING("Default locale should be specified when using lookup strategy."); - } - - FilterMatches(aRequested, aAvailable, aStrategy, aRetVal); - - if (aStrategy == LangNegStrategy::Lookup) { - // If the strategy is Lookup and Filtering returned no matches, use - // the default locale. - if (aRetVal.Length() == 0) { - // If the default locale is empty, we already issued a warning, so - // now we will just pick up the LocaleService's defaultLocale. - if (aDefaultLocale.IsEmpty()) { - nsAutoCString defaultLocale; - GetDefaultLocale(defaultLocale); - aRetVal.AppendElement(defaultLocale); - } else { - aRetVal.AppendElement(aDefaultLocale); - } - } - } else if (!aDefaultLocale.IsEmpty() && !aRetVal.Contains(aDefaultLocale)) { - // If it's not a Lookup strategy, add the default locale only if it's - // set and it's not in the results already. - aRetVal.AppendElement(aDefaultLocale); - } -} - bool LocaleService::IsAppLocaleRTL() { @@ -593,17 +462,6 @@ LocaleService::IsServer() return mIsServer; } -static char** -CreateOutArray(const nsTArray& aArray) -{ - uint32_t n = aArray.Length(); - char** result = static_cast(moz_xmalloc(n * sizeof(char*))); - for (uint32_t i = 0; i < n; i++) { - result[i] = moz_xstrdup(aArray[i].get()); - } - return result; -} - static bool GetGREFileContents(const char* aFilePath, nsCString* aOutString) { @@ -673,15 +531,6 @@ LocaleService::InitPackagedLocales() } } -void -LocaleService::GetPackagedLocales(nsTArray& aRetVal) -{ - if (mPackagedLocales.IsEmpty()) { - InitPackagedLocales(); - } - aRetVal = mPackagedLocales; -} - /** * mozILocaleService methods */ @@ -723,25 +572,30 @@ LocaleService::GetLastFallbackLocale(nsACString& aRetVal) } NS_IMETHODIMP -LocaleService::GetAppLocalesAsLangTags(uint32_t* aCount, char*** aOutArray) -{ - AutoTArray locales; - GetAppLocalesAsLangTags(locales); - - *aCount = locales.Length(); - *aOutArray = CreateOutArray(locales); - - return NS_OK; -} - -NS_IMETHODIMP -LocaleService::GetAppLocalesAsBCP47(uint32_t* aCount, char*** aOutArray) +LocaleService::GetAppLocalesAsLangTags(nsTArray& aRetVal) { if (mAppLocales.IsEmpty()) { NegotiateAppLocales(mAppLocales); } - *aCount = mAppLocales.Length(); - *aOutArray = CreateOutArray(mAppLocales); + for (uint32_t i = 0; i < mAppLocales.Length(); i++) { + nsAutoCString locale(mAppLocales[i]); + if (locale.LowerCaseEqualsASCII("ja-jp-macos")) { + aRetVal.AppendElement("ja-JP-mac"); + } else { + aRetVal.AppendElement(locale); + } + } + return NS_OK; +} + + +NS_IMETHODIMP +LocaleService::GetAppLocalesAsBCP47(nsTArray& aRetVal) +{ + if (mAppLocales.IsEmpty()) { + NegotiateAppLocales(mAppLocales); + } + aRetVal = mAppLocales; return NS_OK; } @@ -767,137 +621,116 @@ LocaleService::GetAppLocaleAsBCP47(nsACString& aRetVal) } NS_IMETHODIMP -LocaleService::GetRegionalPrefsLocales(uint32_t* aCount, char*** aOutArray) +LocaleService::GetRegionalPrefsLocales(nsTArray& aRetVal) { - AutoTArray rgLocales; + bool useOSLocales = Preferences::GetBool("intl.regional_prefs.use_os_locales", false); - GetRegionalPrefsLocales(rgLocales); + // If the user specified that they want to use OS Regional Preferences locales, + // try to retrieve them and use. + if (useOSLocales) { + if (OSPreferences::GetInstance()->GetRegionalPrefsLocales(aRetVal)) { + return NS_OK; + } - *aCount = rgLocales.Length(); - *aOutArray = static_cast(moz_xmalloc(*aCount * sizeof(char*))); - - for (uint32_t i = 0; i < *aCount; i++) { - (*aOutArray)[i] = moz_xstrdup(rgLocales[i].get()); + // If we fail to retrieve them, return the app locales. + GetAppLocalesAsBCP47(aRetVal); + return NS_OK; } + // Otherwise, fetch OS Regional Preferences locales and compare the first one + // to the app locale. If the language subtag matches, we can safely use + // the OS Regional Preferences locale. + // + // This facilitates scenarios such as Firefox in "en-US" and User sets + // regional prefs to "en-GB". + nsAutoCString appLocale; + AutoTArray regionalPrefsLocales; + LocaleService::GetInstance()->GetAppLocaleAsBCP47(appLocale); + + if (!OSPreferences::GetInstance()->GetRegionalPrefsLocales(regionalPrefsLocales)) { + GetAppLocalesAsBCP47(aRetVal); + return NS_OK; + } + + if (LocaleService::LanguagesMatch(appLocale, regionalPrefsLocales[0])) { + aRetVal = regionalPrefsLocales; + return NS_OK; + } + + // Otherwise use the app locales. + GetAppLocalesAsBCP47(aRetVal); return NS_OK; } -static LocaleService::LangNegStrategy -ToLangNegStrategy(int32_t aStrategy) -{ - switch (aStrategy) { - case 1: - return LocaleService::LangNegStrategy::Matching; - case 2: - return LocaleService::LangNegStrategy::Lookup; - default: - return LocaleService::LangNegStrategy::Filtering; - } -} - NS_IMETHODIMP -LocaleService::NegotiateLanguages(const char** aRequested, - const char** aAvailable, - const char* aDefaultLocale, +LocaleService::NegotiateLanguages(const nsTArray& aRequested, + const nsTArray& aAvailable, + const nsACString& aDefaultLocale, int32_t aStrategy, - uint32_t aRequestedCount, - uint32_t aAvailableCount, - uint32_t* aCount, char*** aRetVal) + nsTArray& aRetVal) { if (aStrategy < 0 || aStrategy > 2) { return NS_ERROR_INVALID_ARG; } - // Check that the given string contains only ASCII characters valid in tags - // (i.e. alphanumerics, plus '-' and '_'), and is non-empty. - auto validTagChars = [](const char* s) { - if (!s || !*s) { - return false; - } - while (*s) { - if (isalnum((unsigned char)*s) || *s == '-' || *s == '_' || *s == '*') { - s++; + MOZ_ASSERT(aDefaultLocale.IsEmpty() || Locale(aDefaultLocale).IsWellFormed(), + "If specified, default locale must be a well-formed BCP47 language tag."); + + if (aStrategy == kLangNegStrategyLookup && aDefaultLocale.IsEmpty()) { + NS_WARNING("Default locale should be specified when using lookup strategy."); + } + + FilterMatches(aRequested, aAvailable, aStrategy, aRetVal); + + if (aStrategy == kLangNegStrategyLookup) { + // If the strategy is Lookup and Filtering returned no matches, use + // the default locale. + if (aRetVal.Length() == 0) { + // If the default locale is empty, we already issued a warning, so + // now we will just pick up the LocaleService's defaultLocale. + if (aDefaultLocale.IsEmpty()) { + nsAutoCString defaultLocale; + GetDefaultLocale(defaultLocale); + aRetVal.AppendElement(defaultLocale); } else { - return false; + aRetVal.AppendElement(aDefaultLocale); } } - return true; - }; - - AutoTArray requestedLocales; - for (uint32_t i = 0; i < aRequestedCount; i++) { - if (!validTagChars(aRequested[i])) { - continue; - } - requestedLocales.AppendElement(aRequested[i]); + } else if (!aDefaultLocale.IsEmpty() && !aRetVal.Contains(aDefaultLocale)) { + // If it's not a Lookup strategy, add the default locale only if it's + // set and it's not in the results already. + aRetVal.AppendElement(aDefaultLocale); } - - AutoTArray availableLocales; - for (uint32_t i = 0; i < aAvailableCount; i++) { - if (!validTagChars(aAvailable[i])) { - continue; - } - availableLocales.AppendElement(aAvailable[i]); - } - - nsAutoCString defaultLocale(aDefaultLocale); - - LangNegStrategy strategy = ToLangNegStrategy(aStrategy); - - AutoTArray supportedLocales; - NegotiateLanguages(requestedLocales, availableLocales, - defaultLocale, strategy, supportedLocales); - - *aRetVal = - static_cast(moz_xmalloc(sizeof(char*) * supportedLocales.Length())); - - *aCount = 0; - for (const auto& supported : supportedLocales) { - (*aRetVal)[(*aCount)++] = moz_xstrdup(supported.get()); - } - return NS_OK; } NS_IMETHODIMP -LocaleService::GetRequestedLocales(uint32_t* aCount, char*** aOutArray) +LocaleService::GetRequestedLocales(nsTArray& aRetVal) { - AutoTArray requestedLocales; - bool res = GetRequestedLocales(requestedLocales); - - if (!res) { - NS_ERROR("Couldn't retrieve selected locales from prefs!"); - return NS_ERROR_FAILURE; + if (mRequestedLocales.IsEmpty()) { + ReadRequestedLocales(mRequestedLocales); } - *aCount = requestedLocales.Length(); - *aOutArray = CreateOutArray(requestedLocales); - + aRetVal = mRequestedLocales; return NS_OK; } NS_IMETHODIMP LocaleService::GetRequestedLocale(nsACString& aRetVal) { - AutoTArray requestedLocales; - bool res = GetRequestedLocales(requestedLocales); - - if (!res) { - NS_ERROR("Couldn't retrieve selected locales from prefs!"); - return NS_ERROR_FAILURE; + if (mRequestedLocales.IsEmpty()) { + ReadRequestedLocales(mRequestedLocales); } - if (requestedLocales.Length() > 0) { - aRetVal = requestedLocales[0]; + if (mRequestedLocales.Length() > 0) { + aRetVal = mRequestedLocales[0]; } return NS_OK; } NS_IMETHODIMP -LocaleService::SetRequestedLocales(const char** aRequested, - uint32_t aRequestedCount) +LocaleService::SetRequestedLocales(const nsTArray& aRequested) { MOZ_ASSERT(mIsServer, "This should only be called in the server mode."); if (!mIsServer) { @@ -906,14 +739,14 @@ LocaleService::SetRequestedLocales(const char** aRequested, nsAutoCString str; - for (uint32_t i = 0; i < aRequestedCount; i++) { - nsAutoCString locale(aRequested[i]); + for (auto& req : aRequested) { + nsAutoCString locale(req); if (!SanitizeForBCP47(locale, true)) { NS_ERROR("Invalid language tag provided to SetRequestedLocales!"); return NS_ERROR_INVALID_ARG; } - if (i > 0) { + if (!str.IsEmpty()) { str.AppendLiteral(","); } str.Append(locale); @@ -924,18 +757,21 @@ LocaleService::SetRequestedLocales(const char** aRequested, } NS_IMETHODIMP -LocaleService::GetAvailableLocales(uint32_t* aCount, char*** aOutArray) +LocaleService::GetAvailableLocales(nsTArray& aRetVal) { - AutoTArray availableLocales; - bool res = GetAvailableLocales(availableLocales); - - if (!res) { - NS_ERROR("Couldn't retrieve available locales!"); - return NS_ERROR_FAILURE; + MOZ_ASSERT(mIsServer, "This should only be called in the server mode."); + if (!mIsServer) { + return NS_ERROR_UNEXPECTED; } - *aCount = availableLocales.Length(); - *aOutArray = CreateOutArray(availableLocales); + if (mAvailableLocales.IsEmpty()) { + // If there are no available locales set, it means that L10nRegistry + // did not register its locale pool yet. The best course of action + // is to use packaged locales until that happens. + GetPackagedLocales(mAvailableLocales); + } + + aRetVal = mAvailableLocales; return NS_OK; } @@ -947,8 +783,7 @@ LocaleService::GetIsAppLocaleRTL(bool* aRetVal) } NS_IMETHODIMP -LocaleService::SetAvailableLocales(const char** aAvailable, - uint32_t aAvailableCount) +LocaleService::SetAvailableLocales(const nsTArray& aAvailable) { MOZ_ASSERT(mIsServer, "This should only be called in the server mode."); if (!mIsServer) { @@ -957,8 +792,8 @@ LocaleService::SetAvailableLocales(const char** aAvailable, nsTArray newLocales; - for (uint32_t i = 0; i < aAvailableCount; i++) { - nsAutoCString locale(aAvailable[i]); + for (auto& avail : aAvailable) { + nsAutoCString locale(avail); if (!SanitizeForBCP47(locale, true)) { NS_ERROR("Invalid language tag provided to SetAvailableLocales!"); return NS_ERROR_INVALID_ARG; @@ -975,14 +810,11 @@ LocaleService::SetAvailableLocales(const char** aAvailable, } NS_IMETHODIMP -LocaleService::GetPackagedLocales(uint32_t* aCount, char*** aOutArray) +LocaleService::GetPackagedLocales(nsTArray& aRetVal) { if (mPackagedLocales.IsEmpty()) { InitPackagedLocales(); } - - *aCount = mPackagedLocales.Length(); - *aOutArray = CreateOutArray(mPackagedLocales); - + aRetVal = mPackagedLocales; return NS_OK; } diff --git a/intl/locale/LocaleService.h b/intl/locale/LocaleService.h index d39808354821..e419b80ddbf7 100644 --- a/intl/locale/LocaleService.h +++ b/intl/locale/LocaleService.h @@ -83,11 +83,9 @@ public: * See the mozILocaleService.idl for detailed description of the * strategies. */ - enum class LangNegStrategy { - Filtering, - Matching, - Lookup - }; + static const int32_t kLangNegStrategyFiltering = 0; + static const int32_t kLangNegStrategyMatching = 1; + static const int32_t kLangNegStrategyLookup = 2; explicit LocaleService(bool aIsServer); @@ -109,45 +107,6 @@ public: return RefPtr(GetInstance()).forget(); } - /** - * Returns a list of locales that the application should be localized to. - * - * The result is a ordered list of valid locale IDs and it should be - * used for all APIs that accept list of locales, like ECMA402 and L10n APIs. - * - * This API always returns at least one locale. - * - * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] - * - * Usage: - * nsTArray appLocales; - * LocaleService::GetInstance()->GetAppLocalesAsLangTags(appLocales); - * - * (See mozILocaleService.idl for a JS-callable version of this.) - */ - void GetAppLocalesAsLangTags(nsTArray& aRetVal); - void GetAppLocalesAsBCP47(nsTArray& aRetVal); - - - /** - * Returns a list of locales to use for any regional specific operations - * like date formatting, calendars, unit formatting etc. - * - * The result is a ordered list of valid locale IDs and it should be - * used for all APIs that accept list of locales, like ECMA402 and L10n APIs. - * - * This API always returns at least one locale. - * - * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] - * - * Usage: - * nsTArray rgLocales; - * LocaleService::GetInstance()->GetRegionalPrefsLocales(rgLocales); - * - * (See mozILocaleService.idl for a JS-callable version of this.) - */ - void GetRegionalPrefsLocales(nsTArray& aRetVal); - /** * This method should only be called in the client mode. * @@ -160,53 +119,6 @@ public: void AssignAppLocales(const nsTArray& aAppLocales); void AssignRequestedLocales(const nsTArray& aRequestedLocales); - /** - * Returns a list of locales that the user requested the app to be - * localized to. - * - * The result is a sorted list of valid locale IDs and it should be - * used as a requestedLocales input list for languages negotiation. - * - * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] - * - * Usage: - * nsTArray reqLocales; - * LocaleService::GetInstance()->GetRequestedLocales(reqLocales); - * - * Returns a boolean indicating if the attempt to retrieve prefs - * was successful. - * - * (See mozILocaleService.idl for a JS-callable version of this.) - */ - bool GetRequestedLocales(nsTArray& aRetVal); - - /** - * Returns a list of available locales that can be used to - * localize the app. - * - * The result is an unsorted list of valid locale IDs and it should be - * used as a availableLocales input list for languages negotiation. - * - * Example: ["de", "en-US", "pl", "sr-Cyrl", "zh-Hans-HK"] - * - * Usage: - * nsTArray availLocales; - * LocaleService::GetInstance()->GetAvailableLocales(availLocales); - * - * Returns a boolean indicating if the attempt to retrieve at least - * one locale was successful. - * - * (See mozILocaleService.idl for a JS-callable version of this.) - */ - bool GetAvailableLocales(nsTArray& aRetVal); - - /** - * Returns a list of locales packaged into the app bundle. - * - * (See mozILocaleService.idl for a JS-callable version of this.) - */ - void GetPackagedLocales(nsTArray& aRetVal); - /** * Those two functions allow to trigger cache invalidation on one of the * three cached values. @@ -223,32 +135,6 @@ public: void RequestedLocalesChanged(); void LocalesChanged(); - /** - * Negotiates the best locales out of an ordered list of requested locales and - * a list of available locales. - * - * Internally it uses the following naming scheme: - * - * Requested - locales requested by the user - * Available - locales for which the data is available - * Supported - locales negotiated by the algorithm - * - * Additionally, if defaultLocale is provided, it adds it to the end of the - * result list as a "last resort" locale. - * - * Strategy is one of the three strategies described at the top of this file. - * - * The result list is canonicalized and ordered according to the order - * of the requested locales. - * - * (See mozILocaleService.idl for a JS-callable version of this.) - */ - void NegotiateLanguages(const nsTArray& aRequested, - const nsTArray& aAvailable, - const nsACString& aDefaultLocale, - LangNegStrategy aLangNegStrategy, - nsTArray& aRetVal); - /** * Returns whether the current app locale is RTL. */ @@ -262,7 +148,7 @@ public: private: void FilterMatches(const nsTArray& aRequested, const nsTArray& aAvailable, - LangNegStrategy aStrategy, + int32_t aStrategy, nsTArray& aRetVal); void NegotiateAppLocales(nsTArray& aRetVal); diff --git a/intl/locale/mozILocaleService.idl b/intl/locale/mozILocaleService.idl index 5aae5b61b3fc..41ca6e3e6af0 100644 --- a/intl/locale/mozILocaleService.idl +++ b/intl/locale/mozILocaleService.idl @@ -80,13 +80,9 @@ interface mozILocaleService : nsISupports * use the BCP47 form. * * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] - * - * (See LocaleService.h for a more C++-friendly version of this.) */ - void getAppLocalesAsLangTags([optional] out unsigned long aCount, - [retval, array, size_is(aCount)] out string aLocales); - void getAppLocalesAsBCP47([optional] out unsigned long aCount, - [retval, array, size_is(aCount)] out string aLocales); + readonly attribute Array appLocalesAsLangTags; + readonly attribute Array appLocalesAsBCP47; /** * Returns a list of locales to use for any regional specific operations @@ -98,11 +94,8 @@ interface mozILocaleService : nsISupports * This API always returns at least one locale. * * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] - * - * (See LocaleService.h for a more C++-friendly version of this.) */ - void getRegionalPrefsLocales([optional] out unsigned long aCount, - [retval, array, size_is(aCount)] out string aOutArray); + readonly attribute Array regionalPrefsLocales; /** * Negotiates the best locales out of a ordered list of requested locales and @@ -124,14 +117,10 @@ interface mozILocaleService : nsISupports * * (See LocaleService.h for a more C++-friendly version of this.) */ - void negotiateLanguages([array, size_is(aRequestedCount)] in string aRequested, - [array, size_is(aAvailableCount)] in string aAvailable, - [optional] in string aDefaultLocale, - [optional] in long langNegStrategy, - [optional] in unsigned long aRequestedCount, - [optional] in unsigned long aAvailableCount, - [optional] out unsigned long aCount, - [retval, array, size_is(aCount)] out string aLocales); + Array negotiateLanguages(in Array aRequested, + in Array aAvailable, + [optional] in ACString aDefaultLocale, + [optional] in long langNegStrategy); /** * Returns the best locale that the application should be localized to. @@ -144,15 +133,15 @@ interface mozILocaleService : nsISupports * When retrieving the locales for Intl API or ICU locale settings, * use the BCP47 form. * - * Where possible, getAppLocales*() should be preferred over this API and + * Where possible, appLocales* should be preferred over this API and * all callsites should handle some form of "best effort" language * negotiation to respect user preferences in case the use case does * not have data for the first locale in the list. * * Example: "zh-Hans-HK" */ - ACString getAppLocaleAsLangTag(); - ACString getAppLocaleAsBCP47(); + readonly attribute ACString appLocaleAsLangTag; + readonly attribute ACString appLocaleAsBCP47; /** * Returns a list of locales that the user requested the app to be @@ -163,32 +152,12 @@ interface mozILocaleService : nsISupports * * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] */ - void getRequestedLocales([optional] out unsigned long aCount, - [retval, array, size_is(aCount)] out string aLocales); + attribute Array requestedLocales; /** * Returns the top-requested locale from the user, or an empty string if none is set. */ - ACString getRequestedLocale(); - - /** - * Sets a list of locales that the user requested the app to be - * localized to. - * - * The argument is an ordered list of locale IDs which should be - * used as a requestedLocales input list for language negotiation. - * - * The current implementation is limited to handle at most one - * locale passed to the API. In the future we'll transition to support - * whole fallback chain. - * - * If an empty list is passed, the list of requested locales will - * be picked from the operating system. - * - * Example: ["de"] - */ - void setRequestedLocales([array, size_is(aRequestedCount)] in string aRequested, - [optional] in unsigned long aRequestedCount); + readonly attribute ACString requestedLocale; /** * Returns a list of locales that the app can be localized to. @@ -198,37 +167,17 @@ interface mozILocaleService : nsISupports * * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] */ - void getAvailableLocales([optional] out unsigned long aCount, - [retval, array, size_is(aCount)] out string aLocales); + attribute Array availableLocales; /** * Returns whether the current app locale is RTL. */ readonly attribute boolean isAppLocaleRTL; - /** - * Sets a list of locales the application has resources to be localized into. - * - * The primary use of this function is to let L10nRegistry communicate all - * locale updates. - * - * The secondary use case is for testing purposes in scenarios in which the - * actual resources don't have to be available. - * It is recommended for tests to create a mock FileSource and register it in - * the L10nRegistry rather than using this call, in order to emulate full - * resource availability cycle. - * - */ - void setAvailableLocales([array, size_is(aAvailableCount)] in string aAvailable, - [optional] in unsigned long aAvailableCount); - /** * Returns a list of locales packaged into the app bundle. * * Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"] - * - * (See LocaleService.h for a more C++-friendly version of this.) */ - void getPackagedLocales([optional] out unsigned long aCount, - [retval, array, size_is(aCount)] out string aOutArray); + readonly attribute Array packagedLocales; }; diff --git a/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp b/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp index a8192fb25c73..5d4abc842b9b 100644 --- a/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp +++ b/intl/locale/tests/gtest/TestLocaleServiceNegotiate.cpp @@ -15,8 +15,8 @@ TEST(Intl_Locale_LocaleService, Negotiate) { nsTArray availableLocales; nsTArray supportedLocales; nsAutoCString defaultLocale("en-US"); - LocaleService::LangNegStrategy strategy = - LocaleService::LangNegStrategy::Filtering; + int32_t strategy = + LocaleService::kLangNegStrategyFiltering; requestedLocales.AppendElement(NS_LITERAL_CSTRING("sr")); @@ -36,8 +36,8 @@ TEST(Intl_Locale_LocaleService, UseLSDefaultLocale) { nsTArray availableLocales; nsTArray supportedLocales; nsAutoCString defaultLocale(""); - LocaleService::LangNegStrategy strategy = - LocaleService::LangNegStrategy::Lookup; + int32_t strategy = + LocaleService::kLangNegStrategyLookup; requestedLocales.AppendElement(NS_LITERAL_CSTRING("sr")); diff --git a/intl/locale/tests/unit/test_localeService.js b/intl/locale/tests/unit/test_localeService.js index 2c071782c6d3..1999e4c0cba8 100644 --- a/intl/locale/tests/unit/test_localeService.js +++ b/intl/locale/tests/unit/test_localeService.js @@ -30,11 +30,11 @@ add_test(function test_lastFallbackLocale() { run_next_test(); }); -add_test(function test_getAppLocalesAsLangTags() { - const appLocale = localeService.getAppLocaleAsLangTag(); +add_test(function test_appLocalesAsLangTags() { + const appLocale = localeService.appLocaleAsLangTag; Assert.ok(appLocale != "", "appLocale is non-empty"); - const appLocales = localeService.getAppLocalesAsLangTags(); + const appLocales = localeService.appLocalesAsLangTags; Assert.ok(Array.isArray(appLocales), "appLocales returns an array"); Assert.ok(appLocale == appLocales[0], "appLocale matches first entry in appLocales"); @@ -48,8 +48,8 @@ add_test(function test_getAppLocalesAsLangTags() { const PREF_REQUESTED_LOCALES = "intl.locale.requested"; const REQ_LOC_CHANGE_EVENT = "intl:requested-locales-changed"; -add_test(function test_getRequestedLocales() { - const requestedLocales = localeService.getRequestedLocales(); +add_test(function test_requestedLocales() { + const requestedLocales = localeService.requestedLocales; Assert.ok(Array.isArray(requestedLocales), "requestedLocales returns an array"); run_next_test(); @@ -61,9 +61,9 @@ add_test(function test_getRequestedLocales() { * pref for matchOS is set to true. * * Then, we test that when the matchOS is set to true, we will retrieve - * OS locale from getRequestedLocales. + * OS locale from requestedLocales. */ -add_test(function test_getRequestedLocales_matchOS() { +add_test(function test_requestedLocales_matchOS() { do_test_pending(); Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "ar-IR"); @@ -72,7 +72,7 @@ add_test(function test_getRequestedLocales_matchOS() { observe: function (aSubject, aTopic, aData) { switch (aTopic) { case REQ_LOC_CHANGE_EVENT: - const reqLocs = localeService.getRequestedLocales(); + const reqLocs = localeService.requestedLocales; Assert.ok(reqLocs[0] === osPrefs.systemLocale); Services.obs.removeObserver(observer, REQ_LOC_CHANGE_EVENT); do_test_finished(); @@ -91,7 +91,7 @@ add_test(function test_getRequestedLocales_matchOS() { * event for requested locales change, it will be fired when the * pref for browser UI locale changes. */ -add_test(function test_getRequestedLocales_onChange() { +add_test(function test_requestedLocales_onChange() { do_test_pending(); Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "ar-IR"); @@ -100,7 +100,7 @@ add_test(function test_getRequestedLocales_onChange() { observe: function (aSubject, aTopic, aData) { switch (aTopic) { case REQ_LOC_CHANGE_EVENT: - const reqLocs = localeService.getRequestedLocales(); + const reqLocs = localeService.requestedLocales; Assert.ok(reqLocs[0] === "sr-RU"); Services.obs.removeObserver(observer, REQ_LOC_CHANGE_EVENT); do_test_finished(); @@ -114,10 +114,10 @@ add_test(function test_getRequestedLocales_onChange() { run_next_test(); }); -add_test(function test_getRequestedLocale() { +add_test(function test_requestedLocale() { Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "tlh"); - let requestedLocale = localeService.getRequestedLocale(); + let requestedLocale = localeService.requestedLocale; Assert.ok(requestedLocale === "tlh", "requestedLocale returns the right value"); Services.prefs.clearUserPref(PREF_REQUESTED_LOCALES); @@ -125,10 +125,10 @@ add_test(function test_getRequestedLocale() { run_next_test(); }); -add_test(function test_setRequestedLocales() { - localeService.setRequestedLocales(['de-AT', 'de-DE', 'de-CH']); +add_test(function test_requestedLocales() { + localeService.requestedLocales = ['de-AT', 'de-DE', 'de-CH']; - let locales = localeService.getRequestedLocales(); + let locales = localeService.requestedLocales; Assert.ok(locales[0] === 'de-AT'); Assert.ok(locales[1] === 'de-DE'); Assert.ok(locales[2] === 'de-CH'); @@ -142,22 +142,22 @@ add_test(function test_isAppLocaleRTL() { run_next_test(); }); -add_test(function test_getPackagedLocales() { - const locales = localeService.getPackagedLocales(); +add_test(function test_packagedLocales() { + const locales = localeService.packagedLocales; Assert.ok(locales.length !== 0, "Packaged locales are empty"); run_next_test(); }); -add_test(function test_setAvailableLocales() { - const avLocales = localeService.getAvailableLocales(); - localeService.setAvailableLocales(["und", "ar-IR"]); +add_test(function test_availableLocales() { + const avLocales = localeService.availableLocales; + localeService.availableLocales = ["und", "ar-IR"]; - let locales = localeService.getAvailableLocales(); + let locales = localeService.availableLocales; Assert.ok(locales.length == 2); Assert.ok(locales[0] === 'und'); Assert.ok(locales[1] === 'ar-IR'); - localeService.setAvailableLocales(avLocales); + localeService.availableLocales = avLocales; run_next_test(); }); @@ -165,10 +165,10 @@ add_test(function test_setAvailableLocales() { /** * This test verifies that all values coming from the pref are sanitized. */ -add_test(function test_getRequestedLocales_sanitize() { +add_test(function test_requestedLocales_sanitize() { Services.prefs.setCharPref(PREF_REQUESTED_LOCALES, "de,2,#$@#,pl,ąó,!a2,DE-at,,;"); - let locales = localeService.getRequestedLocales(); + let locales = localeService.requestedLocales; Assert.equal(locales[0], "de"); Assert.equal(locales[1], "pl"); Assert.equal(locales[2], "de-AT"); @@ -181,27 +181,27 @@ add_test(function test_getRequestedLocales_sanitize() { }); add_test(function test_handle_ja_JP_mac() { - const bkpAvLocales = localeService.getAvailableLocales(); + const bkpAvLocales = localeService.availableLocales; - localeService.setAvailableLocales(["ja-JP-mac", "en-US"]); + localeService.availableLocales = ["ja-JP-mac", "en-US"]; - localeService.setRequestedLocales(['ja-JP-mac']); + localeService.requestedLocales = ['ja-JP-mac']; - let reqLocales = localeService.getRequestedLocales(); + let reqLocales = localeService.requestedLocales; Assert.equal(reqLocales[0], 'ja-JP-macos'); - let avLocales = localeService.getAvailableLocales(); + let avLocales = localeService.availableLocales; Assert.equal(avLocales[0], 'ja-JP-macos'); - let appLocales = localeService.getAppLocalesAsBCP47(); + let appLocales = localeService.appLocalesAsBCP47; Assert.equal(appLocales[0], 'ja-JP-macos'); - let appLocalesAsLT = localeService.getAppLocalesAsLangTags(); + let appLocalesAsLT = localeService.appLocalesAsLangTags; Assert.equal(appLocalesAsLT[0], 'ja-JP-mac'); - Assert.equal(localeService.getAppLocaleAsLangTag(), "ja-JP-mac"); + Assert.equal(localeService.appLocaleAsLangTag, "ja-JP-mac"); - localeService.setAvailableLocales(bkpAvLocales); + localeService.availableLocales = bkpAvLocales; run_next_test(); }); diff --git a/intl/locale/tests/unit/test_localeService_negotiateLanguages.js b/intl/locale/tests/unit/test_localeService_negotiateLanguages.js index fb0007be726b..56bddaf4adf9 100644 --- a/intl/locale/tests/unit/test_localeService_negotiateLanguages.js +++ b/intl/locale/tests/unit/test_localeService_negotiateLanguages.js @@ -82,23 +82,9 @@ const data = { [["ja-JP-mac", "de-DE"], ["ja-JP-mac", "de-DE"], ["ja-JP-mac", "de-DE"]], ], "should not crash on invalid input": [ - [null, ["fr-FR"], []], - [[null], [], []], - [[undefined], [], []], - [[undefined], [null], []], - [[undefined], [undefined], []], - [[null], [null], null, null, []], - [undefined, ["fr-FR"], []], - [2, ["fr-FR"], []], - ["fr-FR", ["fr-FR"], []], [["fą-FŻ"], ["ór_Fń"], []], - [["fr-FR"], null, []], - [["fr-FR"], undefined, []], - [["fr-FR"], 2, []], - [["fr-FR"], "fr-FR", []], [["2"], ["ąóżł"], []], - [[[]], ["fr-FR"], []], - [[[]], [[2]], []], + [[[""]], ["fr-FR"], []], ], }, "matching": { @@ -143,4 +129,26 @@ function run_test() } } } + + // Verify that we error out when requested or available is not an array. + for ([req, avail] in [ + [null, ["fr-FR"]], + [undefined, ["fr-FR"]], + [2, ["fr-FR"]], + ["fr-FR", ["fr-FR"]], + [["fr-FR"], null], + [["fr-FR"], undefined], + [["fr-FR"], 2], + [["fr-FR"], "fr-FR"], + [[null], []], + [[undefined], []], + [[undefined], [null]], + [[undefined], [undefined]], + [[null], [null]], + [[[]], [[2]]], + ]) { + Assert.throws(() => { + nl(req, avail); + }, err => err.result == Cr.NS_ERROR_XPC_CANT_CONVERT_PRIMITIVE_TO_ARRAY); + } } From 83ea94f5baab642aa3a8e81060f5368a483863d9 Mon Sep 17 00:00:00 2001 From: Zibi Braniecki Date: Fri, 21 Sep 2018 15:30:37 +0000 Subject: [PATCH 02/18] Bug 1491394 - Update callsites to use new mozILocaleService API. r=jfkthame Depends on D5924 Differential Revision: https://phabricator.services.mozilla.com/D6339 --HG-- extra : moz-landing-system : lando --- .../customizableui/content/panelUI.js | 2 +- browser/components/distribution.js | 2 +- .../test/browser/head_pageAction.js | 12 +++++------ browser/components/migration/AutoMigrate.jsm | 2 +- .../components/newtab/aboutNewTabService.js | 2 +- browser/components/newtab/lib/ASRouter.jsm | 2 +- .../components/newtab/lib/ActivityStream.jsm | 2 +- .../components/newtab/lib/TelemetryFeed.jsm | 4 ++-- .../browser/browser_packaged_as_locales.js | 12 +++++------ .../test/unit/lib/ActivityStream.test.js | 8 +++---- .../components/newtab/test/unit/unit-entry.js | 4 ++-- browser/components/nsBrowserGlue.js | 6 +++--- .../preferences/browserLanguages.js | 6 +++--- .../components/preferences/in-content/main.js | 16 +++++++------- .../test_bug1409973_date_time_format.html | 12 +++++------ browser/components/search/test/head.js | 2 +- .../xpcshell/test_SyncedTabsDeckComponent.js | 4 ++-- .../components/translation/Translation.jsm | 2 +- .../translation/translation-infobar.xml | 2 +- browser/extensions/formautofill/api.js | 2 +- .../pdfjs/content/PdfStreamConverter.jsm | 2 +- browser/extensions/pocket/content/main.js | 2 +- browser/extensions/pocket/content/pktApi.jsm | 4 ++-- browser/modules/PingCentre.jsm | 2 +- chrome/test/unit/test_bug848297.js | 2 +- .../aboutdebugging-new/aboutdebugging.js | 2 +- devtools/client/application/initializer.js | 2 +- .../server/tests/mochitest/test_device.html | 2 +- devtools/shared/system.js | 2 +- .../test_animation_performance_warning.html | 2 +- .../chrome/test_intlUtils_getLocaleInfo.html | 4 ++-- .../test_window_getRegionalPrefsLocales.html | 2 +- gfx/thebes/gfxPlatformFontList.cpp | 2 +- intl/docs/locale.rst | 21 +++++++++---------- intl/l10n/DOMLocalization.jsm | 2 +- intl/l10n/L10nRegistry.jsm | 6 +++--- intl/l10n/Localization.jsm | 4 ++-- .../dom/test_mozdom_translateElements.html | 4 ++-- .../dom/test_mozdom_translateFragment.html | 4 ++-- .../test/dom/test_mozdom_translateRoots.html | 4 ++-- intl/l10n/test/test_localization.js | 8 +++---- intl/l10n/test/test_mozdomlocalization.js | 4 ++-- intl/l10n/test/test_pseudo.js | 6 +++--- mobile/android/chrome/content/browser.js | 8 +++---- .../android/components/DirectoryProvider.js | 2 +- .../components/geckoview/GeckoViewStartup.js | 4 ++-- .../org/mozilla/geckoview/test/LocaleTest.kt | 2 +- toolkit/components/extensions/Extension.jsm | 4 ++-- .../components/extensions/ExtensionCommon.jsm | 2 +- .../extensions/test/xpcshell/test_ext_i18n.js | 12 +++++------ .../test/xpcshell/test_ext_i18n_css.js | 6 +++--- .../test/xpcshell/test_ext_startup_cache.js | 6 +++--- toolkit/components/mozintl/mozIntl.js | 2 +- .../normandy/lib/NormandyDriver.jsm | 2 +- .../test/unit/test_app_rep_maclinux.js | 6 +++--- .../test/unit/test_app_rep_windows.js | 6 +++--- .../resistfingerprinting/LanguagePrompt.jsm | 2 +- toolkit/components/search/nsSearchService.js | 4 ++-- .../search/tests/xpcshell/head_search.js | 4 ++-- .../tests/xpcshell/test_list_json_locale.js | 8 +++---- .../tests/xpcshell/test_paramSubstitution.js | 6 +++--- .../telemetry/app/TelemetryEnvironment.jsm | 2 +- .../components/urlformatter/nsURLFormatter.js | 2 +- .../tests/unit/test_urlformatter.js | 2 +- .../components/utils/ClientEnvironment.jsm | 2 +- toolkit/content/widgets/datetimepopup.xml | 2 +- toolkit/modules/Troubleshoot.jsm | 8 +++---- toolkit/mozapps/extensions/AddonManager.jsm | 2 +- toolkit/mozapps/extensions/Blocklist.jsm | 2 +- .../extensions/internal/XPIDatabase.jsm | 2 +- .../extensions/test/xpcshell/head_addons.js | 2 +- .../xpcshell/test_blocklist_url_parameters.js | 2 +- .../test/xpcshell/test_manifest_locales.js | 2 +- .../extensions/test/xpcshell/test_update.js | 2 +- .../xpcshell/test_webextension_langpack.js | 18 ++++++++-------- uriloader/exthandler/HandlerService.js | 2 +- 76 files changed, 167 insertions(+), 168 deletions(-) diff --git a/browser/components/customizableui/content/panelUI.js b/browser/components/customizableui/content/panelUI.js index 676f49056f92..d5b5911a01ff 100644 --- a/browser/components/customizableui/content/panelUI.js +++ b/browser/components/customizableui/content/panelUI.js @@ -865,7 +865,7 @@ XPCOMUtils.defineConstant(this, "PanelUI", PanelUI); * @return the selected locale */ function getLocale() { - return Services.locale.getAppLocaleAsLangTag(); + return Services.locale.appLocaleAsLangTag; } function getNotificationFromElement(aElement) { diff --git a/browser/components/distribution.js b/browser/components/distribution.js index c5116170781e..f051cb681725 100644 --- a/browser/components/distribution.js +++ b/browser/components/distribution.js @@ -82,7 +82,7 @@ DistributionCustomizer.prototype = { }, get _locale() { - const locale = Services.locale.getRequestedLocale() || "en-US"; + const locale = Services.locale.requestedLocale || "en-US"; this.__defineGetter__("_locale", () => locale); return this._locale; }, diff --git a/browser/components/extensions/test/browser/head_pageAction.js b/browser/components/extensions/test/browser/head_pageAction.js index a8015b9d64e1..c7f02bc89760 100644 --- a/browser/components/extensions/test/browser/head_pageAction.js +++ b/browser/components/extensions/test/browser/head_pageAction.js @@ -13,11 +13,11 @@ // // In the future, we should provide some way for tests to decouple their // language selection from that of Firefox. - const avLocales = Services.locale.getAvailableLocales(); + const avLocales = Services.locale.availableLocales; - Services.locale.setAvailableLocales(["en-US", "es-ES"]); + Services.locale.availableLocales = ["en-US", "es-ES"]; registerCleanupFunction(() => { - Services.locale.setAvailableLocales(avLocales); + Services.locale.availableLocales = avLocales; }); } @@ -152,8 +152,8 @@ async function runTests(options) { }); }); - let reqLoc = Services.locale.getRequestedLocales(); - Services.locale.setRequestedLocales(["es-ES"]); + let reqLoc = Services.locale.requestedLocales; + Services.locale.requestedLocales = ["es-ES"]; await extension.startup(); @@ -161,7 +161,7 @@ async function runTests(options) { await extension.unload(); - Services.locale.setRequestedLocales(reqLoc); + Services.locale.requestedLocales = reqLoc; let node = document.getElementById(pageActionId); is(node, null, "pageAction image removed from document"); diff --git a/browser/components/migration/AutoMigrate.jsm b/browser/components/migration/AutoMigrate.jsm index d8c141facbbe..66a38318c07a 100644 --- a/browser/components/migration/AutoMigrate.jsm +++ b/browser/components/migration/AutoMigrate.jsm @@ -661,7 +661,7 @@ const AutoMigrate = { // lead to a an array with 1 empty string in it. surveyLocales = new Set(surveyLocales.filter(str => !!str)); canDoSurveyInLocale = - surveyLocales.has(Services.locale.getAppLocaleAsLangTag()); + surveyLocales.has(Services.locale.appLocaleAsLangTag); } catch (ex) { /* ignore exceptions and just don't do the survey. */ } diff --git a/browser/components/newtab/aboutNewTabService.js b/browser/components/newtab/aboutNewTabService.js index 8d185fba0807..f9237309038a 100644 --- a/browser/components/newtab/aboutNewTabService.js +++ b/browser/components/newtab/aboutNewTabService.js @@ -310,7 +310,7 @@ AboutNewTabService.prototype = { return Services.locale.negotiateLanguages( // Fix up incorrect BCP47 that are actually lang tags as a workaround for // bug 1479606 returning the wrong values in the content process - Services.locale.getAppLocalesAsBCP47().map(l => l.replace(/^(ja-JP-mac)$/, "$1os")), + Services.locale.appLocalesAsBCP47.map(l => l.replace(/^(ja-JP-mac)$/, "$1os")), ACTIVITY_STREAM_BCP47, // defaultLocale's strings aren't necessarily packaged, but en-US' are "en-US", diff --git a/browser/components/newtab/lib/ASRouter.jsm b/browser/components/newtab/lib/ASRouter.jsm index 3e94ff9907a3..63c0602682d9 100644 --- a/browser/components/newtab/lib/ASRouter.jsm +++ b/browser/components/newtab/lib/ASRouter.jsm @@ -151,7 +151,7 @@ const MessageLoaderUtils = { }, _getRemoteSettingsMessages(bucket) { - return RemoteSettings(bucket).get({filters: {locale: Services.locale.getAppLocaleAsLangTag()}}); + return RemoteSettings(bucket).get({filters: {locale: Services.locale.appLocaleAsLangTag}}); }, /** diff --git a/browser/components/newtab/lib/ActivityStream.jsm b/browser/components/newtab/lib/ActivityStream.jsm index 1e266d44fb05..dd02333d16d8 100644 --- a/browser/components/newtab/lib/ActivityStream.jsm +++ b/browser/components/newtab/lib/ActivityStream.jsm @@ -441,7 +441,7 @@ this.ActivityStream = class ActivityStream { this.geo = ""; } - this.locale = Services.locale.getAppLocaleAsLangTag(); + this.locale = Services.locale.appLocaleAsLangTag; // Update the pref config of those with dynamic values for (const pref of PREFS_CONFIG.keys()) { diff --git a/browser/components/newtab/lib/TelemetryFeed.jsm b/browser/components/newtab/lib/TelemetryFeed.jsm index c4149a61181e..c37b72717abf 100644 --- a/browser/components/newtab/lib/TelemetryFeed.jsm +++ b/browser/components/newtab/lib/TelemetryFeed.jsm @@ -328,7 +328,7 @@ this.TelemetryFeed = class TelemetryFeed { createPing(portID) { const ping = { addon_version: Services.appinfo.appBuildID, - locale: Services.locale.getAppLocaleAsLangTag(), + locale: Services.locale.appLocaleAsLangTag, user_prefs: this.userPreferences, }; @@ -412,7 +412,7 @@ this.TelemetryFeed = class TelemetryFeed { const ping = { client_id: "n/a", addon_version: Services.appinfo.appBuildID, - locale: Services.locale.getAppLocaleAsLangTag(), + locale: Services.locale.appLocaleAsLangTag, impression_id: this._impressionId, }; if (action.data.includeClientID) { diff --git a/browser/components/newtab/test/browser/browser_packaged_as_locales.js b/browser/components/newtab/test/browser/browser_packaged_as_locales.js index 1e024896b7a7..92cb44658eea 100644 --- a/browser/components/newtab/test/browser/browser_packaged_as_locales.js +++ b/browser/components/newtab/test/browser/browser_packaged_as_locales.js @@ -10,16 +10,16 @@ const DEFAULT_URL = "resource://activity-stream/prerendered/en-US/activity-strea * Temporarily change the app locale to get the localized activity stream url */ async function getUrlForLocale(locale) { - const origAvailable = Services.locale.getAvailableLocales(); - const origRequested = Services.locale.getRequestedLocales(); + const origAvailable = Services.locale.availableLocales; + const origRequested = Services.locale.requestedLocales; try { - Services.locale.setAvailableLocales([locale]); - Services.locale.setRequestedLocales([locale]); + Services.locale.availableLocales = [locale]; + Services.locale.requestedLocales = [locale]; return aboutNewTabService.defaultURL; } finally { // Always clean up after returning the url - Services.locale.setAvailableLocales(origAvailable); - Services.locale.setRequestedLocales(origRequested); + Services.locale.availableLocales = origAvailable; + Services.locale.requestedLocales = origRequested; } } diff --git a/browser/components/newtab/test/unit/lib/ActivityStream.test.js b/browser/components/newtab/test/unit/lib/ActivityStream.test.js index f592b509d7d9..239ff029c5be 100644 --- a/browser/components/newtab/test/unit/lib/ActivityStream.test.js +++ b/browser/components/newtab/test/unit/lib/ActivityStream.test.js @@ -255,7 +255,7 @@ describe("ActivityStream", () => { it("should be false with expected geo and unexpected locale", () => { sandbox.stub(global.Services.prefs, "prefHasUserValue").returns(true); sandbox.stub(global.Services.prefs, "getStringPref").returns("US"); - sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("no-LOCALE"); + sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("no-LOCALE"); as._updateDynamicPrefs(); @@ -264,7 +264,7 @@ describe("ActivityStream", () => { it("should be true with expected geo and locale", () => { sandbox.stub(global.Services.prefs, "prefHasUserValue").returns(true); sandbox.stub(global.Services.prefs, "getStringPref").returns("US"); - sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("en-US"); + sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("en-US"); as._updateDynamicPrefs(); @@ -277,7 +277,7 @@ describe("ActivityStream", () => { .returns("US") .onSecondCall() .returns("NOGEO"); - sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("en-US"); + sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("en-US"); as._updateDynamicPrefs(); as._updateDynamicPrefs(); @@ -308,7 +308,7 @@ describe("ActivityStream", () => { }); it("should set true with expected geo and locale", () => { sandbox.stub(global.Services.prefs, "getStringPref").returns("US"); - sandbox.stub(global.Services.locale, "getAppLocaleAsLangTag").returns("en-US"); + sandbox.stub(global.Services.locale, "appLocaleAsLangTag").returns("en-US"); as._updateDynamicPrefs(); clock.tick(1); diff --git a/browser/components/newtab/test/unit/unit-entry.js b/browser/components/newtab/test/unit/unit-entry.js index 6b46fd4c248b..af722604ad4a 100644 --- a/browser/components/newtab/test/unit/unit-entry.js +++ b/browser/components/newtab/test/unit/unit-entry.js @@ -106,8 +106,8 @@ const TEST_GLOBAL = { DownloadsViewUI: {DownloadElementShell}, Services: { locale: { - getAppLocaleAsLangTag() { return "en-US"; }, - getAppLocalesAsLangTags() {}, + appLocaleAsLangTag: "en-US", + appLocalesAsLangtags: [], negotiateLanguages() {}, }, urlFormatter: {formatURL: str => str, formatURLPref: str => str}, diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 6624276c01e0..d2aca10ad291 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -1061,7 +1061,7 @@ BrowserGlue.prototype = { Normandy.init(); // Initialize the default l10n resource sources for L10nRegistry. - let locales = Services.locale.getPackagedLocales(); + let locales = Services.locale.packagedLocales; const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/"); L10nRegistry.registerSource(greSource); @@ -2345,13 +2345,13 @@ BrowserGlue.prototype = { if (Services.prefs.prefHasUserValue(MATCHOS_LOCALE_PREF) || Services.prefs.prefHasUserValue(SELECTED_LOCALE_PREF)) { if (Services.prefs.getBoolPref(MATCHOS_LOCALE_PREF, false)) { - Services.locale.setRequestedLocales([]); + Services.locale.requestedLocales = []; } else { let locale = Services.prefs.getComplexValue(SELECTED_LOCALE_PREF, Ci.nsIPrefLocalizedString); if (locale) { try { - Services.locale.setRequestedLocales([locale.data]); + Services.locale.requestedLocales = [locale.data]; } catch (e) { /* Don't panic if the value is not a valid locale code. */ } } } diff --git a/browser/components/preferences/browserLanguages.js b/browser/components/preferences/browserLanguages.js index 57e447406bdc..fc4b124f00e8 100644 --- a/browser/components/preferences/browserLanguages.js +++ b/browser/components/preferences/browserLanguages.js @@ -197,7 +197,7 @@ class SortedItemSelectList { } function getLocaleDisplayInfo(localeCodes) { - let packagedLocales = new Set(Services.locale.getPackagedLocales()); + let packagedLocales = new Set(Services.locale.packagedLocales); let localeNames = Services.intl.getLocaleDisplayNames(undefined, localeCodes); return localeCodes.map((code, i) => { return { @@ -223,9 +223,9 @@ var gBrowserLanguagesDialog = { // Maintain the previously requested locales even if we cancel out. this.requestedLocales = window.arguments[0]; - let requested = this.requestedLocales || Services.locale.getRequestedLocales(); + let requested = this.requestedLocales || Services.locale.requestedLocales; let requestedSet = new Set(requested); - let available = Services.locale.getAvailableLocales() + let available = Services.locale.availableLocales .filter(locale => !requestedSet.has(locale)); this.initRequestedLocales(requested); diff --git a/browser/components/preferences/in-content/main.js b/browser/components/preferences/in-content/main.js index 727003f988f7..cf7ad0e3dbee 100644 --- a/browser/components/preferences/in-content/main.js +++ b/browser/components/preferences/in-content/main.js @@ -238,7 +238,7 @@ var promiseLoadHandlersList; function getBundleForLocales(newLocales) { let locales = Array.from(new Set([ ...newLocales, - ...Services.locale.getRequestedLocales(), + ...Services.locale.requestedLocales, Services.locale.lastFallbackLocale, ])); function generateContexts(resourceIds) { @@ -785,7 +785,7 @@ var gMainPane = { }, initBrowserLocale() { - let localeCodes = Services.locale.getAvailableLocales(); + let localeCodes = Services.locale.availableLocales; let localeNames = Services.intl.getLocaleDisplayNames(undefined, localeCodes); let locales = localeCodes.map((code, i) => ({code, name: localeNames[i]})); locales.sort((a, b) => a.name > b.name); @@ -800,7 +800,7 @@ var gMainPane = { let menulist = document.getElementById("defaultBrowserLanguage"); let menupopup = menulist.querySelector("menupopup"); menupopup.appendChild(fragment); - menulist.value = Services.locale.getRequestedLocale(); + menulist.value = Services.locale.requestedLocale; document.getElementById("browserLanguagesBox").hidden = false; }, @@ -836,7 +836,7 @@ var gMainPane = { return; } let locales = localesString.split(","); - Services.locale.setRequestedLocales(locales); + Services.locale.requestedLocales = locales; // Restart with the new locale. let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); @@ -849,13 +849,13 @@ var gMainPane = { /* Show or hide the confirm change message bar based on the new locale. */ onBrowserLanguageChange(event) { let locale = event.target.value; - if (locale == Services.locale.getRequestedLocale()) { + if (locale == Services.locale.requestedLocale) { this.hideConfirmLanguageChangeMessageBar(); return; } let locales = Array.from(new Set([ locale, - ...Services.locale.getRequestedLocales(), + ...Services.locale.requestedLocales, ]).values()); this.showConfirmLanguageChangeMessageBar(locales); }, @@ -993,14 +993,14 @@ var gMainPane = { /* Show or hide the confirm change message bar based on the updated ordering. */ browserLanguagesClosed() { let requesting = this.gBrowserLanguagesDialog.requestedLocales; - let requested = Services.locale.getRequestedLocales(); + let requested = Services.locale.requestedLocales; let defaultBrowserLanguage = document.getElementById("defaultBrowserLanguage"); if (requesting && requesting.join(",") != requested.join(",")) { gMainPane.showConfirmLanguageChangeMessageBar(requesting); defaultBrowserLanguage.value = requesting[0]; return; } - defaultBrowserLanguage.value = Services.locale.getRequestedLocale(); + defaultBrowserLanguage.value = Services.locale.requestedLocale; gMainPane.hideConfirmLanguageChangeMessageBar(); }, diff --git a/browser/components/resistfingerprinting/test/chrome/test_bug1409973_date_time_format.html b/browser/components/resistfingerprinting/test/chrome/test_bug1409973_date_time_format.html index f976f3fc0233..8325e88b7070 100644 --- a/browser/components/resistfingerprinting/test/chrome/test_bug1409973_date_time_format.html +++ b/browser/components/resistfingerprinting/test/chrome/test_bug1409973_date_time_format.html @@ -8,10 +8,10 @@ SimpleTest.waitForExplicitFinish(); - const originalAvailable = Services.locale.getAvailableLocales(); - const originalRequested = Services.locale.getRequestedLocales(); - Services.locale.setAvailableLocales(["ko-KR"]); - Services.locale.setRequestedLocales(["ko-KR"]); + const originalAvailable = Services.locale.availableLocales; + const originalRequested = Services.locale.requestedLocales; + Services.locale.availableLocales = ["ko-KR"]; + Services.locale.requestedLocales = ["ko-KR"]; // First be sure we have a non-UTC timezone and a non en-US locale. var setTimeZone = SpecialPowers.Cu.getJSTestingFunctions().setTimeZone; @@ -58,8 +58,8 @@ SimpleTest.is(options.timeZoneName, "long", "Resist Fingerprinting Intl.DateTimeFormat.format.timeZoneName"); // Cleanup - Services.locale.setRequestedLocales(originalRequested); - Services.locale.setAvailableLocales(originalAvailable); + Services.locale.requestedLocales = originalRequested; + Services.locale.availableLocales = originalAvailable; SimpleTest.finish(); }); diff --git a/browser/components/search/test/head.js b/browser/components/search/test/head.js index 4b3cf5dcea01..a36067ef6997 100644 --- a/browser/components/search/test/head.js +++ b/browser/components/search/test/head.js @@ -22,7 +22,7 @@ function isSubObjectOf(expectedObj, actualObj, name) { } function getLocale() { - return Services.locale.getRequestedLocale() || undefined; + return Services.locale.requestedLocale || undefined; } function promiseEvent(aTarget, aEventName, aPreventDefault) { diff --git a/browser/components/syncedtabs/test/xpcshell/test_SyncedTabsDeckComponent.js b/browser/components/syncedtabs/test/xpcshell/test_SyncedTabsDeckComponent.js index 024b7e3c1a88..835276ba1724 100644 --- a/browser/components/syncedtabs/test/xpcshell/test_SyncedTabsDeckComponent.js +++ b/browser/components/syncedtabs/test/xpcshell/test_SyncedTabsDeckComponent.js @@ -131,8 +131,8 @@ add_task(async function testObserver() { "component is notified of login change"); Assert.equal(component.updatePanel.callCount, 4, "triggers panel update again"); - Services.locale.setAvailableLocales(["ab-CD"]); - Services.locale.setRequestedLocales(["ab-CD"]); + Services.locale.availableLocales = ["ab-CD"]; + Services.locale.requestedLocales = ["ab-CD"]; Assert.ok(component.updateDir.calledTwice, "locale change triggers UI direction update"); diff --git a/browser/components/translation/Translation.jsm b/browser/components/translation/Translation.jsm index 558b266cd608..97dc127ff668 100644 --- a/browser/components/translation/Translation.jsm +++ b/browser/components/translation/Translation.jsm @@ -29,7 +29,7 @@ var Translation = { _defaultTargetLanguage: "", get defaultTargetLanguage() { if (!this._defaultTargetLanguage) { - this._defaultTargetLanguage = Services.locale.getAppLocaleAsLangTag() + this._defaultTargetLanguage = Services.locale.appLocaleAsLangTag .split("-")[0]; } return this._defaultTargetLanguage; diff --git a/browser/components/translation/translation-infobar.xml b/browser/components/translation/translation-infobar.xml index 35d990a582e6..126dab21dd27 100644 --- a/browser/components/translation/translation-infobar.xml +++ b/browser/components/translation/translation-infobar.xml @@ -270,7 +270,7 @@ "C\u1EA3m \u01A1n"], }; - let locale = Services.locale.getAppLocaleAsLangTag(); + let locale = Services.locale.appLocaleAsLangTag; if (!(locale in localizedStrings)) locale = "en"; let strings = localizedStrings[locale]; diff --git a/browser/extensions/formautofill/api.js b/browser/extensions/formautofill/api.js index 85ad442f064a..6713e762b0b2 100644 --- a/browser/extensions/formautofill/api.js +++ b/browser/extensions/formautofill/api.js @@ -53,7 +53,7 @@ function isAvailable() { if (availablePref == "on") { return true; } else if (availablePref == "detect") { - let locale = Services.locale.getRequestedLocale(); + let locale = Services.locale.requestedLocale; let region = Services.prefs.getCharPref("browser.search.region", ""); let supportedCountries = Services.prefs.getCharPref("extensions.formautofill.supportedCountries") .split(","); diff --git a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm index 59492f54d2b2..06caac0a89a6 100644 --- a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm +++ b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm @@ -306,7 +306,7 @@ class ChromeActions { } getLocale() { - return Services.locale.getRequestedLocale() || "en-US"; + return Services.locale.requestedLocale || "en-US"; } getStrings(data) { diff --git a/browser/extensions/pocket/content/main.js b/browser/extensions/pocket/content/main.js index 937f9d8aa48e..d93a38e6bcdf 100644 --- a/browser/extensions/pocket/content/main.js +++ b/browser/extensions/pocket/content/main.js @@ -624,7 +624,7 @@ var pktUI = (function() { } function getUILocale() { - return Services.locale.getAppLocaleAsLangTag(); + return Services.locale.appLocaleAsLangTag; } /** diff --git a/browser/extensions/pocket/content/pktApi.jsm b/browser/extensions/pocket/content/pktApi.jsm index 32a80158b1e6..48d428405476 100644 --- a/browser/extensions/pocket/content/pktApi.jsm +++ b/browser/extensions/pocket/content/pktApi.jsm @@ -246,7 +246,7 @@ var pktApi = (function() { var url = baseAPIUrl + options.path; var data = options.data || {}; - data.locale_lang = Services.locale.getAppLocaleAsLangTag(); + data.locale_lang = Services.locale.appLocaleAsLangTag; data.consumer_key = oAuthConsumerKey; var request = new XMLHttpRequest(); @@ -358,7 +358,7 @@ var pktApi = (function() { // Define variant for ho2 if (data.flags) { - var showHo2 = (Services.locale.getAppLocaleAsLangTag() === "en-US") ? data.flags.show_ffx_mobile_prompt : "control"; + var showHo2 = (Services.locale.appLocaleAsLangTag === "en-US") ? data.flags.show_ffx_mobile_prompt : "control"; setSetting("test.ho2", showHo2); } data.ho2 = getSetting("test.ho2"); diff --git a/browser/modules/PingCentre.jsm b/browser/modules/PingCentre.jsm index 4c0d2f0b7e25..c6106797d7d6 100644 --- a/browser/modules/PingCentre.jsm +++ b/browser/modules/PingCentre.jsm @@ -143,7 +143,7 @@ class PingCentre { } let clientID = data.client_id || await this.telemetryClientId; - let locale = data.locale || Services.locale.getAppLocalesAsLangTags().pop(); + let locale = data.locale || Services.locale.appLocaleAsLangTag; let profileCreationDate = TelemetryEnvironment.currentEnvironment.profile.resetDate || TelemetryEnvironment.currentEnvironment.profile.creationDate; const payload = Object.assign({ diff --git a/chrome/test/unit/test_bug848297.js b/chrome/test/unit/test_bug848297.js index 84c694e889a3..1ec29c0915cc 100644 --- a/chrome/test/unit/test_bug848297.js +++ b/chrome/test/unit/test_bug848297.js @@ -25,7 +25,7 @@ function enum_to_array(strings) { function run_test() { // without override - Services.locale.setRequestedLocales(["de"]); + Services.locale.requestedLocales = ["de"]; Assert.equal(chromeReg.getSelectedLocale("basepack"), "en-US"); Assert.equal(chromeReg.getSelectedLocale("overpack"), "de"); Assert.deepEqual(enum_to_array(chromeReg.getLocalesForPackage("basepack")), diff --git a/devtools/client/aboutdebugging-new/aboutdebugging.js b/devtools/client/aboutdebugging-new/aboutdebugging.js index dcfd72252f7a..65a0bbe4a149 100644 --- a/devtools/client/aboutdebugging-new/aboutdebugging.js +++ b/devtools/client/aboutdebugging-new/aboutdebugging.js @@ -80,7 +80,7 @@ const AboutDebugging = { L10nRegistry.registerSource(temporarySource); } - const locales = Services.locale.getAppLocalesAsBCP47(); + const locales = Services.locale.appLocalesAsBCP47; const generator = L10nRegistry.generateContexts(locales, ["aboutdebugging.ftl"]); diff --git a/devtools/client/application/initializer.js b/devtools/client/application/initializer.js index 0ac40e188351..683d4859126f 100644 --- a/devtools/client/application/initializer.js +++ b/devtools/client/application/initializer.js @@ -65,7 +65,7 @@ window.Application = { * MessageContext elements. */ async createMessageContexts() { - const locales = Services.locale.getAppLocalesAsBCP47(); + const locales = Services.locale.appLocalesAsBCP47; const generator = L10nRegistry.generateContexts(locales, ["devtools/application.ftl"]); diff --git a/devtools/server/tests/mochitest/test_device.html b/devtools/server/tests/mochitest/test_device.html index 0c2b44c907d5..cee2b483cc87 100644 --- a/devtools/server/tests/mochitest/test_device.html +++ b/devtools/server/tests/mochitest/test_device.html @@ -45,7 +45,7 @@ window.onload = function() { geckobuildid: appInfo.platformBuildID, geckoversion: appInfo.platformVersion, useragent: window.navigator.userAgent, - locale: Services.locale.getAppLocaleAsLangTag(), + locale: Services.locale.appLocaleAsLangTag, os: appInfo.OS, processor: appInfo.XPCOMABI.split("-")[0], compiler: appInfo.XPCOMABI.split("-")[1], diff --git a/devtools/shared/system.js b/devtools/shared/system.js index 88f808f766d4..7a0fe2e9c17f 100644 --- a/devtools/shared/system.js +++ b/devtools/shared/system.js @@ -114,7 +114,7 @@ async function getSystemInfo() { geckoversion: geckoVersion, // Locale used in this build - locale: Services.locale.getAppLocaleAsLangTag(), + locale: Services.locale.appLocaleAsLangTag, /** * Information regarding the operating system. diff --git a/dom/animation/test/chrome/test_animation_performance_warning.html b/dom/animation/test/chrome/test_animation_performance_warning.html index bbf53adcf055..cfc1dc1f8009 100644 --- a/dom/animation/test/chrome/test_animation_performance_warning.html +++ b/dom/animation/test/chrome/test_animation_performance_warning.html @@ -32,7 +32,7 @@ var gStringBundle; W3CTest.runner.requestLongerTimeout(2); const { Services } = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm"); -Services.locale.setRequestedLocales(["en-US"]); +Services.locale.requestedLocales = ["en-US"]; SpecialPowers.pushPrefEnv({ "set": [ // Need to set devPixelsPerPx explicitly to gain diff --git a/dom/tests/mochitest/chrome/test_intlUtils_getLocaleInfo.html b/dom/tests/mochitest/chrome/test_intlUtils_getLocaleInfo.html index 0aedd39eddee..52df9ef3b5ff 100644 --- a/dom/tests/mochitest/chrome/test_intlUtils_getLocaleInfo.html +++ b/dom/tests/mochitest/chrome/test_intlUtils_getLocaleInfo.html @@ -18,8 +18,8 @@ const localeService = Cc["@mozilla.org/intl/localeservice;1"].getService(Ci.mozILocaleService); const mozIntl = Cc["@mozilla.org/mozintl;1"].getService(Ci.mozIMozIntl); -let rpLocale = localeService.negotiateLanguages(localeService.getRegionalPrefsLocales(), - localeService.getAvailableLocales())[0]; +let rpLocale = localeService.negotiateLanguages(localeService.regionalPrefsLocales, + localeService.availableLocales)[0]; let testData = [ { diff --git a/dom/tests/mochitest/chrome/test_window_getRegionalPrefsLocales.html b/dom/tests/mochitest/chrome/test_window_getRegionalPrefsLocales.html index 401a0731fc41..f9785669979a 100644 --- a/dom/tests/mochitest/chrome/test_window_getRegionalPrefsLocales.html +++ b/dom/tests/mochitest/chrome/test_window_getRegionalPrefsLocales.html @@ -18,7 +18,7 @@ const localeService = Cc["@mozilla.org/intl/localeservice;1"].getService(Ci.mozILocaleService); let rpLocales = localeService.negotiateLanguages(window.getRegionalPrefsLocales(), - localeService.getAvailableLocales()); + localeService.availableLocales); ok(rpLocales.length > 0, "getRegionalPrefsLocales returns at least one locale."); is(rpLocales[0], "en-US", "The first regional prefs locale should resolve to en-US."); diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 9bfc150d9c44..d3a34efbdd40 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -1288,7 +1288,7 @@ gfxPlatformFontList::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], uint32_t &aL if (OSPreferences::GetInstance()->GetSystemLocales(sysLocales)) { LocaleService::GetInstance()->NegotiateLanguages( sysLocales, prefLocales, NS_LITERAL_CSTRING(""), - LocaleService::LangNegStrategy::Filtering, negLocales); + LocaleService::kLangNegStrategyFiltering, negLocales); for (const auto& localeStr : negLocales) { Locale locale(localeStr); diff --git a/intl/docs/locale.rst b/intl/docs/locale.rst index dd1c9e21cc67..1478e4139de6 100644 --- a/intl/docs/locale.rst +++ b/intl/docs/locale.rst @@ -333,8 +333,7 @@ carry different lists of available locales. Requested Locales ================= -The list of requested locales can be read using :js:`LocaleService::GetRequestedLocales` API, -and set using :js:`LocaleService::SetRequestedLocales` API. +The list of requested locales can be read and set using :js:`LocaleService::requestedLocales` API. Using the API will perform necessary sanity checks and canonicalize the values. @@ -349,7 +348,7 @@ The former is the current default setting for Firefox Desktop, and the latter is default setting for Firefox for Android. If the developer wants to programmatically request the app to follow OS locales, -they can call the :js:`SetRequestedLocales` API with no argument. +they can assign :js:`null` to :js:`requestedLocales`. Regional Preferences ==================== @@ -450,8 +449,8 @@ a legacy "ja-JP-mac" locale. The "mac" is a variant and BCP47 requires all varia to be 5-8 character long. Gecko supports the limitation by accepting the 3-letter variants in our APIs and also -provides a special :js:`GetAppLocalesAsLangTags` method which returns this locale in that form. -(:js:`GetAppLocalesAsBCP47` will canonicalize it and turn into `"ja-JP-macos"`). +provides a special :js:`appLocalesAsLangTags` method which returns this locale in that form. +(:js:`appLocalesAsBCP47` will canonicalize it and turn into `"ja-JP-macos"`). Usage of language negotiation etc. shouldn't rely on this behavior. @@ -507,14 +506,14 @@ It may look like this: L10nRegistry.registerSource(fs); - let availableLocales = Services.locale.getAvailableLocales(); + let availableLocales = Services.locale.availableLocales; assert(availableLocales.includes("ko-KR")); assert(availableLocales.includes("ar")); - Services.locale.setRequestedLocales(["ko-KR"); + Services.locale.requestedLocales = ["ko-KR"]; - let appLocales = Services.locale.getAppLocalesAsBCP47(); + let appLocales = Services.locale.appLocalesAsBCP47; assert(appLocales[0], "ko-KR"); From here, a resource :js:`test.ftl` can be added to a `Localization` and for ID :js:`key` @@ -528,10 +527,10 @@ but it is also simpler: .. code-block:: javascript - Services.locale.setAvailableLocales(["ko-KR", "ar"]); - Services.locale.setRequestedLocales(["ko-KR"]); + Services.locale.availableLocales = ["ko-KR", "ar"]; + Services.locale.requestedLocales = ["ko-KR"]; - let appLocales = Services.locale.getAppLocalesAsBCP47(); + let appLocales = Services.locale.appLocalesAsBCP47; assert(appLocales[0], "ko-KR"); In the future, Mozilla plans to add a third way for add-ons (`bug 1440969`_) diff --git a/intl/l10n/DOMLocalization.jsm b/intl/l10n/DOMLocalization.jsm index 1dcce96eeb19..70cb14bc55f0 100644 --- a/intl/l10n/DOMLocalization.jsm +++ b/intl/l10n/DOMLocalization.jsm @@ -581,7 +581,7 @@ class DOMLocalization extends Localization { // This means that the DOM alternations and directionality // are set in the same microtask. await this.translateFragment(root); - let primaryLocale = Services.locale.getAppLocaleAsBCP47(); + let primaryLocale = Services.locale.appLocaleAsBCP47; let direction = Services.locale.isAppLocaleRTL ? "rtl" : "ltr"; root.setAttribute("lang", primaryLocale); root.setAttribute(root.namespaceURI === diff --git a/intl/l10n/L10nRegistry.jsm b/intl/l10n/L10nRegistry.jsm index a429acaf5dbc..df06e866acb7 100644 --- a/intl/l10n/L10nRegistry.jsm +++ b/intl/l10n/L10nRegistry.jsm @@ -121,7 +121,7 @@ const L10nRegistry = { throw new Error(`Source with name "${source.name}" already registered.`); } this.sources.set(source.name, source); - Services.locale.setAvailableLocales(this.getAvailableLocales()); + Services.locale.availableLocales = this.getAvailableLocales(); }, /** @@ -137,7 +137,7 @@ const L10nRegistry = { throw new Error(`Source with name "${source.name}" is not registered.`); } this.sources.set(source.name, source); - Services.locale.setAvailableLocales(this.getAvailableLocales()); + Services.locale.availableLocales = this.getAvailableLocales(); }, /** @@ -147,7 +147,7 @@ const L10nRegistry = { */ removeSource(sourceName) { this.sources.delete(sourceName); - Services.locale.setAvailableLocales(this.getAvailableLocales()); + Services.locale.availableLocales = this.getAvailableLocales(); }, /** diff --git a/intl/l10n/Localization.jsm b/intl/l10n/Localization.jsm index a022cf151b68..53c7acdb30d2 100644 --- a/intl/l10n/Localization.jsm +++ b/intl/l10n/Localization.jsm @@ -135,7 +135,7 @@ class CachedAsyncIterable extends CachedIterable { * be localized into a different language - for example DevTools. */ function defaultGenerateMessages(resourceIds) { - const appLocales = Services.locale.getAppLocalesAsBCP47(); + const appLocales = Services.locale.appLocalesAsBCP47; return L10nRegistry.generateContexts(appLocales, resourceIds); } @@ -335,7 +335,7 @@ class Localization { // we want to eagerly fetch just that one. // Otherwise, we're in a scenario where the first locale may // be partial and we want to eagerly fetch a fallback as well. - const appLocale = Services.locale.getAppLocaleAsBCP47(); + const appLocale = Services.locale.appLocaleAsBCP47; const lastFallback = Services.locale.lastFallbackLocale; const prefetchCount = appLocale === lastFallback ? 1 : 2; this.ctxs.touchNext(prefetchCount); diff --git a/intl/l10n/test/dom/test_mozdom_translateElements.html b/intl/l10n/test/dom/test_mozdom_translateElements.html index 1198df2e6b56..072c21cfbe68 100644 --- a/intl/l10n/test/dom/test_mozdom_translateElements.html +++ b/intl/l10n/test/dom/test_mozdom_translateElements.html @@ -22,7 +22,7 @@ link = `, }; const originalLoad = L10nRegistry.load; - const originalRequested = Services.locale.getRequestedLocales(); + const originalRequested = Services.locale.requestedLocales; L10nRegistry.load = async function(url) { return fs.hasOwnProperty(url) ? fs[url] : false; @@ -47,7 +47,7 @@ link = // Cleanup L10nRegistry.removeSource(source.name); L10nRegistry.load = originalLoad; - Services.locale.setRequestedLocales(originalRequested); + Services.locale.requestedLocales = originalRequested; SimpleTest.finish(); }; diff --git a/intl/l10n/test/dom/test_mozdom_translateFragment.html b/intl/l10n/test/dom/test_mozdom_translateFragment.html index b85f0b5a2f62..3d7715efe26a 100644 --- a/intl/l10n/test/dom/test_mozdom_translateFragment.html +++ b/intl/l10n/test/dom/test_mozdom_translateFragment.html @@ -21,7 +21,7 @@ subtitle = Welcome to Fluent `, }; const originalLoad = L10nRegistry.load; - const originalRequested = Services.locale.getRequestedLocales(); + const originalRequested = Services.locale.requestedLocales; L10nRegistry.load = async function(url) { return fs.hasOwnProperty(url) ? fs[url] : false; @@ -46,7 +46,7 @@ subtitle = Welcome to Fluent // Cleanup L10nRegistry.removeSource(source.name); L10nRegistry.load = originalLoad; - Services.locale.setRequestedLocales(originalRequested); + Services.locale.requestedLocales = originalRequested; SimpleTest.finish(); }; diff --git a/intl/l10n/test/dom/test_mozdom_translateRoots.html b/intl/l10n/test/dom/test_mozdom_translateRoots.html index c6e7344b1b0c..3afdc20ed937 100644 --- a/intl/l10n/test/dom/test_mozdom_translateRoots.html +++ b/intl/l10n/test/dom/test_mozdom_translateRoots.html @@ -21,7 +21,7 @@ title2 = Hello Another World `, }; const originalLoad = L10nRegistry.load; - const originalRequested = Services.locale.getRequestedLocales(); + const originalRequested = Services.locale.requestedLocales; L10nRegistry.load = async function(url) { return fs.hasOwnProperty(url) ? fs[url] : false; @@ -51,7 +51,7 @@ title2 = Hello Another World // Cleanup L10nRegistry.removeSource(source.name); L10nRegistry.load = originalLoad; - Services.locale.setRequestedLocales(originalRequested); + Services.locale.requestedLocales = originalRequested; SimpleTest.finish(); }; diff --git a/intl/l10n/test/test_localization.js b/intl/l10n/test/test_localization.js index 0f9c9d857652..38d53b2710e2 100644 --- a/intl/l10n/test/test_localization.js +++ b/intl/l10n/test/test_localization.js @@ -20,7 +20,7 @@ add_task(async function test_methods_calling() { "/localization/en-US/browser/menu.ftl": "key = [en] Value2\nkey2 = [en] Value3", }; const originalLoad = L10nRegistry.load; - const originalRequested = Services.locale.getRequestedLocales(); + const originalRequested = Services.locale.requestedLocales; L10nRegistry.load = async function(url) { return fs[url]; @@ -44,7 +44,7 @@ add_task(async function test_methods_calling() { L10nRegistry.sources.clear(); L10nRegistry.load = originalLoad; - Services.locale.setRequestedLocales(originalRequested); + Services.locale.requestedLocales = originalRequested; }); add_task(async function test_builtins() { @@ -101,7 +101,7 @@ add_task(async function test_add_remove_resourceIds() { "/localization/en-US/toolkit/menu.ftl": "key2 = Value2", }; const originalLoad = L10nRegistry.load; - const originalRequested = Services.locale.getRequestedLocales(); + const originalRequested = Services.locale.requestedLocales; L10nRegistry.load = async function(url) { return fs[url]; @@ -137,5 +137,5 @@ add_task(async function test_add_remove_resourceIds() { L10nRegistry.sources.clear(); L10nRegistry.load = originalLoad; - Services.locale.setRequestedLocales(originalRequested); + Services.locale.requestedLocales = originalRequested; }); diff --git a/intl/l10n/test/test_mozdomlocalization.js b/intl/l10n/test/test_mozdomlocalization.js index 5c063558a291..64566651dd1b 100644 --- a/intl/l10n/test/test_mozdomlocalization.js +++ b/intl/l10n/test/test_mozdomlocalization.js @@ -10,7 +10,7 @@ const fs = { "/localization/en-US/browser/menu.ftl": "key = [en] Value", }; const originalLoad = L10nRegistry.load; -const originalRequested = Services.locale.getRequestedLocales(); +const originalRequested = Services.locale.requestedLocales; // Variable used to test for `L10nRegistry.load` // execution count. @@ -92,5 +92,5 @@ add_task(async function test_ready() { add_task(function cleanup() { L10nRegistry.sources.clear(); L10nRegistry.load = originalLoad; - Services.locale.setRequestedLocales(originalRequested); + Services.locale.requestedLocales = originalRequested; }); diff --git a/intl/l10n/test/test_pseudo.js b/intl/l10n/test/test_pseudo.js index bfa3d2d9f9a1..5e8086982c0d 100644 --- a/intl/l10n/test/test_pseudo.js +++ b/intl/l10n/test/test_pseudo.js @@ -17,7 +17,7 @@ key = This is a single message .accesskey = f`, }; originalValues.load = L10nRegistry.load; - originalValues.requested = Services.locale.getRequestedLocales(); + originalValues.requested = Services.locale.requestedLocales; L10nRegistry.load = async function(url) { return fs[url]; @@ -95,7 +95,7 @@ add_task(async function test_accented_works() { L10nRegistry.sources.clear(); L10nRegistry.load = originalValues.load; - Services.locale.setRequestedLocales(originalValues.requested); + Services.locale.requestedLocales = originalValues.requested; }); /** @@ -126,5 +126,5 @@ add_task(async function test_unavailable_strategy_works() { Services.prefs.setStringPref("intl.l10n.pseudo", ""); L10nRegistry.sources.clear(); L10nRegistry.load = originalValues.load; - Services.locale.setRequestedLocales(originalValues.requested); + Services.locale.requestedLocales = originalValues.requested; }); diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 43d61deda03e..54cf5cfb90fa 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -396,7 +396,7 @@ var BrowserApp = { ]); // Initialize the default l10n resource sources for L10nRegistry. - let locales = Services.locale.getPackagedLocales(); + let locales = Services.locale.packagedLocales; const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/"); L10nRegistry.registerSource(greSource); @@ -1698,7 +1698,7 @@ var BrowserApp = { }, getUALocalePref: function () { - return Services.locale.getRequestedLocale() || undefined; + return Services.locale.requestedLocale || undefined; }, getOSLocalePref: function () { @@ -1775,9 +1775,9 @@ var BrowserApp = { case "Locale:Changed": { if (data) { - Services.locale.setRequestedLocales([data.languageTag]); + Services.locale.requestedLocales = [data.languageTag]; } else { - Services.locale.setRequestedLocales([]); + Services.locale.requestedLocales = []; } console.log("Gecko display locale: " + this.getUALocalePref()); diff --git a/mobile/android/components/DirectoryProvider.js b/mobile/android/components/DirectoryProvider.js index 18b2be3c3aa1..503d37588d0d 100644 --- a/mobile/android/components/DirectoryProvider.js +++ b/mobile/android/components/DirectoryProvider.js @@ -106,7 +106,7 @@ DirectoryProvider.prototype = { return; let curLocale = ""; - let reqLocales = Services.locale.getRequestedLocales(); + let reqLocales = Services.locale.requestedLocales; if (reqLocales.length > 0) { curLocale = reqLocales[0]; } diff --git a/mobile/android/components/geckoview/GeckoViewStartup.js b/mobile/android/components/geckoview/GeckoViewStartup.js index 31441de3dcd7..34f96ce6c513 100644 --- a/mobile/android/components/geckoview/GeckoViewStartup.js +++ b/mobile/android/components/geckoview/GeckoViewStartup.js @@ -119,13 +119,13 @@ GeckoViewStartup.prototype = { GeckoViewTelemetryController.setup(); // Initialize the default l10n resource sources for L10nRegistry. - let locales = Services.locale.getPackagedLocales(); + let locales = Services.locale.packagedLocales; const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/"); L10nRegistry.registerSource(greSource); // Listen for global EventDispatcher messages EventDispatcher.instance.registerListener( - (aEvent, aData, aCallback) => Services.locale.setRequestedLocales([aData.languageTag]), + (aEvent, aData, aCallback) => Services.locale.requestedLocales = [aData.languageTag], "GeckoView:SetLocale"); break; } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt index 59d0c20d2a3a..e075397c7859 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt @@ -25,7 +25,7 @@ class LocaleTest : BaseSessionTest() { val index = sessionRule.waitForChromeJS(String.format( "(function() {" + " return ChromeUtils.import('resource://gre/modules/Services.jsm', {})" + - " .Services.locale.getRequestedLocales().indexOf('en-GB');" + + " .Services.locale.requestedLocales.indexOf('en-GB');" + "})()")) as Double; assertThat("Requested locale is found", index, greaterThanOrEqualTo(0.0)); diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm index 7ac362112339..8b034a2b2119 100644 --- a/toolkit/components/extensions/Extension.jsm +++ b/toolkit/components/extensions/Extension.jsm @@ -1491,7 +1491,7 @@ class Extension extends ExtensionData { } get manifestCacheKey() { - return [this.id, this.version, Services.locale.getAppLocaleAsLangTag()]; + return [this.id, this.version, Services.locale.appLocaleAsLangTag]; } get isPrivileged() { @@ -1723,7 +1723,7 @@ class Extension extends ExtensionData { let locales = await this.promiseLocales(); let matches = Services.locale.negotiateLanguages( - Services.locale.getAppLocalesAsLangTags(), + Services.locale.appLocalesAsLangTags, Array.from(locales.keys()), this.defaultLocale); diff --git a/toolkit/components/extensions/ExtensionCommon.jsm b/toolkit/components/extensions/ExtensionCommon.jsm index 8f803de41920..560c93c61a21 100644 --- a/toolkit/components/extensions/ExtensionCommon.jsm +++ b/toolkit/components/extensions/ExtensionCommon.jsm @@ -1929,7 +1929,7 @@ LocaleData.prototype = { get uiLocale() { - return Services.locale.getAppLocaleAsBCP47(); + return Services.locale.appLocaleAsBCP47; }, }; diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js b/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js index cb57448f9c26..f54ae7ca9af4 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js @@ -11,11 +11,11 @@ server.registerDirectory("/data/", do_get_file("data")); const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`; -var originalReqLocales = Services.locale.getRequestedLocales(); +var originalReqLocales = Services.locale.requestedLocales; registerCleanupFunction(() => { Preferences.reset("intl.accept_languages"); - Services.locale.setRequestedLocales(originalReqLocales); + Services.locale.requestedLocales = originalReqLocales; }); @@ -221,12 +221,12 @@ add_task(async function test_i18n_negotiation() { // // In the future, we should provide some way for tests to decouple their // language selection from that of Firefox. - Services.locale.setAvailableLocales(["en-US", "fr", "jp"]); + Services.locale.availableLocales = ["en-US", "fr", "jp"]; let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`); for (let [lang, msg] of [["en-US", "English."], ["jp", "\u65e5\u672c\u8a9e"]]) { - Services.locale.setRequestedLocales([lang]); + Services.locale.requestedLocales = [lang]; let extension = ExtensionTestUtils.loadExtension(extensionData); await extension.startup(); @@ -238,7 +238,7 @@ add_task(async function test_i18n_negotiation() { await extension.unload(); } - Services.locale.setRequestedLocales(originalReqLocales); + Services.locale.requestedLocales = originalReqLocales; await contentPage.close(); }); @@ -383,7 +383,7 @@ add_task(async function test_get_ui_language() { // We don't currently have a good way to mock this. if (false) { - Services.locale.setRequestedLocales(["he"]); + Services.locale.requestedLocales = ["he"]; extension.sendMessage(["expect-results", "he"]); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js b/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js index e0a383c8d8aa..0239e6e5266d 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n_css.js @@ -129,14 +129,14 @@ async function test_i18n_css(options = {}) { // We don't wind up actually switching the chrome registry locale, since we // don't have a chrome package for Hebrew. So just override it, and force // RTL directionality. - const origReqLocales = Services.locale.getRequestedLocales(); - Services.locale.setRequestedLocales(["he"]); + const origReqLocales = Services.locale.requestedLocales; + Services.locale.requestedLocales = ["he"]; Preferences.set(DIR, 1); css = await fetch(baseURL + "locale.css"); equal(css, '* { content: "he rtl ltr right left" }', "CSS file localized in mochitest scope"); - Services.locale.setRequestedLocales(origReqLocales); + Services.locale.requestedLocales = origReqLocales; Preferences.reset(DIR); } diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_startup_cache.js b/toolkit/components/extensions/test/xpcshell/test_ext_startup_cache.js index 3693223120d0..a5679e32d4be 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_startup_cache.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_startup_cache.js @@ -69,7 +69,7 @@ add_task(async function() { // // In the future, we should provide some way for tests to decouple their // language selection from that of Firefox. - Services.locale.setAvailableLocales(["en-US", "fr", "jp"]); + Services.locale.availableLocales = ["en-US", "fr", "jp"]; await extension.startup(); @@ -88,7 +88,7 @@ add_task(async function() { info("Change locale to 'fr' and restart"); - Services.locale.setRequestedLocales(["fr"]); + Services.locale.requestedLocales = ["fr"]; await AddonTestUtils.promiseRestartManager(); await extension.awaitStartup(); @@ -106,7 +106,7 @@ add_task(async function() { info("Change locale to 'en-US' and restart"); - Services.locale.setRequestedLocales(["en-US"]); + Services.locale.requestedLocales = ["en-US"]; await AddonTestUtils.promiseRestartManager(); await extension.awaitStartup(); diff --git a/toolkit/components/mozintl/mozIntl.js b/toolkit/components/mozintl/mozIntl.js index b6d9304635cb..eca985fcdb3e 100644 --- a/toolkit/components/mozintl/mozIntl.js +++ b/toolkit/components/mozintl/mozIntl.js @@ -22,7 +22,7 @@ const languageTagMatch = /^([a-z]{2,3}|[a-z]{4}|[a-z]{5,8})(?:[-_]([a-z]{4}))?(? */ function getLocales(locales) { if (!locales) { - return Services.locale.getRegionalPrefsLocales(); + return Services.locale.regionalPrefsLocales; } return locales; } diff --git a/toolkit/components/normandy/lib/NormandyDriver.jsm b/toolkit/components/normandy/lib/NormandyDriver.jsm index f6281db75d78..2755f439288f 100644 --- a/toolkit/components/normandy/lib/NormandyDriver.jsm +++ b/toolkit/components/normandy/lib/NormandyDriver.jsm @@ -37,7 +37,7 @@ var NormandyDriver = function(sandboxManager) { get locale() { if (Services.locale.getAppLocaleAsLangTag) { - return Services.locale.getAppLocaleAsLangTag(); + return Services.locale.getAppLocaleAsLangTag; } return Cc["@mozilla.org/chrome/chrome-registry;1"] diff --git a/toolkit/components/reputationservice/test/unit/test_app_rep_maclinux.js b/toolkit/components/reputationservice/test/unit/test_app_rep_maclinux.js index 4735450fd9eb..0f437bf11232 100644 --- a/toolkit/components/reputationservice/test/unit/test_app_rep_maclinux.js +++ b/toolkit/components/reputationservice/test/unit/test_app_rep_maclinux.js @@ -74,14 +74,14 @@ add_task(function test_setup() { Services.prefs.setCharPref("urlclassifier.downloadBlockTable", "goog-badbinurl-shavar"); // SendRemoteQueryInternal needs locale preference. - let originalReqLocales = Services.locale.getRequestedLocales(); - Services.locale.setRequestedLocales(["en-US"]); + let originalReqLocales = Services.locale.requestedLocales; + Services.locale.requestedLocales = ["en-US"]; registerCleanupFunction(function() { Services.prefs.clearUserPref("browser.safebrowsing.malware.enabled"); Services.prefs.clearUserPref("browser.safebrowsing.downloads.enabled"); Services.prefs.clearUserPref("urlclassifier.downloadBlockTable"); - Services.locale.setRequestedLocales(originalReqLocales); + Services.locale.requestedLocales = originalReqLocales; }); gHttpServer = new HttpServer(); diff --git a/toolkit/components/reputationservice/test/unit/test_app_rep_windows.js b/toolkit/components/reputationservice/test/unit/test_app_rep_windows.js index 06eb5bd7534d..5b635f400de7 100644 --- a/toolkit/components/reputationservice/test/unit/test_app_rep_windows.js +++ b/toolkit/components/reputationservice/test/unit/test_app_rep_windows.js @@ -163,15 +163,15 @@ add_task(async function test_setup() { Services.prefs.setCharPref("urlclassifier.downloadAllowTable", "goog-downloadwhite-digest256"); // SendRemoteQueryInternal needs locale preference. - let originalReqLocales = Services.locale.getRequestedLocales(); - Services.locale.setRequestedLocales(["en-US"]); + let originalReqLocales = Services.locale.requestedLocales; + Services.locale.requestedLocales = ["en-US"]; registerCleanupFunction(function() { Services.prefs.clearUserPref("browser.safebrowsing.malware.enabled"); Services.prefs.clearUserPref("browser.safebrowsing.downloads.enabled"); Services.prefs.clearUserPref("urlclassifier.downloadBlockTable"); Services.prefs.clearUserPref("urlclassifier.downloadAllowTable"); - Services.locale.setRequestedLocales(originalReqLocales); + Services.locale.requestedLocales = originalReqLocales; }); gHttpServer = new HttpServer(); diff --git a/toolkit/components/resistfingerprinting/LanguagePrompt.jsm b/toolkit/components/resistfingerprinting/LanguagePrompt.jsm index 90c4cab4a20d..0ca1b3976098 100644 --- a/toolkit/components/resistfingerprinting/LanguagePrompt.jsm +++ b/toolkit/components/resistfingerprinting/LanguagePrompt.jsm @@ -64,7 +64,7 @@ class _LanguagePrompt { } _shouldPromptForLanguagePref() { - return (Services.locale.getAppLocaleAsLangTag().substr(0, 2) !== "en") + return (Services.locale.appLocaleAsLangTag.substr(0, 2) !== "en") && (Services.prefs.getIntPref(kPrefSpoofEnglish) === 0); } diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index 875ba12ca801..bbf9db8d210f 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -800,7 +800,7 @@ function getDir(aKey, aIFace) { * exists in nsHttpHandler.cpp when building the UA string. */ function getLocale() { - return Services.locale.getRequestedLocale(); + return Services.locale.requestedLocale; } /** @@ -3441,7 +3441,7 @@ SearchService.prototype = { } let searchSettings; - let locale = Services.locale.getAppLocaleAsBCP47(); + let locale = Services.locale.appLocaleAsBCP47; if ("locales" in json && locale in json.locales) { searchSettings = json.locales[locale]; diff --git a/toolkit/components/search/tests/xpcshell/head_search.js b/toolkit/components/search/tests/xpcshell/head_search.js index 35924dcf84a8..2bc3f7897a20 100644 --- a/toolkit/components/search/tests/xpcshell/head_search.js +++ b/toolkit/components/search/tests/xpcshell/head_search.js @@ -234,7 +234,7 @@ function getDefaultEngineName(isUS) { let defaultEngineName = searchSettings.default.searchDefault; if (isUS === undefined) - isUS = Services.locale.getRequestedLocale() == "en-US" && isUSTimezone(); + isUS = Services.locale.requestedLocale == "en-US" && isUSTimezone(); if (isUS && ("US" in searchSettings && "searchDefault" in searchSettings.US)) { @@ -253,7 +253,7 @@ function getDefaultEngineList(isUS) { let visibleDefaultEngines = json.default.visibleDefaultEngines; if (isUS === undefined) - isUS = Services.locale.getRequestedLocale() == "en-US" && isUSTimezone(); + isUS = Services.locale.requestedLocale == "en-US" && isUSTimezone(); if (isUS) { let searchSettings = json.locales["en-US"]; diff --git a/toolkit/components/search/tests/xpcshell/test_list_json_locale.js b/toolkit/components/search/tests/xpcshell/test_list_json_locale.js index b50c63ff85f6..a8ae19766045 100644 --- a/toolkit/components/search/tests/xpcshell/test_list_json_locale.js +++ b/toolkit/components/search/tests/xpcshell/test_list_json_locale.js @@ -19,8 +19,8 @@ add_task(async function test_listJSONlocale() { .QueryInterface(Ci.nsIResProtocolHandler); resProt.setSubstitution("search-plugins", Services.io.newURI(url)); - Services.locale.setAvailableLocales(["de"]); - Services.locale.setRequestedLocales(["de"]); + Services.locale.availableLocales = ["de"]; + Services.locale.requestedLocales = ["de"]; await asyncInit(); @@ -35,8 +35,8 @@ add_task(async function test_listJSONlocale() { add_task(async function test_listJSONlocaleSwitch() { let promise = waitForSearchNotification("reinit-complete"); - Services.locale.setAvailableLocales(["fr"]); - Services.locale.setRequestedLocales(["fr"]); + Services.locale.availableLocales = ["fr"]; + Services.locale.requestedLocales = ["fr"]; await promise; diff --git a/toolkit/components/search/tests/xpcshell/test_paramSubstitution.js b/toolkit/components/search/tests/xpcshell/test_paramSubstitution.js index fb04ee645021..eef899be6774 100644 --- a/toolkit/components/search/tests/xpcshell/test_paramSubstitution.js +++ b/toolkit/components/search/tests/xpcshell/test_paramSubstitution.js @@ -34,8 +34,8 @@ add_task(async function test_paramSubstitution() { check("{unknownOptional?}", ""); check("{unknownRequired}", "{unknownRequired}"); - check("{language}", Services.locale.getRequestedLocale()); - check("{language?}", Services.locale.getRequestedLocale()); + check("{language}", Services.locale.requestedLocale); + check("{language?}", Services.locale.requestedLocale); engine.wrappedJSObject._queryCharset = "UTF-8"; check("{inputEncoding}", "UTF-8"); @@ -63,5 +63,5 @@ add_task(async function test_paramSubstitution() { check("{moz:official}", "official"); Services.prefs.setBoolPref("browser.search.official", false); check("{moz:official}", "unofficial"); - check("{moz:locale}", Services.locale.getRequestedLocale()); + check("{moz:locale}", Services.locale.requestedLocale); }); diff --git a/toolkit/components/telemetry/app/TelemetryEnvironment.jsm b/toolkit/components/telemetry/app/TelemetryEnvironment.jsm index 205c3806eff1..12ac7a57cb9f 100644 --- a/toolkit/components/telemetry/app/TelemetryEnvironment.jsm +++ b/toolkit/components/telemetry/app/TelemetryEnvironment.jsm @@ -298,7 +298,7 @@ function enforceBoolean(aValue) { */ function getBrowserLocale() { try { - return Services.locale.getAppLocaleAsLangTag(); + return Services.locale.appLocaleAsLangTag; } catch (e) { return null; } diff --git a/toolkit/components/urlformatter/nsURLFormatter.js b/toolkit/components/urlformatter/nsURLFormatter.js index 9ea51ae52b44..315dddaec592 100644 --- a/toolkit/components/urlformatter/nsURLFormatter.js +++ b/toolkit/components/urlformatter/nsURLFormatter.js @@ -60,7 +60,7 @@ nsURLFormatterService.prototype = { QueryInterface: ChromeUtils.generateQI([Ci.nsIURLFormatter]), _defaults: { - LOCALE: () => Services.locale.getAppLocaleAsLangTag(), + LOCALE: () => Services.locale.appLocaleAsLangTag, REGION() { try { // When the geoip lookup failed to identify the region, we fallback to diff --git a/toolkit/components/urlformatter/tests/unit/test_urlformatter.js b/toolkit/components/urlformatter/tests/unit/test_urlformatter.js index 23c7a7946d0e..64e35e4027f1 100644 --- a/toolkit/components/urlformatter/tests/unit/test_urlformatter.js +++ b/toolkit/components/urlformatter/tests/unit/test_urlformatter.js @@ -6,7 +6,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm"); function run_test() { var formatter = Services.urlFormatter; - var locale = Services.locale.getAppLocaleAsLangTag(); + var locale = Services.locale.appLocaleAsLangTag; var OSVersion = Services.sysinfo.getProperty("name") + " " + Services.sysinfo.getProperty("version"); try { diff --git a/toolkit/components/utils/ClientEnvironment.jsm b/toolkit/components/utils/ClientEnvironment.jsm index 33ecc712c2e7..39aa7d02589f 100644 --- a/toolkit/components/utils/ClientEnvironment.jsm +++ b/toolkit/components/utils/ClientEnvironment.jsm @@ -118,7 +118,7 @@ class ClientEnvironmentBase { } static get locale() { - return Services.locale.getAppLocaleAsLangTag(); + return Services.locale.appLocaleAsLangTag; } static get doNotTrack() { diff --git a/toolkit/content/widgets/datetimepopup.xml b/toolkit/content/widgets/datetimepopup.xml index 65090c819779..2fbb85554b5b 100644 --- a/toolkit/content/widgets/datetimepopup.xml +++ b/toolkit/content/widgets/datetimepopup.xml @@ -110,7 +110,7 @@ loc.locales)); - let requestedLocales = Services.locale.getRequestedLocales(); + let requestedLocales = Services.locale.requestedLocales; /** * If en-US is not in the list, add it as the last fallback. diff --git a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js index 64d667b9b260..5509409a338a 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js +++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js @@ -510,7 +510,7 @@ function isNightlyChannel() { async function restartWithLocales(locales) { - Services.locale.setRequestedLocales(locales); + Services.locale.requestedLocales = locales; await promiseRestartManager(); } diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_url_parameters.js b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_url_parameters.js index 7948043ac522..dc4f0bfd0aec 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_url_parameters.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_url_parameters.js @@ -84,7 +84,7 @@ add_task(async function test_blocklist_disabled() { defaults.setCharPref(PREF_APP_UPDATE_CHANNEL, EXPECTED.channel); defaults.setCharPref(PREF_APP_DISTRIBUTION, EXPECTED.distribution); defaults.setCharPref(PREF_APP_DISTRIBUTION_VERSION, EXPECTED.distribution_version); - Services.locale.setRequestedLocales([EXPECTED.locale]); + Services.locale.requestedLocales = [EXPECTED.locale]; // This should correctly escape everything Services.prefs.setCharPref(PREF_BLOCKLIST_URL, "http://example.com/2?" + PARAMS); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_manifest_locales.js b/toolkit/mozapps/extensions/test/xpcshell/test_manifest_locales.js index e6a81edce278..8c366eda17a0 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_manifest_locales.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_manifest_locales.js @@ -62,7 +62,7 @@ const ADDON = { add_task(async function setup() { createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1"); - Services.locale.setRequestedLocales(["fr-FR"]); + Services.locale.requestedLocales = ["fr-FR"]; await promiseStartupManager(); await promiseInstallXPI(ADDON); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_update.js b/toolkit/mozapps/extensions/test/xpcshell/test_update.js index 6d07765a10ef..15c76664c69c 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_update.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update.js @@ -77,7 +77,7 @@ for (let [name, addon] of Object.entries(ADDONS)) { add_task(async function setup() { createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); - Services.locale.setRequestedLocales(["fr-FR"]); + Services.locale.requestedLocales = ["fr-FR"]; }); add_task(async function() { diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_langpack.js b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_langpack.js index 4fd843498cc9..000eb2f85468 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_langpack.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_langpack.js @@ -73,7 +73,7 @@ add_task(async function() { // Make sure that `und` locale is not installed. equal(L10nRegistry.getAvailableLocales().includes("und"), false); - equal(Services.locale.getAvailableLocales().includes("und"), false); + equal(Services.locale.availableLocales.includes("und"), false); let [, {addon}] = await Promise.all([ promiseLangpackStartup(), @@ -82,13 +82,13 @@ add_task(async function() { // Now make sure that `und` locale is available. equal(L10nRegistry.getAvailableLocales().includes("und"), true); - equal(Services.locale.getAvailableLocales().includes("und"), true); + equal(Services.locale.availableLocales.includes("und"), true); await addon.disable(); // It is not available after the langpack has been disabled. equal(L10nRegistry.getAvailableLocales().includes("und"), false); - equal(Services.locale.getAvailableLocales().includes("und"), false); + equal(Services.locale.availableLocales.includes("und"), false); // This quirky code here allows us to handle a scenario where enabling the // addon is synchronous or asynchronous. @@ -99,13 +99,13 @@ add_task(async function() { // After re-enabling it, the `und` locale is available again. equal(L10nRegistry.getAvailableLocales().includes("und"), true); - equal(Services.locale.getAvailableLocales().includes("und"), true); + equal(Services.locale.availableLocales.includes("und"), true); await addon.uninstall(); // After the langpack has been uninstalled, no more `und` in locales. equal(L10nRegistry.getAvailableLocales().includes("und"), false); - equal(Services.locale.getAvailableLocales().includes("und"), false); + equal(Services.locale.availableLocales.includes("und"), false); }); /** @@ -134,8 +134,8 @@ add_task(async function() { { // Test chrome package - let reqLocs = Services.locale.getRequestedLocales(); - Services.locale.setRequestedLocales(["und"]); + let reqLocs = Services.locale.requestedLocales; + Services.locale.requestedLocales = ["und"]; let bundle = Services.strings.createBundle( "chrome://global/locale/test.properties" @@ -143,7 +143,7 @@ add_task(async function() { let entry = bundle.GetStringFromName("message"); equal(entry, "Value from .properties"); - Services.locale.setRequestedLocales(reqLocs); + Services.locale.requestedLocales = reqLocs; } await addon.uninstall(); @@ -153,7 +153,7 @@ add_task(async function() { add_task(async function test_amazing_disappearing_langpacks() { let check = (yes) => { equal(L10nRegistry.getAvailableLocales().includes("und"), yes); - equal(Services.locale.getAvailableLocales().includes("und"), yes); + equal(Services.locale.availableLocales.includes("und"), yes); }; await promiseStartupManager(); diff --git a/uriloader/exthandler/HandlerService.js b/uriloader/exthandler/HandlerService.js index aea2abfed2aa..1bc1151ca3d6 100644 --- a/uriloader/exthandler/HandlerService.js +++ b/uriloader/exthandler/HandlerService.js @@ -88,7 +88,7 @@ HandlerService.prototype = { try { prefsDefaultHandlersVersion = Number(prefsDefaultHandlersVersion.data); - let locale = Services.locale.getAppLocaleAsLangTag(); + let locale = Services.locale.appLocaleAsLangTag; let defaultHandlersVersion = this._store.data.defaultHandlersVersion[locale] || 0; From 8d1b27c4a26c5ec68d732f1f42da004a251db498 Mon Sep 17 00:00:00 2001 From: Bryce Van Dyk Date: Fri, 21 Sep 2018 15:58:13 +0000 Subject: [PATCH 03/18] Bug 1492915 - Stop WebMDemuxer from inspecting partially encrypted packets for keyframe information. r=jya Differential Revision: https://phabricator.services.mozilla.com/D6415 --HG-- extra : moz-landing-system : lando --- dom/media/webm/WebMDemuxer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dom/media/webm/WebMDemuxer.cpp b/dom/media/webm/WebMDemuxer.cpp index 2e14af8515e7..71c33829fa7b 100644 --- a/dom/media/webm/WebMDemuxer.cpp +++ b/dom/media/webm/WebMDemuxer.cpp @@ -672,11 +672,16 @@ WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType, if (aType == TrackInfo::kAudioTrack) { isKeyframe = true; } else if (aType == TrackInfo::kVideoTrack) { - if (packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_ENCRYPTED) { + if (packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_ENCRYPTED || + packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_PARTITIONED) { // Packet is encrypted, can't peek, use packet info isKeyframe = nestegg_packet_has_keyframe(holder->Packet()) == NESTEGG_PACKET_HAS_KEYFRAME_TRUE; } else { + MOZ_ASSERT(packetEncryption == + NESTEGG_PACKET_HAS_SIGNAL_BYTE_UNENCRYPTED || + packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_FALSE, + "Unencrypted packet expected"); auto sample = MakeSpan(data, length); auto alphaSample = MakeSpan(alphaData, alphaLength); From 846bdbd5712fd1fd3a6f5da28883d97cb87fa41f Mon Sep 17 00:00:00 2001 From: "Byron Campen [:bwc]" Date: Fri, 21 Sep 2018 15:48:52 +0000 Subject: [PATCH 04/18] Bug 1493146: Lengthen ice-pwd r=mjf Differential Revision: https://phabricator.services.mozilla.com/D6490 --HG-- extra : moz-landing-system : lando --- .../signaling/src/jsep/JsepSessionImpl.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp index 8d3453736ff8..ec220696fa5e 100644 --- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp +++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp @@ -55,18 +55,21 @@ static std::bitset<128> GetForbiddenSdpPayloadTypes() { return forbidden; } -static std::string GetRandomHex() +static std::string GetRandomHex(size_t words) { - uint32_t rand; - SECStatus rv = - PK11_GenerateRandom(reinterpret_cast(&rand), sizeof(rand)); - if (rv != SECSuccess) { - MOZ_CRASH(); - return ""; - } - std::ostringstream os; - os << std::hex << std::setfill('0') << std::setw(8) << rand; + + for (size_t i = 0; i < words; ++i) { + uint32_t rand; + SECStatus rv = + PK11_GenerateRandom(reinterpret_cast(&rand), sizeof(rand)); + if (rv != SECSuccess) { + MOZ_CRASH(); + return ""; + } + + os << std::hex << std::setfill('0') << std::setw(8) << rand; + } return os.str(); } @@ -88,8 +91,8 @@ JsepSessionImpl::Init() mRunSdpComparer = Preferences::GetBool("media.peerconnection.sdp.rust.compare", false); - mIceUfrag = GetRandomHex(); - mIcePwd = GetRandomHex(); + mIceUfrag = GetRandomHex(1); + mIcePwd = GetRandomHex(4); return NS_OK; } @@ -2390,8 +2393,8 @@ JsepSessionImpl::SetIceRestarting(bool restarting) mOldIceUfrag = mIceUfrag; mOldIcePwd = mIcePwd; } - mIceUfrag = GetRandomHex(); - mIcePwd = GetRandomHex(); + mIceUfrag = GetRandomHex(1); + mIcePwd = GetRandomHex(4); } else if (IsIceRestarting()) { // restarting -> not restarting, restore old ufrag/pwd mIceUfrag = mOldIceUfrag; From fb9c5e11eb299dabdf4d8a0f7eddc79d15a2b018 Mon Sep 17 00:00:00 2001 From: "arthur.iakab" Date: Fri, 21 Sep 2018 19:28:04 +0300 Subject: [PATCH 05/18] Backed out 2 changesets (bug 1489224) Backed out changeset d414a44d8119 (bug 1489224) Backed out changeset 6300cdbc0e04 (bug 1489224) --- .../src/components/sidebar/Sidebar.js | 2 +- .../test/browser/browser.ini | 3 +- ...aboutdebugging_sidebar_network_runtimes.js | 47 ------------------- 3 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js diff --git a/devtools/client/aboutdebugging-new/src/components/sidebar/Sidebar.js b/devtools/client/aboutdebugging-new/src/components/sidebar/Sidebar.js index 284afdf81c7d..e4f2ce472211 100644 --- a/devtools/client/aboutdebugging-new/src/components/sidebar/Sidebar.js +++ b/devtools/client/aboutdebugging-new/src/components/sidebar/Sidebar.js @@ -37,7 +37,7 @@ class Sidebar extends PureComponent { id: "about-debugging-sidebar-no-devices" }, dom.span( { - className: "sidebar__devices__no-devices-message js-sidebar-no-devices" + className: "sidebar__devices__no-devices-message" }, "No devices discovered" ) diff --git a/devtools/client/aboutdebugging-new/test/browser/browser.ini b/devtools/client/aboutdebugging-new/test/browser/browser.ini index e9b56a74808e..70a4fb1dd052 100644 --- a/devtools/client/aboutdebugging-new/test/browser/browser.ini +++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini @@ -7,8 +7,7 @@ support-files = !/devtools/client/shared/test/shared-head.js !/devtools/client/shared/test/telemetry-test-helpers.js -[browser_aboutdebugging_connect_networklocations.js] [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js] [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js] -[browser_aboutdebugging_sidebar_network_runtimes.js] [browser_aboutdebugging_thisfirefox.js] +[browser_aboutdebugging_connect_networklocations.js] diff --git a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js deleted file mode 100644 index 1d4860777536..000000000000 --- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js +++ /dev/null @@ -1,47 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const networkLocationsModule = - require("devtools/client/aboutdebugging-new/src/modules/network-locations.js"); - -/** - * Test the sidebar is updated correctly when network runtimes are added/removed. - */ - -add_task(async function() { - registerCleanupFunction(() => { - Services.prefs.clearUserPref("devtools.aboutdebugging.network-locations"); - }); - - const { document, tab } = await openAboutDebugging(); - - const noDevicesElement = document.querySelector(".js-sidebar-no-devices"); - ok(noDevicesElement, "Sidebar shows the 'no devices' element"); - - info("Add a network location"); - networkLocationsModule.addNetworkLocation("localhost:6080"); - - info("Wait for 'no devices' element to disappear"); - waitUntil(() => !document.querySelector(".js-sidebar-no-devices")); - ok(findSidebarItemByText("localhost:6080", document), - "Found a sidebar item for localhost:6080"); - - info("Remove the network location"); - networkLocationsModule.removeNetworkLocation("localhost:6080"); - - info("Wait for 'no devices' element to reappear"); - waitUntil(() => document.querySelector(".js-sidebar-no-devices")); - ok(!findSidebarItemByText("localhost:6080", document), - "Sidebar item for localhost:6080 removed"); - - await removeTab(tab); -}); - -function findSidebarItemByText(text, document) { - const sidebarItems = document.querySelectorAll(".js-sidebar-item"); - return [...sidebarItems].find(element => { - return element.textContent.includes(text); - }); -} From 9136559bb311758beb508a1a91f626ddaa09485b Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Fri, 21 Sep 2018 16:50:02 +0000 Subject: [PATCH 06/18] Bug 1493202: Don't store offline startup state in nsIToolkitProfileService. r=florian Differential Revision: https://phabricator.services.mozilla.com/D6503 --HG-- extra : moz-landing-system : lando --- toolkit/profile/content/profileSelection.js | 5 ++--- toolkit/profile/nsIToolkitProfileService.idl | 1 - toolkit/profile/nsToolkitProfileService.cpp | 18 +----------------- toolkit/xre/nsAppRunner.cpp | 7 +++++-- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/toolkit/profile/content/profileSelection.js b/toolkit/profile/content/profileSelection.js index 7a35ec2bb19d..452c757f9081 100644 --- a/toolkit/profile/content/profileSelection.js +++ b/toolkit/profile/content/profileSelection.js @@ -98,6 +98,8 @@ function acceptDialog() { updateStartupPrefs(); gDialogParams.SetInt(0, 1); + /* Bug 257777 */ + gDialogParams.SetInt(1, document.getElementById("offlineState").checked ? 1 : 0); gDialogParams.SetString(0, selectedProfile.profile.name); @@ -113,9 +115,6 @@ function exitDialog() { function updateStartupPrefs() { var autoSelectLastProfile = document.getElementById("autoSelectLastProfile"); gProfileService.startWithLastProfile = autoSelectLastProfile.checked; - - /* Bug 257777 */ - gProfileService.startOffline = document.getElementById("offlineState").checked; } // handle key event on listboxes diff --git a/toolkit/profile/nsIToolkitProfileService.idl b/toolkit/profile/nsIToolkitProfileService.idl index 68cb1f19ffef..69ba1f4827b6 100644 --- a/toolkit/profile/nsIToolkitProfileService.idl +++ b/toolkit/profile/nsIToolkitProfileService.idl @@ -14,7 +14,6 @@ interface nsIProfileLock; interface nsIToolkitProfileService : nsISupports { attribute boolean startWithLastProfile; - attribute boolean startOffline; readonly attribute nsISimpleEnumerator /*nsIToolkitProfile*/ profiles; diff --git a/toolkit/profile/nsToolkitProfileService.cpp b/toolkit/profile/nsToolkitProfileService.cpp index 16de4dbea5d9..463b24048ab8 100644 --- a/toolkit/profile/nsToolkitProfileService.cpp +++ b/toolkit/profile/nsToolkitProfileService.cpp @@ -119,8 +119,7 @@ private: friend nsresult NS_NewToolkitProfileService(nsIToolkitProfileService**); nsToolkitProfileService() : - mStartWithLast(true), - mStartOffline(false) + mStartWithLast(true) { gService = this; } @@ -140,7 +139,6 @@ private: nsCOMPtr mTempData; nsCOMPtr mListFile; bool mStartWithLast; - bool mStartOffline; static nsToolkitProfileService *gService; @@ -573,20 +571,6 @@ nsToolkitProfileService::GetStartWithLastProfile(bool *aResult) return NS_OK; } -NS_IMETHODIMP -nsToolkitProfileService::GetStartOffline(bool *aResult) -{ - *aResult = mStartOffline; - return NS_OK; -} - -NS_IMETHODIMP -nsToolkitProfileService::SetStartOffline(bool aValue) -{ - mStartOffline = aValue; - return NS_OK; -} - NS_IMETHODIMP nsToolkitProfileService::GetProfiles(nsISimpleEnumerator* *aResult) { diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index a444b0753a9d..e0c5137db711 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -2119,6 +2119,7 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc, nsCOMPtr profD, profLD; char16_t* profileNamePtr; nsAutoCString profileName; + bool offline = false; { ScopedXPCOMStartup xpcom; @@ -2172,6 +2173,10 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc, rv = ioParamBlock->GetInt(0, &dialogConfirmed); if (NS_FAILED(rv) || dialogConfirmed == 0) return NS_ERROR_ABORT; + int32_t startOffline; + rv = ioParamBlock->GetInt(1, &startOffline); + offline = NS_SUCCEEDED(rv) && startOffline == 1; + nsCOMPtr lock; rv = dlgArray->QueryElementAt(0, NS_GET_IID(nsIProfileLock), getter_AddRefs(lock)); @@ -2197,8 +2202,6 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc, SaveFileToEnv("XRE_PROFILE_LOCAL_PATH", profLD); SaveWordToEnv("XRE_PROFILE_NAME", profileName); - bool offline = false; - aProfileSvc->GetStartOffline(&offline); if (offline) { SaveToEnv("XRE_START_OFFLINE=1"); } From 8dccd09804e2c37059ff3ab4ee324a85b84b7eea Mon Sep 17 00:00:00 2001 From: Julien Wajsberg Date: Fri, 21 Sep 2018 15:57:05 +0000 Subject: [PATCH 07/18] Bug 1492893 - [Devtools Performance-new] Remove the unused toolbox object from the redux store r=gregtatum MozReview-Commit-ID: 1LJ6HypOYbM Differential Revision: https://phabricator.services.mozilla.com/D6469 --HG-- extra : moz-landing-system : lando --- .../performance-new/components/Description.js | 14 ++------------ devtools/client/performance-new/initializer.js | 5 ++--- devtools/client/performance-new/panel.js | 2 +- devtools/client/performance-new/store/reducers.js | 1 - devtools/client/performance-new/store/selectors.js | 2 -- .../client/performance-new/test/chrome/head.js | 2 -- 6 files changed, 5 insertions(+), 21 deletions(-) diff --git a/devtools/client/performance-new/components/Description.js b/devtools/client/performance-new/components/Description.js index 8741898938da..a020297f5d81 100644 --- a/devtools/client/performance-new/components/Description.js +++ b/devtools/client/performance-new/components/Description.js @@ -6,9 +6,6 @@ const { PureComponent } = require("devtools/client/shared/vendor/react"); const { div, button, p } = require("devtools/client/shared/vendor/react-dom-factories"); const { openDocLink } = require("devtools/client/shared/link"); -const PropTypes = require("devtools/client/shared/vendor/react-prop-types"); -const { connect } = require("devtools/client/shared/vendor/react-redux"); -const selectors = require("devtools/client/performance-new/store/selectors"); /** * This component provides a helpful description for what is going on in the component @@ -16,10 +13,7 @@ const selectors = require("devtools/client/performance-new/store/selectors"); */ class Description extends PureComponent { static get propTypes() { - return { - // StateProps: - toolbox: PropTypes.object.isRequired - }; + return {}; } constructor(props) { @@ -71,8 +65,4 @@ class Description extends PureComponent { } } -const mapStateToProps = state => ({ - toolbox: selectors.getToolbox(state) -}); - -module.exports = connect(mapStateToProps)(Description); +module.exports = Description; diff --git a/devtools/client/performance-new/initializer.js b/devtools/client/performance-new/initializer.js index 861951903c80..82667b98ebad 100644 --- a/devtools/client/performance-new/initializer.js +++ b/devtools/client/performance-new/initializer.js @@ -28,16 +28,15 @@ const { /** * Initialize the panel by creating a redux store, and render the root component. * - * @param toolbox - The toolbox * @param perfFront - The Perf actor's front. Used to start and stop recordings. + * @param preferenceFront - Used to get the recording preferences from the device. */ -async function gInit(toolbox, perfFront, preferenceFront) { +async function gInit(perfFront, preferenceFront) { const store = createStore(reducers); // Do some initialization, especially with privileged things that are part of the // the browser. store.dispatch(actions.initializeStore({ - toolbox, perfFront, receiveProfile, // Pull the default recording settings from the reducer, and update them according diff --git a/devtools/client/performance-new/panel.js b/devtools/client/performance-new/panel.js index 5e1dfc3cf803..501972893ea5 100644 --- a/devtools/client/performance-new/panel.js +++ b/devtools/client/performance-new/panel.js @@ -35,7 +35,7 @@ class PerformancePanel { this.isReady = true; this.emit("ready"); - this.panelWin.gInit(this.toolbox, perfFront, preferenceFront); + this.panelWin.gInit(perfFront, preferenceFront); return this; } diff --git a/devtools/client/performance-new/store/reducers.js b/devtools/client/performance-new/store/reducers.js index 626c66d9301c..dfb6e5e09453 100644 --- a/devtools/client/performance-new/store/reducers.js +++ b/devtools/client/performance-new/store/reducers.js @@ -129,7 +129,6 @@ function initializedValues(state = null, action) { switch (action.type) { case "INITIALIZE_STORE": return { - toolbox: action.toolbox, perfFront: action.perfFront, receiveProfile: action.receiveProfile, setRecordingPreferences: action.setRecordingPreferences diff --git a/devtools/client/performance-new/store/selectors.js b/devtools/client/performance-new/store/selectors.js index 51385bf5031d..2400addcd9df 100644 --- a/devtools/client/performance-new/store/selectors.js +++ b/devtools/client/performance-new/store/selectors.js @@ -30,7 +30,6 @@ const getInitializedValues = state => { }; const getPerfFront = state => getInitializedValues(state).perfFront; -const getToolbox = state => getInitializedValues(state).toolbox; const getReceiveProfileFn = state => getInitializedValues(state).receiveProfile; const getSetRecordingPreferencesFn = state => getInitializedValues(state).setRecordingPreferences; @@ -47,7 +46,6 @@ module.exports = { getRecordingSettings, getInitializedValues, getPerfFront, - getToolbox, getReceiveProfileFn, getSetRecordingPreferencesFn }; diff --git a/devtools/client/performance-new/test/chrome/head.js b/devtools/client/performance-new/test/chrome/head.js index 410edc8f33aa..f18d34253cfe 100644 --- a/devtools/client/performance-new/test/chrome/head.js +++ b/devtools/client/performance-new/test/chrome/head.js @@ -169,7 +169,6 @@ function createPerfComponent() { const selectors = require("devtools/client/performance-new/store/selectors"); const perfFrontMock = new MockPerfFront(); - const toolboxMock = {}; const store = createStore(reducers); const container = document.querySelector("#container"); const receiveProfileCalls = []; @@ -185,7 +184,6 @@ function createPerfComponent() { function mountComponent() { store.dispatch(actions.initializeStore({ - toolbox: toolboxMock, perfFront: perfFrontMock, receiveProfile: receiveProfileMock, recordingSettingsFromPreferences: selectors.getRecordingSettings(store.getState()), From b87616547538bf840e673094f79146fc6e8fbea6 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Wed, 19 Sep 2018 20:20:15 +0000 Subject: [PATCH 08/18] Bug 1476995 - Use device-width as the fallback for unrecognized width values in a meta viewport tag. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D6189 --HG-- extra : moz-landing-system : lando --- dom/base/nsDocument.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 225c57fbd79d..3ce48b80a74c 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -7301,6 +7301,12 @@ nsIDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize) mValidWidth = (!widthStr.IsEmpty() && NS_SUCCEEDED(widthErrorCode) && mViewportSize.width > 0); mValidHeight = (!heightStr.IsEmpty() && NS_SUCCEEDED(heightErrorCode) && mViewportSize.height > 0); + // If the width is set to some unrecognized value, and there is no + // height set, treat it as if device-width were specified. + if ((!mValidWidth && !widthStr.IsEmpty()) && !mValidHeight) { + mAutoSize = true; + } + mAllowZoom = true; nsAutoString userScalable; GetHeaderData(nsGkAtoms::viewport_user_scalable, userScalable); From 071957050789d39e38ef8f87fafe7986e1c04149 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Fri, 21 Sep 2018 17:18:52 +0000 Subject: [PATCH 09/18] Bug 1457603 - Downgrade the diagnostic assert in InputBlockState::SetConfirmedTargetApzc() to a regular assert. r=kats As explained in the bug, it has been difficult ot find reliable STR for the diagnostic assert, and it has been impacting the stability and usability of Nightly builds. Differential Revision: https://phabricator.services.mozilla.com/D6518 --HG-- extra : moz-landing-system : lando --- gfx/layers/apz/src/InputBlockState.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gfx/layers/apz/src/InputBlockState.cpp b/gfx/layers/apz/src/InputBlockState.cpp index d7470e7263cc..294748b95dbc 100644 --- a/gfx/layers/apz/src/InputBlockState.cpp +++ b/gfx/layers/apz/src/InputBlockState.cpp @@ -57,8 +57,8 @@ InputBlockState::SetConfirmedTargetApzc(const RefPtr& aT // a different target than the main thread. If this happens for a drag // block created for a scrollbar drag, the consequences can be fairly // user-unfriendly, such as the scrollbar not being draggable at all, - // or it scrolling the contents of the wrong scrollframe. In Nightly - // builds, we issue a diagnostic assert in this situation, so that the + // or it scrolling the contents of the wrong scrollframe. In debug + // builds, we assert in this situation, so that the // underlying compositor hit testing bug can be fixed. In release builds, // however, we just silently accept the main thread's confirmed target, // which will produce the expected behaviour (apart from drag events @@ -68,9 +68,7 @@ InputBlockState::SetConfirmedTargetApzc(const RefPtr& aT aState == TargetConfirmationState::eConfirmed && mTargetApzc && aTargetApzc && mTargetApzc->GetGuid() != aTargetApzc->GetGuid()) { -#ifdef NIGHTLY_BUILD - MOZ_RELEASE_ASSERT(false, "APZ and main thread confirmed scrollbar drag block with different targets"); -#endif + MOZ_ASSERT(false, "APZ and main thread confirmed scrollbar drag block with different targets"); UpdateTargetApzc(aTargetApzc); return true; } From 1fdd6d2defa4ff2a61d271ecece4469c0adfb39a Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Fri, 21 Sep 2018 17:45:49 +0000 Subject: [PATCH 10/18] Bug 1493043 - Change function arguments in RestyleManager from nsIFrame& to nsIFrame* r=emilio Differential Revision: https://phabricator.services.mozilla.com/D6452 --HG-- extra : moz-landing-system : lando --- layout/base/RestyleManager.cpp | 36 +++++++++++++++++----------------- layout/base/RestyleManager.h | 4 ++-- layout/generic/nsFrame.cpp | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 9203d01e0fc4..3692e7a4b94b 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -1921,9 +1921,9 @@ RestyleManager::AnimationsWithDestroyedFrame #ifdef DEBUG static bool -IsAnonBox(const nsIFrame& aFrame) +IsAnonBox(const nsIFrame* aFrame) { - return aFrame.Style()->IsAnonBox(); + return aFrame->Style()->IsAnonBox(); } static const nsIFrame* @@ -1937,15 +1937,15 @@ FirstContinuationOrPartOfIBSplit(const nsIFrame* aFrame) } static const nsIFrame* -ExpectedOwnerForChild(const nsIFrame& aFrame) +ExpectedOwnerForChild(const nsIFrame* aFrame) { - const nsIFrame* parent = aFrame.GetParent(); - if (aFrame.IsTableFrame()) { + const nsIFrame* parent = aFrame->GetParent(); + if (aFrame->IsTableFrame()) { MOZ_ASSERT(parent->IsTableWrapperFrame()); parent = parent->GetParent(); } - if (IsAnonBox(aFrame) && !aFrame.IsTextFrame()) { + if (IsAnonBox(aFrame) && !aFrame->IsTextFrame()) { if (parent->IsLineFrame()) { parent = parent->GetParent(); } @@ -1953,11 +1953,11 @@ ExpectedOwnerForChild(const nsIFrame& aFrame) nullptr : FirstContinuationOrPartOfIBSplit(parent); } - if (aFrame.IsBulletFrame()) { + if (aFrame->IsBulletFrame()) { return FirstContinuationOrPartOfIBSplit(parent); } - if (aFrame.IsLineFrame()) { + if (aFrame->IsLineFrame()) { // A ::first-line always ends up here via its block, which is therefore the // right expected owner. That block can be an // anonymous box. For example, we could have a ::first-line on a columnated @@ -1967,7 +1967,7 @@ ExpectedOwnerForChild(const nsIFrame& aFrame) return parent; } - if (aFrame.IsLetterFrame()) { + if (aFrame->IsLetterFrame()) { // Ditto for ::first-letter. A first-letter always arrives here via its // direct parent, except when it's parented to a ::first-line. if (parent->IsLineFrame()) { @@ -1987,13 +1987,13 @@ ExpectedOwnerForChild(const nsIFrame& aFrame) // We've handled already anon boxes and bullet frames, so now we're looking at // a frame of a DOM element or pseudo. Hop through anon and line-boxes // generated by our DOM parent, and go find the owner frame for it. - while (parent && (IsAnonBox(*parent) || parent->IsLineFrame())) { + while (parent && (IsAnonBox(parent) || parent->IsLineFrame())) { auto* pseudo = parent->Style()->GetPseudo(); if (pseudo == nsCSSAnonBoxes::tableWrapper()) { const nsIFrame* tableFrame = parent->PrincipalChildList().FirstChild(); MOZ_ASSERT(tableFrame->IsTableFrame()); // Handle :-moz-table and :-moz-inline-table. - parent = IsAnonBox(*tableFrame) ? parent->GetParent() : tableFrame; + parent = IsAnonBox(tableFrame) ? parent->GetParent() : tableFrame; } else { // We get the in-flow parent here so that we can handle the OOF anonymous // boxed to get the correct parent. @@ -2016,12 +2016,12 @@ ServoRestyleState::AssertOwner(const ServoRestyleState& aParent) const // chains of ServoRestyleStates in some cases where it's just not worth it. #ifdef DEBUG if (aParent.mOwner) { - const nsIFrame* owner = ExpectedOwnerForChild(*mOwner); + const nsIFrame* owner = ExpectedOwnerForChild(mOwner); if (owner != aParent.mOwner) { - MOZ_ASSERT(IsAnonBox(*owner), + MOZ_ASSERT(IsAnonBox(owner), "Should only have expected owner weirdness when anon boxes are involved"); bool found = false; - for (; owner; owner = ExpectedOwnerForChild(*owner)) { + for (; owner; owner = ExpectedOwnerForChild(owner)) { if (owner == aParent.mOwner) { found = true; break; @@ -2034,7 +2034,7 @@ ServoRestyleState::AssertOwner(const ServoRestyleState& aParent) const } nsChangeHint -ServoRestyleState::ChangesHandledFor(const nsIFrame& aFrame) const +ServoRestyleState::ChangesHandledFor(const nsIFrame* aFrame) const { if (!mOwner) { MOZ_ASSERT(!mChangesHandled); @@ -2399,7 +2399,7 @@ public: uint32_t equalStructs; mComputedHint = oldStyle->CalcStyleDifference(&aNewStyle, &equalStructs); mComputedHint = NS_RemoveSubsumedHints( - mComputedHint, mParentRestyleState.ChangesHandledFor(*aTextFrame)); + mComputedHint, mParentRestyleState.ChangesHandledFor(aTextFrame)); } if (mComputedHint) { @@ -2515,7 +2515,7 @@ UpdateOneAdditionalComputedStyle(nsIFrame* aFrame, aOldContext.CalcStyleDifference(newStyle, &equalStructs); if (!aFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) { childHint = NS_RemoveSubsumedHints( - childHint, aRestyleState.ChangesHandledFor(*aFrame)); + childHint, aRestyleState.ChangesHandledFor(aFrame)); } if (childHint) { @@ -2685,7 +2685,7 @@ RestyleManager::ProcessPostTraversal( } else { maybeAnonBoxChild = primaryFrame; changeHint = NS_RemoveSubsumedHints( - changeHint, aRestyleState.ChangesHandledFor(*styleFrame)); + changeHint, aRestyleState.ChangesHandledFor(styleFrame)); } // If the parent wasn't restyled, the styles of our anon box parents won't diff --git a/layout/base/RestyleManager.h b/layout/base/RestyleManager.h index 8dbf8cc74e23..7fff65a7a855 100644 --- a/layout/base/RestyleManager.h +++ b/layout/base/RestyleManager.h @@ -105,10 +105,10 @@ public: #ifdef DEBUG void AssertOwner(const ServoRestyleState& aParentState) const; - nsChangeHint ChangesHandledFor(const nsIFrame&) const; + nsChangeHint ChangesHandledFor(const nsIFrame*) const; #else void AssertOwner(const ServoRestyleState&) const {} - nsChangeHint ChangesHandledFor(const nsIFrame&) const + nsChangeHint ChangesHandledFor(const nsIFrame*) const { return mChangesHandled; } diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 8d07a8522562..655505de4a22 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -10781,7 +10781,7 @@ nsIFrame::UpdateStyleOfOwnedChildFrame( // frame tree. if (!aChildFrame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) { childHint = NS_RemoveSubsumedHints( - childHint, aRestyleState.ChangesHandledFor(*aChildFrame)); + childHint, aRestyleState.ChangesHandledFor(aChildFrame)); } if (childHint) { if (childHint & nsChangeHint_ReconstructFrame) { From e0f982a753f3c0eedd658e1ce4671694dd384fb3 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Thu, 20 Sep 2018 16:33:56 +0000 Subject: [PATCH 11/18] Bug 1492341 - Bump mozrunner version to 7.0.2; r=tcsc TPS is currently depending on mozrunner v7.0.1, which depends on an earlier version of mozprofile. For TPS to be able to use the latest version of mozprofile we need to release a new version of mozrunner with the recent mozprofile version identifier update. Differential Revision: https://phabricator.services.mozilla.com/D6406 --HG-- extra : moz-landing-system : lando --- testing/mozbase/mozrunner/setup.py | 2 +- testing/tps/setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/mozbase/mozrunner/setup.py b/testing/mozbase/mozrunner/setup.py index 29920874a8c4..8138c167e7b6 100644 --- a/testing/mozbase/mozrunner/setup.py +++ b/testing/mozbase/mozrunner/setup.py @@ -7,7 +7,7 @@ from __future__ import absolute_import from setuptools import setup, find_packages PACKAGE_NAME = 'mozrunner' -PACKAGE_VERSION = '7.0.1' +PACKAGE_VERSION = '7.0.2' desc = """Reliable start/stop/configuration of Mozilla Applications (Firefox, Thunderbird, etc.)""" diff --git a/testing/tps/setup.py b/testing/tps/setup.py index 999cb58ed034..af999e7adfd4 100644 --- a/testing/tps/setup.py +++ b/testing/tps/setup.py @@ -15,7 +15,7 @@ deps = ['httplib2 == 0.9.2', 'mozinstall == 1.16', 'mozprocess == 0.26', 'mozprofile == 2.0.0', - 'mozrunner == 7.0.1', + 'mozrunner == 7.0.2', 'mozversion == 1.5', ] From 2abe1a8480efd17faad47c3b6481b18ede32ba48 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Fri, 21 Sep 2018 18:20:33 +0000 Subject: [PATCH 12/18] Bug 1351501, part 1 - Handlify TryPreserveWrapper r=bzbarsky The patch in the next part will need a handle to the object in TryPreserveWrapper. Differential Revision: https://phabricator.services.mozilla.com/D6197 --HG-- extra : moz-landing-system : lando --- dom/bindings/BindingUtils.cpp | 2 +- dom/bindings/BindingUtils.h | 2 +- dom/workers/RuntimeService.cpp | 2 +- dom/worklet/WorkletThread.cpp | 2 +- js/src/jsfriendapi.h | 2 +- js/src/shell/js.cpp | 2 +- js/xpconnect/src/XPCJSRuntime.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index a8d54b4ef820..df3a6cf4ecf1 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -1148,7 +1148,7 @@ NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx, } bool -TryPreserveWrapper(JSObject* obj) +TryPreserveWrapper(JS::Handle obj) { MOZ_ASSERT(IsDOMObject(obj)); diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 8504be8756c8..839e08b53c15 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -1518,7 +1518,7 @@ UpdateWrapper(T* p, void*, JSObject* obj, const JSObject* old) // This operation will return false only for non-nsISupports cycle-collected // objects, because we cannot determine if they are wrappercached or not. bool -TryPreserveWrapper(JSObject* obj); +TryPreserveWrapper(JS::Handle obj); // Can only be called with a DOM JSClass. bool diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 8ad239d32373..edb6a51459d9 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -913,7 +913,7 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSContext* aWorkerCx) } static bool -PreserveWrapper(JSContext *cx, JSObject *obj) +PreserveWrapper(JSContext *cx, JS::HandleObject obj) { MOZ_ASSERT(cx); MOZ_ASSERT(obj); diff --git a/dom/worklet/WorkletThread.cpp b/dom/worklet/WorkletThread.cpp index 3f76a16995cc..ecaa0fbb1825 100644 --- a/dom/worklet/WorkletThread.cpp +++ b/dom/worklet/WorkletThread.cpp @@ -30,7 +30,7 @@ const uint32_t kWorkletStackSize = 256 * sizeof(size_t) * 1024; // Helper functions bool -PreserveWrapper(JSContext* aCx, JSObject* aObj) +PreserveWrapper(JSContext* aCx, JS::HandleObject aObj) { MOZ_ASSERT(aCx); MOZ_ASSERT(aObj); diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index b804c799683c..e8326e799cca 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -464,7 +464,7 @@ extern JS_FRIEND_API(JS::Zone*) GetRealmZone(JS::Realm* realm); typedef bool -(* PreserveWrapperCallback)(JSContext* cx, JSObject* obj); +(* PreserveWrapperCallback)(JSContext* cx, JS::HandleObject obj); typedef enum { CollectNurseryBeforeDump, diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index db781df4f041..8d7ced16a829 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -3511,7 +3511,7 @@ DisassWithSrc(JSContext* cx, unsigned argc, Value* vp) /* Pretend we can always preserve wrappers for dummy DOM objects. */ static bool -DummyPreserveWrapperCallback(JSContext* cx, JSObject* obj) +DummyPreserveWrapperCallback(JSContext* cx, HandleObject obj) { return true; } diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index d91485af0263..8add67939710 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -2828,7 +2828,7 @@ DestroyRealm(JSFreeOp* fop, JS::Realm* realm) } static bool -PreserveWrapper(JSContext* cx, JSObject* obj) +PreserveWrapper(JSContext* cx, JS::Handle obj) { MOZ_ASSERT(cx); MOZ_ASSERT(obj); From fee317ab0df6906b34d56fd7d94d094bc5fc1b7c Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Fri, 21 Sep 2018 18:20:35 +0000 Subject: [PATCH 13/18] Bug 1351501, part 2 - Preserve wrappers for non-nsISupports cycle collected weak map keys r=bzbarsky A C++ object that is exposed to JS can have its reflector used as a key in a weak map. Because a weak map does not keep its keys alive, this means that the reflector can be discarded if it has no other references aside from the C++ object, which will in turn remove its weak map entry. If the C++ object can be accessed again later from JS, it will get a new reflector which will have no weak map entry. This is bad because it means some internal implementation detail has resulted in data loss that is visible to JS. (Side note: this is also an issue for cross compartment wrappers, which is handled by another mechanism.) To fix this, we can preserve the wrapper of any DOM reflector used as a weak map key. This ensures that the reflector and its C++ object have the same lifetime. If a WebIDL object is not wrapper cached, that means that it cannot be accessed via C++, so we don't need to preserve the wrapper. This is currently implemented for nsISupports classes, but not other classes. For non-nsISupports classes, it would throw an error rather than silently fail. My patch adds support for non-nsISupports cycle collected objects. It turns out that the existing addProperty hook just does wrapper preservation, so we just call it for cycle collected classes. This does mean that if addProperty changes in the future to do something else, this code will need to be changed. I verified that this test fails if TryPreserveWrapper is changed to do nothing besides return true in the non-nsISuports case. Depends on D6197 Differential Revision: https://phabricator.services.mozilla.com/D6198 --HG-- extra : moz-landing-system : lando --- dom/bindings/BindingUtils.cpp | 25 ++++++++++--- dom/bindings/Codegen.py | 7 ++++ .../tests/chrome/test_paris_weakmap_keys.xul | 35 +++++++++++++------ 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index df3a6cf4ecf1..c036e5aa9283 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -1152,6 +1152,9 @@ TryPreserveWrapper(JS::Handle obj) { MOZ_ASSERT(IsDOMObject(obj)); + // nsISupports objects are special cased because DOM proxies are nsISupports + // and have addProperty hooks that do more than wrapper preservation (so we + // don't want to call them). if (nsISupports* native = UnwrapDOMObjectToISupports(obj)) { nsWrapperCache* cache = nullptr; CallQueryInterface(native, &cache); @@ -1161,11 +1164,25 @@ TryPreserveWrapper(JS::Handle obj) return true; } - // If this DOMClass is not cycle collected, then it isn't wrappercached, - // so it does not need to be preserved. If it is cycle collected, then - // we can't tell if it is wrappercached or not, so we just return false. + // The addProperty hook for WebIDL classes does wrapper preservation, and + // nothing else, so call it, if present. const DOMJSClass* domClass = GetDOMClass(obj); - return domClass && !domClass->mParticipant; + const JSClass* clasp = domClass->ToJSClass(); + JSAddPropertyOp addProperty = clasp->getAddProperty(); + + // We expect all proxies to be nsISupports. + MOZ_RELEASE_ASSERT(!js::Valueify(clasp)->isProxy(), "Should not call addProperty for proxies."); + + // The class should have an addProperty hook iff it is a CC participant. + MOZ_RELEASE_ASSERT(bool(domClass->mParticipant) == bool(addProperty)); + + if (!addProperty) { + return true; + } + + JS::Rooted dummyId(RootingCx()); + JS::Rooted dummyValue(RootingCx()); + return addProperty(nullptr, obj, dummyId, dummyValue); } // Can only be called with a DOM JSClass. diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 9bf8f18d409a..3c1d37c1ee25 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -102,6 +102,9 @@ def idlTypeNeedsCycleCollection(type): raise CycleCollectionUnsupported("Don't know whether to cycle-collect type %s" % type) +# TryPreserveWrapper uses the addProperty hook to preserve the wrapper of +# non-nsISupports cycle collected objects, so if wantsAddProperty is changed +# to not cover that case then TryPreserveWrapper will need to be changed. def wantsAddProperty(desc): return (desc.concrete and desc.wrapperCache and not desc.isGlobal()) @@ -1683,6 +1686,10 @@ class CGAddPropertyHook(CGAbstractClassHook): def generate_code(self): assert self.descriptor.wrapperCache + # This hook is also called by TryPreserveWrapper on non-nsISupports + # cycle collected objects, so if addProperty is ever changed to do + # anything more or less than preserve the wrapper, TryPreserveWrapper + # will need to be changed. return dedent(""" // We don't want to preserve if we don't have a wrapper, and we // obviously can't preserve if we're not initialized. diff --git a/js/xpconnect/tests/chrome/test_paris_weakmap_keys.xul b/js/xpconnect/tests/chrome/test_paris_weakmap_keys.xul index 67aac2e77dfd..9786ce59f37c 100644 --- a/js/xpconnect/tests/chrome/test_paris_weakmap_keys.xul +++ b/js/xpconnect/tests/chrome/test_paris_weakmap_keys.xul @@ -43,18 +43,32 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=777385 make_live_map(); - // DOMPoint is a non-nsISupports refCounted class using WebIDL bindings. - // non-nsISupports cycle-collected classes should fail as weak map keys. - let context = new DOMPoint(1, 2, 3); - let contextFail = false; - try { - live_map.set(context, 2); - } catch (e) { - contextFail = true; + // CanvasGradient is a non-nsISupports wrapper cached class using WebIDL + // bindings. If we used it as a key in a weak map, then it should not be + // removed from the weak map as long as it remains alive. + let doc = new DOMParser().parseFromString("", "text/html"); + let canv = doc.createElement("canvas"); + let ctx = canv.getContext("2d"); + + let add_non_isupports2 = function () { + let grad = ctx.createLinearGradient(0, 0, 0, 0); + ctx.strokeStyle = grad; + + let gradFail = false; + try { + live_map.set(grad, 23456); + } catch (e) { + gradFail = true; + } + + ok(!gradFail, "Using a wrapper cached non-nsISupports class as a weak map key should not produce an exception."); + + is(live_map.get(grad), 23456, "Live map should have live DOMPoint with right value before GC."); } - ok(contextFail, "Cycle collected non-nsISupports classes aren't allowed as weak map keys."); + add_non_isupports2(); + /* Set up for running precise GC/CC then check the results. */ @@ -65,10 +79,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=777385 SpecialPowers.DOMWindowUtils.garbageCollect(); SpecialPowers.DOMWindowUtils.garbageCollect(); - is(ChromeUtils.nondeterministicGetWeakMapKeys(live_map).length, 1, + is(ChromeUtils.nondeterministicGetWeakMapKeys(live_map).length, 2, "Live nsISupports new DOM bindings wrappercached native weak map key should not be removed."); is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value after GC."); + is(live_map.get(ctx.strokeStyle), 23456, "Live map should have live gradient with right value after GC."); SimpleTest.finish(); }); From f8292a843581bbee06b4b34ebf5ac474d32dc381 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 21 Sep 2018 18:23:35 +0000 Subject: [PATCH 14/18] Bug 1493173 - Remove the unneeded dependency from win64-st-autotest/debug r=dmajor Not quite sure why this dependency ever existed. These builds never use clang-tidy, so this dependency was probably never needed in the first place. Differential Revision: https://phabricator.services.mozilla.com/D6493 --HG-- extra : moz-landing-system : lando --- taskcluster/ci/static-analysis-autotest/kind.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/taskcluster/ci/static-analysis-autotest/kind.yml b/taskcluster/ci/static-analysis-autotest/kind.yml index a2caba0906e6..b0aae0ceffeb 100644 --- a/taskcluster/ci/static-analysis-autotest/kind.yml +++ b/taskcluster/ci/static-analysis-autotest/kind.yml @@ -76,5 +76,4 @@ jobs: - win64-rust - win64-sccache - win64-cbindgen - - win64-clang-tidy - win64-node From b1a30b1cb4391641274e792c0999c8d7fa95916d Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Fri, 21 Sep 2018 12:56:53 +0000 Subject: [PATCH 15/18] Bug 1492615. Improve logging even more r=mstange Differential Revision: https://phabricator.services.mozilla.com/D6432 --HG-- extra : moz-landing-system : lando --- gfx/layers/wr/WebRenderCommandBuilder.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gfx/layers/wr/WebRenderCommandBuilder.cpp b/gfx/layers/wr/WebRenderCommandBuilder.cpp index 0519c2baa344..32cc0c1e88b0 100644 --- a/gfx/layers/wr/WebRenderCommandBuilder.cpp +++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp @@ -1188,22 +1188,22 @@ WebRenderCommandBuilder::DoGroupingForDisplayList(nsDisplayList* aList, GP("Property change. Deleting blob\n"); if (group.mAppUnitsPerDevPixel != appUnitsPerDevPixel) { - GP(" app unit change%d %d\n", group.mAppUnitsPerDevPixel, appUnitsPerDevPixel); + GP(" App unit change %d -> %d\n", group.mAppUnitsPerDevPixel, appUnitsPerDevPixel); } // The bounds have changed so we need to discard the old image and add all // the commands again. auto p = group.mGroupBounds; auto q = groupBounds; if (!group.mGroupBounds.IsEqualEdges(groupBounds)) { - GP(" Bounds change: %d %d %d %d vs %d %d %d %d\n", p.x, p.y, p.width, p.height, q.x, q.y, q.width, q.height); + GP(" Bounds change: %d %d %d %d -> %d %d %d %d\n", p.x, p.y, p.width, p.height, q.x, q.y, q.width, q.height); } if (group.mScale != scale) { - GP(" Scale %f %f vs %f %f\n", group.mScale.width, group.mScale.height, scale.width, scale.height); + GP(" Scale %f %f -> %f %f\n", group.mScale.width, group.mScale.height, scale.width, scale.height); } if (group.mResidualOffset != residualOffset) { - GP(" Residual Offset %f %f vs %f %f\n", group.mResidualOffset.x, group.mResidualOffset.y, residualOffset.x, residualOffset.y); + GP(" Residual Offset %f %f -> %f %f\n", group.mResidualOffset.x, group.mResidualOffset.y, residualOffset.x, residualOffset.y); } group.ClearItems(); From 0a3b2c463486e0159ebf35d5b1f435d40b99501b Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 21 Sep 2018 13:59:25 -0400 Subject: [PATCH 16/18] Backout changeset c5b3caf36ddf (bug 1490297) for causing bug 1493081 and making Nightly unusable; a=Aryx --- view/nsView.cpp | 21 --------------------- view/nsView.h | 3 --- 2 files changed, 24 deletions(-) diff --git a/view/nsView.cpp b/view/nsView.cpp index 8bdf09d25011..8acedb73d731 100644 --- a/view/nsView.cpp +++ b/view/nsView.cpp @@ -234,17 +234,6 @@ bool nsView::IsEffectivelyVisible() return true; } -uint32_t nsView::GetParentWindowScaleFactor() -{ - uint32_t scaleFactor = 1; - nsIWidget* parentWidget = - GetParent() ? GetParent()->GetNearestWidget(nullptr) : nullptr; - if (parentWidget) { - scaleFactor = parentWidget->RoundsWidgetCoordinatesTo(); - } - return scaleFactor; -} - LayoutDeviceIntRect nsView::CalcWidgetBounds(nsWindowType aType) { int32_t p2a = mViewManager->AppUnitsPerDevPixel(); @@ -331,9 +320,7 @@ void nsView::DoResetWidgetBounds(bool aMoveOnly, // Stash a copy of these and use them so we can handle this being deleted (say // from sync painting/flushing from Show/Move/Resize on the widget). LayoutDeviceIntRect newBounds; -#if !defined(MOZ_WIDGET_GTK) RefPtr dx = mViewManager->GetDeviceContext(); -#endif nsWindowType type = widget->WindowType(); @@ -373,15 +360,7 @@ void nsView::DoResetWidgetBounds(bool aMoveOnly, // because of the potential for device-pixel coordinate spaces for mixed // hidpi/lodpi screens to overlap each other and result in bad placement // (bug 814434). -#if defined(MOZ_WIDGET_GTK) - // The GetDesktopToDeviceScale does not work under Wayland because we - // don't know the absolute position of the window in Wayland. We can - // use the same for X11, because it always returns 1 for both calls. - DesktopToLayoutDeviceScale scale = mozilla::DesktopToLayoutDeviceScale( - GetParentWindowScaleFactor()); -#else DesktopToLayoutDeviceScale scale = dx->GetDesktopToDeviceScale(); -#endif DesktopRect deskRect = newBounds / scale; if (changedPos) { diff --git a/view/nsView.h b/view/nsView.h index d49a706a5d7d..f61b44bac92d 100644 --- a/view/nsView.h +++ b/view/nsView.h @@ -462,9 +462,6 @@ private: // Update the cached RootViewManager for all view manager descendents. void InvalidateHierarchy(); - // Return current scale factor of the monitor where the parent window of the popup - // is mostly located. - uint32_t GetParentWindowScaleFactor(); nsViewManager *mViewManager; nsView *mParent; From a60da103fe82e922288a1c8440d19b11871cc28e Mon Sep 17 00:00:00 2001 From: Brindusan Cristian Date: Fri, 21 Sep 2018 21:58:21 +0300 Subject: [PATCH 17/18] Backed out changeset ae99a39d6497 (bug 1493173) for bustage on static-analysis autotest. CLOSED TREE --- taskcluster/ci/static-analysis-autotest/kind.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/taskcluster/ci/static-analysis-autotest/kind.yml b/taskcluster/ci/static-analysis-autotest/kind.yml index b0aae0ceffeb..a2caba0906e6 100644 --- a/taskcluster/ci/static-analysis-autotest/kind.yml +++ b/taskcluster/ci/static-analysis-autotest/kind.yml @@ -76,4 +76,5 @@ jobs: - win64-rust - win64-sccache - win64-cbindgen + - win64-clang-tidy - win64-node From 84601ca6bfce64209eddde9dd8074a8176e6c3d8 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Fri, 21 Sep 2018 15:08:40 -0400 Subject: [PATCH 18/18] Backed out changeset c173cb530f63 (bug 1490009) for violating invariants. --- dom/bindings/CallbackObject.h | 5 ----- xpcom/base/CycleCollectedJSContext.cpp | 6 ------ 2 files changed, 11 deletions(-) diff --git a/dom/bindings/CallbackObject.h b/dom/bindings/CallbackObject.h index f0c3f89f459f..79b8296a3d4b 100644 --- a/dom/bindings/CallbackObject.h +++ b/dom/bindings/CallbackObject.h @@ -148,11 +148,6 @@ public: return mIncumbentGlobal; } - void Reset() - { - ClearJSReferences(); - } - enum ExceptionHandling { // Report any exception and don't throw it to the caller code. eReportExceptions, diff --git a/xpcom/base/CycleCollectedJSContext.cpp b/xpcom/base/CycleCollectedJSContext.cpp index d10cc41499fa..553ead94d7db 100644 --- a/xpcom/base/CycleCollectedJSContext.cpp +++ b/xpcom/base/CycleCollectedJSContext.cpp @@ -227,12 +227,6 @@ protected: mCallback->Call("promise callback"); aAso.CheckForInterrupt(); } - // Now that mCallback is no longer needed, clear any pointers it contains to - // JS GC things. This removes any storebuffer entries associated with those - // pointers, which can cause problems by taking up memory and by triggering - // minor GCs. This otherwise would not happen until the next minor GC or - // cycle collection. - mCallback->Reset(); } virtual bool Suppressed() override