OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/options/chromeos/system_options_handler.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/bind.h" | |
11 #include "base/bind_helpers.h" | |
12 #include "base/command_line.h" | |
13 #include "base/string_number_conversions.h" | |
14 #include "base/utf_string_conversions.h" | |
15 #include "base/values.h" | |
16 #include "chrome/browser/browser_process.h" | |
17 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | |
18 #include "chrome/browser/chromeos/cros_settings.h" | |
19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | |
20 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | |
21 #include "chrome/browser/chromeos/language_preferences.h" | |
22 #include "chrome/browser/chromeos/system/input_device_settings.h" | |
23 #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" | |
24 #include "chrome/browser/extensions/extension_service.h" | |
25 #include "chrome/browser/prefs/pref_service.h" | |
26 #include "chrome/browser/profiles/profile.h" | |
27 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h" | |
28 #include "chrome/common/chrome_switches.h" | |
29 #include "chrome/common/extensions/extension.h" | |
30 #include "chrome/common/pref_names.h" | |
31 #include "content/public/browser/web_ui.h" | |
32 #include "grit/browser_resources.h" | |
33 #include "grit/chromium_strings.h" | |
34 #include "grit/generated_resources.h" | |
35 #include "grit/locale_settings.h" | |
36 #include "grit/theme_resources.h" | |
37 #include "ui/base/l10n/l10n_util.h" | |
38 #include "ui/base/resource/resource_bundle.h" | |
39 | |
40 using content::BrowserThread; | |
41 | |
42 namespace { | |
43 | |
44 void TouchpadExistsFileThread(bool* exists) { | |
45 *exists = chromeos::system::touchpad_settings::TouchpadExists(); | |
46 } | |
47 | |
48 void MouseExistsFileThread(bool* exists) { | |
49 *exists = chromeos::system::mouse_settings::MouseExists(); | |
50 } | |
51 | |
52 } // namespace | |
53 | |
54 SystemOptionsHandler::SystemOptionsHandler() { | |
55 } | |
56 | |
57 SystemOptionsHandler::~SystemOptionsHandler() { | |
58 chromeos::XInputHierarchyChangedEventListener::GetInstance() | |
59 ->RemoveObserver(this); | |
60 } | |
61 | |
62 void SystemOptionsHandler::GetLocalizedValues( | |
63 DictionaryValue* localized_strings) { | |
64 DCHECK(localized_strings); | |
65 | |
66 RegisterTitle(localized_strings, "systemPage", IDS_OPTIONS_SYSTEM_TAB_LABEL); | |
67 localized_strings->SetString("datetimeTitle", | |
68 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME)); | |
69 localized_strings->SetString("timezone", | |
70 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION)); | |
71 localized_strings->SetString("use24HourClock", | |
72 l10n_util::GetStringUTF16( | |
73 IDS_OPTIONS_SETTINGS_USE_24HOUR_CLOCK_DESCRIPTION)); | |
74 | |
75 localized_strings->SetString("screen", | |
76 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_SCREEN)); | |
77 localized_strings->SetString("brightness", | |
78 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BRIGHTNESS_DESCRIPTION)); | |
79 localized_strings->SetString("brightnessDecrease", | |
80 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BRIGHTNESS_DECREASE)); | |
81 localized_strings->SetString("brightnessIncrease", | |
82 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BRIGHTNESS_INCREASE)); | |
83 | |
84 localized_strings->SetString("pointer", | |
85 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_POINTER)); | |
86 localized_strings->SetString("touchpad", | |
87 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_TOUCHPAD)); | |
88 localized_strings->SetString("mouse", | |
89 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_MOUSE)); | |
90 localized_strings->SetString("enableTapToClick", | |
91 l10n_util::GetStringUTF16( | |
92 IDS_OPTIONS_SETTINGS_TAP_TO_CLICK_ENABLED_DESCRIPTION)); | |
93 localized_strings->SetString("sensitivity", | |
94 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SENSITIVITY_DESCRIPTION)); | |
95 localized_strings->SetString("sensitivityLess", | |
96 l10n_util::GetStringUTF16( | |
97 IDS_OPTIONS_SETTINGS_SENSITIVITY_LESS_DESCRIPTION)); | |
98 localized_strings->SetString("sensitivityMore", | |
99 l10n_util::GetStringUTF16( | |
100 IDS_OPTIONS_SETTINGS_SENSITIVITY_MORE_DESCRIPTION)); | |
101 localized_strings->SetString("primaryMouseRight", | |
102 l10n_util::GetStringUTF16( | |
103 IDS_OPTIONS_SETTINGS_PRIMARY_MOUSE_RIGHT_DESCRIPTION)); | |
104 | |
105 localized_strings->SetString("language", | |
106 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE)); | |
107 localized_strings->SetString("languageCustomize", | |
108 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE)); | |
109 localized_strings->SetString("modifierKeysCustomize", | |
110 l10n_util::GetStringUTF16( | |
111 IDS_OPTIONS_SETTINGS_LANGUAGES_MODIFIER_KEYS_CUSTOMIZE)); | |
112 | |
113 localized_strings->SetString("accessibilityTitle", | |
114 l10n_util::GetStringUTF16( | |
115 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY)); | |
116 localized_strings->SetString("accessibilitySpokenFeedback", | |
117 l10n_util::GetStringUTF16( | |
118 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_DESCRIPTION)); | |
119 localized_strings->SetString("accessibilityHighContrast", | |
120 l10n_util::GetStringUTF16( | |
121 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_HIGH_CONTRAST_DESCRIPTION)); | |
122 localized_strings->SetString("accessibilityScreenMagnifier", | |
123 l10n_util::GetStringUTF16( | |
124 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_SCREEN_MAGNIFIER_DESCRIPTION)); | |
125 localized_strings->SetString("accessibilityVirtualKeyboard", | |
126 l10n_util::GetStringUTF16( | |
127 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_VIRTUAL_KEYBOARD_DESCRIPTION)); | |
128 | |
129 // TODO(pastarmovj): replace this with a call to the CrosSettings list | |
130 // handling functionality to come. | |
131 localized_strings->Set("timezoneList", | |
132 static_cast<chromeos::SystemSettingsProvider*>( | |
133 chromeos::CrosSettings::Get()->GetProvider( | |
134 chromeos::kSystemTimezone))->GetTimezoneList()); | |
135 } | |
136 | |
137 void SystemOptionsHandler::InitializeHandler() { | |
138 PrefService* pref_service = g_browser_process->local_state(); | |
139 base::FundamentalValue spoken_feedback_enabled( | |
140 pref_service->GetBoolean(prefs::kSpokenFeedbackEnabled)); | |
141 web_ui()->CallJavascriptFunction( | |
142 "options.SystemOptions.setSpokenFeedbackCheckboxState", | |
143 spoken_feedback_enabled); | |
144 base::FundamentalValue high_contrast_enabled( | |
145 pref_service->GetBoolean(prefs::kHighContrastEnabled)); | |
146 web_ui()->CallJavascriptFunction( | |
147 "options.SystemOptions.setHighContrastCheckboxState", | |
148 high_contrast_enabled); | |
149 base::FundamentalValue screen_magnifier_enabled( | |
150 pref_service->GetBoolean(prefs::kScreenMagnifierEnabled)); | |
151 web_ui()->CallJavascriptFunction( | |
152 "options.SystemOptions.setScreenMagnifierCheckboxState", | |
153 screen_magnifier_enabled); | |
154 base::FundamentalValue virtual_keyboard_enabled( | |
155 pref_service->GetBoolean(prefs::kVirtualKeyboardEnabled)); | |
156 web_ui()->CallJavascriptFunction( | |
157 "options.SystemOptions.setVirtualKeyboardCheckboxState", | |
158 virtual_keyboard_enabled); | |
159 | |
160 chromeos::XInputHierarchyChangedEventListener::GetInstance() | |
161 ->AddObserver(this); | |
162 DeviceHierarchyChanged(); | |
163 } | |
164 | |
165 void SystemOptionsHandler::CheckTouchpadExists() { | |
166 bool* exists = new bool; | |
167 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | |
168 base::Bind(&TouchpadExistsFileThread, exists), | |
169 base::Bind(&SystemOptionsHandler::TouchpadExists, AsWeakPtr(), exists)); | |
170 } | |
171 | |
172 void SystemOptionsHandler::CheckMouseExists() { | |
173 bool* exists = new bool; | |
174 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | |
175 base::Bind(&MouseExistsFileThread, exists), | |
176 base::Bind(&SystemOptionsHandler::MouseExists, AsWeakPtr(), exists)); | |
177 } | |
178 | |
179 void SystemOptionsHandler::TouchpadExists(bool* exists) { | |
180 base::FundamentalValue val(*exists); | |
181 web_ui()->CallJavascriptFunction("options.SystemOptions.showTouchpadControls", | |
182 val); | |
183 delete exists; | |
184 } | |
185 | |
186 void SystemOptionsHandler::MouseExists(bool* exists) { | |
187 base::FundamentalValue val(*exists); | |
188 web_ui()->CallJavascriptFunction("options.SystemOptions.showMouseControls", | |
189 val); | |
190 delete exists; | |
191 } | |
192 | |
193 void SystemOptionsHandler::RegisterMessages() { | |
194 web_ui()->RegisterMessageCallback( | |
195 "spokenFeedbackChange", | |
196 base::Bind(&SystemOptionsHandler::SpokenFeedbackChangeCallback, | |
197 base::Unretained(this))); | |
198 web_ui()->RegisterMessageCallback( | |
199 "highContrastChange", | |
200 base::Bind(&SystemOptionsHandler::HighContrastChangeCallback, | |
201 base::Unretained(this))); | |
202 web_ui()->RegisterMessageCallback( | |
203 "screenMagnifierChange", | |
204 base::Bind(&SystemOptionsHandler::ScreenMagnifierChangeCallback, | |
205 base::Unretained(this))); | |
206 web_ui()->RegisterMessageCallback( | |
207 "virtualKeyboardChange", | |
208 base::Bind(&SystemOptionsHandler::VirtualKeyboardChangeCallback, | |
209 base::Unretained(this))); | |
210 | |
211 web_ui()->RegisterMessageCallback( | |
212 "decreaseScreenBrightness", | |
213 base::Bind(&SystemOptionsHandler::DecreaseScreenBrightnessCallback, | |
214 base::Unretained(this))); | |
215 web_ui()->RegisterMessageCallback( | |
216 "increaseScreenBrightness", | |
217 base::Bind(&SystemOptionsHandler::IncreaseScreenBrightnessCallback, | |
218 base::Unretained(this))); | |
219 } | |
220 | |
221 void SystemOptionsHandler::DeviceHierarchyChanged() { | |
222 CheckMouseExists(); | |
223 CheckTouchpadExists(); | |
224 } | |
225 | |
226 void SystemOptionsHandler::SpokenFeedbackChangeCallback(const ListValue* args) { | |
227 bool enabled = false; | |
228 args->GetBoolean(0, &enabled); | |
229 | |
230 chromeos::accessibility::EnableSpokenFeedback(enabled, NULL); | |
231 } | |
232 | |
233 void SystemOptionsHandler::HighContrastChangeCallback(const ListValue* args) { | |
234 bool enabled = false; | |
235 args->GetBoolean(0, &enabled); | |
236 | |
237 chromeos::accessibility::EnableHighContrast(enabled); | |
238 } | |
239 | |
240 void SystemOptionsHandler::ScreenMagnifierChangeCallback( | |
241 const ListValue* args) { | |
242 bool enabled = false; | |
243 args->GetBoolean(0, &enabled); | |
244 | |
245 chromeos::accessibility::EnableScreenMagnifier(enabled); | |
246 } | |
247 | |
248 void SystemOptionsHandler::VirtualKeyboardChangeCallback( | |
249 const ListValue* args) { | |
250 bool enabled = false; | |
251 args->GetBoolean(0, &enabled); | |
252 | |
253 chromeos::accessibility::EnableVirtualKeyboard(enabled); | |
254 } | |
255 | |
256 void SystemOptionsHandler::DecreaseScreenBrightnessCallback( | |
257 const ListValue* args) { | |
258 // Do not allow the options button to turn off the backlight, as that | |
259 // can make it very difficult to see the increase brightness button. | |
260 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
261 DecreaseScreenBrightness(false); | |
262 } | |
263 | |
264 void SystemOptionsHandler::IncreaseScreenBrightnessCallback( | |
265 const ListValue* args) { | |
266 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
267 IncreaseScreenBrightness(); | |
268 } | |
OLD | NEW |