| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/dom_ui/language_options_handler.h" | 5 #include "chrome/browser/chromeos/dom_ui/language_options_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/cros/cros_library.h" | 15 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 16 #include "chrome/browser/chromeos/cros/input_method_library.h" | 16 #include "chrome/browser/chromeos/cros/input_method_library.h" |
| 17 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 17 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 18 #include "chrome/browser/pref_service.h" | 18 #include "chrome/browser/pref_service.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
| 21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 22 | 22 |
| 23 namespace chromeos { |
| 24 |
| 23 LanguageOptionsHandler::LanguageOptionsHandler() { | 25 LanguageOptionsHandler::LanguageOptionsHandler() { |
| 24 } | 26 } |
| 25 | 27 |
| 26 LanguageOptionsHandler::~LanguageOptionsHandler() { | 28 LanguageOptionsHandler::~LanguageOptionsHandler() { |
| 27 } | 29 } |
| 28 | 30 |
| 29 void LanguageOptionsHandler::GetLocalizedValues( | 31 void LanguageOptionsHandler::GetLocalizedValues( |
| 30 DictionaryValue* localized_strings) { | 32 DictionaryValue* localized_strings) { |
| 31 DCHECK(localized_strings); | 33 DCHECK(localized_strings); |
| 32 localized_strings->SetString(L"languagePage", | 34 localized_strings->SetString(L"languagePage", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 62 } | 64 } |
| 63 | 65 |
| 64 void LanguageOptionsHandler::RegisterMessages() { | 66 void LanguageOptionsHandler::RegisterMessages() { |
| 65 DCHECK(dom_ui_); | 67 DCHECK(dom_ui_); |
| 66 dom_ui_->RegisterMessageCallback("uiLanguageChange", | 68 dom_ui_->RegisterMessageCallback("uiLanguageChange", |
| 67 NewCallback(this, | 69 NewCallback(this, |
| 68 &LanguageOptionsHandler::UiLanguageChangeCallback)); | 70 &LanguageOptionsHandler::UiLanguageChangeCallback)); |
| 69 } | 71 } |
| 70 | 72 |
| 71 ListValue* LanguageOptionsHandler::GetInputMethodList() { | 73 ListValue* LanguageOptionsHandler::GetInputMethodList() { |
| 72 using chromeos::CrosLibrary; | |
| 73 | |
| 74 ListValue* input_method_list = new ListValue(); | 74 ListValue* input_method_list = new ListValue(); |
| 75 | 75 |
| 76 // GetSupportedLanguages() never return NULL. | 76 // GetSupportedLanguages() never return NULL. |
| 77 scoped_ptr<chromeos::InputMethodDescriptors> descriptors( | 77 scoped_ptr<InputMethodDescriptors> descriptors( |
| 78 CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); | 78 CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); |
| 79 for (size_t i = 0; i < descriptors->size(); ++i) { | 79 for (size_t i = 0; i < descriptors->size(); ++i) { |
| 80 const chromeos::InputMethodDescriptor& descriptor = descriptors->at(i); | 80 const InputMethodDescriptor& descriptor = descriptors->at(i); |
| 81 const std::string language_code = | 81 const std::string language_code = |
| 82 chromeos::input_method::GetLanguageCodeFromDescriptor(descriptor); | 82 input_method::GetLanguageCodeFromDescriptor(descriptor); |
| 83 const std::string display_name = | 83 const std::string display_name = |
| 84 chromeos::input_method::GetInputMethodDisplayNameFromId(descriptor.id); | 84 input_method::GetInputMethodDisplayNameFromId(descriptor.id); |
| 85 | 85 |
| 86 DictionaryValue* dictionary = new DictionaryValue(); | 86 DictionaryValue* dictionary = new DictionaryValue(); |
| 87 dictionary->SetString(L"id", UTF8ToWide(descriptor.id)); | 87 dictionary->SetString(L"id", UTF8ToWide(descriptor.id)); |
| 88 dictionary->SetString(L"displayName", UTF8ToWide(display_name)); | 88 dictionary->SetString(L"displayName", UTF8ToWide(display_name)); |
| 89 dictionary->SetString(L"languageCode", UTF8ToWide(language_code)); | 89 dictionary->SetString(L"languageCode", UTF8ToWide(language_code)); |
| 90 input_method_list->Append(dictionary); | 90 input_method_list->Append(dictionary); |
| 91 } | 91 } |
| 92 | 92 |
| 93 return input_method_list; | 93 return input_method_list; |
| 94 } | 94 } |
| 95 | 95 |
| 96 ListValue* LanguageOptionsHandler::GetLanguageList() { | 96 ListValue* LanguageOptionsHandler::GetLanguageList() { |
| 97 // Map of display name -> {language code, native_display_name}. | 97 // Map of display name -> {language code, native_display_name}. |
| 98 // In theory, we should be able to create a map that is sorted by | 98 // In theory, we should be able to create a map that is sorted by |
| 99 // display names using ICU comparator, but doing it is hard, thus we'll | 99 // display names using ICU comparator, but doing it is hard, thus we'll |
| 100 // use an auxiliary vector to achieve the same result. | 100 // use an auxiliary vector to achieve the same result. |
| 101 typedef std::pair<std::string, std::wstring> LanguagePair; | 101 typedef std::pair<std::string, std::wstring> LanguagePair; |
| 102 typedef std::map<std::wstring, LanguagePair> LanguageMap; | 102 typedef std::map<std::wstring, LanguagePair> LanguageMap; |
| 103 LanguageMap language_map; | 103 LanguageMap language_map; |
| 104 // The auxiliary vector mentioned above. | 104 // The auxiliary vector mentioned above. |
| 105 std::vector<std::wstring> display_names; | 105 std::vector<std::wstring> display_names; |
| 106 | 106 |
| 107 // Build the list of display names, and build the language map. | 107 // Build the list of display names, and build the language map. |
| 108 const std::vector<std::string>& locales = l10n_util::GetAvailableLocales(); | 108 const std::vector<std::string>& locales = l10n_util::GetAvailableLocales(); |
| 109 for (size_t i = 0; i < locales.size(); ++i) { | 109 for (size_t i = 0; i < locales.size(); ++i) { |
| 110 const std::wstring display_name = | 110 const std::wstring display_name = |
| 111 chromeos::input_method::GetLanguageDisplayNameFromCode(locales[i]); | 111 input_method::GetLanguageDisplayNameFromCode(locales[i]); |
| 112 const std::wstring native_display_name = | 112 const std::wstring native_display_name = |
| 113 chromeos::input_method::GetLanguageNativeDisplayNameFromCode( | 113 input_method::GetLanguageNativeDisplayNameFromCode( |
| 114 locales[i]); | 114 locales[i]); |
| 115 display_names.push_back(display_name); | 115 display_names.push_back(display_name); |
| 116 language_map[display_name] = | 116 language_map[display_name] = |
| 117 std::make_pair(locales[i], native_display_name); | 117 std::make_pair(locales[i], native_display_name); |
| 118 } | 118 } |
| 119 DCHECK_EQ(display_names.size(), language_map.size()); | 119 DCHECK_EQ(display_names.size(), language_map.size()); |
| 120 | 120 |
| 121 // Sort display names using locale specific sorter. | 121 // Sort display names using locale specific sorter. |
| 122 l10n_util::SortStrings(g_browser_process->GetApplicationLocale(), | 122 l10n_util::SortStrings(g_browser_process->GetApplicationLocale(), |
| 123 &display_names); | 123 &display_names); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 150 NOTREACHED(); | 150 NOTREACHED(); |
| 151 LOG(INFO) << "NOTREACHED"; | 151 LOG(INFO) << "NOTREACHED"; |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 PrefService* prefs = g_browser_process->local_state(); | 154 PrefService* prefs = g_browser_process->local_state(); |
| 155 prefs->SetString(prefs::kApplicationLocale, language_code); | 155 prefs->SetString(prefs::kApplicationLocale, language_code); |
| 156 prefs->SavePersistentPrefs(); | 156 prefs->SavePersistentPrefs(); |
| 157 dom_ui_->CallJavascriptFunction( | 157 dom_ui_->CallJavascriptFunction( |
| 158 L"options.LanguageOptions.uiLanguageSaved"); | 158 L"options.LanguageOptions.uiLanguageSaved"); |
| 159 } | 159 } |
| 160 |
| 161 } // namespace chromeos |
| OLD | NEW |