Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: chrome/browser/ui/webui/options2/language_options_handler_common.cc

Issue 8895023: Options2: Pull the trigger. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DIAF. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options2/language_options_handler_common.h"
6
7 #include <map>
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/bind.h"
14 #include "base/command_line.h"
15 #include "base/stringprintf.h"
16 #include "base/utf_string_conversions.h"
17 #include "base/values.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/spellcheck_common.h"
24 #include "content/public/browser/user_metrics.h"
25 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h"
27 #include "ui/base/l10n/l10n_util.h"
28
29 using content::UserMetricsAction;
30
31 LanguageOptionsHandlerCommon::LanguageOptionsHandlerCommon() {
32 }
33
34 LanguageOptionsHandlerCommon::~LanguageOptionsHandlerCommon() {
35 }
36
37 void LanguageOptionsHandlerCommon::GetLocalizedValues(
38 DictionaryValue* localized_strings) {
39 DCHECK(localized_strings);
40 string16 product_name = GetProductName();
41 localized_strings->SetString("add_button",
42 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_BUTTON));
43 localized_strings->SetString("languages",
44 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_LANGUAGES));
45 localized_strings->SetString("please_add_another_language",
46 l10n_util::GetStringUTF16(
47 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE));
48 localized_strings->SetString("remove_button",
49 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON));
50 localized_strings->SetString("add_language_instructions",
51 l10n_util::GetStringUTF16(
52 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS));
53 localized_strings->SetString("cannot_be_displayed_in_this_language",
54 l10n_util::GetStringFUTF16(
55 IDS_OPTIONS_SETTINGS_LANGUAGES_CANNOT_BE_DISPLAYED_IN_THIS_LANGUAGE,
56 product_name));
57 localized_strings->SetString("is_displayed_in_this_language",
58 l10n_util::GetStringFUTF16(
59 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE,
60 product_name));
61 localized_strings->SetString("display_in_this_language",
62 l10n_util::GetStringFUTF16(
63 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE,
64 product_name));
65 localized_strings->SetString("this_language_is_currently_in_use",
66 l10n_util::GetStringFUTF16(
67 IDS_OPTIONS_SETTINGS_LANGUAGES_THIS_LANGUAGE_IS_CURRENTLY_IN_USE,
68 product_name));
69 localized_strings->SetString("restart_required",
70 l10n_util::GetStringUTF16(IDS_OPTIONS_RELAUNCH_REQUIRED));
71 // OS X uses the OS native spellchecker so no need for these strings.
72 #if !defined(OS_MACOSX)
73 localized_strings->SetString("use_this_for_spell_checking",
74 l10n_util::GetStringUTF16(
75 IDS_OPTIONS_SETTINGS_USE_THIS_FOR_SPELL_CHECKING));
76 localized_strings->SetString("cannot_be_used_for_spell_checking",
77 l10n_util::GetStringUTF16(
78 IDS_OPTIONS_SETTINGS_CANNOT_BE_USED_FOR_SPELL_CHECKING));
79 localized_strings->SetString("is_used_for_spell_checking",
80 l10n_util::GetStringUTF16(
81 IDS_OPTIONS_SETTINGS_IS_USED_FOR_SPELL_CHECKING));
82 localized_strings->SetString("enable_spell_check",
83 l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_SPELLCHECK));
84 localized_strings->SetString("enable_auto_spell_correction",
85 l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_AUTO_SPELL_CORRECTION));
86 #endif // !OS_MACOSX
87 localized_strings->SetString("add_language_title",
88 l10n_util::GetStringUTF16(IDS_OPTIONS_LANGUAGES_ADD_TITLE));
89 localized_strings->SetString("add_language_select_label",
90 l10n_util::GetStringUTF16(IDS_OPTIONS_LANGUAGES_ADD_SELECT_LABEL));
91 localized_strings->SetString("restart_button",
92 l10n_util::GetStringUTF16(
93 IDS_OPTIONS_SETTINGS_LANGUAGES_RELAUNCH_BUTTON));
94
95 // The following are resources, rather than local strings.
96 localized_strings->SetString("currentUiLanguageCode",
97 g_browser_process->GetApplicationLocale());
98 localized_strings->Set("spellCheckLanguageCodeSet",
99 GetSpellCheckLanguageCodeSet());
100 localized_strings->Set("uiLanguageCodeSet", GetUILanguageCodeSet());
101
102 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
103 bool experimental_spell_check_features =
104 command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures);
105 localized_strings->SetBoolean("experimentalSpellCheckFeatures",
106 experimental_spell_check_features);
107 }
108
109 void LanguageOptionsHandlerCommon::RegisterMessages() {
110 DCHECK(web_ui_);
111 web_ui_->RegisterMessageCallback("languageOptionsOpen",
112 base::Bind(
113 &LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback,
114 base::Unretained(this)));
115 web_ui_->RegisterMessageCallback("spellCheckLanguageChange",
116 base::Bind(
117 &LanguageOptionsHandlerCommon::SpellCheckLanguageChangeCallback,
118 base::Unretained(this)));
119 web_ui_->RegisterMessageCallback("uiLanguageChange",
120 base::Bind(
121 &LanguageOptionsHandlerCommon::UiLanguageChangeCallback,
122 base::Unretained(this)));
123 }
124
125 DictionaryValue* LanguageOptionsHandlerCommon::GetUILanguageCodeSet() {
126 DictionaryValue* dictionary = new DictionaryValue();
127 const std::vector<std::string>& available_locales =
128 l10n_util::GetAvailableLocales();
129 for (size_t i = 0; i < available_locales.size(); ++i) {
130 dictionary->SetBoolean(available_locales[i], true);
131 }
132 return dictionary;
133 }
134
135 DictionaryValue* LanguageOptionsHandlerCommon::GetSpellCheckLanguageCodeSet() {
136 DictionaryValue* dictionary = new DictionaryValue();
137 std::vector<std::string> spell_check_languages;
138 SpellCheckCommon::SpellCheckLanguages(&spell_check_languages);
139 for (size_t i = 0; i < spell_check_languages.size(); ++i) {
140 dictionary->SetBoolean(spell_check_languages[i], true);
141 }
142 return dictionary;
143 }
144
145 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback(
146 const ListValue* args) {
147 content::RecordAction(UserMetricsAction("LanguageOptions_Open"));
148 }
149
150 void LanguageOptionsHandlerCommon::UiLanguageChangeCallback(
151 const ListValue* args) {
152 const std::string language_code = UTF16ToASCII(ExtractStringValue(args));
153 CHECK(!language_code.empty());
154 const std::string action = base::StringPrintf(
155 "LanguageOptions_UiLanguageChange_%s", language_code.c_str());
156 content::RecordComputedAction(action);
157 SetApplicationLocale(language_code);
158 web_ui_->CallJavascriptFunction("options.LanguageOptions.uiLanguageSaved");
159 }
160
161 void LanguageOptionsHandlerCommon::SpellCheckLanguageChangeCallback(
162 const ListValue* args) {
163 const std::string language_code = UTF16ToASCII(ExtractStringValue(args));
164 CHECK(!language_code.empty());
165 const std::string action = base::StringPrintf(
166 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str());
167 content::RecordComputedAction(action);
168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698