| 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 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const char kJsScreenPath[] = "login.HIDDetectionScreen"; | 26 const char kJsScreenPath[] = "login.HIDDetectionScreen"; |
| 27 | 27 |
| 28 // Variants of pairing state. | 28 // Variants of pairing state. |
| 29 const char kRemotePinCode[] = "bluetoothRemotePinCode"; | 29 const char kRemotePinCode[] = "bluetoothRemotePinCode"; |
| 30 const char kRemotePasskey[] = "bluetoothRemotePasskey"; | 30 const char kRemotePasskey[] = "bluetoothRemotePasskey"; |
| 31 | 31 |
| 32 // Possible ui-states for device-blocks. | 32 // Possible ui-states for device-blocks. Same as CONNECTION dict of |
| 33 // HIDDetectionScreen |
| 33 const char kSearchingState[] = "searching"; | 34 const char kSearchingState[] = "searching"; |
| 34 const char kUSBConnectedState[] = "connected"; | 35 const char kUSBConnectedState[] = "connected"; |
| 35 const char kBTPairedState[] = "paired"; | 36 const char kBTPairedState[] = "paired"; |
| 36 const char kBTPairingState[] = "pairing"; | 37 const char kBTPairingState[] = "pairing"; |
| 37 // Special state for notifications that don't switch ui-state, but add info. | 38 // Special state for notifications that doesn't switch ui-state, but adds info. |
| 38 const char kBTUpdateState[] = "update"; | 39 const char kBTUpdateState[] = "update"; |
| 39 | 40 |
| 40 // Names of possible arguments used for ui update. | 41 // Names of possible arguments used for ui update. |
| 41 const char kPincodeArgName[] = "pincode"; | 42 const char kPincodeArgName[] = "pincode"; |
| 42 const char kDeviceNameArgName[] = "name"; | 43 const char kDeviceNameArgName[] = "name"; |
| 43 const char kLabelArgName[] = "keyboard-label"; | 44 const char kLabelArgName[] = "keyboard-label"; |
| 44 | 45 |
| 45 // Standard length of pincode for pairing BT keyboards. | 46 // Standard length of pincode for pairing BT keyboards. |
| 46 const int kPincodeLength = 6; | 47 const int kPincodeLength = 6; |
| 47 | 48 |
| 48 bool DeviceIsPointing(device::BluetoothDevice::DeviceType device_type) { | 49 bool DeviceIsPointing(device::BluetoothDevice::DeviceType device_type) { |
| 49 return device_type == device::BluetoothDevice::DEVICE_MOUSE || | 50 return device_type == device::BluetoothDevice::DEVICE_MOUSE || |
| 50 device_type == device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO || | 51 device_type == device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO || |
| 51 device_type == device::BluetoothDevice::DEVICE_TABLET; | 52 device_type == device::BluetoothDevice::DEVICE_TABLET; |
| 52 } | 53 } |
| 53 | 54 |
| 54 bool DeviceIsPointing(const device::InputServiceLinux::InputDeviceInfo& info) { | 55 bool DeviceIsPointing(const device::InputServiceLinux::InputDeviceInfo& info) { |
| 55 return info.is_mouse || info.is_touchpad || info.is_touchscreen || | 56 return info.is_mouse || info.is_touchpad || info.is_touchscreen || |
| 56 info.is_tablet; | 57 info.is_tablet; |
| 57 } | 58 } |
| 58 | 59 |
| 59 bool DeviceIsKeyboard(device::BluetoothDevice::DeviceType device_type) { | 60 bool DeviceIsKeyboard(device::BluetoothDevice::DeviceType device_type) { |
| 60 return device_type == device::BluetoothDevice::DEVICE_KEYBOARD || | 61 return device_type == device::BluetoothDevice::DEVICE_KEYBOARD || |
| 61 device_type == device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO; | 62 device_type == device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO; |
| 62 } | 63 } |
| 63 | 64 |
| 65 bool DeviceIsKeyboard(const device::InputServiceLinux::InputDeviceInfo& info) { |
| 66 return info.is_keyboard || info.is_touchscreen || info.is_tablet; |
| 67 } |
| 68 |
| 64 } // namespace | 69 } // namespace |
| 65 | 70 |
| 66 namespace chromeos { | 71 namespace chromeos { |
| 67 | 72 |
| 68 HIDDetectionScreenHandler::HIDDetectionScreenHandler( | 73 HIDDetectionScreenHandler::HIDDetectionScreenHandler( |
| 69 CoreOobeActor* core_oobe_actor) | 74 CoreOobeActor* core_oobe_actor) |
| 70 : BaseScreenHandler(kJsScreenPath), | 75 : BaseScreenHandler(kJsScreenPath), |
| 71 delegate_(NULL), | 76 delegate_(NULL), |
| 72 core_oobe_actor_(core_oobe_actor), | 77 core_oobe_actor_(core_oobe_actor), |
| 73 show_on_init_(false), | 78 show_on_init_(false), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 input_service_proxy_.AddObserver(this); | 121 input_service_proxy_.AddObserver(this); |
| 117 UpdateDevices(); | 122 UpdateDevices(); |
| 118 | 123 |
| 119 PrefService* local_state = g_browser_process->local_state(); | 124 PrefService* local_state = g_browser_process->local_state(); |
| 120 int num_of_times_dialog_was_shown = local_state->GetInteger( | 125 int num_of_times_dialog_was_shown = local_state->GetInteger( |
| 121 prefs::kTimesHIDDialogShown); | 126 prefs::kTimesHIDDialogShown); |
| 122 local_state->SetInteger(prefs::kTimesHIDDialogShown, | 127 local_state->SetInteger(prefs::kTimesHIDDialogShown, |
| 123 num_of_times_dialog_was_shown + 1); | 128 num_of_times_dialog_was_shown + 1); |
| 124 | 129 |
| 125 ShowScreen(OobeUI::kScreenHIDDetection, NULL); | 130 ShowScreen(OobeUI::kScreenHIDDetection, NULL); |
| 126 if (!pointing_device_id_.empty()) | 131 SendPointingDeviceNotification(); |
| 127 SendPointingDeviceNotification(); | 132 SendKeyboardDeviceNotification(NULL); |
| 128 if (!keyboard_device_id_.empty()) | |
| 129 SendKeyboardDeviceNotification(NULL); | |
| 130 } | 133 } |
| 131 | 134 |
| 132 void HIDDetectionScreenHandler::Hide() { | 135 void HIDDetectionScreenHandler::Hide() { |
| 133 if (adapter_.get()) | 136 if (adapter_.get()) |
| 134 adapter_->RemoveObserver(this); | 137 adapter_->RemoveObserver(this); |
| 135 input_service_proxy_.RemoveObserver(this); | 138 input_service_proxy_.RemoveObserver(this); |
| 136 } | 139 } |
| 137 | 140 |
| 138 void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) { | 141 void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) { |
| 139 delegate_ = delegate; | 142 delegate_ = delegate; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // TODO(merkulova): deal with all available device types, e.g. joystick. | 365 // TODO(merkulova): deal with all available device types, e.g. joystick. |
| 363 if (!keyboard_device_id_.empty() && !pointing_device_id_.empty()) | 366 if (!keyboard_device_id_.empty() && !pointing_device_id_.empty()) |
| 364 return; | 367 return; |
| 365 | 368 |
| 366 if (pointing_device_id_.empty() && DeviceIsPointing(info)) { | 369 if (pointing_device_id_.empty() && DeviceIsPointing(info)) { |
| 367 pointing_device_id_ = info.id; | 370 pointing_device_id_ = info.id; |
| 368 pointing_device_name_ = info.name; | 371 pointing_device_name_ = info.name; |
| 369 pointing_device_connect_type_ = info.type; | 372 pointing_device_connect_type_ = info.type; |
| 370 SendPointingDeviceNotification(); | 373 SendPointingDeviceNotification(); |
| 371 } | 374 } |
| 372 if (keyboard_device_id_.empty() && info.is_keyboard) { | 375 if (keyboard_device_id_.empty() && DeviceIsKeyboard(info)) { |
| 373 keyboard_device_id_ = info.id; | 376 keyboard_device_id_ = info.id; |
| 374 keyboard_device_name_ = info.name; | 377 keyboard_device_name_ = info.name; |
| 375 keyboard_device_connect_type_ = info.type; | 378 keyboard_device_connect_type_ = info.type; |
| 376 SendKeyboardDeviceNotification(NULL); | 379 SendKeyboardDeviceNotification(NULL); |
| 377 } | 380 } |
| 378 } | 381 } |
| 379 | 382 |
| 380 void HIDDetectionScreenHandler::OnInputDeviceRemoved(const std::string& id) { | 383 void HIDDetectionScreenHandler::OnInputDeviceRemoved(const std::string& id) { |
| 381 if (id == keyboard_device_id_) { | 384 if (id == keyboard_device_id_) { |
| 382 keyboard_device_id_.clear(); | 385 keyboard_device_id_.clear(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 l10n_util::GetStringFUTF16( | 584 l10n_util::GetStringFUTF16( |
| 582 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD, | 585 IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD, |
| 583 base::UTF8ToUTF16(keyboard_device_name_))); | 586 base::UTF8ToUTF16(keyboard_device_name_))); |
| 584 } else { | 587 } else { |
| 585 state_info.SetString("state", kUSBConnectedState); | 588 state_info.SetString("state", kUSBConnectedState); |
| 586 } | 589 } |
| 587 CallJS("setKeyboardDeviceState", state_info); | 590 CallJS("setKeyboardDeviceState", state_info); |
| 588 } | 591 } |
| 589 | 592 |
| 590 } // namespace chromeos | 593 } // namespace chromeos |
| OLD | NEW |