Commit 0f365711 authored by Alexander Hendrich's avatar Alexander Hendrich Committed by Commit Bot

Refactored AllowedUILocales (isAllowedUILocale to isProhibitedUILocale)

Refactored optional attribute 'isAllowedUILocale' to
'isProhibitedUILocale' (default=false). Also set the attribute in c++
and pass it through LanguageSettingsPrivateAPI instead of accessing the
pref in the UI code.

Bug: 695042
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Id904a54e4798bb9a951dd65f8748bd40867e4425
Reviewed-on: https://chromium-review.googlesource.com/1111710Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Alexander Hendrich <hendrich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569979}
parent 656c9ee2
......@@ -78,6 +78,16 @@ std::unordered_set<std::string> GetIMEsFromPref(PrefService* prefs,
enabled_imes.end());
}
// Returns the set of allowed UI locales.
std::unordered_set<std::string> GetAllowedUILocales(PrefService* prefs) {
std::unordered_set<std::string> allowed_ui_locales;
const base::Value::ListStorage& pref_value =
prefs->GetList(prefs::kAllowedUILocales)->GetList();
for (const base::Value& locale_value : pref_value)
allowed_ui_locales.insert(locale_value.GetString());
return allowed_ui_locales;
}
// Sorts the input methods by the order of their associated languages. For
// example, if the enabled language order is:
// - French
......@@ -191,6 +201,10 @@ LanguageSettingsPrivateGetLanguageListFunction::Run() {
// Build the language list.
std::unique_ptr<base::ListValue> language_list(new base::ListValue);
#if defined(OS_CHROMEOS)
const std::unordered_set<std::string> allowed_ui_locales(
GetAllowedUILocales(chrome_details_.GetProfile()->GetPrefs()));
#endif // defined(OS_CHROMEOS)
for (const auto& entry : languages) {
language_settings_private::Language language;
......@@ -213,6 +227,12 @@ LanguageSettingsPrivateGetLanguageListFunction::Run() {
} else if (base::ContainsKey(locale_set, entry.code)) {
language.supports_ui.reset(new bool(true));
}
#if defined(OS_CHROMEOS)
if (!allowed_ui_locales.empty() &&
allowed_ui_locales.count(language.code) == 0) {
language.is_prohibited_ui_locale.reset(new bool(true));
}
#endif // defined(OS_CHROMEOS)
language_list->Append(language.ToValue());
}
......
......@@ -219,8 +219,6 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
#if defined(OS_CHROMEOS)
(*s_whitelist)[::prefs::kLanguageImeMenuActivated] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[::prefs::kAllowedUILocales] =
settings_api::PrefType::PREF_TYPE_LIST;
#endif
// Search page.
......
......@@ -375,22 +375,6 @@ Polymer({
}
},
/**
* @private
* @param {string} languageCode language code
* @return {boolean} True if the locale is in the list of allowed UI locales
* ('AllowedUILocales' policy) or if the policy is not set (empty list).
* @private
*/
isAllowedUILocale_: function(languageCode) {
if (!cr.isChromeOS)
return true;
const pref = /** @type {!chrome.settingsPrivate.PrefObject} */ (
this.get('intl.allowed_ui_locales', this.prefs));
return (pref.value.length == 0 || pref.value.indexOf(languageCode) != -1);
},
/**
* Constructs the languages model.
* @param {!Array<!chrome.languageSettingsPrivate.Language>}
......@@ -412,7 +396,7 @@ Polymer({
language.supportsUI = !!language.supportsUI;
language.supportsTranslate = !!language.supportsTranslate;
language.supportsSpellcheck = !!language.supportsSpellcheck;
language.isAllowedUILocale = this.isAllowedUILocale_(language.code);
language.isProhibitedUILocale = !!language.isProhibitedUILocale;
this.supportedLanguageMap_.set(language.code, language);
}
......
......@@ -107,6 +107,10 @@
.name-with-error-list[disabled] {
pointer-events: none;
}
iron-icon.policy {
-webkit-margin-start: 10px;
}
</style>
<settings-languages languages="{{languages}}" prefs="{{prefs}}"
language-helper="{{languageHelper}}">
......@@ -328,10 +332,9 @@
disabled="[[disableUILanguageCheckbox_(
detailLanguage_, languages.prospectiveUILanguage)]]">
<span>$i18n{displayInThisLanguage}</span>
<cr-policy-indicator indicator-type="[[
getPolicyIndicatorStatus_(
detailLanguage_.language)]]">
</cr-policy-indicator>
<iron-icon class="policy" icon="cr20:domain" hidden$="[[
!detailLanguage_.language.isProhibitedUILocale]]">
</iron-icon>
</cr-checkbox>
</if>
<cr-checkbox id="offerTranslations" slot="item"
......
......@@ -301,25 +301,15 @@ Polymer({
if (languageState.language.code == prospectiveUILanguage)
return true;
// Check if the language is allowed by the current "AllowedUILocales"
// Check if the language is prohibited by the current "AllowedUILocales"
// policy.
if (!languageState.language.isAllowedUILocale)
if (languageState.language.isProhibitedUILocale)
return true;
// Otherwise, the prospective language can be changed to this language.
return false;
},
/**
* @param {!chrome.languageSettingsPrivate.Language} language
* @return {string} 'userPolicy' if the language is not allowed by the
* AllowedUILocales policy, 'none' otherwise.
* @private
*/
getPolicyIndicatorStatus_: function(language) {
return (language.isAllowedUILocale ? 'none' : 'userPolicy');
},
/**
* Handler for changes to the UI language checkbox.
* @param {!{target: !Element}} e
......
......@@ -32,9 +32,9 @@ namespace languageSettingsPrivate {
// Defaults to false.
boolean? supportsTranslate;
// Whether this language is in the list of allowed locales (see
// 'AllowedUILocales' policy). Defaults to false.
boolean? isAllowedUILocale;
// Whether this language is prohibited as a UI locale (not in the list of
// the 'AllowedUILocales' policy). Defaults to false.
boolean? isProhibitedUILocale;
};
dictionary SpellcheckDictionaryStatus {
......
......@@ -389,11 +389,6 @@ cr.define('settings', function() {
type: chrome.settingsPrivate.PrefType.STRING,
value: 'en-US,sw',
},
{
key: 'intl.allowed_ui_locales',
type: chrome.settingsPrivate.PrefType.LIST,
value: [],
},
{
key: 'spellcheck.dictionaries',
type: chrome.settingsPrivate.PrefType.LIST,
......
......@@ -34,7 +34,7 @@ chrome.languageSettingsPrivate.MoveType = {
* supportsUI: (boolean|undefined),
* supportsSpellcheck: (boolean|undefined),
* supportsTranslate: (boolean|undefined),
* isAllowedUILocale: (boolean|undefined)
* isProhibitedUILocale: (boolean|undefined)
* }}
*/
chrome.languageSettingsPrivate.Language;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment