Index: chrome/browser/ui/webui/chromeos/login/l10n_util.cc |
diff --git a/chrome/browser/ui/webui/chromeos/login/l10n_util.cc b/chrome/browser/ui/webui/chromeos/login/l10n_util.cc |
index 1613b4d2485d3884fdc4faaba1bbd940d3ebb14c..98ef4523ca474c953ae6f4fce8a54a08c5309fd1 100644 |
--- a/chrome/browser/ui/webui/chromeos/login/l10n_util.cc |
+++ b/chrome/browser/ui/webui/chromeos/login/l10n_util.cc |
@@ -26,8 +26,6 @@ |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/chromeos/customization_document.h" |
#include "chrome/browser/chromeos/input_method/input_method_util.h" |
-#include "chrome/browser/chromeos/profiles/profile_helper.h" |
-#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/grit/generated_resources.h" |
#include "chromeos/ime/component_extension_ime_manager.h" |
#include "chromeos/ime/input_method_descriptor.h" |
@@ -36,8 +34,6 @@ |
#include "ui/base/l10n/l10n_util.h" |
namespace chromeos { |
- |
-const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER"; |
namespace { |
@@ -75,27 +71,6 @@ |
} |
#endif |
-base::DictionaryValue* CreateLanguageEntry( |
- const std::string& language_code, |
- const base::string16& language_display_name, |
- const base::string16& language_native_display_name) { |
- base::string16 display_name = language_display_name; |
- const bool markup_removal = |
- base::i18n::UnadjustStringForLocaleDirection(&display_name); |
- DCHECK(markup_removal); |
- |
- const bool has_rtl_chars = |
- base::i18n::StringContainsStrongRTLChars(display_name); |
- const std::string directionality = has_rtl_chars ? "rtl" : "ltr"; |
- |
- scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); |
- dictionary->SetString("code", language_code); |
- dictionary->SetString("displayName", language_display_name); |
- dictionary->SetString("textDirection", directionality); |
- dictionary->SetString("nativeDisplayName", language_native_display_name); |
- return dictionary.release(); |
-} |
- |
// Gets the list of languages with |descriptors| based on |base_language_codes|. |
// The |most_relevant_language_codes| will be first in the list. If |
// |insert_divider| is true, an entry with its "code" attribute set to |
@@ -280,10 +255,20 @@ |
language_list->Append(dictionary); |
continue; |
} |
+ const bool markup_removal = |
+ base::i18n::UnadjustStringForLocaleDirection(&display_name); |
+ DCHECK(markup_removal); |
+ const bool has_rtl_chars = |
+ base::i18n::StringContainsStrongRTLChars(display_name); |
+ const std::string directionality = has_rtl_chars ? "rtl" : "ltr"; |
const LanguagePair& pair = language_map[out_display_names[i]]; |
- language_list->Append( |
- CreateLanguageEntry(pair.first, out_display_names[i], pair.second)); |
+ base::DictionaryValue* dictionary = new base::DictionaryValue(); |
+ dictionary->SetString("code", pair.first); |
+ dictionary->SetString("displayName", out_display_names[i]); |
+ dictionary->SetString("textDirection", directionality); |
+ dictionary->SetString("nativeDisplayName", pair.second); |
+ language_list->Append(dictionary); |
} |
return language_list.Pass(); |
@@ -326,151 +311,16 @@ |
callback.Run(input_methods_list.Pass()); |
} |
-// For "UI Language" drop-down menu at OOBE screen we need to decide which |
-// entry to mark "selected". If user has just selected "requested_locale", |
-// but "loaded_locale" was actually loaded, we mark original user choice |
-// "selected" only if loaded_locale is a backup for "requested_locale". |
-std::string CalculateSelectedLanguage(const std::string& requested_locale, |
- const std::string& loaded_locale) { |
- std::string resolved_locale; |
- if (!l10n_util::CheckAndResolveLocale(requested_locale, &resolved_locale)) |
- return loaded_locale; |
- |
- if (resolved_locale == loaded_locale) |
- return requested_locale; |
- |
- return loaded_locale; |
-} |
- |
-void ResolveLanguageListOnBlockingPool( |
- const chromeos::locale_util::LanguageSwitchResult* language_switch_result, |
- scoped_ptr<base::ListValue>* list, |
- std::string* list_locale, |
- std::string* selected_language) { |
- DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
- |
- if (!language_switch_result) { |
- *selected_language = |
- StartupCustomizationDocument::GetInstance()->initial_locale_default(); |
- } else { |
- if (language_switch_result->success) { |
- if (language_switch_result->requested_locale == |
- language_switch_result->loaded_locale) { |
- *selected_language = language_switch_result->requested_locale; |
- } else { |
- *selected_language = |
- CalculateSelectedLanguage(language_switch_result->requested_locale, |
- language_switch_result->loaded_locale); |
- } |
- } else { |
- *selected_language = language_switch_result->loaded_locale; |
- } |
- } |
- const std::string selected_code = |
- selected_language->empty() ? g_browser_process->GetApplicationLocale() |
- : *selected_language; |
- |
- *list_locale = language_switch_result |
- ? language_switch_result->loaded_locale |
- : g_browser_process->GetApplicationLocale(); |
- list->reset(chromeos::GetUILanguageList(NULL, selected_code).release()); |
-} |
- |
-void OnLanguageListResolved( |
- UILanguageListResolvedCallback callback, |
- scoped_ptr<scoped_ptr<base::ListValue>> new_language_list, |
- scoped_ptr<std::string> new_language_list_locale, |
- scoped_ptr<std::string> new_selected_language) { |
- callback.Run(new_language_list->Pass(), |
- *new_language_list_locale, |
- *new_selected_language); |
-} |
- |
-void AdjustUILanguageList(const std::string& selected, |
- base::ListValue* languages_list) { |
- for (size_t i = 0; i < languages_list->GetSize(); ++i) { |
- base::DictionaryValue* language_info = NULL; |
- if (!languages_list->GetDictionary(i, &language_info)) |
- NOTREACHED(); |
- |
- std::string value; |
- language_info->GetString("code", &value); |
- std::string display_name; |
- language_info->GetString("displayName", &display_name); |
- std::string native_name; |
- language_info->GetString("nativeDisplayName", &native_name); |
- |
- // If it's an option group divider, add field name. |
- if (value == kMostRelevantLanguagesDivider) { |
- language_info->SetString( |
- "optionGroupName", |
- l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); |
- } |
- if (display_name != native_name) { |
- display_name = base::StringPrintf("%s - %s", |
- display_name.c_str(), |
- native_name.c_str()); |
- } |
- |
- language_info->SetString("value", value); |
- language_info->SetString("title", display_name); |
- if (value == selected) |
- language_info->SetBoolean("selected", true); |
- } |
-} |
- |
} // namespace |
-void ResolveUILanguageList( |
- scoped_ptr<chromeos::locale_util::LanguageSwitchResult> |
- language_switch_result, |
- UILanguageListResolvedCallback callback) { |
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
- |
- scoped_ptr<scoped_ptr<base::ListValue>> new_language_list( |
- new scoped_ptr<base::ListValue>()); |
- scoped_ptr<std::string> new_language_list_locale(new std::string); |
- scoped_ptr<std::string> new_selected_language(new std::string); |
- |
- base::Closure resolve_on_pool = |
- base::Bind(&ResolveLanguageListOnBlockingPool, |
- base::Owned(language_switch_result.release()), |
- base::Unretained(new_language_list.get()), |
- base::Unretained(new_language_list_locale.get()), |
- base::Unretained(new_selected_language.get())); |
- |
- base::Closure on_language_list_resolved = |
- base::Bind(&OnLanguageListResolved, |
- callback, |
- base::Passed(new_language_list.Pass()), |
- base::Passed(new_language_list_locale.Pass()), |
- base::Passed(new_selected_language.Pass())); |
- |
- content::BrowserThread::GetBlockingPool()->PostTaskAndReply( |
- FROM_HERE, resolve_on_pool, on_language_list_resolved); |
-} |
- |
-scoped_ptr<base::ListValue> GetMinimalUILanguageList() { |
- const std::string application_locale = |
- g_browser_process->GetApplicationLocale(); |
- base::string16 language_native_display_name = |
- l10n_util::GetDisplayNameForLocale( |
- application_locale, application_locale, true); |
- |
- scoped_ptr<base::ListValue> language_list(new base::ListValue()); |
- language_list->Append(CreateLanguageEntry(application_locale, |
- language_native_display_name, |
- language_native_display_name)); |
- AdjustUILanguageList(std::string(), language_list.get()); |
- return language_list.Pass(); |
-} |
+const char kMostRelevantLanguagesDivider[] = "MOST_RELEVANT_LANGUAGES_DIVIDER"; |
scoped_ptr<base::ListValue> GetUILanguageList( |
const std::vector<std::string>* most_relevant_language_codes, |
const std::string& selected) { |
ComponentExtensionIMEManager* manager = |
- input_method::InputMethodManager::Get() |
- ->GetComponentExtensionIMEManager(); |
+ input_method::InputMethodManager::Get()-> |
+ GetComponentExtensionIMEManager(); |
input_method::InputMethodDescriptors descriptors = |
manager->GetXkbIMEAsInputMethodDescriptor(); |
scoped_ptr<base::ListValue> languages_list(GetLanguageList( |
@@ -480,7 +330,36 @@ |
? *most_relevant_language_codes |
: StartupCustomizationDocument::GetInstance()->configured_locales(), |
true)); |
- AdjustUILanguageList(selected, languages_list.get()); |
+ |
+ for (size_t i = 0; i < languages_list->GetSize(); ++i) { |
+ base::DictionaryValue* language_info = NULL; |
+ if (!languages_list->GetDictionary(i, &language_info)) |
+ NOTREACHED(); |
+ |
+ std::string value; |
+ language_info->GetString("code", &value); |
+ std::string display_name; |
+ language_info->GetString("displayName", &display_name); |
+ std::string native_name; |
+ language_info->GetString("nativeDisplayName", &native_name); |
+ |
+ // If it's an option group divider, add field name. |
+ if (value == kMostRelevantLanguagesDivider) { |
+ language_info->SetString( |
+ "optionGroupName", |
+ l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); |
+ } |
+ if (display_name != native_name) { |
+ display_name = base::StringPrintf("%s - %s", |
+ display_name.c_str(), |
+ native_name.c_str()); |
+ } |
+ |
+ language_info->SetString("value", value); |
+ language_info->SetString("title", display_name); |
+ if (value == selected) |
+ language_info->SetBoolean("selected", true); |
+ } |
return languages_list.Pass(); |
} |
@@ -524,8 +403,7 @@ |
scoped_ptr<base::ListValue> GetAndActivateLoginKeyboardLayouts( |
const std::string& locale, |
- const std::string& selected, |
- bool activate_keyboards) { |
+ const std::string& selected) { |
scoped_ptr<base::ListValue> input_methods_list(new base::ListValue); |
#if !defined(USE_ATHENA) |
// TODO(dpolukhin): crbug.com/407579 |
@@ -536,12 +414,8 @@ |
const std::vector<std::string>& hardware_login_input_methods = |
util->GetHardwareLoginInputMethodIds(); |
- if (activate_keyboards) { |
- DCHECK( |
- ProfileHelper::IsSigninProfile(ProfileManager::GetActiveUserProfile())); |
- manager->GetActiveIMEState()->EnableLoginLayouts( |
- locale, hardware_login_input_methods); |
- } |
+ manager->GetActiveIMEState()->EnableLoginLayouts( |
+ locale, hardware_login_input_methods); |
scoped_ptr<input_method::InputMethodDescriptors> input_methods( |
manager->GetActiveIMEState()->GetActiveInputMethods()); |