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