Chromium Code Reviews| Index: chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h |
| diff --git a/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h |
| index e3c8ad882176d3ef1d698fcf18fe5daa61e3a4af..547ec34ee585b53835a8b5caf57806abaee35643 100644 |
| --- a/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h |
| +++ b/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h |
| @@ -5,9 +5,22 @@ |
| #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ |
| #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ |
|
ygorshenin1
2014/04/24 11:30:24
#include <string>
merkulova
2014/04/24 12:49:46
Done.
|
| +#include <vector> |
| + |
| +#include "base/callback.h" |
|
ygorshenin1
2014/04/24 11:30:24
Where this header is used in this file?
merkulova
2014/04/24 12:49:46
Removed
|
| +#include "base/compiler_specific.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/strings/string16.h" |
|
ygorshenin1
2014/04/24 11:30:24
Where this header is used in this file?
ygorshenin1
2014/04/24 11:30:24
Where this header is used in this file?
merkulova
2014/04/24 12:49:46
Removed
merkulova
2014/04/24 12:49:46
Done.
|
| +#include "base/values.h" |
| +#include "chrome/browser/chromeos/device/input_service_proxy.h" |
| #include "chrome/browser/chromeos/login/screens/hid_detection_screen_actor.h" |
| #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" |
| #include "content/public/browser/web_ui.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_device.h" |
| +#include "device/bluetooth/bluetooth_discovery_session.h" |
| + |
| namespace base { |
| class DictionaryValue; |
| @@ -16,9 +29,14 @@ class DictionaryValue; |
| namespace chromeos { |
| // WebUI implementation of HIDDetectionScreenActor. |
| -class HIDDetectionScreenHandler : public HIDDetectionScreenActor, |
| - public BaseScreenHandler { |
| +class HIDDetectionScreenHandler |
| + : public HIDDetectionScreenActor, |
| + public BaseScreenHandler, |
| + public device::BluetoothAdapter::Observer, |
| + public device::BluetoothDevice::PairingDelegate, |
| + public InputServiceProxy::Observer { |
| public: |
| + typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; |
| HIDDetectionScreenHandler(); |
|
ygorshenin1
2014/04/24 11:30:24
nit: add a black line after the typedef.
merkulova
2014/04/24 12:49:46
Done.
|
| virtual ~HIDDetectionScreenHandler(); |
| @@ -35,6 +53,130 @@ class HIDDetectionScreenHandler : public HIDDetectionScreenActor, |
| // WebUIMessageHandler implementation: |
| virtual void RegisterMessages() OVERRIDE; |
| + // device::BluetoothDevice::PairingDelegate override. |
| + // |
| + // This method will be called when the Bluetooth daemon requires a |
|
ygorshenin1
2014/04/24 11:30:24
Don't copy comments from the interface methods, be
merkulova
2014/04/24 12:49:46
Done.
|
| + // PIN Code for authentication of the device |device|, the UI will display |
| + // a blank entry form to obtain the PIN code from the user. |
| + // |
| + // PIN Codes are generally required for Bluetooth 2.0 and earlier devices |
| + // for which there is no automatic pairing or special handling. |
| + virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; |
| + |
| + // device::BluetoothDevice::PairingDelegate override. |
|
Nikita (slow)
2014/04/24 12:14:23
Please remove comments for these methods (override
merkulova
2014/04/24 12:49:46
Done.
|
| + // |
| + // This method will be called when the Bluetooth daemon requires a |
| + // Passkey for authentication of the device |device|, the UI will display |
| + // a blank entry form to obtain the passkey from the user (a numeric in the |
| + // range 0-999999). |
| + // |
| + // Passkeys are generally required for Bluetooth 2.1 and later devices |
| + // which cannot provide input or display on their own, and don't accept |
| + // passkey-less pairing. |
| + virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; |
| + |
| + // device::BluetoothDevice::PairingDelegate override. |
| + // |
| + // This method will be called when the Bluetooth daemon requires that the |
| + // user enter the PIN code |pincode| into the device |device| so that it |
| + // may be authenticated, the UI will display the PIN code with accompanying |
| + // instructions. |
| + // |
| + // This is used for Bluetooth 2.0 and earlier keyboard devices, the |
| + // |pincode| will always be a six-digit numeric in the range 000000-999999 |
| + // for compatibilty with later specifications. |
| + virtual void DisplayPinCode(device::BluetoothDevice* device, |
| + const std::string& pincode) OVERRIDE; |
| + |
| + // device::BluetoothDevice::PairingDelegate override. |
| + // |
| + // This method will be called when the Bluetooth daemon requires that the |
| + // user enter the Passkey |passkey| into the device |device| so that it |
| + // may be authenticated, the UI will display the passkey with accompanying |
| + // instructions. |
| + // |
| + // This is used for Bluetooth 2.1 and later devices that support input |
| + // but not display, such as keyboards. The Passkey is a numeric in the |
| + // range 0-999999 and should be always presented zero-padded to six |
| + // digits. |
| + virtual void DisplayPasskey( |
| + device::BluetoothDevice* device, uint32 passkey) OVERRIDE; |
| + |
| + // device::BluetoothDevice::PairingDelegate override. |
| + // |
| + // This method will be called when the Bluetooth daemon gets a notification |
| + // of a key entered on the device |device| while pairing with the device |
| + // using a PIN code or a Passkey. |
| + // |
| + // The UI will show a visual indication that a given key was pressed in the |
| + // same pairing overlay where the PIN code or Passkey is displayed. |
| + // |
| + // A first call with |entered| as 0 will indicate that this notification |
| + // mechanism is supported by the device allowing the UI to display this fact. |
| + // A last call with |entered| as the length of the key plus one will indicate |
| + // that the [enter] key was pressed. |
| + virtual void KeysEntered(device::BluetoothDevice* device, |
| + uint32 entered) OVERRIDE; |
| + |
| + // device::BluetoothDevice::PairingDelegate override. |
| + // |
| + // This method will be called when the Bluetooth daemon requires that the |
| + // user confirm that the Passkey |passkey| is displayed on the screen |
| + // of the device |device| so that it may be authenticated, the UI will |
| + // display the passkey with accompanying instructions. |
| + // |
| + // This is used for Bluetooth 2.1 and later devices that support display, |
| + // such as other computers or phones. The Passkey is a numeric in the |
| + // range 0-999999 and should be always present zero-padded to six |
| + // digits. |
| + virtual void ConfirmPasskey( |
| + device::BluetoothDevice* device, uint32 passkey) OVERRIDE; |
| + |
| + // device::BluetoothDevice::PairingDelegate override. |
| + virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE; |
| + |
| + // Displays a Bluetooth error. |
| + // |error| maps to a localized resource for the error message. |
| + // |address| is the address of the Bluetooth device. May be an empty |
| + // string if the error is not specific to a single device. |
| + void ReportError(const std::string& error, const std::string& address); |
| + |
| + // device::BluetoothAdapter::Observer implementation. |
| + virtual void DeviceAdded(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) OVERRIDE; |
| + virtual void DeviceChanged(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) OVERRIDE; |
| + virtual void DeviceRemoved(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) OVERRIDE; |
| + |
| + // InputServiceProxy::Observer implementation. |
| + virtual void OnInputDeviceAdded(const InputDeviceInfo& info) OVERRIDE; |
| + virtual void OnInputDeviceRemoved(const std::string& id) OVERRIDE; |
| + |
| + void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| + |
| + // Sends a notification to the Web UI of the status of available Bluetooth/USB |
| + // pointing device. |
| + void SendPointingDeviceNotification(); |
| + |
| + // Sends a notification to the Web UI of the status of available Bluetooth/USB |
| + // keyboard device. |
| + void SendKeyboardDeviceNotification(base::DictionaryValue* params); |
| + void OnGetInputDevicesList(bool skipScreenIfDevicesPresent, |
| + const std::vector<InputDeviceInfo>& devices); |
| + |
| + void StartBTDiscoverySession(); |
| + |
| + // Called by device::BluetoothDevice on a successful pairing and connection |
| + // to a device. |
| + void BTConnected(); |
| + |
| + // Called by device::BluetoothDevice in response to a failure to |
| + // connect to the device with bluetooth address |address| due to an error |
| + // encoded in |error_code|. |
| + void BTConnectError(const std::string& address, |
| + device::BluetoothDevice::ConnectErrorCode error_code); |
| + |
| private: |
| // JS messages handlers. |
| void HandleOnContinue(); |
| @@ -44,6 +186,105 @@ class HIDDetectionScreenHandler : public HIDDetectionScreenActor, |
| // Keeps whether screen should be shown right after initialization. |
| bool show_on_init_; |
| + // Displays in the UI a connecting to the device |device| message. |
| + void DeviceConnecting(device::BluetoothDevice* device); |
| + |
| + // Called by device::BluetoothAdapter in response to a failure to |
| + // change the power status of the adapter. |
| + void EnableChangeError(); |
| + |
| + // Called by device::BluetoothAdapter in response to a successful request |
| + // to initiate a discovery session. |
| + void OnStartDiscoverySession( |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
| + |
| + // Called by device::BluetoothAdapter in response to a failure to |
| + // initiate a discovery session. |
| + void FindDevicesError(); |
| + |
| + // Called by device::BluetoothAdapter in response to a failure to |
| + // terminate a discovery session. |
| + void StopDiscoveryError(); |
| + |
| + // Called by device::BluetoothDevice on a successful pairing and connection |
| + // to a device. |
| + void Connected(); |
| + |
| + // Called by device::BluetoothDevice in response to a failure to |
| + // connect to the device with bluetooth address |address| due to an error |
| + // encoded in |error_code|. |
| + void ConnectError(const std::string& address, |
| + device::BluetoothDevice::ConnectErrorCode error_code); |
| + |
| + // Called by device::BluetoothDevice in response to a failure to |
| + // disconnect the device with bluetooth address |address|. |
| + void DisconnectError(const std::string& address); |
| + |
| + // Called by device::BluetoothDevice in response to a failure to |
| + // disconnect and unpair the device with bluetooth address |address|. |
| + void ForgetError(const std::string& address); |
| + |
| + // Called when the 'Enable bluetooth' checkbox value is changed. |
| + // |args| will contain the checkbox checked state as a string |
| + // ("true" or "false"). |
| + void EnableChangeCallback(const base::ListValue* args); |
| + |
| + // Called when the 'Find Devices' button is pressed from the Bluetooth |
| + // ssettings. |
| + // |args| will be an empty list. |
| + void FindDevicesCallback(const base::ListValue* args); |
| + |
| + // Called when the "Add a device" dialog closes to stop the discovery |
| + // process. |
| + // |args| will be an empty list. |
| + void StopDiscoveryCallback(const base::ListValue* args); |
| + |
| + // Called when the list of paired devices is initialized in order to |
| + // populate the list. |
| + // |args| will be an empty list. |
| + void GetPairedDevicesCallback(const base::ListValue* args); |
| + |
| + void UpdateDevices(bool skipScreenIfDevicesPresent = false); |
|
ygorshenin1
2014/04/24 11:30:24
We don't use default arguments in Chrome code: htt
Nikita (slow)
2014/04/24 12:14:23
nit: Comment is missing.
merkulova
2014/04/24 12:49:46
Done.
merkulova
2014/04/24 12:49:46
Done.
|
| + |
| + void ConnectBTDevice(device::BluetoothDevice* device); |
| + |
| + // Default bluetooth adapter, used for all operations. |
| + scoped_refptr<device::BluetoothAdapter> adapter_; |
| + |
| + InputServiceProxy input_service_proxy_; |
| + |
| + // True, if the UI has requested device discovery. False, if either no device |
| + // discovery was requested or the dialog responsible for device discovery was |
| + // dismissed. |
| + bool should_run_device_discovery_; |
| + |
| + // The current device discovery session. Only one active discovery session is |
| + // kept at a time and the instance that |discovery_session_| points to gets |
| + // replaced by a new one when a new discovery session is initiated. |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| + |
| + // Cached information about the current pairing device, if any. |
| + std::string pairing_device_address_; |
| + std::string pairing_device_pairing_; |
| + std::string pairing_device_pincode_; |
| + int pairing_device_passkey_; |
| + int pairing_device_entered_; |
| + |
| + // Current pointing device, if any. |
| + std::string pointing_device_name_; |
| + std::string pointing_device_id_; |
| + InputDeviceInfo::Type pointing_device_connect_type_; |
| + |
| + // Current keyboard device, if any. |
| + std::string keyboard_device_name_; |
| + std::string keyboard_device_id_; |
| + bool keyboard_is_connecting_; |
| + InputDeviceInfo::Type keyboard_device_connect_type_; |
| + |
| + // Weak pointer factory for generating 'this' pointers that might live longer |
|
ygorshenin1
2014/04/24 11:30:24
nit: weak factories are very common, so comment is
merkulova
2014/04/24 12:49:46
Done.
|
| + // than this object does. |
| + base::WeakPtrFactory<HIDDetectionScreenHandler> weak_ptr_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreenHandler); |
| }; |