[go: nahoru, domu]

cros: Dedup concurrent auth attempts on views-based lock screen.

If there are concurrent attempts (ie, spamming spacebar and enter) lock
would get into a bad state. Prevent concurrent attempts.

Bug: 719015
Change-Id: I4e40368fc8daa1d6ba3c47d4d181a0331b29d2a2
Reviewed-on: https://chromium-review.googlesource.com/688734
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521111}
diff --git a/ash/login/ui/login_password_view.cc b/ash/login/ui/login_password_view.cc
index f186157..88bd591 100644
--- a/ash/login/ui/login_password_view.cc
+++ b/ash/login/ui/login_password_view.cc
@@ -327,7 +327,7 @@
 
 LoginPasswordView::TestApi::~TestApi() = default;
 
-views::View* LoginPasswordView::TestApi::textfield() const {
+views::Textfield* LoginPasswordView::TestApi::textfield() const {
   return view_->textfield_;
 }
 
@@ -501,13 +501,17 @@
                                   ui::DomCode::BACKSPACE, ui::EF_NONE));
 }
 
-void LoginPasswordView::Submit() {}
-
 void LoginPasswordView::SetPlaceholderText(
     const base::string16& placeholder_text) {
   textfield_->set_placeholder_text(placeholder_text);
 }
 
+void LoginPasswordView::SetReadOnly(bool read_only) {
+  textfield_->SetReadOnly(read_only);
+  textfield_->SetCursorEnabled(!read_only);
+  UpdateUiState();
+}
+
 const char* LoginPasswordView::GetClassName() const {
   return kLoginPasswordViewName;
 }
@@ -540,9 +544,13 @@
 void LoginPasswordView::ContentsChanged(views::Textfield* sender,
                                         const base::string16& new_contents) {
   DCHECK_EQ(sender, textfield_);
-  bool is_enabled = !new_contents.empty();
+  UpdateUiState();
+  on_password_text_changed_.Run(new_contents.empty() /*is_empty*/);
+}
+
+void LoginPasswordView::UpdateUiState() {
+  bool is_enabled = !textfield_->text().empty() && !textfield_->read_only();
   submit_button_->SetEnabled(is_enabled);
-  on_password_text_changed_.Run(!is_enabled);
   SkColor color = is_enabled
                       ? login_constants::kButtonEnabledColor
                       : SkColorSetA(login_constants::kButtonEnabledColor,
@@ -558,8 +566,9 @@
 }
 
 void LoginPasswordView::SubmitPassword() {
+  if (textfield_->read_only())
+    return;
   on_submit_.Run(textfield_->text());
-  Clear();
 }
 
 }  // namespace ash