OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/options/chromeos/cros_language_options_handler
.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler
.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 l10n_util::GetStringUTF16( | 87 l10n_util::GetStringUTF16( |
88 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_EXTENSION_DESCRIPTION)); | 88 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_EXTENSION_DESCRIPTION)); |
89 localized_strings->SetString("noInputMethods", | 89 localized_strings->SetString("noInputMethods", |
90 l10n_util::GetStringUTF16( | 90 l10n_util::GetStringUTF16( |
91 IDS_OPTIONS_SETTINGS_LANGUAGES_NO_INPUT_METHODS)); | 91 IDS_OPTIONS_SETTINGS_LANGUAGES_NO_INPUT_METHODS)); |
92 localized_strings->SetString("activateImeMenu", | 92 localized_strings->SetString("activateImeMenu", |
93 l10n_util::GetStringUTF16( | 93 l10n_util::GetStringUTF16( |
94 IDS_OPTIONS_SETTINGS_LANGUAGES_ACTIVATE_IME_MENU)); | 94 IDS_OPTIONS_SETTINGS_LANGUAGES_ACTIVATE_IME_MENU)); |
95 | 95 |
96 // GetSupportedInputMethods() never returns NULL. | 96 // GetSupportedInputMethods() never returns NULL. |
97 localized_strings->Set("languageList", GetAcceptLanguageList()); | 97 localized_strings->Set("languageList", GetAcceptLanguageList().release()); |
98 localized_strings->Set("inputMethodList", GetInputMethodList()); | 98 localized_strings->Set("inputMethodList", GetInputMethodList()); |
99 | 99 |
100 input_method::InputMethodManager* manager = | 100 input_method::InputMethodManager* manager = |
101 input_method::InputMethodManager::Get(); | 101 input_method::InputMethodManager::Get(); |
102 input_method::InputMethodDescriptors ext_ime_descriptors; | 102 input_method::InputMethodDescriptors ext_ime_descriptors; |
103 manager->GetActiveIMEState()->GetInputMethodExtensions(&ext_ime_descriptors); | 103 manager->GetActiveIMEState()->GetInputMethodExtensions(&ext_ime_descriptors); |
104 | 104 |
105 std::unique_ptr<base::ListValue> ext_ime_list = | 105 base::ListValue* ext_ime_list = ConvertInputMethodDescriptorsToIMEList( |
106 ConvertInputMethodDescriptorsToIMEList(ext_ime_descriptors); | 106 ext_ime_descriptors); |
107 AddImeProvider(ext_ime_list.get()); | 107 AddImeProvider(ext_ime_list); |
108 localized_strings->Set("extensionImeList", std::move(ext_ime_list)); | 108 localized_strings->Set("extensionImeList", ext_ime_list); |
109 | 109 |
110 ComponentExtensionIMEManager* component_extension_manager = | 110 ComponentExtensionIMEManager* component_extension_manager = |
111 input_method::InputMethodManager::Get() | 111 input_method::InputMethodManager::Get() |
112 ->GetComponentExtensionIMEManager(); | 112 ->GetComponentExtensionIMEManager(); |
113 localized_strings->Set( | 113 localized_strings->Set( |
114 "componentExtensionImeList", | 114 "componentExtensionImeList", |
115 ConvertInputMethodDescriptorsToIMEList( | 115 ConvertInputMethodDescriptorsToIMEList( |
116 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); | 116 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); |
117 } | 117 } |
118 | 118 |
119 void CrosLanguageOptionsHandler::RegisterMessages() { | 119 void CrosLanguageOptionsHandler::RegisterMessages() { |
120 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); | 120 ::options::LanguageOptionsHandlerCommon::RegisterMessages(); |
121 | 121 |
122 web_ui()->RegisterMessageCallback("inputMethodDisable", | 122 web_ui()->RegisterMessageCallback("inputMethodDisable", |
123 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, | 123 base::Bind(&CrosLanguageOptionsHandler::InputMethodDisableCallback, |
124 base::Unretained(this))); | 124 base::Unretained(this))); |
125 web_ui()->RegisterMessageCallback("inputMethodEnable", | 125 web_ui()->RegisterMessageCallback("inputMethodEnable", |
126 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, | 126 base::Bind(&CrosLanguageOptionsHandler::InputMethodEnableCallback, |
127 base::Unretained(this))); | 127 base::Unretained(this))); |
128 web_ui()->RegisterMessageCallback("inputMethodOptionsOpen", | 128 web_ui()->RegisterMessageCallback("inputMethodOptionsOpen", |
129 base::Bind(&CrosLanguageOptionsHandler::InputMethodOptionsOpenCallback, | 129 base::Bind(&CrosLanguageOptionsHandler::InputMethodOptionsOpenCallback, |
130 base::Unretained(this))); | 130 base::Unretained(this))); |
131 web_ui()->RegisterMessageCallback("uiLanguageRestart", | 131 web_ui()->RegisterMessageCallback("uiLanguageRestart", |
132 base::Bind(&CrosLanguageOptionsHandler::RestartCallback, | 132 base::Bind(&CrosLanguageOptionsHandler::RestartCallback, |
133 base::Unretained(this))); | 133 base::Unretained(this))); |
134 } | 134 } |
135 | 135 |
136 // static | 136 // static |
137 std::unique_ptr<base::ListValue> | 137 base::ListValue* CrosLanguageOptionsHandler::GetInputMethodList() { |
138 CrosLanguageOptionsHandler::GetInputMethodList() { | |
139 input_method::InputMethodManager* manager = | 138 input_method::InputMethodManager* manager = |
140 input_method::InputMethodManager::Get(); | 139 input_method::InputMethodManager::Get(); |
141 // GetSupportedInputMethods() never return NULL. | 140 // GetSupportedInputMethods() never return NULL. |
142 std::unique_ptr<input_method::InputMethodDescriptors> descriptors( | 141 std::unique_ptr<input_method::InputMethodDescriptors> descriptors( |
143 manager->GetSupportedInputMethods()); | 142 manager->GetSupportedInputMethods()); |
144 | 143 |
145 auto input_method_list = base::MakeUnique<base::ListValue>(); | 144 base::ListValue* input_method_list = new base::ListValue(); |
146 | 145 |
147 for (size_t i = 0; i < descriptors->size(); ++i) { | 146 for (size_t i = 0; i < descriptors->size(); ++i) { |
148 const input_method::InputMethodDescriptor& descriptor = | 147 const input_method::InputMethodDescriptor& descriptor = |
149 (*descriptors)[i]; | 148 (*descriptors)[i]; |
150 const std::string display_name = | 149 const std::string display_name = |
151 manager->GetInputMethodUtil()->GetInputMethodDisplayNameFromId( | 150 manager->GetInputMethodUtil()->GetInputMethodDisplayNameFromId( |
152 descriptor.id()); | 151 descriptor.id()); |
153 auto dictionary = base::MakeUnique<base::DictionaryValue>(); | 152 auto dictionary = base::MakeUnique<base::DictionaryValue>(); |
154 dictionary->SetString("id", descriptor.id()); | 153 dictionary->SetString("id", descriptor.id()); |
155 dictionary->SetString("displayName", display_name); | 154 dictionary->SetString("displayName", display_name); |
156 | 155 |
157 // One input method can be associated with multiple languages, hence | 156 // One input method can be associated with multiple languages, hence |
158 // we use a dictionary here. | 157 // we use a dictionary here. |
159 auto languages = base::MakeUnique<base::DictionaryValue>(); | 158 base::DictionaryValue* languages = new base::DictionaryValue(); |
160 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) { | 159 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) { |
161 languages->SetBoolean(descriptor.language_codes().at(i), true); | 160 languages->SetBoolean(descriptor.language_codes().at(i), true); |
162 } | 161 } |
163 dictionary->Set("languageCodeSet", std::move(languages)); | 162 dictionary->Set("languageCodeSet", languages); |
164 | 163 |
165 input_method_list->Append(std::move(dictionary)); | 164 input_method_list->Append(std::move(dictionary)); |
166 } | 165 } |
167 | 166 |
168 return input_method_list; | 167 return input_method_list; |
169 } | 168 } |
170 | 169 |
171 std::unique_ptr<base::ListValue> | 170 base::ListValue* |
172 CrosLanguageOptionsHandler::ConvertInputMethodDescriptorsToIMEList( | 171 CrosLanguageOptionsHandler::ConvertInputMethodDescriptorsToIMEList( |
173 const input_method::InputMethodDescriptors& descriptors) { | 172 const input_method::InputMethodDescriptors& descriptors) { |
174 input_method::InputMethodUtil* util = | 173 input_method::InputMethodUtil* util = |
175 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 174 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
176 std::unique_ptr<base::ListValue> ime_ids_list(new base::ListValue()); | 175 std::unique_ptr<base::ListValue> ime_ids_list(new base::ListValue()); |
177 for (size_t i = 0; i < descriptors.size(); ++i) { | 176 for (size_t i = 0; i < descriptors.size(); ++i) { |
178 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; | 177 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; |
179 std::unique_ptr<base::DictionaryValue> dictionary( | 178 std::unique_ptr<base::DictionaryValue> dictionary( |
180 new base::DictionaryValue()); | 179 new base::DictionaryValue()); |
181 dictionary->SetString("id", descriptor.id()); | 180 dictionary->SetString("id", descriptor.id()); |
182 dictionary->SetString( | 181 dictionary->SetString( |
183 "displayName", util->GetLocalizedDisplayName(descriptor)); | 182 "displayName", util->GetLocalizedDisplayName(descriptor)); |
184 dictionary->SetString("optionsPage", descriptor.options_page_url().spec()); | 183 dictionary->SetString("optionsPage", descriptor.options_page_url().spec()); |
185 std::unique_ptr<base::DictionaryValue> language_codes( | 184 std::unique_ptr<base::DictionaryValue> language_codes( |
186 new base::DictionaryValue()); | 185 new base::DictionaryValue()); |
187 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) | 186 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) |
188 language_codes->SetBoolean(descriptor.language_codes().at(i), true); | 187 language_codes->SetBoolean(descriptor.language_codes().at(i), true); |
189 dictionary->Set("languageCodeSet", std::move(language_codes)); | 188 dictionary->Set("languageCodeSet", language_codes.release()); |
190 ime_ids_list->Append(std::move(dictionary)); | 189 ime_ids_list->Append(std::move(dictionary)); |
191 } | 190 } |
192 return ime_ids_list; | 191 return ime_ids_list.release(); |
193 } | 192 } |
194 | 193 |
195 void CrosLanguageOptionsHandler::SetApplicationLocale( | 194 void CrosLanguageOptionsHandler::SetApplicationLocale( |
196 const std::string& language_code) { | 195 const std::string& language_code) { |
197 Profile* profile = Profile::FromWebUI(web_ui()); | 196 Profile* profile = Profile::FromWebUI(web_ui()); |
198 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 197 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
199 | 198 |
200 // Secondary users and public session users cannot change the locale. | 199 // Secondary users and public session users cannot change the locale. |
201 const user_manager::User* user = | 200 const user_manager::User* user = |
202 ProfileHelper::Get()->GetUserByProfile(profile); | 201 ProfileHelper::Get()->GetUserByProfile(profile); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); | 269 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); |
271 const extensions::Extension* extension = | 270 const extensions::Extension* extension = |
272 enabled_extensions.GetByID(extension_id); | 271 enabled_extensions.GetByID(extension_id); |
273 if (extension) | 272 if (extension) |
274 entry->SetString("extensionName", extension->name()); | 273 entry->SetString("extensionName", extension->name()); |
275 } | 274 } |
276 } | 275 } |
277 | 276 |
278 } // namespace options | 277 } // namespace options |
279 } // namespace chromeos | 278 } // namespace chromeos |
OLD | NEW |