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