OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/ui/webui/options/chromeos/system_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/system_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 IDS_OPTIONS_SETTINGS_TAP_TO_CLICK_ENABLED_DESCRIPTION)); | 72 IDS_OPTIONS_SETTINGS_TAP_TO_CLICK_ENABLED_DESCRIPTION)); |
73 localized_strings->SetString("sensitivity", | 73 localized_strings->SetString("sensitivity", |
74 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SENSITIVITY_DESCRIPTION)); | 74 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SENSITIVITY_DESCRIPTION)); |
75 localized_strings->SetString("sensitivityLess", | 75 localized_strings->SetString("sensitivityLess", |
76 l10n_util::GetStringUTF16( | 76 l10n_util::GetStringUTF16( |
77 IDS_OPTIONS_SETTINGS_SENSITIVITY_LESS_DESCRIPTION)); | 77 IDS_OPTIONS_SETTINGS_SENSITIVITY_LESS_DESCRIPTION)); |
78 localized_strings->SetString("sensitivityMore", | 78 localized_strings->SetString("sensitivityMore", |
79 l10n_util::GetStringUTF16( | 79 l10n_util::GetStringUTF16( |
80 IDS_OPTIONS_SETTINGS_SENSITIVITY_MORE_DESCRIPTION)); | 80 IDS_OPTIONS_SETTINGS_SENSITIVITY_MORE_DESCRIPTION)); |
81 | 81 |
82 localized_strings->SetString("bluetooth", | |
83 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH)); | |
84 localized_strings->SetString("enableBluetooth", | |
85 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_ENABLE)); | |
86 localized_strings->SetString("findBluetoothDevices", | |
87 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_FIND_BLUETOOTH_DEVICES)); | |
88 localized_strings->SetString("bluetoothScanning", | |
89 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_SCANNING)); | |
90 localized_strings->SetString("bluetoothDeviceConnected", | |
91 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTED)); | |
92 localized_strings->SetString("bluetoothDeviceNotPaired", | |
93 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_NOT_PAIRED)); | |
94 localized_strings->SetString("bluetoothConnectDevice", | |
95 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECT)); | |
96 localized_strings->SetString("bluetoothDisconnectDevice", | |
97 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_DISCONNECT)); | |
98 | |
99 localized_strings->SetString("language", | 82 localized_strings->SetString("language", |
100 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE)); | 83 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE)); |
101 localized_strings->SetString("languageCustomize", | 84 localized_strings->SetString("languageCustomize", |
102 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE)); | 85 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE)); |
103 localized_strings->SetString("modifierKeysCustomize", | 86 localized_strings->SetString("modifierKeysCustomize", |
104 l10n_util::GetStringUTF16( | 87 l10n_util::GetStringUTF16( |
105 IDS_OPTIONS_SETTINGS_LANGUAGES_MODIFIER_KEYS_CUSTOMIZE)); | 88 IDS_OPTIONS_SETTINGS_LANGUAGES_MODIFIER_KEYS_CUSTOMIZE)); |
106 | 89 |
107 localized_strings->SetString("accessibilityTitle", | 90 localized_strings->SetString("accessibilityTitle", |
108 l10n_util::GetStringUTF16( | 91 l10n_util::GetStringUTF16( |
109 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY)); | 92 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY)); |
110 localized_strings->SetString("accessibility", | 93 localized_strings->SetString("accessibility", |
111 l10n_util::GetStringUTF16( | 94 l10n_util::GetStringUTF16( |
112 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_DESCRIPTION)); | 95 IDS_OPTIONS_SETTINGS_ACCESSIBILITY_DESCRIPTION)); |
113 | 96 |
114 localized_strings->Set("timezoneList", | 97 localized_strings->Set("timezoneList", |
115 reinterpret_cast<chromeos::SystemSettingsProvider*>( | 98 reinterpret_cast<chromeos::SystemSettingsProvider*>( |
116 settings_provider_.get())->GetTimezoneList()); | 99 settings_provider_.get())->GetTimezoneList()); |
117 } | 100 } |
118 | 101 |
119 void SystemOptionsHandler::Initialize() { | 102 void SystemOptionsHandler::Initialize() { |
120 DCHECK(web_ui_); | 103 DCHECK(web_ui_); |
121 PrefService* pref_service = g_browser_process->local_state(); | 104 PrefService* pref_service = g_browser_process->local_state(); |
122 bool acc_enabled = pref_service->GetBoolean(prefs::kAccessibilityEnabled); | 105 bool acc_enabled = pref_service->GetBoolean(prefs::kAccessibilityEnabled); |
123 base::FundamentalValue checked(acc_enabled); | 106 base::FundamentalValue checked(acc_enabled); |
124 web_ui_->CallJavascriptFunction( | 107 web_ui_->CallJavascriptFunction( |
125 "options.SystemOptions.SetAccessibilityCheckboxState", checked); | 108 "options.SystemOptions.SetAccessibilityCheckboxState", checked); |
126 | |
127 // Bluetooth support is a work in progress. Supress the feature unless | |
128 // explicitly enabled via a command line flag. | |
129 // TODO (kevers) - Test for presence of bluetooth hardware. | |
130 if (CommandLine::ForCurrentProcess() | |
131 ->HasSwitch(switches::kEnableBluetooth)) { | |
132 web_ui_->CallJavascriptFunction( | |
133 "options.SystemOptions.showBluetoothSettings"); | |
134 } | |
135 } | 109 } |
136 | 110 |
137 void SystemOptionsHandler::RegisterMessages() { | 111 void SystemOptionsHandler::RegisterMessages() { |
138 DCHECK(web_ui_); | 112 DCHECK(web_ui_); |
139 web_ui_->RegisterMessageCallback("accessibilityChange", | 113 web_ui_->RegisterMessageCallback("accessibilityChange", |
140 base::Bind(&SystemOptionsHandler::AccessibilityChangeCallback, | 114 base::Bind(&SystemOptionsHandler::AccessibilityChangeCallback, |
141 base::Unretained(this))); | 115 base::Unretained(this))); |
142 | 116 |
143 web_ui_->RegisterMessageCallback("decreaseScreenBrightness", | 117 web_ui_->RegisterMessageCallback("decreaseScreenBrightness", |
144 base::Bind(&SystemOptionsHandler::DecreaseScreenBrightnessCallback, | 118 base::Bind(&SystemOptionsHandler::DecreaseScreenBrightnessCallback, |
145 base::Unretained(this))); | 119 base::Unretained(this))); |
146 web_ui_->RegisterMessageCallback("increaseScreenBrightness", | 120 web_ui_->RegisterMessageCallback("increaseScreenBrightness", |
147 base::Bind(&SystemOptionsHandler::IncreaseScreenBrightnessCallback, | 121 base::Bind(&SystemOptionsHandler::IncreaseScreenBrightnessCallback, |
148 base::Unretained(this))); | 122 base::Unretained(this))); |
149 | |
150 web_ui_->RegisterMessageCallback("bluetoothEnableChange", | |
151 base::Bind(&SystemOptionsHandler::BluetoothEnableChangeCallback, | |
152 base::Unretained(this))); | |
153 web_ui_->RegisterMessageCallback("findBluetoothDevices", | |
154 base::Bind(&SystemOptionsHandler::FindBluetoothDevicesCallback, | |
155 base::Unretained(this))); | |
156 } | 123 } |
157 | 124 |
158 void SystemOptionsHandler::AccessibilityChangeCallback(const ListValue* args) { | 125 void SystemOptionsHandler::AccessibilityChangeCallback(const ListValue* args) { |
159 std::string checked_str; | 126 std::string checked_str; |
160 args->GetString(0, &checked_str); | 127 args->GetString(0, &checked_str); |
161 bool accessibility_enabled = (checked_str == "true"); | 128 bool accessibility_enabled = (checked_str == "true"); |
162 | 129 |
163 chromeos::accessibility::EnableAccessibility(accessibility_enabled, NULL); | 130 chromeos::accessibility::EnableAccessibility(accessibility_enabled, NULL); |
164 } | 131 } |
165 | 132 |
166 void SystemOptionsHandler::DecreaseScreenBrightnessCallback( | 133 void SystemOptionsHandler::DecreaseScreenBrightnessCallback( |
167 const ListValue* args) { | 134 const ListValue* args) { |
168 // Do not allow the options button to turn off the backlight, as that | 135 // Do not allow the options button to turn off the backlight, as that |
169 // can make it very difficult to see the increase brightness button. | 136 // can make it very difficult to see the increase brightness button. |
170 chromeos::DBusThreadManager::Get()->power_manager_client()-> | 137 chromeos::DBusThreadManager::Get()->power_manager_client()-> |
171 DecreaseScreenBrightness(false); | 138 DecreaseScreenBrightness(false); |
172 } | 139 } |
173 | 140 |
174 void SystemOptionsHandler::IncreaseScreenBrightnessCallback( | 141 void SystemOptionsHandler::IncreaseScreenBrightnessCallback( |
175 const ListValue* args) { | 142 const ListValue* args) { |
176 chromeos::DBusThreadManager::Get()->power_manager_client()-> | 143 chromeos::DBusThreadManager::Get()->power_manager_client()-> |
177 IncreaseScreenBrightness(); | 144 IncreaseScreenBrightness(); |
178 } | 145 } |
179 | |
180 void SystemOptionsHandler::BluetoothEnableChangeCallback( | |
181 const ListValue* args) { | |
182 // TODO (kevers) - Call Bluetooth API to enable or disable. | |
183 } | |
184 | |
185 void SystemOptionsHandler::FindBluetoothDevicesCallback( | |
186 const ListValue* args) { | |
187 // TODO (kevers) - Call Bluetooth API to fetch devices. | |
188 // Generate a fake list until the bluetooth API is ready. | |
189 // Afterwards keep fake list only for cases where emulating | |
190 // ChromeOS from the desktop launch. | |
191 GenerateFakeDeviceList(); | |
192 } | |
193 | |
194 void SystemOptionsHandler::BluetoothDeviceNotification( | |
195 const DictionaryValue& device) { | |
196 web_ui_->CallJavascriptFunction( | |
197 "options.SystemOptions.addBluetoothDevice", device); | |
198 } | |
199 | |
200 void SystemOptionsHandler::GenerateFakeDeviceList() { | |
201 // TODO (kevers) - Send notifications asynchronously simulating that the | |
202 // process of discovering bluetooth devices takes time. | |
203 // Fire each notification using OneShotTimer with a | |
204 // varying delay. | |
205 std::string data[9] = { | |
206 "Fake Wireless Keyboard", "01-02-03-04-05", "keyboard", | |
207 "Fake Wireless Mouse", "02-03-04-05-01", "mouse", | |
208 "Fake Wireless Headset", "03-04-05-01-02", "headset"}; | |
209 | |
210 for (int i = 0; i < 3; i++) { | |
211 DictionaryValue device; | |
212 device.SetString("deviceName", data[3*i]); | |
213 device.SetString("deviceId", data[3*i+1]); | |
214 device.SetString("deviceType", data[3*i+2]); | |
215 device.SetString("deviceStatus", "bluetoothDeviceNotPaired"); | |
216 web_ui_->CallJavascriptFunction( | |
217 "options.SystemOptions.addBluetoothDevice", device); | |
218 } | |
219 web_ui_->CallJavascriptFunction( | |
220 "options.SystemOptions.notifyBluetoothSearchComplete"); | |
221 } | |
OLD | NEW |