| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | |
| 15 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | |
| 16 #include "chrome/browser/ui/webui/options/options_ui.h" | 14 #include "chrome/browser/ui/webui/options/options_ui.h" |
| 15 #include "device/bluetooth/bluetooth_adapter.h" |
| 16 #include "device/bluetooth/bluetooth_device.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class DictionaryValue; | 19 class DictionaryValue; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 namespace options { | 23 namespace options { |
| 24 | 24 |
| 25 // Handler for Bluetooth options on the system options page. | 25 // Handler for Bluetooth options on the system options page. |
| 26 class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler, | 26 class BluetoothOptionsHandler |
| 27 public chromeos::BluetoothAdapter::Observer, | 27 : public ::options::OptionsPageUIHandler, |
| 28 public BluetoothDevice::PairingDelegate { | 28 public bluetooth::BluetoothAdapter::Observer, |
| 29 public bluetooth::BluetoothDevice::PairingDelegate { |
| 29 public: | 30 public: |
| 30 BluetoothOptionsHandler(); | 31 BluetoothOptionsHandler(); |
| 31 virtual ~BluetoothOptionsHandler(); | 32 virtual ~BluetoothOptionsHandler(); |
| 32 | 33 |
| 33 // OptionsPageUIHandler implementation. | 34 // OptionsPageUIHandler implementation. |
| 34 virtual void GetLocalizedValues( | 35 virtual void GetLocalizedValues( |
| 35 base::DictionaryValue* localized_strings) OVERRIDE; | 36 base::DictionaryValue* localized_strings) OVERRIDE; |
| 36 virtual void RegisterMessages() OVERRIDE; | 37 virtual void RegisterMessages() OVERRIDE; |
| 37 virtual void InitializeHandler() OVERRIDE; | 38 virtual void InitializeHandler() OVERRIDE; |
| 38 virtual void InitializePage() OVERRIDE; | 39 virtual void InitializePage() OVERRIDE; |
| 39 | 40 |
| 40 // Sends a notification to the Web UI of the status of a Bluetooth device. | 41 // Sends a notification to the Web UI of the status of a Bluetooth device. |
| 41 // |device| is the Bluetooth device. | 42 // |device| is the Bluetooth device. |
| 42 // |params| is an optional set of parameters. | 43 // |params| is an optional set of parameters. |
| 43 void SendDeviceNotification(const BluetoothDevice* device, | 44 void SendDeviceNotification(const bluetooth::BluetoothDevice* device, |
| 44 base::DictionaryValue* params); | 45 base::DictionaryValue* params); |
| 45 | 46 |
| 46 // BluetoothDevice::PairingDelegate override. | 47 // bluetooth::BluetoothDevice::PairingDelegate override. |
| 47 // | 48 // |
| 48 // This method will be called when the Bluetooth daemon requires a | 49 // This method will be called when the Bluetooth daemon requires a |
| 49 // PIN Code for authentication of the device |device|, the UI will display | 50 // PIN Code for authentication of the device |device|, the UI will display |
| 50 // a blank entry form to obtain the PIN code from the user. | 51 // a blank entry form to obtain the PIN code from the user. |
| 51 // | 52 // |
| 52 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices | 53 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices |
| 53 // for which there is no automatic pairing or special handling. | 54 // for which there is no automatic pairing or special handling. |
| 54 virtual void RequestPinCode(BluetoothDevice* device) OVERRIDE; | 55 virtual void RequestPinCode( |
| 56 bluetooth::BluetoothDevice* device) OVERRIDE; |
| 55 | 57 |
| 56 // BluetoothDevice::PairingDelegate override. | 58 // bluetooth::BluetoothDevice::PairingDelegate override. |
| 57 // | 59 // |
| 58 // This method will be called when the Bluetooth daemon requires a | 60 // This method will be called when the Bluetooth daemon requires a |
| 59 // Passkey for authentication of the device |device|, the UI will display | 61 // Passkey for authentication of the device |device|, the UI will display |
| 60 // a blank entry form to obtain the passkey from the user (a numeric in the | 62 // a blank entry form to obtain the passkey from the user (a numeric in the |
| 61 // range 0-999999). | 63 // range 0-999999). |
| 62 // | 64 // |
| 63 // Passkeys are generally required for Bluetooth 2.1 and later devices | 65 // Passkeys are generally required for Bluetooth 2.1 and later devices |
| 64 // which cannot provide input or display on their own, and don't accept | 66 // which cannot provide input or display on their own, and don't accept |
| 65 // passkey-less pairing. | 67 // passkey-less pairing. |
| 66 virtual void RequestPasskey(BluetoothDevice* device) OVERRIDE; | 68 virtual void RequestPasskey( |
| 69 bluetooth::BluetoothDevice* device) OVERRIDE; |
| 67 | 70 |
| 68 // BluetoothDevice::PairingDelegate override. | 71 // bluetooth::BluetoothDevice::PairingDelegate override. |
| 69 // | 72 // |
| 70 // This method will be called when the Bluetooth daemon requires that the | 73 // This method will be called when the Bluetooth daemon requires that the |
| 71 // user enter the PIN code |pincode| into the device |device| so that it | 74 // user enter the PIN code |pincode| into the device |device| so that it |
| 72 // may be authenticated, the UI will display the PIN code with accompanying | 75 // may be authenticated, the UI will display the PIN code with accompanying |
| 73 // instructions. | 76 // instructions. |
| 74 // | 77 // |
| 75 // This is used for Bluetooth 2.0 and earlier keyboard devices, the | 78 // This is used for Bluetooth 2.0 and earlier keyboard devices, the |
| 76 // |pincode| will always be a six-digit numeric in the range 000000-999999 | 79 // |pincode| will always be a six-digit numeric in the range 000000-999999 |
| 77 // for compatibilty with later specifications. | 80 // for compatibilty with later specifications. |
| 78 virtual void DisplayPinCode(BluetoothDevice* device, | 81 virtual void DisplayPinCode(bluetooth::BluetoothDevice* device, |
| 79 const std::string& pincode) OVERRIDE; | 82 const std::string& pincode) OVERRIDE; |
| 80 | 83 |
| 81 // BluetoothDevice::PairingDelegate override. | 84 // bluetooth::BluetoothDevice::PairingDelegate override. |
| 82 // | 85 // |
| 83 // This method will be called when the Bluetooth daemon requires that the | 86 // This method will be called when the Bluetooth daemon requires that the |
| 84 // user enter the Passkey |passkey| into the device |device| so that it | 87 // user enter the Passkey |passkey| into the device |device| so that it |
| 85 // may be authenticated, the UI will display the passkey with accompanying | 88 // may be authenticated, the UI will display the passkey with accompanying |
| 86 // instructions. | 89 // instructions. |
| 87 // | 90 // |
| 88 // This is used for Bluetooth 2.1 and later devices that support input | 91 // This is used for Bluetooth 2.1 and later devices that support input |
| 89 // but not display, such as keyboards. The Passkey is a numeric in the | 92 // but not display, such as keyboards. The Passkey is a numeric in the |
| 90 // range 0-999999 and should be always presented zero-padded to six | 93 // range 0-999999 and should be always presented zero-padded to six |
| 91 // digits. | 94 // digits. |
| 92 virtual void DisplayPasskey(BluetoothDevice* device, uint32 passkey) OVERRIDE; | 95 virtual void DisplayPasskey( |
| 96 bluetooth::BluetoothDevice* device, uint32 passkey) OVERRIDE; |
| 93 | 97 |
| 94 // BluetoothDevice::PairingDelegate override. | 98 // bluetooth::BluetoothDevice::PairingDelegate override. |
| 95 // | 99 // |
| 96 // This method will be called when the Bluetooth daemon requires that the | 100 // This method will be called when the Bluetooth daemon requires that the |
| 97 // user confirm that the Passkey |passkey| is displayed on the screen | 101 // user confirm that the Passkey |passkey| is displayed on the screen |
| 98 // of the device |device| so that it may be authenticated, the UI will | 102 // of the device |device| so that it may be authenticated, the UI will |
| 99 // display the passkey with accompanying instructions. | 103 // display the passkey with accompanying instructions. |
| 100 // | 104 // |
| 101 // This is used for Bluetooth 2.1 and later devices that support display, | 105 // This is used for Bluetooth 2.1 and later devices that support display, |
| 102 // such as other computers or phones. The Passkey is a numeric in the | 106 // such as other computers or phones. The Passkey is a numeric in the |
| 103 // range 0-999999 and should be always present zero-padded to six | 107 // range 0-999999 and should be always present zero-padded to six |
| 104 // digits. | 108 // digits. |
| 105 virtual void ConfirmPasskey(BluetoothDevice* device, uint32 passkey) OVERRIDE; | 109 virtual void ConfirmPasskey( |
| 110 bluetooth::BluetoothDevice* device, uint32 passkey) OVERRIDE; |
| 106 | 111 |
| 107 // BluetoothDevice::PairingDelegate override. | 112 // bluetooth::BluetoothDevice::PairingDelegate override. |
| 108 // | 113 // |
| 109 // This method will be called when any previous DisplayPinCode(), | 114 // This method will be called when any previous DisplayPinCode(), |
| 110 // DisplayPasskey() or ConfirmPasskey() request should be concluded | 115 // DisplayPasskey() or ConfirmPasskey() request should be concluded |
| 111 // and removed from the user. | 116 // and removed from the user. |
| 112 virtual void DismissDisplayOrConfirm() OVERRIDE; | 117 virtual void DismissDisplayOrConfirm() OVERRIDE; |
| 113 | 118 |
| 114 // Displays a Bluetooth error. | 119 // Displays a Bluetooth error. |
| 115 // |error| maps to a localized resource for the error message. | 120 // |error| maps to a localized resource for the error message. |
| 116 // |address| is the address of the Bluetooth device. May be an empty | 121 // |address| is the address of the Bluetooth device. May be an empty |
| 117 // string if the error is not specific to a single device. | 122 // string if the error is not specific to a single device. |
| 118 void ReportError(const std::string& error, const std::string& address); | 123 void ReportError(const std::string& error, const std::string& address); |
| 119 | 124 |
| 120 // BluetoothAdapter::Observer implementation. | 125 // bluetooth::BluetoothAdapter::Observer implementation. |
| 121 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | 126 virtual void AdapterPresentChanged( |
| 122 bool present) OVERRIDE; | 127 bluetooth::BluetoothAdapter* adapter, |
| 123 virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, | 128 bool present) OVERRIDE; |
| 124 bool powered) OVERRIDE; | 129 virtual void AdapterPoweredChanged( |
| 125 virtual void DeviceAdded(BluetoothAdapter* adapter, | 130 bluetooth::BluetoothAdapter* adapter, |
| 126 BluetoothDevice* device) OVERRIDE; | 131 bool powered) OVERRIDE; |
| 127 virtual void DeviceChanged(BluetoothAdapter* adapter, | 132 virtual void DeviceAdded(bluetooth::BluetoothAdapter* adapter, |
| 128 BluetoothDevice* device) OVERRIDE; | 133 bluetooth::BluetoothDevice* device) OVERRIDE; |
| 129 virtual void DeviceRemoved(BluetoothAdapter* adapter, | 134 virtual void DeviceChanged( |
| 130 BluetoothDevice* device) OVERRIDE; | 135 bluetooth::BluetoothAdapter* adapter, |
| 136 bluetooth::BluetoothDevice* device) OVERRIDE; |
| 137 virtual void DeviceRemoved( |
| 138 bluetooth::BluetoothAdapter* adapter, |
| 139 bluetooth::BluetoothDevice* device) OVERRIDE; |
| 131 | 140 |
| 132 private: | 141 private: |
| 133 // Called by BluetoothAdapter in response to a failure to change the power | 142 // Called by bluetooth::BluetoothAdapter in response to a failure to |
| 134 // status of the adapter. | 143 // change the power status of the adapter. |
| 135 void EnableChangeError(); | 144 void EnableChangeError(); |
| 136 | 145 |
| 137 // Called by BluetoothAdapter in response to a failure to set the adapter into | 146 // Called by bluetooth::BluetoothAdapter in response to a failure to |
| 138 // discovery mode. | 147 // set the adapter into discovery mode. |
| 139 void FindDevicesError(); | 148 void FindDevicesError(); |
| 140 | 149 |
| 141 // Called by BluetoothAdapter in response to a failure to remove the adapter | 150 // Called by bluetooth::BluetoothAdapter in response to a failure to |
| 142 // from discovery mode. | 151 // remove the adapter from discovery mode. |
| 143 void StopDiscoveryError(); | 152 void StopDiscoveryError(); |
| 144 | 153 |
| 145 // Called by BluetoothDevice in response to a failure to connect to the device | 154 // Called by bluetooth::BluetoothDevice in response to a failure to |
| 146 // with bluetooth address |address|. | 155 // connect to the device with bluetooth address |address|. |
| 147 void ConnectError(const std::string& address); | 156 void ConnectError(const std::string& address); |
| 148 | 157 |
| 149 // Called by BluetoothDevice in response to a failure to disconnect the device | 158 // Called by bluetooth::BluetoothDevice in response to a failure to |
| 150 // with bluetooth address |address|. | 159 // disconnect the device with bluetooth address |address|. |
| 151 void DisconnectError(const std::string& address); | 160 void DisconnectError(const std::string& address); |
| 152 | 161 |
| 153 // Called by BluetoothDevice in response to a failure to disconnect and unpair | 162 // Called by bluetooth::BluetoothDevice in response to a failure to |
| 154 // the device with bluetooth address |address|. | 163 // disconnect and unpair the device with bluetooth address |address|. |
| 155 void ForgetError(const std::string& address); | 164 void ForgetError(const std::string& address); |
| 156 | 165 |
| 157 // Called when the 'Enable bluetooth' checkbox value is changed. | 166 // Called when the 'Enable bluetooth' checkbox value is changed. |
| 158 // |args| will contain the checkbox checked state as a string | 167 // |args| will contain the checkbox checked state as a string |
| 159 // ("true" or "false"). | 168 // ("true" or "false"). |
| 160 void EnableChangeCallback(const base::ListValue* args); | 169 void EnableChangeCallback(const base::ListValue* args); |
| 161 | 170 |
| 162 // Called when the 'Find Devices' button is pressed from the Bluetooth | 171 // Called when the 'Find Devices' button is pressed from the Bluetooth |
| 163 // ssettings. | 172 // ssettings. |
| 164 // |args| will be an empty list. | 173 // |args| will be an empty list. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 175 // process. | 184 // process. |
| 176 // |args| will be an empty list. | 185 // |args| will be an empty list. |
| 177 void StopDiscoveryCallback(const base::ListValue* args); | 186 void StopDiscoveryCallback(const base::ListValue* args); |
| 178 | 187 |
| 179 // Called when the list of paired devices is initialized in order to | 188 // Called when the list of paired devices is initialized in order to |
| 180 // populate the list. | 189 // populate the list. |
| 181 // |args| will be an empty list. | 190 // |args| will be an empty list. |
| 182 void GetPairedDevicesCallback(const base::ListValue* args); | 191 void GetPairedDevicesCallback(const base::ListValue* args); |
| 183 | 192 |
| 184 // Default bluetooth adapter, used for all operations. | 193 // Default bluetooth adapter, used for all operations. |
| 185 scoped_refptr<BluetoothAdapter> adapter_; | 194 scoped_refptr<bluetooth::BluetoothAdapter> adapter_; |
| 186 | 195 |
| 187 // Weak pointer factory for generating 'this' pointers that might live longer | 196 // Weak pointer factory for generating 'this' pointers that might live longer |
| 188 // than this object does. | 197 // than this object does. |
| 189 base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_; | 198 base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_; |
| 190 | 199 |
| 191 DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler); | 200 DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler); |
| 192 }; | 201 }; |
| 193 | 202 |
| 194 } // namespace options | 203 } // namespace options |
| 195 } // namespace chromeos | 204 } // namespace chromeos |
| 196 | 205 |
| 197 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ | 206 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_ |
| OLD | NEW |