1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
ash / auth / views / auth_textfield_timer.cc [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/auth/views/auth_textfield_timer.h"
#include <string>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/auth/views/auth_textfield.h"
#include "ash/shell.h"
#include "base/functional/bind.h"
#include "base/timer/timer.h"
namespace ash {
namespace {
// Delay after which the text gets cleared if nothing has been typed. It is
// only running if the display password button is shown, as there is no
// potential security threat otherwise.
constexpr base::TimeDelta kClearTextAfterDelay = base::Seconds(30);
// Delay after which the password gets back to hidden state, for security.
constexpr base::TimeDelta kHideTextAfterDelay = base::Seconds(5);
} // namespace
AuthTextfieldTimer::AuthTextfieldTimer(AuthTextfield* auth_textfield)
: auth_textfield_(auth_textfield),
clear_text_timer_(
FROM_HERE,
kClearTextAfterDelay,
base::BindRepeating(&AuthTextfieldTimer::ClearTextTimerElapsed,
base::Unretained(this))),
hide_text_timer_(
FROM_HERE,
kHideTextAfterDelay,
base::BindRepeating(&AuthTextfieldTimer::HideTextTimerElapsed,
base::Unretained(this))) {
auth_textfield_->AddObserver(this);
}
AuthTextfieldTimer::~AuthTextfieldTimer() {
auth_textfield_->RemoveObserver(this);
auth_textfield_ = nullptr;
}
void AuthTextfieldTimer::OnContentsChanged(const std::u16string& new_contents) {
if (new_contents.empty()) {
hide_text_timer_.Stop();
clear_text_timer_.Stop();
return;
}
if (auth_textfield_->IsTextVisible()) {
hide_text_timer_.Reset();
} else {
hide_text_timer_.Stop();
}
clear_text_timer_.Reset();
}
void AuthTextfieldTimer::OnTextVisibleChanged(bool visible) {
if (visible) {
hide_text_timer_.Reset();
} else {
hide_text_timer_.Stop();
}
}
void AuthTextfieldTimer::ClearTextTimerElapsed() {
auth_textfield_->Reset();
}
void AuthTextfieldTimer::HideTextTimerElapsed() {
// The password is not hidden if ChromeVox is enabled.
if (Shell::Get()->accessibility_controller()->spoken_feedback().enabled()) {
return;
}
auth_textfield_->SetTextVisible(false);
}
} // namespace ash