Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/dom_ui/language_options_handler.h" | 5 #include "chrome/browser/chromeos/dom_ui/language_options_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/browser.h" | 16 #include "chrome/browser/browser.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros/input_method_library.h" | 19 #include "chrome/browser/chromeos/cros/input_method_library.h" |
| 20 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 20 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 21 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profile.h" | |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/spellcheck_common.h" | 26 #include "chrome/common/spellcheck_common.h" |
| 26 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
| 27 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 28 | 29 |
| 29 namespace chromeos { | 30 namespace chromeos { |
| 30 | 31 |
| 31 LanguageOptionsHandler::LanguageOptionsHandler() { | 32 LanguageOptionsHandler::LanguageOptionsHandler() { |
| 32 } | 33 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 50 localized_strings->SetString("please_add_another_input_method", | 51 localized_strings->SetString("please_add_another_input_method", |
| 51 l10n_util::GetStringUTF16( | 52 l10n_util::GetStringUTF16( |
| 52 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_INPUT_METHOD)); | 53 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_INPUT_METHOD)); |
| 53 localized_strings->SetString("please_add_another_language", | 54 localized_strings->SetString("please_add_another_language", |
| 54 l10n_util::GetStringUTF16( | 55 l10n_util::GetStringUTF16( |
| 55 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE)); | 56 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE)); |
| 56 localized_strings->SetString("ok_button", l10n_util::GetStringUTF16(IDS_OK)); | 57 localized_strings->SetString("ok_button", l10n_util::GetStringUTF16(IDS_OK)); |
| 57 localized_strings->SetString("remove_button", | 58 localized_strings->SetString("remove_button", |
| 58 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); | 59 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); |
| 59 localized_strings->SetString("sign_out_button", | 60 localized_strings->SetString("sign_out_button", |
| 60 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON)) ; | 61 l10n_util::GetStringUTF16( |
| 62 IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON)); | |
| 61 localized_strings->SetString("add_language_instructions", | 63 localized_strings->SetString("add_language_instructions", |
| 62 l10n_util::GetStringUTF16( | 64 l10n_util::GetStringUTF16( |
| 63 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); | 65 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); |
| 64 localized_strings->SetString("input_method_instructions", | 66 localized_strings->SetString("input_method_instructions", |
| 65 l10n_util::GetStringUTF16( | 67 l10n_util::GetStringUTF16( |
| 66 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_INSTRUCTIONS)); | 68 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_INSTRUCTIONS)); |
| 67 localized_strings->SetString("switch_input_methods_hint", | 69 localized_strings->SetString("switch_input_methods_hint", |
| 68 l10n_util::GetStringFUTF16( | 70 l10n_util::GetStringFUTF16( |
| 69 IDS_OPTIONS_SETTINGS_LANGUAGES_SWITCH_INPUT_METHODS_HINT, | 71 IDS_OPTIONS_SETTINGS_LANGUAGES_SWITCH_INPUT_METHODS_HINT, |
| 70 ASCIIToUTF16("alt+shift"))); | 72 ASCIIToUTF16("alt+shift"))); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 } | 282 } |
| 281 | 283 |
| 282 void LanguageOptionsHandler::UiLanguageChangeCallback( | 284 void LanguageOptionsHandler::UiLanguageChangeCallback( |
| 283 const ListValue* args) { | 285 const ListValue* args) { |
| 284 const std::string language_code = WideToASCII(ExtractStringValue(args)); | 286 const std::string language_code = WideToASCII(ExtractStringValue(args)); |
| 285 CHECK(!language_code.empty()); | 287 CHECK(!language_code.empty()); |
| 286 const std::string action = StringPrintf( | 288 const std::string action = StringPrintf( |
| 287 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); | 289 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); |
| 288 UserMetrics::RecordComputedAction(action); | 290 UserMetrics::RecordComputedAction(action); |
| 289 | 291 |
| 290 PrefService* prefs = g_browser_process->local_state(); | 292 PrefService* prefs[] = { |
| 291 prefs->SetString(prefs::kApplicationLocale, language_code); | 293 g_browser_process->local_state(), |
| 292 prefs->SavePersistentPrefs(); | 294 dom_ui_->GetProfile()->GetPrefs() |
| 295 }; | |
| 296 for (size_t i = 0; i < sizeof(prefs) / sizeof(prefs[0]); ++i) { | |
|
tfarina
2010/11/11 16:54:25
use arraysize for this from base/basictypes.h, ple
Denis Lagno
2010/11/11 17:07:12
Done.
| |
| 297 prefs[i]->SetString(prefs::kApplicationLocale, language_code); | |
| 298 prefs[i]->SavePersistentPrefs(); | |
| 299 } | |
| 293 dom_ui_->CallJavascriptFunction( | 300 dom_ui_->CallJavascriptFunction( |
| 294 L"options.LanguageOptions.uiLanguageSaved"); | 301 L"options.LanguageOptions.uiLanguageSaved"); |
| 295 } | 302 } |
| 296 | 303 |
| 297 void LanguageOptionsHandler::SpellCheckLanguageChangeCallback( | 304 void LanguageOptionsHandler::SpellCheckLanguageChangeCallback( |
| 298 const ListValue* args) { | 305 const ListValue* args) { |
| 299 const std::string language_code = WideToASCII(ExtractStringValue(args)); | 306 const std::string language_code = WideToASCII(ExtractStringValue(args)); |
| 300 CHECK(!language_code.empty()); | 307 CHECK(!language_code.empty()); |
| 301 const std::string action = StringPrintf( | 308 const std::string action = StringPrintf( |
| 302 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); | 309 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); |
| 303 UserMetrics::RecordComputedAction(action); | 310 UserMetrics::RecordComputedAction(action); |
| 304 } | 311 } |
| 305 | 312 |
| 306 void LanguageOptionsHandler::SignOutCallback(const ListValue* args) { | 313 void LanguageOptionsHandler::SignOutCallback(const ListValue* args) { |
| 307 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_SignOut")); | 314 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_SignOut")); |
| 308 | 315 |
| 309 Browser* browser = Browser::GetBrowserForController( | 316 Browser* browser = Browser::GetBrowserForController( |
| 310 &dom_ui_->tab_contents()->controller(), NULL); | 317 &dom_ui_->tab_contents()->controller(), NULL); |
| 311 if (browser) | 318 if (browser) |
| 312 browser->ExecuteCommand(IDC_EXIT); | 319 browser->ExecuteCommand(IDC_EXIT); |
| 313 } | 320 } |
| 314 | 321 |
| 315 } // namespace chromeos | 322 } // namespace chromeos |
| OLD | NEW |