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/language_options_handler_common.h" | 5 #include "chrome/browser/ui/webui/options/language_options_handler_common.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
17 #include "base/metrics/user_metrics.h" | 18 #include "base/metrics/user_metrics.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 26 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
26 #include "chrome/browser/spellchecker/spellcheck_service.h" | 27 #include "chrome/browser/spellchecker/spellcheck_service.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 Profile* profile = Profile::FromWebUI(web_ui()); | 111 Profile* profile = Profile::FromWebUI(web_ui()); |
111 PrefService* prefs = profile->GetPrefs(); | 112 PrefService* prefs = profile->GetPrefs(); |
112 std::string default_target_language = | 113 std::string default_target_language = |
113 TranslateService::GetTargetLanguage(prefs); | 114 TranslateService::GetTargetLanguage(prefs); |
114 localized_strings->SetString("defaultTargetLanguage", | 115 localized_strings->SetString("defaultTargetLanguage", |
115 default_target_language); | 116 default_target_language); |
116 | 117 |
117 std::vector<std::string> languages; | 118 std::vector<std::string> languages; |
118 translate::TranslateDownloadManager::GetSupportedLanguages(&languages); | 119 translate::TranslateDownloadManager::GetSupportedLanguages(&languages); |
119 | 120 |
120 base::ListValue* languages_list = new base::ListValue(); | 121 auto languages_list = base::MakeUnique<base::ListValue>(); |
121 for (std::vector<std::string>::iterator it = languages.begin(); | 122 for (std::vector<std::string>::iterator it = languages.begin(); |
122 it != languages.end(); ++it) { | 123 it != languages.end(); ++it) { |
123 languages_list->AppendString(*it); | 124 languages_list->AppendString(*it); |
124 } | 125 } |
125 | 126 |
126 localized_strings->Set("translateSupportedLanguages", languages_list); | 127 localized_strings->Set("translateSupportedLanguages", |
| 128 std::move(languages_list)); |
127 } | 129 } |
128 | 130 |
129 void LanguageOptionsHandlerCommon::Uninitialize() { | 131 void LanguageOptionsHandlerCommon::Uninitialize() { |
130 SpellcheckService* service = GetSpellcheckService(); | 132 SpellcheckService* service = GetSpellcheckService(); |
131 if (!service) | 133 if (!service) |
132 return; | 134 return; |
133 | 135 |
134 for (const auto& dict : service->GetHunspellDictionaries()) | 136 for (const auto& dict : service->GetHunspellDictionaries()) |
135 dict->RemoveObserver(this); | 137 dict->RemoveObserver(this); |
136 } | 138 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 base::Value(language)); | 178 base::Value(language)); |
177 } | 179 } |
178 | 180 |
179 void LanguageOptionsHandlerCommon::OnHunspellDictionaryDownloadFailure( | 181 void LanguageOptionsHandlerCommon::OnHunspellDictionaryDownloadFailure( |
180 const std::string& language) { | 182 const std::string& language) { |
181 web_ui()->CallJavascriptFunctionUnsafe( | 183 web_ui()->CallJavascriptFunctionUnsafe( |
182 "options.LanguageOptions.onDictionaryDownloadFailure", | 184 "options.LanguageOptions.onDictionaryDownloadFailure", |
183 base::Value(language)); | 185 base::Value(language)); |
184 } | 186 } |
185 | 187 |
186 base::DictionaryValue* LanguageOptionsHandlerCommon::GetUILanguageCodeSet() { | 188 std::unique_ptr<base::DictionaryValue> |
187 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 189 LanguageOptionsHandlerCommon::GetUILanguageCodeSet() { |
| 190 auto dictionary = base::MakeUnique<base::DictionaryValue>(); |
188 const std::vector<std::string>& available_locales = | 191 const std::vector<std::string>& available_locales = |
189 l10n_util::GetAvailableLocales(); | 192 l10n_util::GetAvailableLocales(); |
190 for (size_t i = 0; i < available_locales.size(); ++i) | 193 for (size_t i = 0; i < available_locales.size(); ++i) |
191 dictionary->SetBoolean(available_locales[i], true); | 194 dictionary->SetBoolean(available_locales[i], true); |
192 return dictionary; | 195 return dictionary; |
193 } | 196 } |
194 | 197 |
195 base::DictionaryValue* | 198 std::unique_ptr<base::DictionaryValue> |
196 LanguageOptionsHandlerCommon::GetSpellCheckLanguageCodeSet() { | 199 LanguageOptionsHandlerCommon::GetSpellCheckLanguageCodeSet() { |
197 base::DictionaryValue* dictionary = new base::DictionaryValue(); | 200 auto dictionary = base::MakeUnique<base::DictionaryValue>(); |
198 std::vector<std::string> spell_check_languages; | 201 std::vector<std::string> spell_check_languages; |
199 spellcheck::SpellCheckLanguages(&spell_check_languages); | 202 spellcheck::SpellCheckLanguages(&spell_check_languages); |
200 for (size_t i = 0; i < spell_check_languages.size(); ++i) { | 203 for (size_t i = 0; i < spell_check_languages.size(); ++i) { |
201 dictionary->SetBoolean(spell_check_languages[i], true); | 204 dictionary->SetBoolean(spell_check_languages[i], true); |
202 } | 205 } |
203 return dictionary; | 206 return dictionary; |
204 } | 207 } |
205 | 208 |
206 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback( | 209 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback( |
207 const base::ListValue* args) { | 210 const base::ListValue* args) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return; | 293 return; |
291 } | 294 } |
292 } | 295 } |
293 } | 296 } |
294 | 297 |
295 SpellcheckService* LanguageOptionsHandlerCommon::GetSpellcheckService() { | 298 SpellcheckService* LanguageOptionsHandlerCommon::GetSpellcheckService() { |
296 return SpellcheckServiceFactory::GetForContext(Profile::FromWebUI(web_ui())); | 299 return SpellcheckServiceFactory::GetForContext(Profile::FromWebUI(web_ui())); |
297 } | 300 } |
298 | 301 |
299 } // namespace options | 302 } // namespace options |
OLD | NEW |