Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2941)

Unified Diff: chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.cc

Issue 252503002: Base version of HID detection OOBE screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Logic bug-fix. Progress dots hidden. Style improved. BT names support. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.cc
diff --git a/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.cc
index a2a26b51c9d388b45c3dc5e02a6d186914254b25..41cd47df25cdc9fedb64e923ad01d1741a1e15a9 100644
--- a/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.cc
@@ -4,16 +4,31 @@
#include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h"
+#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
+#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
namespace {
const char kJsScreenPath[] = "login.HIDDetectionScreen";
+const char kRemotePinCode[] = "bluetoothRemotePinCode";
+
+const char kSearchingState[] = "searching";
+const char kUSBConnectedState[] = "connected";
+const char kBTPairedState[] = "paired";
+const char kBTPairingState[] = "pairing";
+
+const char kPincodeArgName[] = "pincode";
+const char kDeviceNameArgName[] = "name";
+const char kLabelArgName[] = "keyboard-label";
+
} // namespace
namespace chromeos {
@@ -21,15 +36,37 @@ namespace chromeos {
HIDDetectionScreenHandler::HIDDetectionScreenHandler()
: BaseScreenHandler(kJsScreenPath),
delegate_(NULL),
- show_on_init_(false) {
+ show_on_init_(false),
+ keyboard_is_connecting_(false),
+ switch_on_adapter_when_ready_(false),
+ weak_ptr_factory_(this) {
+ pointing_device_id_.clear();
+ keyboard_device_id_.clear();
}
HIDDetectionScreenHandler::~HIDDetectionScreenHandler() {
+ if (adapter_.get())
+ adapter_->RemoveObserver(this);
+ input_service_proxy_.RemoveObserver(this);
if (delegate_)
delegate_->OnActorDestroyed(this);
}
-void HIDDetectionScreenHandler::PrepareToShow() {
+void HIDDetectionScreenHandler::PrepareToShow() {}
+
+void HIDDetectionScreenHandler::OnStartDiscoverySession(
+ scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
+ VLOG(1) << "BT Discovery session started";
+ discovery_session_ = discovery_session.Pass();
+ UpdateDevices(false /* skip screen if devices present */);
+}
+
+void HIDDetectionScreenHandler::SetPoweredError() {
+ LOG(ERROR) << "Failed to power BT adapter";
+}
+
+void HIDDetectionScreenHandler::FindDevicesError() {
+ VLOG(1) << "Failed to start Bluetooth discovery.";
}
void HIDDetectionScreenHandler::Show() {
@@ -37,10 +74,15 @@ void HIDDetectionScreenHandler::Show() {
show_on_init_ = true;
return;
}
+ input_service_proxy_.AddObserver(this);
+ UpdateDevices(true /* skip screen if devices present */);
ShowScreen(OobeUI::kScreenHIDDetection, NULL);
}
void HIDDetectionScreenHandler::Hide() {
+ if (adapter_.get())
+ adapter_->RemoveObserver(this);
+ input_service_proxy_.RemoveObserver(this);
}
void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) {
@@ -52,12 +94,29 @@ void HIDDetectionScreenHandler::SetDelegate(Delegate* delegate) {
void HIDDetectionScreenHandler::DeclareLocalizedValues(
LocalizedValuesBuilder* builder) {
builder->Add("hidDetectionContinue", IDS_HID_DETECTION_CONTINUE_BUTTON);
+ builder->Add("hidDetectionInvitation", IDS_HID_DETECTION_INVITATION_TEXT);
+ builder->Add("hidDetectionPrerequisites",
+ IDS_HID_DETECTION_PRECONDITION_TEXT);
+ builder->Add("hidDetectionMouseSearching", IDS_HID_DETECTION_SEARCHING_MOUSE);
+ builder->Add("hidDetectionKeyboardSearching",
+ IDS_HID_DETECTION_SEARCHING_KEYBOARD);
+ builder->Add("hidDetectionUSBMouseConnected",
+ IDS_HID_DETECTION_CONNECTED_USB_MOUSE);
+ builder->Add("hidDetectionUSBKeyboardConnected",
+ IDS_HID_DETECTION_CONNECTED_USB_KEYBOARD);
+ builder->Add("hidDetectionBTMousePaired",
+ IDS_HID_DETECTION_PAIRED_BLUETOOTH_MOUSE);
+ builder->Add("hidDetectionBTEnterKey", IDS_HID_DETECTION_BLUETOOTH_ENTER_KEY);
}
void HIDDetectionScreenHandler::Initialize() {
if (!page_is_ready() || !delegate_)
return;
+ device::BluetoothAdapterFactory::GetAdapter(
+ base::Bind(&HIDDetectionScreenHandler::InitializeAdapter,
+ weak_ptr_factory_.GetWeakPtr()));
+
if (show_on_init_) {
Show();
show_on_init_ = false;
@@ -74,4 +133,301 @@ void HIDDetectionScreenHandler::HandleOnContinue() {
delegate_->OnExit();
}
+void HIDDetectionScreenHandler::InitializeAdapter(
+ scoped_refptr<device::BluetoothAdapter> adapter) {
+ adapter_ = adapter;
+ CHECK(adapter_.get());
+
+ adapter_->AddObserver(this);
+ UpdateDevices(false);
+}
+
+void HIDDetectionScreenHandler::StartBTDiscoverySession() {
+ adapter_->StartDiscoverySession(
+ base::Bind(&HIDDetectionScreenHandler::OnStartDiscoverySession,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&HIDDetectionScreenHandler::FindDevicesError,
+ weak_ptr_factory_.GetWeakPtr()));
+
+}
+
+void HIDDetectionScreenHandler::RequestPinCode(
+ device::BluetoothDevice* device) {
+ VLOG(1) << "RequestPinCode id = " << device->GetDeviceID()
+ << " name = " << device->GetName();
+ NOTIMPLEMENTED();
keybuk 2014/04/27 10:11:55 device->CancelPairing() is acceptable here
merkulova 2014/04/28 07:53:38 Done.
+}
+
+void HIDDetectionScreenHandler::RequestPasskey(
+ device::BluetoothDevice* device) {
+ VLOG(1) << "RequestPassKey id = " << device->GetDeviceID()
+ << " name = " << device->GetName();
+ NOTIMPLEMENTED();
keybuk 2014/04/27 10:11:55 device->CancelPairing() is acceptable here
merkulova 2014/04/28 07:53:38 Done.
+}
+
+void HIDDetectionScreenHandler::DisplayPinCode(device::BluetoothDevice* device,
+ const std::string& pincode) {
+ VLOG(1) << "DisplayPinCode id = " << device->GetDeviceID()
+ << " name = " << device->GetName();
+ base::DictionaryValue params;
+ params.SetString("state", kBTPairingState);
+ params.SetString("pairing-state", kRemotePinCode);
+ params.SetString("pincode", pincode);
+ params.SetString(kDeviceNameArgName, device->GetName());
+ SendKeyboardDeviceNotification(&params);
+}
+
+void HIDDetectionScreenHandler::DisplayPasskey(
+ device::BluetoothDevice* device, uint32 passkey) {
+ VLOG(1) << "DisplayPassKey id = " << device->GetDeviceID()
+ << " name = " << device->GetName();
+ NOTIMPLEMENTED();
keybuk 2014/04/27 10:11:55 This should be implemented, it'll be used for HID
merkulova 2014/04/28 07:53:38 Done.
+}
+
+void HIDDetectionScreenHandler::KeysEntered(
+ device::BluetoothDevice* device, uint32 entered) {
+ VLOG(1) << "Keys entered";
+ NOTIMPLEMENTED();
keybuk 2014/04/27 10:11:55 Useful to do the pairing UI property
merkulova 2014/04/28 07:53:38 What do you mean?
+}
+
+void HIDDetectionScreenHandler::ConfirmPasskey(
+ device::BluetoothDevice* device, uint32 passkey) {
+ VLOG(1) << "Confirm Passkey";
+ NOTIMPLEMENTED();
keybuk 2014/04/27 10:11:55 device->CancelPairing() is acceptable here
merkulova 2014/04/28 07:53:38 Done.
+}
+
+void HIDDetectionScreenHandler::AuthorizePairing(
+ device::BluetoothDevice* device) {
+ // There is never any circumstance where this will be called, since the
+ // HID detection screen handler will only be used for outgoing pairing
+ // requests, but play it safe.
+ VLOG(1) << "Authorize pairing";
+ device->ConfirmPairing();
+}
+
+void HIDDetectionScreenHandler::AdapterPresentChanged(
+ device::BluetoothAdapter* adapter, bool present) {
+ if (present && switch_on_adapter_when_ready_) {
+ adapter_->SetPowered(
+ true,
+ base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&HIDDetectionScreenHandler::SetPoweredError,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+}
+
+void HIDDetectionScreenHandler::DeviceAdded(
+ device::BluetoothAdapter* adapter, device::BluetoothDevice* device) {
+ VLOG(1) << "BT input device added id = " << device->GetDeviceID() <<
+ " name = " << device->GetName();
+ if (pointing_device_id_.empty() &&
+ device->GetDeviceType() == device::BluetoothDevice::DEVICE_MOUSE) {
+ ConnectBTDevice(device);
+ }
+ if (keyboard_device_id_.empty() &&
+ device->GetDeviceType() == device::BluetoothDevice::DEVICE_KEYBOARD) {
+ ConnectBTDevice(device);
+ }
keybuk 2014/04/27 10:11:55 should also handle DEVICE_KEYBOARD_MOUSE_COMBO
merkulova 2014/04/28 07:53:38 Done.
+}
+
+void HIDDetectionScreenHandler::DeviceChanged(
+ device::BluetoothAdapter* adapter, device::BluetoothDevice* device) {
+ VLOG(1) << "BT device changed id = " << device->GetDeviceID() << " name = " <<
+ device->GetName();
+ NOTIMPLEMENTED();
keybuk 2014/04/27 10:11:55 The property that changed might be the class, so y
merkulova 2014/04/28 07:53:38 Done.
+}
+
+void HIDDetectionScreenHandler::DeviceRemoved(
+ device::BluetoothAdapter* adapter, device::BluetoothDevice* device) {
+ VLOG(1) << "BT device removed id = " << device->GetDeviceID() << " name = " <<
+ device->GetName();
+ NOTIMPLEMENTED();
keybuk 2014/04/27 10:11:55 Probably no need to implement, the method is optio
merkulova 2014/04/28 07:53:38 Done.
+}
+
+void HIDDetectionScreenHandler::OnInputDeviceAdded(
+ const InputDeviceInfo& info) {
+ VLOG(1) << "Input device added id = " << info.id << " name = " << info.name;
+ // TODO(merkulova): deal with all available device types.
+ if (!keyboard_device_id_.empty() && !pointing_device_id_.empty())
+ return;
+
+ if (pointing_device_id_.empty() && (info.is_mouse || info.is_touchpad)) {
+ pointing_device_id_ = info.id;
+ pointing_device_name_ = info.name;
+ pointing_device_connect_type_ = info.type;
+ SendPointingDeviceNotification();
+ } else if (keyboard_device_id_.empty() && info.is_keyboard) {
+ keyboard_device_id_ = info.id;
+ keyboard_device_name_ = info.name;
+ keyboard_device_connect_type_ = info.type;
+ SendKeyboardDeviceNotification(NULL);
+ }
+}
+
+void HIDDetectionScreenHandler::OnInputDeviceRemoved(const std::string& id) {
+ if (id == keyboard_device_id_) {
+ keyboard_device_id_.clear();
+ keyboard_device_name_.clear();
+ keyboard_device_connect_type_ = InputDeviceInfo::TYPE_UNKNOWN;
+ SendKeyboardDeviceNotification(NULL);
+ UpdateDevices(false /* skip screen if devices present */);
+ } else if (id == pointing_device_id_) {
+ pointing_device_id_.clear();
+ pointing_device_name_.clear();
+ pointing_device_connect_type_ = InputDeviceInfo::TYPE_UNKNOWN;
+ SendPointingDeviceNotification();
+ UpdateDevices(false /* skip screen if devices present */);
+ }
+}
+
+void HIDDetectionScreenHandler::UpdateDevices(
+ bool skip_screen_if_devices_present) {
+ input_service_proxy_.GetDevices(
+ base::Bind(&HIDDetectionScreenHandler::OnGetInputDevicesList,
+ base::Unretained(this),
+ skip_screen_if_devices_present));
+}
+
+void HIDDetectionScreenHandler::UpdateBTDevices() {
+ if (!adapter_ || !adapter_->IsPresent() || !adapter_->IsPowered())
+ return;
+ // If no connected devices found as pointing device and keyboard, we try to
+ // connect some type-suitable active bluetooth device.
+ std::vector<device::BluetoothDevice*> bt_devices = adapter_->GetDevices();
+ for (std::vector<device::BluetoothDevice*>::const_iterator it =
+ bt_devices.begin();
+ it != bt_devices.end() &&
+ (keyboard_device_id_.empty() || pointing_device_id_.empty());
+ ++it) {
+ if (keyboard_device_id_.empty() &&
+ (*it)->GetDeviceType() == device::BluetoothDevice::DEVICE_KEYBOARD &&
+ !keyboard_is_connecting_) {
+ keyboard_is_connecting_ = true;
+ ConnectBTDevice(*it);
+ break;
+ }
+ if (pointing_device_id_.empty() &&
+ (*it)->GetDeviceType() == device::BluetoothDevice::DEVICE_MOUSE) {
+ ConnectBTDevice((*it));
+ }
keybuk 2014/04/27 10:11:55 Also handle DEVICE_KEYBOARD_MOUSE_COMBO
merkulova 2014/04/28 07:53:38 Done.
+ }
+}
+
+void HIDDetectionScreenHandler::OnGetInputDevicesList(
+ bool skip_screen_if_devices_present,
+ const std::vector<InputDeviceInfo>& devices) {
+ for (std::vector<InputDeviceInfo>::const_iterator it = devices.begin();
+ it != devices.end() &&
+ (pointing_device_id_.empty() || keyboard_device_id_.empty());
+ ++it) {
+ if (pointing_device_id_.empty() && (it->is_mouse || it->is_touchpad)) {
+ pointing_device_id_ = it->id;
+ pointing_device_name_ = it->name;
+ pointing_device_connect_type_ = it->type;
+ SendPointingDeviceNotification();
+ }
+ if (keyboard_device_id_.empty() && it->is_keyboard) {
+ keyboard_device_id_ = it->id;
+ keyboard_device_name_ = it->name;
+ keyboard_device_connect_type_ = it->type;
+ SendKeyboardDeviceNotification(NULL);
+ }
+ }
+ // Skip screen if both devices are present and skip was requested.
+ if (!pointing_device_id_.empty() &&
+ !keyboard_device_id_.empty() &&
+ skip_screen_if_devices_present) {
+ HandleOnContinue();
+ }
+ if ((pointing_device_id_.empty() || keyboard_device_id_.empty()) &&
+ adapter_) {
+ if (!adapter_->IsPresent()) {
+ // Switch on BT adapter later when it's available.
+ switch_on_adapter_when_ready_ = true;
+ } else if (!adapter_->IsPowered()) {
+ adapter_->SetPowered(
+ true,
+ base::Bind(&HIDDetectionScreenHandler::StartBTDiscoverySession,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&HIDDetectionScreenHandler::SetPoweredError,
+ weak_ptr_factory_.GetWeakPtr()));
+ } else {
+ UpdateBTDevices();
+ }
+ }
+}
+
+void HIDDetectionScreenHandler::ConnectBTDevice(
+ device::BluetoothDevice* device) {
+ if (!device->IsPairable())
+ return;
+ device->Connect(this,
+ base::Bind(&HIDDetectionScreenHandler::BTConnected,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&HIDDetectionScreenHandler::BTConnectError,
+ weak_ptr_factory_.GetWeakPtr(),
+ device->GetAddress()));
+}
+
+void HIDDetectionScreenHandler::BTConnected() {
+ keyboard_is_connecting_ = false;
+}
+
+void HIDDetectionScreenHandler::BTConnectError(
+ const std::string& address,
+ device::BluetoothDevice::ConnectErrorCode error_code) {
+ LOG(WARNING) << "BTConnectError";
+ keyboard_is_connecting_ = false;
+ UpdateDevices(false /* skip screen if devices present */);
+}
+
+
+void HIDDetectionScreenHandler::SendPointingDeviceNotification() {
+ std::string state;
+ if (pointing_device_id_.empty())
+ state = kSearchingState;
+ else if (pointing_device_connect_type_ == InputDeviceInfo::TYPE_BLUETOOTH)
+ state = kBTPairedState;
+ else
+ state = kUSBConnectedState;
+ CallJS("setPointingDeviceState", state);
+}
+
+void HIDDetectionScreenHandler::SendKeyboardDeviceNotification(
+ base::DictionaryValue* params) {
+ base::DictionaryValue state_info;
+ if (params)
+ state_info.MergeDictionary(params);
+
+ std::string device_name;
+ if (!state_info.GetString(kDeviceNameArgName, &device_name)) {
+ device_name = base::UTF16ToASCII(
+ l10n_util::GetStringUTF16(IDS_HID_DETECTION_DEFAULT_KEYBOARD_NAME));
+ }
+
+ if (keyboard_device_id_.empty()) {
+ std::string pairing;
+ if (!state_info.GetString("pairing-state", &pairing)) {
+ state_info.SetString("state", kSearchingState);
+ } else if (state_info.HasKey(kPincodeArgName)) {
+ state_info.SetString(
+ kLabelArgName,
+ l10n_util::GetStringFUTF16(
+ IDS_HID_DETECTION_BLUETOOTH_REMOTE_PIN_CODE_REQUEST,
+ base::ASCIIToUTF16(device_name)));
+ }
+ } else if (keyboard_device_connect_type_ == InputDeviceInfo::TYPE_BLUETOOTH) {
+ state_info.SetString("state", kBTPairedState);
+ state_info.SetString(
+ kLabelArgName,
+ l10n_util::GetStringFUTF16(
+ IDS_HID_DETECTION_PAIRED_BLUETOOTH_KEYBOARD,
+ base::ASCIIToUTF16(keyboard_device_name_)));
+ } else {
+ state_info.SetString("state", kUSBConnectedState);
+ }
+ CallJS("setKeyboardDeviceState", state_info);
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698