Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(csilv): This is for the move CL. Changes to make this cross-platform | |
| 6 // will come in the followup CL. | |
| 7 #if defined(OS_CHROMEOS) | |
| 8 | |
| 9 #include "chrome/browser/dom_ui/options/language_options_handler.h" | 5 #include "chrome/browser/dom_ui/options/language_options_handler.h" |
| 10 | 6 |
| 11 #include <map> | 7 #include <map> |
| 12 #include <set> | 8 #include <set> |
| 13 #include <string> | 9 #include <string> |
| 14 #include <utility> | 10 #include <utility> |
| 15 #include <vector> | 11 #include <vector> |
| 16 | 12 |
| 17 #include "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
| 18 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/command_line.h" | |
| 19 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 20 #include "base/values.h" | 17 #include "base/values.h" |
| 21 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/browser_list.h" | |
| 22 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 24 #include "chrome/browser/chromeos/cros/input_method_library.h" | |
| 25 #include "chrome/browser/chromeos/input_method/input_method_util.h" | |
| 26 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | |
| 27 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
| 29 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/common/chrome_switches.h" | |
| 30 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/spellcheck_common.h" | 28 #include "chrome/common/spellcheck_common.h" |
| 32 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 33 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 34 | 31 |
| 35 namespace chromeos { | 32 #if defined(OS_CHROMEOS) |
| 33 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 34 #include "chrome/browser/chromeos/cros/input_method_library.h" | |
| 35 #endif | |
| 36 | 36 |
| 37 LanguageOptionsHandler::LanguageOptionsHandler() { | 37 LanguageOptionsHandler::LanguageOptionsHandler() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 LanguageOptionsHandler::~LanguageOptionsHandler() { | 40 LanguageOptionsHandler::~LanguageOptionsHandler() { |
| 41 } | 41 } |
| 42 | 42 |
| 43 void LanguageOptionsHandler::GetLocalizedValues( | 43 void LanguageOptionsHandler::GetLocalizedValues( |
| 44 DictionaryValue* localized_strings) { | 44 DictionaryValue* localized_strings) { |
| 45 DCHECK(localized_strings); | 45 DCHECK(localized_strings); |
| 46 string16 product_name; | |
| 47 #if defined(OS_CHROMEOS) | |
| 48 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME); | |
| 49 #else | |
| 50 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | |
| 51 #endif | |
| 46 localized_strings->SetString("languagePage", | 52 localized_strings->SetString("languagePage", |
| 47 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_DIALOG_TITLE)); | 53 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_DIALOG_TITLE)); |
| 48 localized_strings->SetString("add_button", | 54 localized_strings->SetString("add_button", |
| 49 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_BUTTON)); | 55 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_BUTTON)); |
| 50 localized_strings->SetString("configure", | |
| 51 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CONFIGURE)); | |
| 52 localized_strings->SetString("input_method", | |
| 53 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD)); | |
| 54 localized_strings->SetString("languages", | 56 localized_strings->SetString("languages", |
| 55 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_LANGUAGES)); | 57 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_LANGUAGES)); |
| 56 localized_strings->SetString("please_add_another_input_method", | |
| 57 l10n_util::GetStringUTF16( | |
| 58 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_INPUT_METHOD)); | |
| 59 localized_strings->SetString("please_add_another_language", | 58 localized_strings->SetString("please_add_another_language", |
| 60 l10n_util::GetStringUTF16( | 59 l10n_util::GetStringUTF16( |
| 61 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE)); | 60 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE)); |
| 62 localized_strings->SetString("ok_button", l10n_util::GetStringUTF16(IDS_OK)); | |
| 63 localized_strings->SetString("remove_button", | 61 localized_strings->SetString("remove_button", |
| 64 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); | 62 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); |
| 65 localized_strings->SetString("sign_out_button", | |
| 66 l10n_util::GetStringUTF16( | |
| 67 IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON)); | |
| 68 localized_strings->SetString("add_language_instructions", | 63 localized_strings->SetString("add_language_instructions", |
| 69 l10n_util::GetStringUTF16( | 64 l10n_util::GetStringUTF16( |
| 70 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); | 65 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); |
| 71 localized_strings->SetString("input_method_instructions", | |
| 72 l10n_util::GetStringUTF16( | |
| 73 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_INSTRUCTIONS)); | |
| 74 localized_strings->SetString("switch_input_methods_hint", | |
| 75 l10n_util::GetStringFUTF16( | |
| 76 IDS_OPTIONS_SETTINGS_LANGUAGES_SWITCH_INPUT_METHODS_HINT, | |
| 77 ASCIIToUTF16("alt+shift"))); | |
| 78 localized_strings->SetString("select_previous_input_method_hint", | |
| 79 l10n_util::GetStringFUTF16( | |
| 80 IDS_OPTIONS_SETTINGS_LANGUAGES_SELECT_PREVIOUS_INPUT_METHOD_HINT, | |
| 81 ASCIIToUTF16("ctrl+space"))); | |
| 82 localized_strings->SetString("cannot_be_displayed_in_this_language", | 66 localized_strings->SetString("cannot_be_displayed_in_this_language", |
| 83 l10n_util::GetStringFUTF16( | 67 l10n_util::GetStringFUTF16( |
| 84 IDS_OPTIONS_SETTINGS_LANGUAGES_CANNOT_BE_DISPLAYED_IN_THIS_LANGUAGE, | 68 IDS_OPTIONS_SETTINGS_LANGUAGES_CANNOT_BE_DISPLAYED_IN_THIS_LANGUAGE, |
| 85 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME))); | 69 product_name)); |
| 86 localized_strings->SetString("is_displayed_in_this_language", | 70 localized_strings->SetString("is_displayed_in_this_language", |
| 87 l10n_util::GetStringFUTF16( | 71 l10n_util::GetStringFUTF16( |
| 88 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, | 72 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, |
| 89 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME))); | 73 product_name)); |
| 90 localized_strings->SetString("display_in_this_language", | 74 localized_strings->SetString("display_in_this_language", |
| 91 l10n_util::GetStringFUTF16( | 75 l10n_util::GetStringFUTF16( |
| 92 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, | 76 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, |
| 93 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME))); | 77 product_name)); |
| 94 localized_strings->SetString("sign_out_required", | |
| 95 l10n_util::GetStringUTF16(IDS_OPTIONS_RESTART_REQUIRED)); | |
| 96 localized_strings->SetString("this_language_is_currently_in_use", | 78 localized_strings->SetString("this_language_is_currently_in_use", |
| 97 l10n_util::GetStringFUTF16( | 79 l10n_util::GetStringFUTF16( |
| 98 IDS_OPTIONS_SETTINGS_LANGUAGES_THIS_LANGUAGE_IS_CURRENTLY_IN_USE, | 80 IDS_OPTIONS_SETTINGS_LANGUAGES_THIS_LANGUAGE_IS_CURRENTLY_IN_USE, |
| 99 l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME))); | 81 product_name)); |
| 100 localized_strings->SetString("use_this_for_spell_checking", | 82 localized_strings->SetString("use_this_for_spell_checking", |
| 101 l10n_util::GetStringUTF16( | 83 l10n_util::GetStringUTF16( |
| 102 IDS_OPTIONS_SETTINGS_USE_THIS_FOR_SPELL_CHECKING)); | 84 IDS_OPTIONS_SETTINGS_USE_THIS_FOR_SPELL_CHECKING)); |
| 103 localized_strings->SetString("cannot_be_used_for_spell_checking", | 85 localized_strings->SetString("cannot_be_used_for_spell_checking", |
| 104 l10n_util::GetStringUTF16( | 86 l10n_util::GetStringUTF16( |
| 105 IDS_OPTIONS_SETTINGS_CANNOT_BE_USED_FOR_SPELL_CHECKING)); | 87 IDS_OPTIONS_SETTINGS_CANNOT_BE_USED_FOR_SPELL_CHECKING)); |
| 106 localized_strings->SetString("is_used_for_spell_checking", | 88 localized_strings->SetString("is_used_for_spell_checking", |
| 107 l10n_util::GetStringUTF16( | 89 l10n_util::GetStringUTF16( |
| 108 IDS_OPTIONS_SETTINGS_IS_USED_FOR_SPELL_CHECKING)); | 90 IDS_OPTIONS_SETTINGS_IS_USED_FOR_SPELL_CHECKING)); |
| 91 localized_strings->SetString("restart_required", | |
| 92 l10n_util::GetStringUTF16(IDS_OPTIONS_RESTART_REQUIRED)); | |
| 93 localized_strings->SetString("enable_spell_check", | |
| 94 l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_SPELLCHECK)); | |
| 95 localized_strings->SetString("enable_auto_spell_correction", | |
| 96 l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_AUTO_SPELL_CORRECTION)); | |
| 97 localized_strings->SetString("add_language_title", | |
| 98 l10n_util::GetStringUTF16(IDS_OPTIONS_LANGUAGES_ADD_TITLE)); | |
| 99 localized_strings->SetString("add_language_select_label", | |
| 100 l10n_util::GetStringUTF16(IDS_OPTIONS_LANGUAGES_ADD_SELECT_LABEL)); | |
| 109 | 101 |
| 110 // GetSupportedInputMethods() never return NULL. | 102 #if defined(OS_CHROMEOS) |
| 111 scoped_ptr<InputMethodDescriptors> descriptors( | 103 localized_strings->SetString("ok_button", l10n_util::GetStringUTF16(IDS_OK)); |
| 112 CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); | 104 localized_strings->SetString("configure", |
| 105 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CONFIGURE)); | |
| 106 localized_strings->SetString("input_method", | |
| 107 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD)); | |
| 108 localized_strings->SetString("please_add_another_input_method", | |
| 109 l10n_util::GetStringUTF16( | |
| 110 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_INPUT_METHOD)); | |
| 111 localized_strings->SetString("input_method_instructions", | |
| 112 l10n_util::GetStringUTF16( | |
| 113 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_INSTRUCTIONS)); | |
| 114 localized_strings->SetString("switch_input_methods_hint", | |
| 115 l10n_util::GetStringFUTF16( | |
| 116 IDS_OPTIONS_SETTINGS_LANGUAGES_SWITCH_INPUT_METHODS_HINT, | |
| 117 ASCIIToUTF16("alt+shift"))); | |
| 118 localized_strings->SetString("select_previous_input_method_hint", | |
| 119 l10n_util::GetStringFUTF16( | |
| 120 IDS_OPTIONS_SETTINGS_LANGUAGES_SELECT_PREVIOUS_INPUT_METHOD_HINT, | |
| 121 ASCIIToUTF16("ctrl+space"))); | |
| 122 localized_strings->SetString("restart_button", | |
| 123 l10n_util::GetStringUTF16( | |
| 124 IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON)); | |
| 125 #else | |
| 126 localized_strings->SetString("restart_button", | |
| 127 l10n_util::GetStringUTF16( | |
| 128 IDS_OPTIONS_SETTINGS_LANGUAGES_RESTART_BUTTON)); | |
| 129 #endif | |
| 113 | 130 |
| 114 // The followigns are resources, rather than local strings. | 131 // The followigns are resources, rather than local strings. |
| 115 localized_strings->SetString("currentUiLanguageCode", | 132 localized_strings->SetString("currentUiLanguageCode", |
| 116 g_browser_process->GetApplicationLocale()); | 133 g_browser_process->GetApplicationLocale()); |
| 117 localized_strings->Set("inputMethodList", GetInputMethodList(*descriptors)); | |
| 118 localized_strings->Set("languageList", GetLanguageList(*descriptors)); | |
| 119 localized_strings->Set("spellCheckLanguageCodeSet", | 134 localized_strings->Set("spellCheckLanguageCodeSet", |
| 120 GetSpellCheckLanguageCodeSet()); | 135 GetSpellCheckLanguageCodeSet()); |
| 121 localized_strings->Set("uiLanguageCodeSet", GetUiLanguageCodeSet()); | 136 localized_strings->Set("uiLanguageCodeSet", GetUiLanguageCodeSet()); |
| 137 | |
| 138 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 139 bool experimental_spell_check_features = | |
| 140 command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures); | |
| 141 localized_strings->SetString("experimentalSpellCheckFeatures", | |
| 142 experimental_spell_check_features ? "true" : "false"); | |
| 143 | |
| 144 #if defined(OS_CHROMEOS) | |
| 145 // GetSupportedInputMethods() never return NULL. | |
| 146 scoped_ptr<chromeos::InputMethodDescriptors> descriptors( | |
| 147 chromeos::CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMe thods()); | |
|
James Hawkins
2011/01/20 03:11:08
80cols.
csilv
2011/01/20 20:09:55
Done.
| |
| 148 localized_strings->Set("languageList", GetLanguageList(*descriptors)); | |
| 149 localized_strings->Set("inputMethodList", GetInputMethodList(*descriptors)); | |
| 150 #else | |
| 151 localized_strings->Set("languageList", GetLanguageList()); | |
| 152 #endif | |
| 122 } | 153 } |
| 123 | 154 |
| 124 void LanguageOptionsHandler::RegisterMessages() { | 155 void LanguageOptionsHandler::RegisterMessages() { |
| 125 DCHECK(dom_ui_); | 156 DCHECK(dom_ui_); |
| 157 #if defined(OS_CHROMEOS) | |
| 126 dom_ui_->RegisterMessageCallback("inputMethodDisable", | 158 dom_ui_->RegisterMessageCallback("inputMethodDisable", |
| 127 NewCallback(this, &LanguageOptionsHandler::InputMethodDisableCallback)); | 159 NewCallback(this, &LanguageOptionsHandler::InputMethodDisableCallback)); |
| 128 dom_ui_->RegisterMessageCallback("inputMethodEnable", | 160 dom_ui_->RegisterMessageCallback("inputMethodEnable", |
| 129 NewCallback(this, &LanguageOptionsHandler::InputMethodEnableCallback)); | 161 NewCallback(this, &LanguageOptionsHandler::InputMethodEnableCallback)); |
| 130 dom_ui_->RegisterMessageCallback("inputMethodOptionsOpen", | 162 dom_ui_->RegisterMessageCallback("inputMethodOptionsOpen", |
| 131 NewCallback(this, | 163 NewCallback(this, |
| 132 &LanguageOptionsHandler::InputMethodOptionsOpenCallback)); | 164 &LanguageOptionsHandler::InputMethodOptionsOpenCallback)); |
| 165 #endif | |
| 133 dom_ui_->RegisterMessageCallback("languageOptionsOpen", | 166 dom_ui_->RegisterMessageCallback("languageOptionsOpen", |
| 134 NewCallback(this, &LanguageOptionsHandler::LanguageOptionsOpenCallback)); | 167 NewCallback(this, &LanguageOptionsHandler::LanguageOptionsOpenCallback)); |
| 135 dom_ui_->RegisterMessageCallback("spellCheckLanguageChange", | 168 dom_ui_->RegisterMessageCallback("spellCheckLanguageChange", |
| 136 NewCallback(this, | 169 NewCallback(this, |
| 137 &LanguageOptionsHandler::SpellCheckLanguageChangeCallback)); | 170 &LanguageOptionsHandler::SpellCheckLanguageChangeCallback)); |
| 138 dom_ui_->RegisterMessageCallback("uiLanguageChange", | 171 dom_ui_->RegisterMessageCallback("uiLanguageChange", |
| 139 NewCallback(this, &LanguageOptionsHandler::UiLanguageChangeCallback)); | 172 NewCallback(this, &LanguageOptionsHandler::UiLanguageChangeCallback)); |
| 140 dom_ui_->RegisterMessageCallback("uiLanguageSignOut", | 173 dom_ui_->RegisterMessageCallback("uiLanguageRestart", |
| 141 NewCallback(this, &LanguageOptionsHandler::SignOutCallback)); | 174 NewCallback(this, &LanguageOptionsHandler::RestartCallback)); |
| 142 } | 175 } |
| 143 | 176 |
| 177 #if defined(OS_CHROMEOS) | |
| 144 ListValue* LanguageOptionsHandler::GetInputMethodList( | 178 ListValue* LanguageOptionsHandler::GetInputMethodList( |
| 145 const InputMethodDescriptors& descriptors) { | 179 const chromeos::InputMethodDescriptors& descriptors) { |
| 146 ListValue* input_method_list = new ListValue(); | 180 ListValue* input_method_list = new ListValue(); |
| 147 | 181 |
| 148 for (size_t i = 0; i < descriptors.size(); ++i) { | 182 for (size_t i = 0; i < descriptors.size(); ++i) { |
| 149 const InputMethodDescriptor& descriptor = descriptors[i]; | 183 const chromeos::InputMethodDescriptor& descriptor = descriptors[i]; |
| 150 const std::string language_code = | 184 const std::string language_code = |
| 151 input_method::GetLanguageCodeFromDescriptor(descriptor); | 185 chromeos::input_method::GetLanguageCodeFromDescriptor(descriptor); |
| 152 const std::string display_name = | 186 const std::string display_name = |
| 153 input_method::GetInputMethodDisplayNameFromId(descriptor.id); | 187 chromeos::input_method::GetInputMethodDisplayNameFromId(descriptor.id); |
| 154 | 188 |
| 155 DictionaryValue* dictionary = new DictionaryValue(); | 189 DictionaryValue* dictionary = new DictionaryValue(); |
| 156 dictionary->SetString("id", descriptor.id); | 190 dictionary->SetString("id", descriptor.id); |
| 157 dictionary->SetString("displayName", display_name); | 191 dictionary->SetString("displayName", display_name); |
| 158 | 192 |
| 159 // One input method can be associated with multiple languages, hence | 193 // One input method can be associated with multiple languages, hence |
| 160 // we use a dictionary here. | 194 // we use a dictionary here. |
| 161 DictionaryValue* language_codes = new DictionaryValue(); | 195 DictionaryValue* language_codes = new DictionaryValue(); |
| 162 language_codes->SetBoolean(language_code, true); | 196 language_codes->SetBoolean(language_code, true); |
| 163 // Check kExtraLanguages to see if there are languages associated with | 197 // Check kExtraLanguages to see if there are languages associated with |
| 164 // this input method. If these are present, add these. | 198 // this input method. If these are present, add these. |
| 165 for (size_t j = 0; j < arraysize(input_method::kExtraLanguages); ++j) { | 199 for (size_t j = 0; j < arraysize(chromeos::input_method::kExtraLanguages); |
| 200 ++j) { | |
| 166 const std::string extra_input_method_id = | 201 const std::string extra_input_method_id = |
| 167 input_method::kExtraLanguages[j].input_method_id; | 202 chromeos::input_method::kExtraLanguages[j].input_method_id; |
| 168 const std::string extra_language_code = | 203 const std::string extra_language_code = |
| 169 input_method::kExtraLanguages[j].language_code; | 204 chromeos::input_method::kExtraLanguages[j].language_code; |
| 170 if (extra_input_method_id == descriptor.id) { | 205 if (extra_input_method_id == descriptor.id) { |
| 171 language_codes->SetBoolean(extra_language_code, true); | 206 language_codes->SetBoolean(extra_language_code, true); |
| 172 } | 207 } |
| 173 } | 208 } |
| 174 dictionary->Set("languageCodeSet", language_codes); | 209 dictionary->Set("languageCodeSet", language_codes); |
| 175 | 210 |
| 176 input_method_list->Append(dictionary); | 211 input_method_list->Append(dictionary); |
| 177 } | 212 } |
| 178 | 213 |
| 179 return input_method_list; | 214 return input_method_list; |
| 180 } | 215 } |
| 181 | 216 |
| 182 ListValue* LanguageOptionsHandler::GetLanguageList( | 217 ListValue* LanguageOptionsHandler::GetLanguageList( |
| 183 const InputMethodDescriptors& descriptors) { | 218 const chromeos::InputMethodDescriptors& descriptors) { |
| 184 std::set<std::string> language_codes; | 219 std::set<std::string> language_codes; |
| 185 // Collect the language codes from the supported input methods. | 220 // Collect the language codes from the supported input methods. |
| 186 for (size_t i = 0; i < descriptors.size(); ++i) { | 221 for (size_t i = 0; i < descriptors.size(); ++i) { |
| 187 const InputMethodDescriptor& descriptor = descriptors[i]; | 222 const chromeos::InputMethodDescriptor& descriptor = descriptors[i]; |
| 188 const std::string language_code = | 223 const std::string language_code = |
| 189 input_method::GetLanguageCodeFromDescriptor(descriptor); | 224 chromeos::input_method::GetLanguageCodeFromDescriptor(descriptor); |
| 190 language_codes.insert(language_code); | 225 language_codes.insert(language_code); |
| 191 } | 226 } |
| 192 // Collect the language codes from kExtraLanguages. | 227 // Collect the language codes from kExtraLanguages. |
| 193 for (size_t i = 0; i < arraysize(input_method::kExtraLanguages); ++i) { | 228 for (size_t i = 0; i < arraysize(chromeos::input_method::kExtraLanguages); |
| 229 ++i) { | |
| 194 const char* language_code = | 230 const char* language_code = |
| 195 input_method::kExtraLanguages[i].language_code; | 231 chromeos::input_method::kExtraLanguages[i].language_code; |
| 196 language_codes.insert(language_code); | 232 language_codes.insert(language_code); |
| 197 } | 233 } |
| 198 | 234 |
| 199 // Map of display name -> {language code, native_display_name}. | 235 // Map of display name -> {language code, native_display_name}. |
| 200 // In theory, we should be able to create a map that is sorted by | 236 // In theory, we should be able to create a map that is sorted by |
| 201 // display names using ICU comparator, but doing it is hard, thus we'll | 237 // display names using ICU comparator, but doing it is hard, thus we'll |
| 202 // use an auxiliary vector to achieve the same result. | 238 // use an auxiliary vector to achieve the same result. |
| 203 typedef std::pair<std::string, string16> LanguagePair; | 239 typedef std::pair<std::string, string16> LanguagePair; |
| 204 typedef std::map<string16, LanguagePair> LanguageMap; | 240 typedef std::map<string16, LanguagePair> LanguageMap; |
| 205 LanguageMap language_map; | 241 LanguageMap language_map; |
| 206 // The auxiliary vector mentioned above. | 242 // The auxiliary vector mentioned above. |
| 207 std::vector<string16> display_names; | 243 std::vector<string16> display_names; |
| 208 | 244 |
| 209 // Build the list of display names, and build the language map. | 245 // Build the list of display names, and build the language map. |
| 210 for (std::set<std::string>::const_iterator iter = language_codes.begin(); | 246 for (std::set<std::string>::const_iterator iter = language_codes.begin(); |
| 211 iter != language_codes.end(); ++iter) { | 247 iter != language_codes.end(); ++iter) { |
| 212 const string16 display_name = | 248 const string16 display_name = |
| 213 input_method::GetLanguageDisplayNameFromCode(*iter); | 249 chromeos::input_method::GetLanguageDisplayNameFromCode(*iter); |
| 214 const string16 native_display_name = | 250 const string16 native_display_name = |
| 215 input_method::GetLanguageNativeDisplayNameFromCode(*iter); | 251 chromeos::input_method::GetLanguageNativeDisplayNameFromCode(*iter); |
| 216 display_names.push_back(display_name); | 252 display_names.push_back(display_name); |
| 217 language_map[display_name] = | 253 language_map[display_name] = |
| 218 std::make_pair(*iter, native_display_name); | 254 std::make_pair(*iter, native_display_name); |
| 219 } | 255 } |
| 220 DCHECK_EQ(display_names.size(), language_map.size()); | 256 DCHECK_EQ(display_names.size(), language_map.size()); |
| 221 | 257 |
| 222 // Sort display names using locale specific sorter. | 258 // Sort display names using locale specific sorter. |
| 223 l10n_util::SortStrings16(g_browser_process->GetApplicationLocale(), | 259 l10n_util::SortStrings16(g_browser_process->GetApplicationLocale(), |
| 224 &display_names); | 260 &display_names); |
| 225 | 261 |
| 226 // Build the language list from the language map. | 262 // Build the language list from the language map. |
| 227 ListValue* language_list = new ListValue(); | 263 ListValue* language_list = new ListValue(); |
| 228 for (size_t i = 0; i < display_names.size(); ++i) { | 264 for (size_t i = 0; i < display_names.size(); ++i) { |
| 229 const LanguagePair& pair = language_map[display_names[i]]; | 265 const LanguagePair& pair = language_map[display_names[i]]; |
| 230 DictionaryValue* dictionary = new DictionaryValue(); | 266 DictionaryValue* dictionary = new DictionaryValue(); |
| 231 dictionary->SetString("code", pair.first); | 267 dictionary->SetString("code", pair.first); |
| 232 dictionary->SetString("displayName", display_names[i]); | 268 dictionary->SetString("displayName", display_names[i]); |
| 233 dictionary->SetString("nativeDisplayName", pair.second); | 269 dictionary->SetString("nativeDisplayName", pair.second); |
| 234 language_list->Append(dictionary); | 270 language_list->Append(dictionary); |
| 235 } | 271 } |
| 236 | 272 |
| 237 return language_list; | 273 return language_list; |
| 238 } | 274 } |
| 275 #endif | |
| 276 | |
| 277 #if !defined(OS_CHROMEOS) | |
| 278 ListValue* LanguageOptionsHandler::GetLanguageList() { | |
| 279 // Collect the language codes from the supported accept-languages. | |
| 280 const std::string app_locale = g_browser_process->GetApplicationLocale(); | |
| 281 std::vector<std::string> language_codes; | |
| 282 l10n_util::GetAcceptLanguagesForLocale(app_locale, &language_codes); | |
| 283 | |
| 284 // Map of display name -> {language code, native_display_name}. | |
| 285 // In theory, we should be able to create a map that is sorted by | |
| 286 // display names using ICU comparator, but doing it is hard, thus we'll | |
| 287 // use an auxiliary vector to achieve the same result. | |
| 288 typedef std::pair<std::string, string16> LanguagePair; | |
| 289 typedef std::map<string16, LanguagePair> LanguageMap; | |
| 290 LanguageMap language_map; | |
| 291 // The auxiliary vector mentioned above. | |
| 292 std::vector<string16> display_names; | |
| 293 | |
| 294 // Build the list of display names, and build the language map. | |
| 295 for (size_t i = 0; i < language_codes.size(); ++i) { | |
| 296 const string16 display_name = | |
| 297 l10n_util::GetDisplayNameForLocale(language_codes[i], app_locale, true); | |
| 298 const string16 native_display_name = | |
| 299 l10n_util::GetDisplayNameForLocale(language_codes[i], language_codes[i], | |
| 300 true); | |
| 301 display_names.push_back(display_name); | |
| 302 language_map[display_name] = | |
| 303 std::make_pair(language_codes[i], native_display_name); | |
| 304 } | |
| 305 DCHECK_EQ(display_names.size(), language_map.size()); | |
| 306 | |
| 307 // Sort display names using locale specific sorter. | |
| 308 l10n_util::SortStrings16(app_locale, &display_names); | |
| 309 | |
| 310 // Build the language list from the language map. | |
| 311 ListValue* language_list = new ListValue(); | |
| 312 for (size_t i = 0; i < display_names.size(); ++i) { | |
| 313 const LanguagePair& pair = language_map[display_names[i]]; | |
| 314 DictionaryValue* dictionary = new DictionaryValue(); | |
| 315 dictionary->SetString("code", pair.first); | |
| 316 dictionary->SetString("displayName", display_names[i]); | |
| 317 dictionary->SetString("nativeDisplayName", pair.second); | |
| 318 language_list->Append(dictionary); | |
| 319 } | |
| 320 | |
| 321 return language_list; | |
| 322 } | |
| 323 #endif | |
| 239 | 324 |
| 240 DictionaryValue* LanguageOptionsHandler::GetUiLanguageCodeSet() { | 325 DictionaryValue* LanguageOptionsHandler::GetUiLanguageCodeSet() { |
| 241 DictionaryValue* dictionary = new DictionaryValue(); | 326 DictionaryValue* dictionary = new DictionaryValue(); |
| 242 const std::vector<std::string>& available_locales = | 327 const std::vector<std::string>& available_locales = |
| 243 l10n_util::GetAvailableLocales(); | 328 l10n_util::GetAvailableLocales(); |
| 244 for (size_t i = 0; i < available_locales.size(); ++i) { | 329 for (size_t i = 0; i < available_locales.size(); ++i) { |
| 245 dictionary->SetBoolean(available_locales[i], true); | 330 dictionary->SetBoolean(available_locales[i], true); |
| 246 } | 331 } |
| 247 return dictionary; | 332 return dictionary; |
| 248 } | 333 } |
| 249 | 334 |
| 250 DictionaryValue* LanguageOptionsHandler::GetSpellCheckLanguageCodeSet() { | 335 DictionaryValue* LanguageOptionsHandler::GetSpellCheckLanguageCodeSet() { |
| 251 DictionaryValue* dictionary = new DictionaryValue(); | 336 DictionaryValue* dictionary = new DictionaryValue(); |
| 252 std::vector<std::string> spell_check_languages; | 337 std::vector<std::string> spell_check_languages; |
| 253 SpellCheckCommon::SpellCheckLanguages(&spell_check_languages); | 338 SpellCheckCommon::SpellCheckLanguages(&spell_check_languages); |
| 254 for (size_t i = 0; i < spell_check_languages.size(); ++i) { | 339 for (size_t i = 0; i < spell_check_languages.size(); ++i) { |
| 255 dictionary->SetBoolean(spell_check_languages[i], true); | 340 dictionary->SetBoolean(spell_check_languages[i], true); |
| 256 } | 341 } |
| 257 return dictionary; | 342 return dictionary; |
| 258 } | 343 } |
| 259 | 344 |
| 345 #if defined(OS_CHROMEOS) | |
| 260 void LanguageOptionsHandler::InputMethodDisableCallback( | 346 void LanguageOptionsHandler::InputMethodDisableCallback( |
| 261 const ListValue* args) { | 347 const ListValue* args) { |
| 262 const std::string input_method_id = WideToASCII(ExtractStringValue(args)); | 348 const std::string input_method_id = WideToASCII(ExtractStringValue(args)); |
| 263 const std::string action = StringPrintf( | 349 const std::string action = StringPrintf( |
| 264 "LanguageOptions_DisableInputMethod_%s", input_method_id.c_str()); | 350 "LanguageOptions_DisableInputMethod_%s", input_method_id.c_str()); |
| 265 UserMetrics::RecordComputedAction(action); | 351 UserMetrics::RecordComputedAction(action); |
| 266 } | 352 } |
| 267 | 353 |
| 268 void LanguageOptionsHandler::InputMethodEnableCallback( | 354 void LanguageOptionsHandler::InputMethodEnableCallback( |
| 269 const ListValue* args) { | 355 const ListValue* args) { |
| 270 const std::string input_method_id = WideToASCII(ExtractStringValue(args)); | 356 const std::string input_method_id = WideToASCII(ExtractStringValue(args)); |
| 271 const std::string action = StringPrintf( | 357 const std::string action = StringPrintf( |
| 272 "LanguageOptions_EnableInputMethod_%s", input_method_id.c_str()); | 358 "LanguageOptions_EnableInputMethod_%s", input_method_id.c_str()); |
| 273 UserMetrics::RecordComputedAction(action); | 359 UserMetrics::RecordComputedAction(action); |
| 274 } | 360 } |
| 275 | 361 |
| 276 void LanguageOptionsHandler::InputMethodOptionsOpenCallback( | 362 void LanguageOptionsHandler::InputMethodOptionsOpenCallback( |
| 277 const ListValue* args) { | 363 const ListValue* args) { |
| 278 const std::string input_method_id = WideToASCII(ExtractStringValue(args)); | 364 const std::string input_method_id = WideToASCII(ExtractStringValue(args)); |
| 279 const std::string action = StringPrintf( | 365 const std::string action = StringPrintf( |
| 280 "InputMethodOptions_Open_%s", input_method_id.c_str()); | 366 "InputMethodOptions_Open_%s", input_method_id.c_str()); |
| 281 UserMetrics::RecordComputedAction(action); | 367 UserMetrics::RecordComputedAction(action); |
| 282 } | 368 } |
| 369 #endif | |
| 283 | 370 |
| 284 void LanguageOptionsHandler::LanguageOptionsOpenCallback( | 371 void LanguageOptionsHandler::LanguageOptionsOpenCallback( |
| 285 const ListValue* args) { | 372 const ListValue* args) { |
| 286 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_Open")); | 373 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_Open")); |
| 287 } | 374 } |
| 288 | 375 |
| 289 void LanguageOptionsHandler::UiLanguageChangeCallback( | 376 void LanguageOptionsHandler::UiLanguageChangeCallback( |
| 290 const ListValue* args) { | 377 const ListValue* args) { |
| 291 const std::string language_code = WideToASCII(ExtractStringValue(args)); | 378 const std::string language_code = WideToASCII(ExtractStringValue(args)); |
| 292 CHECK(!language_code.empty()); | 379 CHECK(!language_code.empty()); |
| 293 const std::string action = StringPrintf( | 380 const std::string action = StringPrintf( |
| 294 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); | 381 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); |
| 295 UserMetrics::RecordComputedAction(action); | 382 UserMetrics::RecordComputedAction(action); |
| 383 #if defined(OS_CHROMEOS) | |
| 296 dom_ui_->GetProfile()->ChangeApplicationLocale(language_code, false); | 384 dom_ui_->GetProfile()->ChangeApplicationLocale(language_code, false); |
| 385 #else | |
| 386 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); | |
| 387 prefs->SetString(prefs::kApplicationLocale, language_code); | |
| 388 #endif | |
| 297 dom_ui_->CallJavascriptFunction( | 389 dom_ui_->CallJavascriptFunction( |
| 298 L"options.LanguageOptions.uiLanguageSaved"); | 390 L"options.LanguageOptions.uiLanguageSaved"); |
| 299 } | 391 } |
| 300 | 392 |
| 301 void LanguageOptionsHandler::SpellCheckLanguageChangeCallback( | 393 void LanguageOptionsHandler::SpellCheckLanguageChangeCallback( |
| 302 const ListValue* args) { | 394 const ListValue* args) { |
| 303 const std::string language_code = WideToASCII(ExtractStringValue(args)); | 395 const std::string language_code = WideToASCII(ExtractStringValue(args)); |
| 304 CHECK(!language_code.empty()); | 396 CHECK(!language_code.empty()); |
| 305 const std::string action = StringPrintf( | 397 const std::string action = StringPrintf( |
| 306 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); | 398 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); |
| 307 UserMetrics::RecordComputedAction(action); | 399 UserMetrics::RecordComputedAction(action); |
| 308 } | 400 } |
| 309 | 401 |
| 310 void LanguageOptionsHandler::SignOutCallback(const ListValue* args) { | 402 void LanguageOptionsHandler::RestartCallback(const ListValue* args) { |
| 403 #if defined(OS_CHROMEOS) | |
| 311 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_SignOut")); | 404 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_SignOut")); |
| 312 | 405 |
| 313 Browser* browser = Browser::GetBrowserForController( | 406 Browser* browser = Browser::GetBrowserForController( |
| 314 &dom_ui_->tab_contents()->controller(), NULL); | 407 &dom_ui_->tab_contents()->controller(), NULL); |
| 315 if (browser) | 408 if (browser) |
| 316 browser->ExecuteCommand(IDC_EXIT); | 409 browser->ExecuteCommand(IDC_EXIT); |
| 410 #else | |
| 411 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_Restart")); | |
| 412 | |
| 413 // Set the flag to restore state after the restart. | |
| 414 PrefService* pref_service = g_browser_process->local_state(); | |
| 415 pref_service->SetBoolean(prefs::kRestartLastSessionOnShutdown, true); | |
| 416 BrowserList::CloseAllBrowsersAndExit(); | |
| 417 #endif | |
| 317 } | 418 } |
| 318 | 419 |
| 319 } // namespace chromeos | |
| 320 | |
| 321 #endif // OS_CHROMEOS | |
| 322 | |
| OLD | NEW |