| 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/metrics/user_metrics.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 25 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 25 #include "chrome/browser/spellchecker/spellcheck_service.h" | 26 #include "chrome/browser/spellchecker/spellcheck_service.h" |
| 26 #include "chrome/browser/translate/chrome_translate_client.h" | 27 #include "chrome/browser/translate/chrome_translate_client.h" |
| 27 #include "chrome/browser/translate/translate_service.h" | 28 #include "chrome/browser/translate/translate_service.h" |
| 28 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/grit/chromium_strings.h" | 32 #include "chrome/grit/chromium_strings.h" |
| 32 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| 33 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 34 #include "components/spellcheck/common/spellcheck_common.h" | 35 #include "components/spellcheck/common/spellcheck_common.h" |
| 35 #include "components/translate/core/browser/translate_download_manager.h" | 36 #include "components/translate/core/browser/translate_download_manager.h" |
| 36 #include "components/translate/core/browser/translate_prefs.h" | 37 #include "components/translate/core/browser/translate_prefs.h" |
| 37 #include "content/public/browser/user_metrics.h" | |
| 38 #include "content/public/browser/web_ui.h" | 38 #include "content/public/browser/web_ui.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 | 40 |
| 41 using base::UserMetricsAction; | 41 using base::UserMetricsAction; |
| 42 | 42 |
| 43 namespace options { | 43 namespace options { |
| 44 | 44 |
| 45 LanguageOptionsHandlerCommon::LanguageOptionsHandlerCommon() { | 45 LanguageOptionsHandlerCommon::LanguageOptionsHandlerCommon() { |
| 46 } | 46 } |
| 47 | 47 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 std::vector<std::string> spell_check_languages; | 198 std::vector<std::string> spell_check_languages; |
| 199 spellcheck::SpellCheckLanguages(&spell_check_languages); | 199 spellcheck::SpellCheckLanguages(&spell_check_languages); |
| 200 for (size_t i = 0; i < spell_check_languages.size(); ++i) { | 200 for (size_t i = 0; i < spell_check_languages.size(); ++i) { |
| 201 dictionary->SetBoolean(spell_check_languages[i], true); | 201 dictionary->SetBoolean(spell_check_languages[i], true); |
| 202 } | 202 } |
| 203 return dictionary; | 203 return dictionary; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback( | 206 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback( |
| 207 const base::ListValue* args) { | 207 const base::ListValue* args) { |
| 208 content::RecordAction(UserMetricsAction("LanguageOptions_Open")); | 208 base::RecordAction(UserMetricsAction("LanguageOptions_Open")); |
| 209 SpellcheckService* service = GetSpellcheckService(); | 209 SpellcheckService* service = GetSpellcheckService(); |
| 210 if (!service) | 210 if (!service) |
| 211 return; | 211 return; |
| 212 | 212 |
| 213 for (const auto& dictionary : service->GetHunspellDictionaries()) { | 213 for (const auto& dictionary : service->GetHunspellDictionaries()) { |
| 214 dictionary->RemoveObserver(this); | 214 dictionary->RemoveObserver(this); |
| 215 dictionary->AddObserver(this); | 215 dictionary->AddObserver(this); |
| 216 | 216 |
| 217 if (dictionary->IsDownloadInProgress()) | 217 if (dictionary->IsDownloadInProgress()) |
| 218 OnHunspellDictionaryDownloadBegin(dictionary->GetLanguage()); | 218 OnHunspellDictionaryDownloadBegin(dictionary->GetLanguage()); |
| 219 else if (dictionary->IsDownloadFailure()) | 219 else if (dictionary->IsDownloadFailure()) |
| 220 OnHunspellDictionaryDownloadFailure(dictionary->GetLanguage()); | 220 OnHunspellDictionaryDownloadFailure(dictionary->GetLanguage()); |
| 221 else | 221 else |
| 222 OnHunspellDictionaryDownloadSuccess(dictionary->GetLanguage()); | 222 OnHunspellDictionaryDownloadSuccess(dictionary->GetLanguage()); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 void LanguageOptionsHandlerCommon::UiLanguageChangeCallback( | 226 void LanguageOptionsHandlerCommon::UiLanguageChangeCallback( |
| 227 const base::ListValue* args) { | 227 const base::ListValue* args) { |
| 228 const std::string language_code = | 228 const std::string language_code = |
| 229 base::UTF16ToASCII(ExtractStringValue(args)); | 229 base::UTF16ToASCII(ExtractStringValue(args)); |
| 230 CHECK(!language_code.empty()); | 230 CHECK(!language_code.empty()); |
| 231 const std::string action = base::StringPrintf( | 231 const std::string action = base::StringPrintf( |
| 232 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); | 232 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); |
| 233 content::RecordComputedAction(action); | 233 base::RecordComputedAction(action); |
| 234 SetApplicationLocale(language_code); | 234 SetApplicationLocale(language_code); |
| 235 base::Value language_value(language_code); | 235 base::Value language_value(language_code); |
| 236 web_ui()->CallJavascriptFunctionUnsafe( | 236 web_ui()->CallJavascriptFunctionUnsafe( |
| 237 "options.LanguageOptions.uiLanguageSaved", language_value); | 237 "options.LanguageOptions.uiLanguageSaved", language_value); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void LanguageOptionsHandlerCommon::SpellCheckLanguageChangeCallback( | 240 void LanguageOptionsHandlerCommon::SpellCheckLanguageChangeCallback( |
| 241 const base::ListValue* args) { | 241 const base::ListValue* args) { |
| 242 const std::string language_code = | 242 const std::string language_code = |
| 243 base::UTF16ToASCII(ExtractStringValue(args)); | 243 base::UTF16ToASCII(ExtractStringValue(args)); |
| 244 const std::string action = base::StringPrintf( | 244 const std::string action = base::StringPrintf( |
| 245 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); | 245 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); |
| 246 content::RecordComputedAction(action); | 246 base::RecordComputedAction(action); |
| 247 | 247 |
| 248 SpellcheckService* service = GetSpellcheckService(); | 248 SpellcheckService* service = GetSpellcheckService(); |
| 249 if (!service) | 249 if (!service) |
| 250 return; | 250 return; |
| 251 | 251 |
| 252 for (const auto& dictionary : service->GetHunspellDictionaries()) { | 252 for (const auto& dictionary : service->GetHunspellDictionaries()) { |
| 253 dictionary->RemoveObserver(this); | 253 dictionary->RemoveObserver(this); |
| 254 dictionary->AddObserver(this); | 254 dictionary->AddObserver(this); |
| 255 } | 255 } |
| 256 } | 256 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 SpellcheckService* LanguageOptionsHandlerCommon::GetSpellcheckService() { | 295 SpellcheckService* LanguageOptionsHandlerCommon::GetSpellcheckService() { |
| 296 return SpellcheckServiceFactory::GetForContext(Profile::FromWebUI(web_ui())); | 296 return SpellcheckServiceFactory::GetForContext(Profile::FromWebUI(web_ui())); |
| 297 } | 297 } |
| 298 | 298 |
| 299 } // namespace options | 299 } // namespace options |
| OLD | NEW |