diff options
Diffstat (limited to 'components/proximity_auth/webui/proximity_auth_webui_handler.cc')
-rw-r--r-- | components/proximity_auth/webui/proximity_auth_webui_handler.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/components/proximity_auth/webui/proximity_auth_webui_handler.cc b/components/proximity_auth/webui/proximity_auth_webui_handler.cc index 9b55d6c..a1a1319 100644 --- a/components/proximity_auth/webui/proximity_auth_webui_handler.cc +++ b/components/proximity_auth/webui/proximity_auth_webui_handler.cc @@ -26,6 +26,7 @@ #include "components/proximity_auth/secure_context.h" #include "components/proximity_auth/webui/cryptauth_enroller_factory_impl.h" #include "components/proximity_auth/webui/proximity_auth_ui_delegate.h" +#include "components/proximity_auth/webui/reachable_phone_flow.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_ui.h" #include "device/bluetooth/bluetooth_uuid.h" @@ -128,6 +129,11 @@ void ProximityAuthWebUIHandler::RegisterMessages() { base::Unretained(this))); web_ui()->RegisterMessageCallback( + "findReachableDevices", + base::Bind(&ProximityAuthWebUIHandler::FindReachableDevices, + base::Unretained(this))); + + web_ui()->RegisterMessageCallback( "getLocalState", base::Bind(&ProximityAuthWebUIHandler::GetLocalState, base::Unretained(this))); @@ -232,6 +238,20 @@ void ProximityAuthWebUIHandler::FindEligibleUnlockDevices( weak_ptr_factory_.GetWeakPtr())); } +void ProximityAuthWebUIHandler::FindReachableDevices( + const base::ListValue* args) { + if (reachable_phone_flow_) { + PA_LOG(INFO) << "Waiting for existing ReachablePhoneFlow to finish."; + return; + } + + reachable_phone_flow_.reset( + new ReachablePhoneFlow(cryptauth_client_factory_.get())); + reachable_phone_flow_->Run( + base::Bind(&ProximityAuthWebUIHandler::OnReachablePhonesFound, + weak_ptr_factory_.GetWeakPtr())); +} + void ProximityAuthWebUIHandler::ForceEnrollment(const base::ListValue* args) { if (enrollment_manager_) { enrollment_manager_->ForceEnrollmentNow( @@ -383,6 +403,17 @@ void ProximityAuthWebUIHandler::OnFoundEligibleUnlockDevices( eligible_devices, ineligible_devices); } +void ProximityAuthWebUIHandler::OnReachablePhonesFound( + const std::vector<cryptauth::ExternalDeviceInfo>& reachable_phones) { + reachable_phone_flow_.reset(); + base::ListValue device_list; + for (const auto& external_device : reachable_phones) { + device_list.Append(ExternalDeviceInfoToDictionary(external_device)); + } + web_ui()->CallJavascriptFunction("CryptAuthInterface.onGotReachableDevices", + device_list); +} + void ProximityAuthWebUIHandler::GetLocalState(const base::ListValue* args) { scoped_ptr<base::DictionaryValue> enrollment_state = GetEnrollmentStateDictionary(); |