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> |
| 10 #include <utility> |
| 11 |
9 #include "base/bind.h" | 12 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/memory/ptr_util.h" |
11 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 17 #include "base/values.h" |
14 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 19 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
17 #include "chrome/browser/extensions/extension_tab_util.h" | 21 #include "chrome/browser/extensions/extension_tab_util.h" |
18 #include "chrome/browser/lifetime/application_lifetime.h" | 22 #include "chrome/browser/lifetime/application_lifetime.h" |
19 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 manager->GetSupportedInputMethods()); | 142 manager->GetSupportedInputMethods()); |
139 | 143 |
140 base::ListValue* input_method_list = new base::ListValue(); | 144 base::ListValue* input_method_list = new base::ListValue(); |
141 | 145 |
142 for (size_t i = 0; i < descriptors->size(); ++i) { | 146 for (size_t i = 0; i < descriptors->size(); ++i) { |
143 const input_method::InputMethodDescriptor& descriptor = | 147 const input_method::InputMethodDescriptor& descriptor = |
144 (*descriptors)[i]; | 148 (*descriptors)[i]; |
145 const std::string display_name = | 149 const std::string display_name = |
146 manager->GetInputMethodUtil()->GetInputMethodDisplayNameFromId( | 150 manager->GetInputMethodUtil()->GetInputMethodDisplayNameFromId( |
147 descriptor.id()); | 151 descriptor.id()); |
148 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 152 auto dictionary = base::MakeUnique<base::DictionaryValue>(); |
149 dictionary->SetString("id", descriptor.id()); | 153 dictionary->SetString("id", descriptor.id()); |
150 dictionary->SetString("displayName", display_name); | 154 dictionary->SetString("displayName", display_name); |
151 | 155 |
152 // One input method can be associated with multiple languages, hence | 156 // One input method can be associated with multiple languages, hence |
153 // we use a dictionary here. | 157 // we use a dictionary here. |
154 base::DictionaryValue* languages = new base::DictionaryValue(); | 158 base::DictionaryValue* languages = new base::DictionaryValue(); |
155 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) { | 159 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) { |
156 languages->SetBoolean(descriptor.language_codes().at(i), true); | 160 languages->SetBoolean(descriptor.language_codes().at(i), true); |
157 } | 161 } |
158 dictionary->Set("languageCodeSet", languages); | 162 dictionary->Set("languageCodeSet", languages); |
159 | 163 |
160 input_method_list->Append(dictionary); | 164 input_method_list->Append(std::move(dictionary)); |
161 } | 165 } |
162 | 166 |
163 return input_method_list; | 167 return input_method_list; |
164 } | 168 } |
165 | 169 |
166 base::ListValue* | 170 base::ListValue* |
167 CrosLanguageOptionsHandler::ConvertInputMethodDescriptorsToIMEList( | 171 CrosLanguageOptionsHandler::ConvertInputMethodDescriptorsToIMEList( |
168 const input_method::InputMethodDescriptors& descriptors) { | 172 const input_method::InputMethodDescriptors& descriptors) { |
169 input_method::InputMethodUtil* util = | 173 input_method::InputMethodUtil* util = |
170 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 174 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
171 std::unique_ptr<base::ListValue> ime_ids_list(new base::ListValue()); | 175 std::unique_ptr<base::ListValue> ime_ids_list(new base::ListValue()); |
172 for (size_t i = 0; i < descriptors.size(); ++i) { | 176 for (size_t i = 0; i < descriptors.size(); ++i) { |
173 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; | 177 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; |
174 std::unique_ptr<base::DictionaryValue> dictionary( | 178 std::unique_ptr<base::DictionaryValue> dictionary( |
175 new base::DictionaryValue()); | 179 new base::DictionaryValue()); |
176 dictionary->SetString("id", descriptor.id()); | 180 dictionary->SetString("id", descriptor.id()); |
177 dictionary->SetString( | 181 dictionary->SetString( |
178 "displayName", util->GetLocalizedDisplayName(descriptor)); | 182 "displayName", util->GetLocalizedDisplayName(descriptor)); |
179 dictionary->SetString("optionsPage", descriptor.options_page_url().spec()); | 183 dictionary->SetString("optionsPage", descriptor.options_page_url().spec()); |
180 std::unique_ptr<base::DictionaryValue> language_codes( | 184 std::unique_ptr<base::DictionaryValue> language_codes( |
181 new base::DictionaryValue()); | 185 new base::DictionaryValue()); |
182 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) | 186 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) |
183 language_codes->SetBoolean(descriptor.language_codes().at(i), true); | 187 language_codes->SetBoolean(descriptor.language_codes().at(i), true); |
184 dictionary->Set("languageCodeSet", language_codes.release()); | 188 dictionary->Set("languageCodeSet", language_codes.release()); |
185 ime_ids_list->Append(dictionary.release()); | 189 ime_ids_list->Append(std::move(dictionary)); |
186 } | 190 } |
187 return ime_ids_list.release(); | 191 return ime_ids_list.release(); |
188 } | 192 } |
189 | 193 |
190 void CrosLanguageOptionsHandler::SetApplicationLocale( | 194 void CrosLanguageOptionsHandler::SetApplicationLocale( |
191 const std::string& language_code) { | 195 const std::string& language_code) { |
192 Profile* profile = Profile::FromWebUI(web_ui()); | 196 Profile* profile = Profile::FromWebUI(web_ui()); |
193 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 197 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
194 | 198 |
195 // Secondary users and public session users cannot change the locale. | 199 // Secondary users and public session users cannot change the locale. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); | 269 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); |
266 const extensions::Extension* extension = | 270 const extensions::Extension* extension = |
267 enabled_extensions.GetByID(extension_id); | 271 enabled_extensions.GetByID(extension_id); |
268 if (extension) | 272 if (extension) |
269 entry->SetString("extensionName", extension->name()); | 273 entry->SetString("extensionName", extension->name()); |
270 } | 274 } |
271 } | 275 } |
272 | 276 |
273 } // namespace options | 277 } // namespace options |
274 } // namespace chromeos | 278 } // namespace chromeos |
OLD | NEW |