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/bluetooth_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 bluetooth_manager->RemoveObserver(this); | 44 bluetooth_manager->RemoveObserver(this); |
45 } | 45 } |
46 | 46 |
47 void BluetoothOptionsHandler::GetLocalizedValues( | 47 void BluetoothOptionsHandler::GetLocalizedValues( |
48 DictionaryValue* localized_strings) { | 48 DictionaryValue* localized_strings) { |
49 DCHECK(localized_strings); | 49 DCHECK(localized_strings); |
50 | 50 |
51 localized_strings->SetString("bluetooth", | 51 localized_strings->SetString("bluetooth", |
52 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH)); | 52 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH)); |
| 53 localized_strings->SetString("disableBluetooth", |
| 54 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_DISABLE)); |
53 localized_strings->SetString("enableBluetooth", | 55 localized_strings->SetString("enableBluetooth", |
54 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_ENABLE)); | 56 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_ENABLE)); |
| 57 localized_strings->SetString("noBluetoothDevicesFound", |
| 58 l10n_util::GetStringUTF16( |
| 59 IDS_OPTIONS_SETTINGS_NO_BLUETOOTH_DEVICES_FOUND)); |
55 localized_strings->SetString("findBluetoothDevices", | 60 localized_strings->SetString("findBluetoothDevices", |
56 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_FIND_BLUETOOTH_DEVICES)); | 61 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_FIND_BLUETOOTH_DEVICES)); |
57 localized_strings->SetString("bluetoothScanning", | 62 localized_strings->SetString("bluetoothScanning", |
58 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_SCANNING)); | 63 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_SCANNING)); |
59 localized_strings->SetString("bluetoothDeviceConnected", | 64 localized_strings->SetString("bluetoothDeviceConnected", |
60 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTED)); | 65 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTED)); |
61 localized_strings->SetString("bluetoothDeviceConnecting", | 66 localized_strings->SetString("bluetoothDeviceConnecting", |
62 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTING)); | 67 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTING)); |
63 localized_strings->SetString("bluetoothDeviceNotPaired", | 68 localized_strings->SetString("bluetoothDeviceNotPaired", |
64 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_NOT_PAIRED)); | 69 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_NOT_PAIRED)); |
(...skipping 29 matching lines...) Expand all Loading... |
94 // explicitly enabled via a command line flag. | 99 // explicitly enabled via a command line flag. |
95 if (!CommandLine::ForCurrentProcess() | 100 if (!CommandLine::ForCurrentProcess() |
96 ->HasSwitch(switches::kEnableBluetooth)) { | 101 ->HasSwitch(switches::kEnableBluetooth)) { |
97 return; | 102 return; |
98 } | 103 } |
99 | 104 |
100 web_ui_->CallJavascriptFunction( | 105 web_ui_->CallJavascriptFunction( |
101 "options.SystemOptions.showBluetoothSettings"); | 106 "options.SystemOptions.showBluetoothSettings"); |
102 | 107 |
103 // TODO(kevers): Determine whether bluetooth adapter is powered. | 108 // TODO(kevers): Determine whether bluetooth adapter is powered. |
104 bool bluetooth_on = true; | 109 bool bluetooth_on = false; |
105 base::FundamentalValue checked(bluetooth_on); | 110 base::FundamentalValue checked(bluetooth_on); |
106 web_ui_->CallJavascriptFunction( | 111 web_ui_->CallJavascriptFunction( |
107 "options.SystemOptions.setBluetoothCheckboxState", checked); | 112 "options.SystemOptions.setBluetoothState", checked); |
108 | 113 |
109 chromeos::BluetoothManager* bluetooth_manager = | 114 chromeos::BluetoothManager* bluetooth_manager = |
110 chromeos::BluetoothManager::GetInstance(); | 115 chromeos::BluetoothManager::GetInstance(); |
111 DCHECK(bluetooth_manager); | 116 DCHECK(bluetooth_manager); |
112 bluetooth_manager->AddObserver(this); | 117 bluetooth_manager->AddObserver(this); |
113 | 118 |
114 chromeos::BluetoothAdapter* default_adapter = | 119 chromeos::BluetoothAdapter* default_adapter = |
115 bluetooth_manager->DefaultAdapter(); | 120 bluetooth_manager->DefaultAdapter(); |
116 DefaultAdapterChanged(default_adapter); | 121 DefaultAdapterChanged(default_adapter); |
117 } | 122 } |
(...skipping 11 matching lines...) Expand all Loading... |
129 base::Unretained(this))); | 134 base::Unretained(this))); |
130 } | 135 } |
131 | 136 |
132 void BluetoothOptionsHandler::EnableChangeCallback( | 137 void BluetoothOptionsHandler::EnableChangeCallback( |
133 const ListValue* args) { | 138 const ListValue* args) { |
134 bool bluetooth_enabled; | 139 bool bluetooth_enabled; |
135 args->GetBoolean(0, &bluetooth_enabled); | 140 args->GetBoolean(0, &bluetooth_enabled); |
136 // TODO(kevers): Call Bluetooth API to enable or disable. | 141 // TODO(kevers): Call Bluetooth API to enable or disable. |
137 base::FundamentalValue checked(bluetooth_enabled); | 142 base::FundamentalValue checked(bluetooth_enabled); |
138 web_ui_->CallJavascriptFunction( | 143 web_ui_->CallJavascriptFunction( |
139 "options.SystemOptions.setBluetoothCheckboxState", checked); | 144 "options.SystemOptions.setBluetoothState", checked); |
140 } | 145 } |
141 | 146 |
142 void BluetoothOptionsHandler::FindDevicesCallback( | 147 void BluetoothOptionsHandler::FindDevicesCallback( |
143 const ListValue* args) { | 148 const ListValue* args) { |
144 // We only initiate a scan if we're running on Chrome OS. Otherwise, we | 149 // We only initiate a scan if we're running on Chrome OS. Otherwise, we |
145 // generate a fake device list. | 150 // generate a fake device list. |
146 if (!chromeos::system::runtime_environment::IsRunningOnChromeOS()) { | 151 if (!chromeos::system::runtime_environment::IsRunningOnChromeOS()) { |
147 GenerateFakeDeviceList(); | 152 GenerateFakeDeviceList(); |
148 return; | 153 return; |
149 } | 154 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 if ((adapter == NULL && !default_adapter_id_.empty()) || | 299 if ((adapter == NULL && !default_adapter_id_.empty()) || |
295 (adapter != NULL && default_adapter_id_ != adapter->Id())) { | 300 (adapter != NULL && default_adapter_id_ != adapter->Id())) { |
296 VLOG(1) << "unexpected default adapter change from \"" | 301 VLOG(1) << "unexpected default adapter change from \"" |
297 << default_adapter_id_ << "\" to \"" << adapter->Id() << "\""; | 302 << default_adapter_id_ << "\" to \"" << adapter->Id() << "\""; |
298 DefaultAdapterChanged(adapter); | 303 DefaultAdapterChanged(adapter); |
299 } | 304 } |
300 } | 305 } |
301 | 306 |
302 void BluetoothOptionsHandler::GenerateFakeDeviceList() { | 307 void BluetoothOptionsHandler::GenerateFakeDeviceList() { |
303 GenerateFakeDevice( | 308 GenerateFakeDevice( |
304 | |
305 "Fake Wireless Keyboard", | 309 "Fake Wireless Keyboard", |
306 "01-02-03-04-05-06", | 310 "01-02-03-04-05-06", |
307 "input-keyboard", | 311 "input-keyboard", |
308 true, | 312 true, |
309 true, | 313 true, |
310 ""); | 314 ""); |
311 GenerateFakeDevice( | 315 GenerateFakeDevice( |
312 "Fake Wireless Mouse", | 316 "Fake Wireless Mouse", |
313 "02-03-04-05-06-01", | 317 "02-03-04-05-06-01", |
314 "input-mouse", | 318 "input-mouse", |
(...skipping 21 matching lines...) Expand all Loading... |
336 false, | 340 false, |
337 false, | 341 false, |
338 "bluetoothConfirmPasskey"); | 342 "bluetoothConfirmPasskey"); |
339 GenerateFakeDevice( | 343 GenerateFakeDevice( |
340 "Fake Connecting Headset", | 344 "Fake Connecting Headset", |
341 "06-01-02-03-04-05", | 345 "06-01-02-03-04-05", |
342 "headset", | 346 "headset", |
343 false, | 347 false, |
344 false, | 348 false, |
345 "bluetoothEnterPasskey"); | 349 "bluetoothEnterPasskey"); |
346 | |
347 web_ui_->CallJavascriptFunction( | 350 web_ui_->CallJavascriptFunction( |
348 "options.SystemOptions.notifyBluetoothSearchComplete"); | 351 "options.SystemOptions.notifyBluetoothSearchComplete"); |
349 } | 352 } |
350 | 353 |
351 void BluetoothOptionsHandler::GenerateFakeDevice( | 354 void BluetoothOptionsHandler::GenerateFakeDevice( |
352 const std::string& name, | 355 const std::string& name, |
353 const std::string& address, | 356 const std::string& address, |
354 const std::string& icon, | 357 const std::string& icon, |
355 bool paired, | 358 bool paired, |
356 bool connected, | 359 bool connected, |
(...skipping 13 matching lines...) Expand all Loading... |
370 } else if (pairing.compare("bluetoothConfirmPasskey") == 0) { | 373 } else if (pairing.compare("bluetoothConfirmPasskey") == 0) { |
371 RequestConfirmation(device, 12345); | 374 RequestConfirmation(device, 12345); |
372 } else if (pairing.compare("bluetoothEnterPasskey") == 0) { | 375 } else if (pairing.compare("bluetoothEnterPasskey") == 0) { |
373 RequestPasskey(device); | 376 RequestPasskey(device); |
374 } | 377 } |
375 delete device; | 378 delete device; |
376 } | 379 } |
377 | 380 |
378 } // namespace chromeos | 381 } // namespace chromeos |
379 | 382 |
OLD | NEW |