[go: nahoru, domu]

Wire up smart cards with new PIN UI.

The CL introduces a new security token request controller similar to the
parent access controller, which was the only user of the PIN UI until
now.

This CL also adds small bits of functionality to the UI that is required
for the new use-case: Disabling input and clearing the input field.

The new UI applies to login and lock screen, but not in-session or for
OOBE, which use different UIs.

Bug: 1001288
Change-Id: I8c69064a0d944bb6b5a7dac13a2ec2bd968deece
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020968
Commit-Queue: Fabian Sommer <fabiansommer@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745037}
diff --git a/ash/login/login_screen_controller.cc b/ash/login/login_screen_controller.cc
index 1cba4cd..94d3c9f 100644
--- a/ash/login/login_screen_controller.cc
+++ b/ash/login/login_screen_controller.cc
@@ -8,6 +8,7 @@
 
 #include "ash/focus_cycler.h"
 #include "ash/login/parent_access_controller.h"
+#include "ash/login/security_token_request_controller.h"
 #include "ash/login/ui/lock_screen.h"
 #include "ash/login/ui/login_data_dispatcher.h"
 #include "ash/public/cpp/ash_pref_names.h"
@@ -210,13 +211,8 @@
   return client_->ValidateParentAccessCode(account_id, code, validation_time);
 }
 
-void LoginScreenController::OnSecurityTokenPinRequestCancelledByUser() {
-  security_token_pin_request_cancelled_ = true;
-  std::move(on_request_security_token_ui_closed_).Run();
-}
-
-bool LoginScreenController::GetSecurityTokenPinRequestCancelled() const {
-  return security_token_pin_request_cancelled_;
+bool LoginScreenController::GetSecurityTokenPinRequestCanceled() const {
+  return security_token_request_controller_.request_canceled();
 }
 
 void LoginScreenController::HardlockPod(const AccountId& account_id) {
@@ -415,33 +411,11 @@
 
 void LoginScreenController::RequestSecurityTokenPin(
     SecurityTokenPinRequest request) {
-  if (LockScreen::HasInstance() && !security_token_pin_request_cancelled_) {
-    // The caller must ensure that there is no unresolved pin request currently
-    // in progress.
-    on_request_security_token_ui_closed_ =
-        std::move(request.pin_ui_closed_callback);
-    // base::Unretained(this) could lead to errors if this controller is
-    // destroyed before the callback happens. This will be fixed by
-    // crbug.com/1001288 by using a UI owned by the controller.
-    request.pin_ui_closed_callback = base::BindOnce(
-        &LoginScreenController::OnSecurityTokenPinRequestCancelledByUser,
-        base::Unretained(this));
-    LockScreen::Get()->RequestSecurityTokenPin(std::move(request));
-  } else {
-    // The user closed the PIN UI on a previous request that was part of the
-    // same smart card login attempt, or the PIN request is made at an
-    // inappropriate time, racing with the lock screen showing/hiding.
-    std::move(request.pin_ui_closed_callback).Run();
-  }
+  security_token_request_controller_.SetPinUiState(std::move(request));
 }
 
 void LoginScreenController::ClearSecurityTokenPinRequest() {
-  if (!LockScreen::HasInstance()) {
-    // Corner case: the request is made at inappropriate time, racing with the
-    // lock screen showing/hiding.
-    return;
-  }
-  LockScreen::Get()->ClearSecurityTokenPinRequest();
+  security_token_request_controller_.ClosePinUi();
 }
 
 void LoginScreenController::ShowLockScreen() {
@@ -506,9 +480,13 @@
     bool success) {
   authentication_stage_ = AuthenticationStage::kUserCallback;
   std::move(callback).Run(base::make_optional<bool>(success));
-  security_token_pin_request_cancelled_ = false;
-  on_request_security_token_ui_closed_.Reset();
   authentication_stage_ = AuthenticationStage::kIdle;
+
+  // During smart card login flow, multiple security token requests can be made.
+  // If the user cancels one, all others should also be canceled.
+  // At this point, the flow is ending and new security token requests are
+  // displayed again.
+  security_token_request_controller_.ResetRequestCanceled();
 }
 
 void LoginScreenController::OnShow() {