Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc

Issue 2812953002: Stop passing raw pointers to base::Value API in c/b/ui (Closed)
Patch Set: No ListValue::SetDouble Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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().release()); 97 localized_strings->Set("languageList", GetAcceptLanguageList());
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 base::ListValue* ext_ime_list = ConvertInputMethodDescriptorsToIMEList( 105 std::unique_ptr<base::ListValue> ext_ime_list =
106 ext_ime_descriptors); 106 ConvertInputMethodDescriptorsToIMEList(ext_ime_descriptors);
107 AddImeProvider(ext_ime_list); 107 AddImeProvider(ext_ime_list.get());
108 localized_strings->Set("extensionImeList", ext_ime_list); 108 localized_strings->Set("extensionImeList", std::move(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 base::ListValue* CrosLanguageOptionsHandler::GetInputMethodList() { 137 std::unique_ptr<base::ListValue>
138 CrosLanguageOptionsHandler::GetInputMethodList() {
138 input_method::InputMethodManager* manager = 139 input_method::InputMethodManager* manager =
139 input_method::InputMethodManager::Get(); 140 input_method::InputMethodManager::Get();
140 // GetSupportedInputMethods() never return NULL. 141 // GetSupportedInputMethods() never return NULL.
141 std::unique_ptr<input_method::InputMethodDescriptors> descriptors( 142 std::unique_ptr<input_method::InputMethodDescriptors> descriptors(
142 manager->GetSupportedInputMethods()); 143 manager->GetSupportedInputMethods());
143 144
144 base::ListValue* input_method_list = new base::ListValue(); 145 auto input_method_list = base::MakeUnique<base::ListValue>();
145 146
146 for (size_t i = 0; i < descriptors->size(); ++i) { 147 for (size_t i = 0; i < descriptors->size(); ++i) {
147 const input_method::InputMethodDescriptor& descriptor = 148 const input_method::InputMethodDescriptor& descriptor =
148 (*descriptors)[i]; 149 (*descriptors)[i];
149 const std::string display_name = 150 const std::string display_name =
150 manager->GetInputMethodUtil()->GetInputMethodDisplayNameFromId( 151 manager->GetInputMethodUtil()->GetInputMethodDisplayNameFromId(
151 descriptor.id()); 152 descriptor.id());
152 auto dictionary = base::MakeUnique<base::DictionaryValue>(); 153 auto dictionary = base::MakeUnique<base::DictionaryValue>();
153 dictionary->SetString("id", descriptor.id()); 154 dictionary->SetString("id", descriptor.id());
154 dictionary->SetString("displayName", display_name); 155 dictionary->SetString("displayName", display_name);
155 156
156 // One input method can be associated with multiple languages, hence 157 // One input method can be associated with multiple languages, hence
157 // we use a dictionary here. 158 // we use a dictionary here.
158 base::DictionaryValue* languages = new base::DictionaryValue(); 159 auto languages = base::MakeUnique<base::DictionaryValue>();
159 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) { 160 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) {
160 languages->SetBoolean(descriptor.language_codes().at(i), true); 161 languages->SetBoolean(descriptor.language_codes().at(i), true);
161 } 162 }
162 dictionary->Set("languageCodeSet", languages); 163 dictionary->Set("languageCodeSet", std::move(languages));
163 164
164 input_method_list->Append(std::move(dictionary)); 165 input_method_list->Append(std::move(dictionary));
165 } 166 }
166 167
167 return input_method_list; 168 return input_method_list;
168 } 169 }
169 170
170 base::ListValue* 171 std::unique_ptr<base::ListValue>
171 CrosLanguageOptionsHandler::ConvertInputMethodDescriptorsToIMEList( 172 CrosLanguageOptionsHandler::ConvertInputMethodDescriptorsToIMEList(
172 const input_method::InputMethodDescriptors& descriptors) { 173 const input_method::InputMethodDescriptors& descriptors) {
173 input_method::InputMethodUtil* util = 174 input_method::InputMethodUtil* util =
174 input_method::InputMethodManager::Get()->GetInputMethodUtil(); 175 input_method::InputMethodManager::Get()->GetInputMethodUtil();
175 std::unique_ptr<base::ListValue> ime_ids_list(new base::ListValue()); 176 std::unique_ptr<base::ListValue> ime_ids_list(new base::ListValue());
176 for (size_t i = 0; i < descriptors.size(); ++i) { 177 for (size_t i = 0; i < descriptors.size(); ++i) {
177 const input_method::InputMethodDescriptor& descriptor = descriptors[i]; 178 const input_method::InputMethodDescriptor& descriptor = descriptors[i];
178 std::unique_ptr<base::DictionaryValue> dictionary( 179 std::unique_ptr<base::DictionaryValue> dictionary(
179 new base::DictionaryValue()); 180 new base::DictionaryValue());
180 dictionary->SetString("id", descriptor.id()); 181 dictionary->SetString("id", descriptor.id());
181 dictionary->SetString( 182 dictionary->SetString(
182 "displayName", util->GetLocalizedDisplayName(descriptor)); 183 "displayName", util->GetLocalizedDisplayName(descriptor));
183 dictionary->SetString("optionsPage", descriptor.options_page_url().spec()); 184 dictionary->SetString("optionsPage", descriptor.options_page_url().spec());
184 std::unique_ptr<base::DictionaryValue> language_codes( 185 std::unique_ptr<base::DictionaryValue> language_codes(
185 new base::DictionaryValue()); 186 new base::DictionaryValue());
186 for (size_t i = 0; i < descriptor.language_codes().size(); ++i) 187 for (size_t i = 0; i < descriptor.language_codes().size(); ++i)
187 language_codes->SetBoolean(descriptor.language_codes().at(i), true); 188 language_codes->SetBoolean(descriptor.language_codes().at(i), true);
188 dictionary->Set("languageCodeSet", language_codes.release()); 189 dictionary->Set("languageCodeSet", std::move(language_codes));
189 ime_ids_list->Append(std::move(dictionary)); 190 ime_ids_list->Append(std::move(dictionary));
190 } 191 }
191 return ime_ids_list.release(); 192 return ime_ids_list;
192 } 193 }
193 194
194 void CrosLanguageOptionsHandler::SetApplicationLocale( 195 void CrosLanguageOptionsHandler::SetApplicationLocale(
195 const std::string& language_code) { 196 const std::string& language_code) {
196 Profile* profile = Profile::FromWebUI(web_ui()); 197 Profile* profile = Profile::FromWebUI(web_ui());
197 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 198 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
198 199
199 // Secondary users and public session users cannot change the locale. 200 // Secondary users and public session users cannot change the locale.
200 const user_manager::User* user = 201 const user_manager::User* user =
201 ProfileHelper::Get()->GetUserByProfile(profile); 202 ProfileHelper::Get()->GetUserByProfile(profile);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id); 270 extension_ime_util::GetExtensionIDFromInputMethodID(input_method_id);
270 const extensions::Extension* extension = 271 const extensions::Extension* extension =
271 enabled_extensions.GetByID(extension_id); 272 enabled_extensions.GetByID(extension_id);
272 if (extension) 273 if (extension)
273 entry->SetString("extensionName", extension->name()); 274 entry->SetString("extensionName", extension->name());
274 } 275 }
275 } 276 }
276 277
277 } // namespace options 278 } // namespace options
278 } // namespace chromeos 279 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698