OLD | NEW |
(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/options/chromeos/bluetooth_options_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 12 #include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h" |
| 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "grit/chromium_strings.h" |
| 15 #include "grit/generated_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 BluetoothOptionsHandler::BluetoothOptionsHandler() |
| 21 : chromeos::CrosOptionsPageUIHandler( |
| 22 new chromeos::SystemSettingsProvider()) { |
| 23 } |
| 24 |
| 25 BluetoothOptionsHandler::~BluetoothOptionsHandler() { |
| 26 // TODO(kevers): Shutdown bluetooth. |
| 27 } |
| 28 |
| 29 void BluetoothOptionsHandler::GetLocalizedValues( |
| 30 DictionaryValue* localized_strings) { |
| 31 DCHECK(localized_strings); |
| 32 |
| 33 localized_strings->SetString("bluetooth", |
| 34 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH)); |
| 35 localized_strings->SetString("enableBluetooth", |
| 36 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_ENABLE)); |
| 37 localized_strings->SetString("findBluetoothDevices", |
| 38 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_FIND_BLUETOOTH_DEVICES)); |
| 39 localized_strings->SetString("bluetoothScanning", |
| 40 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_SCANNING)); |
| 41 localized_strings->SetString("bluetoothDeviceConnected", |
| 42 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECTED)); |
| 43 localized_strings->SetString("bluetoothDeviceNotPaired", |
| 44 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_NOT_PAIRED)); |
| 45 localized_strings->SetString("bluetoothConnectDevice", |
| 46 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_CONNECT)); |
| 47 localized_strings->SetString("bluetoothDisconnectDevice", |
| 48 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_BLUETOOTH_DISCONNECT)); |
| 49 } |
| 50 |
| 51 void BluetoothOptionsHandler::Initialize() { |
| 52 DCHECK(web_ui_); |
| 53 // Bluetooth support is a work in progress. Supress the feature unless |
| 54 // explicitly enabled via a command line flag. |
| 55 // TODO(kevers): Test for presence of bluetooth hardware. |
| 56 if (!CommandLine::ForCurrentProcess() |
| 57 ->HasSwitch(switches::kEnableBluetooth)) { |
| 58 return; |
| 59 } |
| 60 web_ui_->CallJavascriptFunction( |
| 61 "options.SystemOptions.showBluetoothSettings"); |
| 62 // TODO(kevers): Initialize bluetooth. |
| 63 } |
| 64 |
| 65 void BluetoothOptionsHandler::RegisterMessages() { |
| 66 DCHECK(web_ui_); |
| 67 web_ui_->RegisterMessageCallback("bluetoothEnableChange", |
| 68 base::Bind(&BluetoothOptionsHandler::EnableChangeCallback, |
| 69 base::Unretained(this))); |
| 70 web_ui_->RegisterMessageCallback("findBluetoothDevices", |
| 71 base::Bind(&BluetoothOptionsHandler::FindDevicesCallback, |
| 72 base::Unretained(this))); |
| 73 web_ui_->RegisterMessageCallback("updateBluetoothDevice", |
| 74 base::Bind(&BluetoothOptionsHandler::UpdateDeviceCallback, |
| 75 base::Unretained(this))); |
| 76 } |
| 77 |
| 78 void BluetoothOptionsHandler::EnableChangeCallback( |
| 79 const ListValue* args) { |
| 80 // TODO(kevers): Call Bluetooth API to enable or disable. |
| 81 } |
| 82 |
| 83 void BluetoothOptionsHandler::FindDevicesCallback( |
| 84 const ListValue* args) { |
| 85 // We only initiate a scan if we're running on Chrome OS. Otherwise, we |
| 86 // generate a fake device list. |
| 87 if (!chromeos::system::runtime_environment::IsRunningOnChromeOS()) { |
| 88 GenerateFakeDeviceList(); |
| 89 return; |
| 90 } |
| 91 // TODO(kevers): Fetch real Bluetooth devices. |
| 92 } |
| 93 |
| 94 void BluetoothOptionsHandler::UpdateDeviceCallback( |
| 95 const ListValue* args) { |
| 96 // TODO(kevers): Trigger connect/disconnect. |
| 97 } |
| 98 |
| 99 void BluetoothOptionsHandler::DeviceNotification( |
| 100 const DictionaryValue& device) { |
| 101 web_ui_->CallJavascriptFunction( |
| 102 "options.SystemOptions.addBluetoothDevice", device); |
| 103 } |
| 104 |
| 105 void BluetoothOptionsHandler::GenerateFakeDeviceList() { |
| 106 // TODO(kevers): Send notifications asynchronously simulating that the |
| 107 // process of discovering bluetooth devices takes time. |
| 108 // Fire each notification using OneShotTimer with a |
| 109 // varying delay. |
| 110 std::string data[9] = { |
| 111 "Fake Wireless Keyboard", "01-02-03-04-05", "keyboard", |
| 112 "Fake Wireless Mouse", "02-03-04-05-01", "mouse", |
| 113 "Fake Wireless Headset", "03-04-05-01-02", "headset"}; |
| 114 |
| 115 for (int i = 0; i < 3; i++) { |
| 116 DictionaryValue device; |
| 117 device.SetString("deviceName", data[3*i]); |
| 118 device.SetString("deviceId", data[3*i+1]); |
| 119 device.SetString("deviceType", data[3*i+2]); |
| 120 device.SetString("deviceStatus", "bluetoothDeviceNotPaired"); |
| 121 web_ui_->CallJavascriptFunction( |
| 122 "options.SystemOptions.addBluetoothDevice", device); |
| 123 } |
| 124 web_ui_->CallJavascriptFunction( |
| 125 "options.SystemOptions.notifyBluetoothSearchComplete"); |
| 126 } |
| 127 |
| 128 } |
| 129 |
OLD | NEW |