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