| 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/basictypes.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/browser.h" | 17 #include "chrome/browser/browser.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/cros/input_method_library.h" | 20 #include "chrome/browser/chromeos/cros/input_method_library.h" |
| 20 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 21 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 21 #include "chrome/browser/metrics/user_metrics.h" | 22 #include "chrome/browser/metrics/user_metrics.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/profile.h" |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" | 25 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/spellcheck_common.h" | 27 #include "chrome/common/spellcheck_common.h" |
| 26 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
| 27 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 28 | 30 |
| 29 namespace chromeos { | 31 namespace chromeos { |
| 30 | 32 |
| 31 LanguageOptionsHandler::LanguageOptionsHandler() { | 33 LanguageOptionsHandler::LanguageOptionsHandler() { |
| 32 } | 34 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 localized_strings->SetString("please_add_another_input_method", | 52 localized_strings->SetString("please_add_another_input_method", |
| 51 l10n_util::GetStringUTF16( | 53 l10n_util::GetStringUTF16( |
| 52 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_INPUT_METHOD)); | 54 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_INPUT_METHOD)); |
| 53 localized_strings->SetString("please_add_another_language", | 55 localized_strings->SetString("please_add_another_language", |
| 54 l10n_util::GetStringUTF16( | 56 l10n_util::GetStringUTF16( |
| 55 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE)); | 57 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE)); |
| 56 localized_strings->SetString("ok_button", l10n_util::GetStringUTF16(IDS_OK)); | 58 localized_strings->SetString("ok_button", l10n_util::GetStringUTF16(IDS_OK)); |
| 57 localized_strings->SetString("remove_button", | 59 localized_strings->SetString("remove_button", |
| 58 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); | 60 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); |
| 59 localized_strings->SetString("sign_out_button", | 61 localized_strings->SetString("sign_out_button", |
| 60 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON))
; | 62 l10n_util::GetStringUTF16( |
| 63 IDS_OPTIONS_SETTINGS_LANGUAGES_SIGN_OUT_BUTTON)); |
| 61 localized_strings->SetString("add_language_instructions", | 64 localized_strings->SetString("add_language_instructions", |
| 62 l10n_util::GetStringUTF16( | 65 l10n_util::GetStringUTF16( |
| 63 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); | 66 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); |
| 64 localized_strings->SetString("input_method_instructions", | 67 localized_strings->SetString("input_method_instructions", |
| 65 l10n_util::GetStringUTF16( | 68 l10n_util::GetStringUTF16( |
| 66 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_INSTRUCTIONS)); | 69 IDS_OPTIONS_SETTINGS_LANGUAGES_INPUT_METHOD_INSTRUCTIONS)); |
| 67 localized_strings->SetString("switch_input_methods_hint", | 70 localized_strings->SetString("switch_input_methods_hint", |
| 68 l10n_util::GetStringFUTF16( | 71 l10n_util::GetStringFUTF16( |
| 69 IDS_OPTIONS_SETTINGS_LANGUAGES_SWITCH_INPUT_METHODS_HINT, | 72 IDS_OPTIONS_SETTINGS_LANGUAGES_SWITCH_INPUT_METHODS_HINT, |
| 70 ASCIIToUTF16("alt+shift"))); | 73 ASCIIToUTF16("alt+shift"))); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 283 } |
| 281 | 284 |
| 282 void LanguageOptionsHandler::UiLanguageChangeCallback( | 285 void LanguageOptionsHandler::UiLanguageChangeCallback( |
| 283 const ListValue* args) { | 286 const ListValue* args) { |
| 284 const std::string language_code = WideToASCII(ExtractStringValue(args)); | 287 const std::string language_code = WideToASCII(ExtractStringValue(args)); |
| 285 CHECK(!language_code.empty()); | 288 CHECK(!language_code.empty()); |
| 286 const std::string action = StringPrintf( | 289 const std::string action = StringPrintf( |
| 287 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); | 290 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); |
| 288 UserMetrics::RecordComputedAction(action); | 291 UserMetrics::RecordComputedAction(action); |
| 289 | 292 |
| 290 PrefService* prefs = g_browser_process->local_state(); | 293 // We maintain kApplicationLocale property in both a global storage |
| 291 prefs->SetString(prefs::kApplicationLocale, language_code); | 294 // and user's profile. Global property determines locale of login screen, |
| 292 prefs->SavePersistentPrefs(); | 295 // while user's profile determines his personal locale preference. |
| 296 PrefService* prefs[] = { |
| 297 g_browser_process->local_state(), |
| 298 dom_ui_->GetProfile()->GetPrefs() |
| 299 }; |
| 300 for (size_t i = 0; i < arraysize(prefs); ++i) { |
| 301 prefs[i]->SetString(prefs::kApplicationLocale, language_code); |
| 302 prefs[i]->SavePersistentPrefs(); |
| 303 } |
| 293 dom_ui_->CallJavascriptFunction( | 304 dom_ui_->CallJavascriptFunction( |
| 294 L"options.LanguageOptions.uiLanguageSaved"); | 305 L"options.LanguageOptions.uiLanguageSaved"); |
| 295 } | 306 } |
| 296 | 307 |
| 297 void LanguageOptionsHandler::SpellCheckLanguageChangeCallback( | 308 void LanguageOptionsHandler::SpellCheckLanguageChangeCallback( |
| 298 const ListValue* args) { | 309 const ListValue* args) { |
| 299 const std::string language_code = WideToASCII(ExtractStringValue(args)); | 310 const std::string language_code = WideToASCII(ExtractStringValue(args)); |
| 300 CHECK(!language_code.empty()); | 311 CHECK(!language_code.empty()); |
| 301 const std::string action = StringPrintf( | 312 const std::string action = StringPrintf( |
| 302 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); | 313 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); |
| 303 UserMetrics::RecordComputedAction(action); | 314 UserMetrics::RecordComputedAction(action); |
| 304 } | 315 } |
| 305 | 316 |
| 306 void LanguageOptionsHandler::SignOutCallback(const ListValue* args) { | 317 void LanguageOptionsHandler::SignOutCallback(const ListValue* args) { |
| 307 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_SignOut")); | 318 UserMetrics::RecordAction(UserMetricsAction("LanguageOptions_SignOut")); |
| 308 | 319 |
| 309 Browser* browser = Browser::GetBrowserForController( | 320 Browser* browser = Browser::GetBrowserForController( |
| 310 &dom_ui_->tab_contents()->controller(), NULL); | 321 &dom_ui_->tab_contents()->controller(), NULL); |
| 311 if (browser) | 322 if (browser) |
| 312 browser->ExecuteCommand(IDC_EXIT); | 323 browser->ExecuteCommand(IDC_EXIT); |
| 313 } | 324 } |
| 314 | 325 |
| 315 } // namespace chromeos | 326 } // namespace chromeos |
| OLD | NEW |