Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H_ |
| 7 | 7 |
|
ygorshenin1
2014/04/24 11:30:24
#include <string>
merkulova
2014/04/24 12:49:46
Done.
| |
| 8 #include <vector> | |
| 9 | |
| 10 #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
| |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #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.
| |
| 15 #include "base/values.h" | |
| 16 #include "chrome/browser/chromeos/device/input_service_proxy.h" | |
| 8 #include "chrome/browser/chromeos/login/screens/hid_detection_screen_actor.h" | 17 #include "chrome/browser/chromeos/login/screens/hid_detection_screen_actor.h" |
| 9 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" | 18 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" |
| 10 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
| 20 #include "device/bluetooth/bluetooth_adapter.h" | |
| 21 #include "device/bluetooth/bluetooth_device.h" | |
| 22 #include "device/bluetooth/bluetooth_discovery_session.h" | |
| 23 | |
| 11 | 24 |
| 12 namespace base { | 25 namespace base { |
| 13 class DictionaryValue; | 26 class DictionaryValue; |
| 14 } | 27 } |
| 15 | 28 |
| 16 namespace chromeos { | 29 namespace chromeos { |
| 17 | 30 |
| 18 // WebUI implementation of HIDDetectionScreenActor. | 31 // WebUI implementation of HIDDetectionScreenActor. |
| 19 class HIDDetectionScreenHandler : public HIDDetectionScreenActor, | 32 class HIDDetectionScreenHandler |
| 20 public BaseScreenHandler { | 33 : public HIDDetectionScreenActor, |
| 34 public BaseScreenHandler, | |
| 35 public device::BluetoothAdapter::Observer, | |
| 36 public device::BluetoothDevice::PairingDelegate, | |
| 37 public InputServiceProxy::Observer { | |
| 21 public: | 38 public: |
| 39 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; | |
| 22 HIDDetectionScreenHandler(); | 40 HIDDetectionScreenHandler(); |
|
ygorshenin1
2014/04/24 11:30:24
nit: add a black line after the typedef.
merkulova
2014/04/24 12:49:46
Done.
| |
| 23 virtual ~HIDDetectionScreenHandler(); | 41 virtual ~HIDDetectionScreenHandler(); |
| 24 | 42 |
| 25 // HIDDetectionScreenActor implementation: | 43 // HIDDetectionScreenActor implementation: |
| 26 virtual void PrepareToShow() OVERRIDE; | 44 virtual void PrepareToShow() OVERRIDE; |
| 27 virtual void Show() OVERRIDE; | 45 virtual void Show() OVERRIDE; |
| 28 virtual void Hide() OVERRIDE; | 46 virtual void Hide() OVERRIDE; |
| 29 virtual void SetDelegate(Delegate* delegate) OVERRIDE; | 47 virtual void SetDelegate(Delegate* delegate) OVERRIDE; |
| 30 | 48 |
| 31 // BaseScreenHandler implementation: | 49 // BaseScreenHandler implementation: |
| 32 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE; | 50 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE; |
| 33 virtual void Initialize() OVERRIDE; | 51 virtual void Initialize() OVERRIDE; |
| 34 | 52 |
| 35 // WebUIMessageHandler implementation: | 53 // WebUIMessageHandler implementation: |
| 36 virtual void RegisterMessages() OVERRIDE; | 54 virtual void RegisterMessages() OVERRIDE; |
| 37 | 55 |
| 56 // device::BluetoothDevice::PairingDelegate override. | |
| 57 // | |
| 58 // 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.
| |
| 59 // PIN Code for authentication of the device |device|, the UI will display | |
| 60 // a blank entry form to obtain the PIN code from the user. | |
| 61 // | |
| 62 // PIN Codes are generally required for Bluetooth 2.0 and earlier devices | |
| 63 // for which there is no automatic pairing or special handling. | |
| 64 virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; | |
| 65 | |
| 66 // 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.
| |
| 67 // | |
| 68 // This method will be called when the Bluetooth daemon requires a | |
| 69 // Passkey for authentication of the device |device|, the UI will display | |
| 70 // a blank entry form to obtain the passkey from the user (a numeric in the | |
| 71 // range 0-999999). | |
| 72 // | |
| 73 // Passkeys are generally required for Bluetooth 2.1 and later devices | |
| 74 // which cannot provide input or display on their own, and don't accept | |
| 75 // passkey-less pairing. | |
| 76 virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; | |
| 77 | |
| 78 // device::BluetoothDevice::PairingDelegate override. | |
| 79 // | |
| 80 // This method will be called when the Bluetooth daemon requires that the | |
| 81 // user enter the PIN code |pincode| into the device |device| so that it | |
| 82 // may be authenticated, the UI will display the PIN code with accompanying | |
| 83 // instructions. | |
| 84 // | |
| 85 // This is used for Bluetooth 2.0 and earlier keyboard devices, the | |
| 86 // |pincode| will always be a six-digit numeric in the range 000000-999999 | |
| 87 // for compatibilty with later specifications. | |
| 88 virtual void DisplayPinCode(device::BluetoothDevice* device, | |
| 89 const std::string& pincode) OVERRIDE; | |
| 90 | |
| 91 // device::BluetoothDevice::PairingDelegate override. | |
| 92 // | |
| 93 // This method will be called when the Bluetooth daemon requires that the | |
| 94 // user enter the Passkey |passkey| into the device |device| so that it | |
| 95 // may be authenticated, the UI will display the passkey with accompanying | |
| 96 // instructions. | |
| 97 // | |
| 98 // This is used for Bluetooth 2.1 and later devices that support input | |
| 99 // but not display, such as keyboards. The Passkey is a numeric in the | |
| 100 // range 0-999999 and should be always presented zero-padded to six | |
| 101 // digits. | |
| 102 virtual void DisplayPasskey( | |
| 103 device::BluetoothDevice* device, uint32 passkey) OVERRIDE; | |
| 104 | |
| 105 // device::BluetoothDevice::PairingDelegate override. | |
| 106 // | |
| 107 // This method will be called when the Bluetooth daemon gets a notification | |
| 108 // of a key entered on the device |device| while pairing with the device | |
| 109 // using a PIN code or a Passkey. | |
| 110 // | |
| 111 // The UI will show a visual indication that a given key was pressed in the | |
| 112 // same pairing overlay where the PIN code or Passkey is displayed. | |
| 113 // | |
| 114 // A first call with |entered| as 0 will indicate that this notification | |
| 115 // mechanism is supported by the device allowing the UI to display this fact. | |
| 116 // A last call with |entered| as the length of the key plus one will indicate | |
| 117 // that the [enter] key was pressed. | |
| 118 virtual void KeysEntered(device::BluetoothDevice* device, | |
| 119 uint32 entered) OVERRIDE; | |
| 120 | |
| 121 // device::BluetoothDevice::PairingDelegate override. | |
| 122 // | |
| 123 // This method will be called when the Bluetooth daemon requires that the | |
| 124 // user confirm that the Passkey |passkey| is displayed on the screen | |
| 125 // of the device |device| so that it may be authenticated, the UI will | |
| 126 // display the passkey with accompanying instructions. | |
| 127 // | |
| 128 // This is used for Bluetooth 2.1 and later devices that support display, | |
| 129 // such as other computers or phones. The Passkey is a numeric in the | |
| 130 // range 0-999999 and should be always present zero-padded to six | |
| 131 // digits. | |
| 132 virtual void ConfirmPasskey( | |
| 133 device::BluetoothDevice* device, uint32 passkey) OVERRIDE; | |
| 134 | |
| 135 // device::BluetoothDevice::PairingDelegate override. | |
| 136 virtual void AuthorizePairing(device::BluetoothDevice* device) OVERRIDE; | |
| 137 | |
| 138 // Displays a Bluetooth error. | |
| 139 // |error| maps to a localized resource for the error message. | |
| 140 // |address| is the address of the Bluetooth device. May be an empty | |
| 141 // string if the error is not specific to a single device. | |
| 142 void ReportError(const std::string& error, const std::string& address); | |
| 143 | |
| 144 // device::BluetoothAdapter::Observer implementation. | |
| 145 virtual void DeviceAdded(device::BluetoothAdapter* adapter, | |
| 146 device::BluetoothDevice* device) OVERRIDE; | |
| 147 virtual void DeviceChanged(device::BluetoothAdapter* adapter, | |
| 148 device::BluetoothDevice* device) OVERRIDE; | |
| 149 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, | |
| 150 device::BluetoothDevice* device) OVERRIDE; | |
| 151 | |
| 152 // InputServiceProxy::Observer implementation. | |
| 153 virtual void OnInputDeviceAdded(const InputDeviceInfo& info) OVERRIDE; | |
| 154 virtual void OnInputDeviceRemoved(const std::string& id) OVERRIDE; | |
| 155 | |
| 156 void InitializeAdapter(scoped_refptr<device::BluetoothAdapter> adapter); | |
| 157 | |
| 158 // Sends a notification to the Web UI of the status of available Bluetooth/USB | |
| 159 // pointing device. | |
| 160 void SendPointingDeviceNotification(); | |
| 161 | |
| 162 // Sends a notification to the Web UI of the status of available Bluetooth/USB | |
| 163 // keyboard device. | |
| 164 void SendKeyboardDeviceNotification(base::DictionaryValue* params); | |
| 165 void OnGetInputDevicesList(bool skipScreenIfDevicesPresent, | |
| 166 const std::vector<InputDeviceInfo>& devices); | |
| 167 | |
| 168 void StartBTDiscoverySession(); | |
| 169 | |
| 170 // Called by device::BluetoothDevice on a successful pairing and connection | |
| 171 // to a device. | |
| 172 void BTConnected(); | |
| 173 | |
| 174 // Called by device::BluetoothDevice in response to a failure to | |
| 175 // connect to the device with bluetooth address |address| due to an error | |
| 176 // encoded in |error_code|. | |
| 177 void BTConnectError(const std::string& address, | |
| 178 device::BluetoothDevice::ConnectErrorCode error_code); | |
| 179 | |
| 38 private: | 180 private: |
| 39 // JS messages handlers. | 181 // JS messages handlers. |
| 40 void HandleOnContinue(); | 182 void HandleOnContinue(); |
| 41 | 183 |
| 42 Delegate* delegate_; | 184 Delegate* delegate_; |
| 43 | 185 |
| 44 // Keeps whether screen should be shown right after initialization. | 186 // Keeps whether screen should be shown right after initialization. |
| 45 bool show_on_init_; | 187 bool show_on_init_; |
| 46 | 188 |
| 189 // Displays in the UI a connecting to the device |device| message. | |
| 190 void DeviceConnecting(device::BluetoothDevice* device); | |
| 191 | |
| 192 // Called by device::BluetoothAdapter in response to a failure to | |
| 193 // change the power status of the adapter. | |
| 194 void EnableChangeError(); | |
| 195 | |
| 196 // Called by device::BluetoothAdapter in response to a successful request | |
| 197 // to initiate a discovery session. | |
| 198 void OnStartDiscoverySession( | |
| 199 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | |
| 200 | |
| 201 // Called by device::BluetoothAdapter in response to a failure to | |
| 202 // initiate a discovery session. | |
| 203 void FindDevicesError(); | |
| 204 | |
| 205 // Called by device::BluetoothAdapter in response to a failure to | |
| 206 // terminate a discovery session. | |
| 207 void StopDiscoveryError(); | |
| 208 | |
| 209 // Called by device::BluetoothDevice on a successful pairing and connection | |
| 210 // to a device. | |
| 211 void Connected(); | |
| 212 | |
| 213 // Called by device::BluetoothDevice in response to a failure to | |
| 214 // connect to the device with bluetooth address |address| due to an error | |
| 215 // encoded in |error_code|. | |
| 216 void ConnectError(const std::string& address, | |
| 217 device::BluetoothDevice::ConnectErrorCode error_code); | |
| 218 | |
| 219 // Called by device::BluetoothDevice in response to a failure to | |
| 220 // disconnect the device with bluetooth address |address|. | |
| 221 void DisconnectError(const std::string& address); | |
| 222 | |
| 223 // Called by device::BluetoothDevice in response to a failure to | |
| 224 // disconnect and unpair the device with bluetooth address |address|. | |
| 225 void ForgetError(const std::string& address); | |
| 226 | |
| 227 // Called when the 'Enable bluetooth' checkbox value is changed. | |
| 228 // |args| will contain the checkbox checked state as a string | |
| 229 // ("true" or "false"). | |
| 230 void EnableChangeCallback(const base::ListValue* args); | |
| 231 | |
| 232 // Called when the 'Find Devices' button is pressed from the Bluetooth | |
| 233 // ssettings. | |
| 234 // |args| will be an empty list. | |
| 235 void FindDevicesCallback(const base::ListValue* args); | |
| 236 | |
| 237 // Called when the "Add a device" dialog closes to stop the discovery | |
| 238 // process. | |
| 239 // |args| will be an empty list. | |
| 240 void StopDiscoveryCallback(const base::ListValue* args); | |
| 241 | |
| 242 // Called when the list of paired devices is initialized in order to | |
| 243 // populate the list. | |
| 244 // |args| will be an empty list. | |
| 245 void GetPairedDevicesCallback(const base::ListValue* args); | |
| 246 | |
| 247 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.
| |
| 248 | |
| 249 void ConnectBTDevice(device::BluetoothDevice* device); | |
| 250 | |
| 251 // Default bluetooth adapter, used for all operations. | |
| 252 scoped_refptr<device::BluetoothAdapter> adapter_; | |
| 253 | |
| 254 InputServiceProxy input_service_proxy_; | |
| 255 | |
| 256 // True, if the UI has requested device discovery. False, if either no device | |
| 257 // discovery was requested or the dialog responsible for device discovery was | |
| 258 // dismissed. | |
| 259 bool should_run_device_discovery_; | |
| 260 | |
| 261 // The current device discovery session. Only one active discovery session is | |
| 262 // kept at a time and the instance that |discovery_session_| points to gets | |
| 263 // replaced by a new one when a new discovery session is initiated. | |
| 264 scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; | |
| 265 | |
| 266 // Cached information about the current pairing device, if any. | |
| 267 std::string pairing_device_address_; | |
| 268 std::string pairing_device_pairing_; | |
| 269 std::string pairing_device_pincode_; | |
| 270 int pairing_device_passkey_; | |
| 271 int pairing_device_entered_; | |
| 272 | |
| 273 // Current pointing device, if any. | |
| 274 std::string pointing_device_name_; | |
| 275 std::string pointing_device_id_; | |
| 276 InputDeviceInfo::Type pointing_device_connect_type_; | |
| 277 | |
| 278 // Current keyboard device, if any. | |
| 279 std::string keyboard_device_name_; | |
| 280 std::string keyboard_device_id_; | |
| 281 bool keyboard_is_connecting_; | |
| 282 InputDeviceInfo::Type keyboard_device_connect_type_; | |
| 283 | |
| 284 // 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.
| |
| 285 // than this object does. | |
| 286 base::WeakPtrFactory<HIDDetectionScreenHandler> weak_ptr_factory_; | |
| 287 | |
| 47 DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreenHandler); | 288 DISALLOW_COPY_AND_ASSIGN(HIDDetectionScreenHandler); |
| 48 }; | 289 }; |
| 49 | 290 |
| 50 } // namespace chromeos | 291 } // namespace chromeos |
| 51 | 292 |
| 52 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H _ | 293 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_HID_DETECTION_SCREEN_HANDLER_H _ |
| 53 | 294 |
| OLD | NEW |