-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
login_auth_user_view.cc
1725 lines (1488 loc) · 65.7 KB
/
login_auth_user_view.cc
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2017 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/login/ui/login_auth_user_view.h"
#include <map>
#include <memory>
#include <utility>
#include "ash/login/login_screen_controller.h"
#include "ash/login/resources/grit/login_resources.h"
#include "ash/login/ui/arrow_button_view.h"
#include "ash/login/ui/fingerprint_auth_factor_model.h"
#include "ash/login/ui/horizontal_image_sequence_animation_decoder.h"
#include "ash/login/ui/lock_screen.h"
#include "ash/login/ui/login_auth_factors_view.h"
#include "ash/login/ui/login_constants.h"
#include "ash/login/ui/login_display_style.h"
#include "ash/login/ui/login_password_view.h"
#include "ash/login/ui/login_pin_input_view.h"
#include "ash/login/ui/login_pin_view.h"
#include "ash/login/ui/login_user_view.h"
#include "ash/login/ui/non_accessible_view.h"
#include "ash/login/ui/pin_keyboard_animation.h"
#include "ash/login/ui/pin_request_view.h"
#include "ash/login/ui/smart_lock_auth_factor_model.h"
#include "ash/login/ui/views_utils.h"
#include "ash/public/cpp/smartlock_state.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_id.h"
#include "ash/style/ash_color_provider.h"
#include "ash/style/color_util.h"
#include "ash/style/pill_button.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/time/time_of_day.h"
#include "base/functional/bind.h"
#include "base/i18n/time_formatting.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chromeos/ash/components/login/auth/auth_events_recorder.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/user_manager/known_user.h"
#include "components/user_manager/user.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/compositor/callback_layer_animation_observer.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/style/typography.h"
#include "ui/views/view.h"
namespace ash {
namespace {
constexpr const char kLoginAuthUserViewClassName[] = "LoginAuthUserView";
// Distance between the user view (ie, the icon and name) and other elements
const int kDistanceBetweenUserViewAndPasswordDp = 24;
const int kDistanceBetweenUserViewAndPinInputDp = 32;
const int kDistanceBetweenUserViewAndOnlineSigninDp = 24;
const int kDistanceBetweenUserViewAndChallengeResponseDp = 32;
// Distance between the password textfield and the the pin keyboard.
const int kDistanceBetweenPasswordFieldAndPinKeyboardDp = 16;
// Height of button used for switching between pin and password authentication.
const int kPinPasswordToggleButtonHeight = 32;
const int kPinPasswordToggleButtonPaddingTop = 24;
const int kPinPasswordToggleButtonPaddingBottom = 20;
// The background color id of the button used for switching between pin and
// password. Applied only for Jellyroll.
constexpr ui::ColorId kPinPasswordToggleColorId =
cros_tokens::kCrosSysSystemOnBase1;
// Distance from the end of pin keyboard to the bottom of the big user view.
const int kDistanceFromPinKeyboardToBigUserViewBottomDp = 50;
// Distance from the top of the user view to the user icon.
constexpr int kDistanceFromTopOfBigUserViewToUserIconDp = 24;
// Date time format containing only the day of the week, for example: "Tuesday".
constexpr char kDayOfWeekOnlyTimeFormat[] = "EEEE";
constexpr int kDistanceBetweenPasswordFieldAndAuthFactorsViewDp = 90;
constexpr base::TimeDelta kChallengeResponseResetAfterFailureDelay =
base::Seconds(5);
constexpr int kChallengeResponseArrowSizeDp = 48;
constexpr int kSpacingBetweenChallengeResponseArrowAndIconDp = 100;
constexpr int kSpacingBetweenChallengeResponseIconAndLabelDp = 15;
constexpr int kChallengeResponseIconSizeDp = 28;
constexpr int kDistanceBetweenPwdFieldAndChallengeResponseViewDp = 0;
constexpr int kDisabledAuthMessageVerticalBorderDp = 16;
constexpr int kDisabledAuthMessageHorizontalBorderDp = 16;
constexpr int kDisabledAuthMessageChildrenSpacingDp = 4;
constexpr int kDisabledAuthMessageTimeWidthDp = 204;
constexpr int kDisabledAuthMessageMultiprofileWidthDp = 304;
constexpr int kDisabledAuthMessageHeightDp = 98;
constexpr int kDisabledAuthMessageIconSizeDp = 24;
constexpr int kDisabledAuthMessageTitleFontSizeDeltaDp = 3;
constexpr int kDisabledAuthMessageContentsFontSizeDeltaDp = -1;
constexpr int kDisabledAuthMessageRoundedCornerRadiusDp = 8;
constexpr int kLockedTpmMessageVerticalBorderDp = 16;
constexpr int kLockedTpmMessageHorizontalBorderDp = 16;
constexpr int kLockedTpmMessageChildrenSpacingDp = 4;
constexpr int kLockedTpmMessageWidthDp = 360;
constexpr int kLockedTpmMessageHeightDp = 108;
constexpr int kLockedTpmMessageIconSizeDp = 24;
constexpr int kLockedTpmMessageDeltaDp = 0;
constexpr int kLockedTpmMessageRoundedCornerRadiusDp = 8;
constexpr int kAuthFactorHidingPasswordFieldSlideUpDistanceDp = 42;
constexpr base::TimeDelta kAuthFactorHidingPasswordFieldSlideUpDuration =
base::Milliseconds(600);
constexpr int kNonEmptyWidthDp = 1;
gfx::Size SizeFromHeight(int height) {
return gfx::Size(kNonEmptyWidthDp, height);
}
// Returns an observer that will hide |view| when it fires. The observer will
// delete itself after firing (by returning true). Make sure to call
// |observer->SetActive()| after attaching it.
ui::CallbackLayerAnimationObserver* BuildObserverToHideView(views::View* view) {
return new ui::CallbackLayerAnimationObserver(base::BindRepeating(
[](views::View* view,
const ui::CallbackLayerAnimationObserver& observer) {
// Don't hide the view if the animation is aborted, as |view| may no
// longer be valid.
if (observer.aborted_count()) {
return true;
}
view->SetVisible(false);
return true;
},
view));
}
ui::CallbackLayerAnimationObserver* BuildObserverToNotifyA11yLocationChanged(
views::View* view) {
return new ui::CallbackLayerAnimationObserver(base::BindRepeating(
[](views::View* view,
const ui::CallbackLayerAnimationObserver& observer) {
// Don't notify a11y event if the animation is aborted, as |view| may no
// longer be valid.
if (observer.aborted_count()) {
return true;
}
view->NotifyAccessibilityEvent(ax::mojom::Event::kLocationChanged,
false /*send_native_event*/);
return true;
},
view));
}
ui::CallbackLayerAnimationObserver* BuildObserverToNotifyA11yLocationChanged(
LoginPinView* view) {
return new ui::CallbackLayerAnimationObserver(base::BindRepeating(
[](LoginPinView* view,
const ui::CallbackLayerAnimationObserver& observer) {
// Don't notify a11y event if the animation is aborted, as |view| may no
// longer be valid.
if (observer.aborted_count()) {
return true;
}
view->NotifyAccessibilityLocationChanged();
return true;
},
view));
}
// The content needed to render the disabled auth message view.
struct LockScreenMessage {
std::u16string title;
std::u16string content;
raw_ptr<const gfx::VectorIcon, ExperimentalAsh> icon;
};
// Returns the message used when the device was locked due to a time window
// limit.
LockScreenMessage GetWindowLimitMessage(const base::Time& unlock_time,
bool use_24hour_clock) {
LockScreenMessage message;
message.title = l10n_util::GetStringUTF16(IDS_ASH_LOGIN_TIME_FOR_BED_MESSAGE);
base::Time local_midnight = base::Time::Now().LocalMidnight();
std::u16string time_to_display;
if (use_24hour_clock) {
time_to_display = base::TimeFormatTimeOfDayWithHourClockType(
unlock_time, base::k24HourClock, base::kDropAmPm);
} else {
time_to_display = base::TimeFormatTimeOfDayWithHourClockType(
unlock_time, base::k12HourClock, base::kKeepAmPm);
}
if (unlock_time < local_midnight + base::Days(1)) {
// Unlock time is today.
message.content = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_COME_BACK_MESSAGE, time_to_display);
} else if (unlock_time < local_midnight + base::Days(2)) {
// Unlock time is tomorrow.
message.content = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_COME_BACK_TOMORROW_MESSAGE, time_to_display);
} else {
message.content = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_COME_BACK_DAY_OF_WEEK_MESSAGE,
base::TimeFormatWithPattern(unlock_time, kDayOfWeekOnlyTimeFormat),
time_to_display);
}
message.icon = &kLockScreenTimeLimitMoonIcon;
return message;
}
// Returns the message used when the device was locked due to a time usage
// limit.
LockScreenMessage GetUsageLimitMessage(const base::TimeDelta& used_time) {
LockScreenMessage message;
// 1 minute is used instead of 0, because the device is used for a few
// milliseconds before locking.
if (used_time < base::Minutes(1)) {
// The device was locked all day.
message.title = l10n_util::GetStringUTF16(IDS_ASH_LOGIN_TAKE_BREAK_MESSAGE);
message.content =
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_LOCKED_ALL_DAY_MESSAGE);
} else {
// The usage limit is over.
message.title = l10n_util::GetStringUTF16(IDS_ASH_LOGIN_TIME_IS_UP_MESSAGE);
const std::u16string used_time_string = ui::TimeFormat::Detailed(
ui::TimeFormat::Format::FORMAT_DURATION,
ui::TimeFormat::Length::LENGTH_LONG, /*cutoff=*/3, used_time);
message.content = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_SCREEN_TIME_USED_MESSAGE, used_time_string);
}
message.icon = &kLockScreenTimeLimitTimerIcon;
return message;
}
// Returns the message used when the device was locked due to a time limit
// override.
LockScreenMessage GetOverrideMessage() {
LockScreenMessage message;
message.title =
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_TIME_FOR_A_BREAK_MESSAGE);
message.content =
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_MANUAL_LOCK_MESSAGE);
message.icon = &kLockScreenTimeLimitLockIcon;
return message;
}
LockScreenMessage GetLockScreenMessage(AuthDisabledReason lock_reason,
const base::Time& unlock_time,
const base::TimeDelta& used_time,
bool use_24hour_clock) {
switch (lock_reason) {
case AuthDisabledReason::kTimeWindowLimit:
return GetWindowLimitMessage(unlock_time, use_24hour_clock);
case AuthDisabledReason::kTimeUsageLimit:
return GetUsageLimitMessage(used_time);
case AuthDisabledReason::kTimeLimitOverride:
return GetOverrideMessage();
default:
NOTREACHED();
}
}
} // namespace
// Consists of challenge-response icon view and a label.
class LoginAuthUserView::ChallengeResponseView : public views::View {
public:
enum class State { kInitial, kAuthenticating, kFailure };
explicit ChallengeResponseView(base::RepeatingClosure on_start_tap)
: on_start_tap_(std::move(on_start_tap)) {
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
auto arrow_button_view = std::make_unique<ArrowButtonView>(
base::BindRepeating(&ChallengeResponseView::ArrowButtonPressed,
base::Unretained(this)),
kChallengeResponseArrowSizeDp);
arrow_button_view->SetInstallFocusRingOnFocus(true);
views::InstallCircleHighlightPathGenerator(arrow_button_view.get());
arrow_button_ = AddChildView(std::move(arrow_button_view));
arrow_button_->SetAccessibleName(l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_START_SMART_CARD_AUTH_BUTTON_ACCESSIBLE_NAME));
arrow_to_icon_spacer_ = AddChildView(std::make_unique<NonAccessibleView>());
arrow_to_icon_spacer_->SetPreferredSize(
gfx::Size(0, kSpacingBetweenChallengeResponseArrowAndIconDp));
icon_ = AddChildView(std::make_unique<views::ImageView>());
icon_->SetImage(GetImageForIcon());
auto* icon_to_label_spacer =
AddChildView(std::make_unique<NonAccessibleView>());
icon_to_label_spacer->SetPreferredSize(
gfx::Size(0, kSpacingBetweenChallengeResponseIconAndLabelDp));
label_ = AddChildView(std::make_unique<views::Label>(
GetTextForLabel(), views::style::CONTEXT_LABEL,
views::style::STYLE_PRIMARY));
label_->SetAutoColorReadabilityEnabled(false);
label_->SetEnabledColorId(kColorAshTextColorSecondary);
label_->SetSubpixelRenderingEnabled(false);
label_->SetFontList(views::Label::GetDefaultFontList().Derive(
/*size_delta=*/1, gfx::Font::FontStyle::ITALIC,
gfx::Font::Weight::NORMAL));
}
ChallengeResponseView(const ChallengeResponseView&) = delete;
ChallengeResponseView& operator=(const ChallengeResponseView&) = delete;
~ChallengeResponseView() override = default;
void SetState(State state) {
if (state_ == state) {
return;
}
state_ = state;
reset_state_timer_.Stop();
if (state == State::kFailure) {
reset_state_timer_.Start(
FROM_HERE, kChallengeResponseResetAfterFailureDelay,
base::BindOnce(&ChallengeResponseView::SetState,
base::Unretained(this), State::kInitial));
}
arrow_button_->EnableLoadingAnimation(state == State::kAuthenticating);
icon_->SetImage(GetImageForIcon());
label_->SetText(GetTextForLabel());
if (state == State::kFailure) {
label_->NotifyAccessibilityEvent(ax::mojom::Event::kAlert,
/*send_native_event=*/true);
}
Layout();
}
// views::View:
void RequestFocus() override { arrow_button_->RequestFocus(); }
views::Button* GetButtonForTesting() { return arrow_button_; }
views::Label* GetLabelForTesting() { return label_; }
private:
ui::ImageModel GetImageForIcon() const {
switch (state_) {
case State::kInitial:
case State::kAuthenticating:
return ui::ImageModel::FromVectorIcon(kLockScreenSmartCardIcon,
kColorAshIconColorPrimary,
kChallengeResponseIconSizeDp);
case State::kFailure:
return ui::ImageModel::FromVectorIcon(kLockScreenSmartCardFailureIcon,
kColorAshIconColorAlert,
kChallengeResponseIconSizeDp);
}
}
std::u16string GetTextForLabel() const {
switch (state_) {
case State::kInitial:
case State::kAuthenticating:
return l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_SMART_CARD_SIGN_IN_MESSAGE);
case State::kFailure:
return l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_SMART_CARD_SIGN_IN_FAILURE_MESSAGE);
}
}
void ArrowButtonPressed() {
// Ignore further clicks while handling the previous one.
if (state_ != State::kAuthenticating) {
on_start_tap_.Run();
}
}
base::RepeatingClosure on_start_tap_;
State state_ = State::kInitial;
raw_ptr<ArrowButtonView, ExperimentalAsh> arrow_button_ = nullptr;
raw_ptr<NonAccessibleView, ExperimentalAsh> arrow_to_icon_spacer_ = nullptr;
raw_ptr<views::ImageView, ExperimentalAsh> icon_ = nullptr;
raw_ptr<views::Label, ExperimentalAsh> label_ = nullptr;
base::OneShotTimer reset_state_timer_;
};
// The message shown to the user when auth is disabled. This could happen when:
// -auth method is |AUTH_DISABLED|
// -auth method is |AUTH_ONLINE_SIGN_IN| and the user is on the secondary login
// screen
// -the selected account has a restricted multiprofile policy set and the user
// is on the secondary login screen
class LoginAuthUserView::DisabledAuthMessageView : public views::View {
public:
class ASH_EXPORT TestApi {
public:
explicit TestApi(DisabledAuthMessageView* view) : view_(view) {}
~TestApi() = default;
const std::u16string& GetDisabledAuthMessageContent() const {
return view_->message_contents_->GetText();
}
private:
const raw_ptr<DisabledAuthMessageView, ExperimentalAsh> view_;
};
DisabledAuthMessageView() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
gfx::Insets::VH(kDisabledAuthMessageVerticalBorderDp,
kDisabledAuthMessageHorizontalBorderDp),
kDisabledAuthMessageChildrenSpacingDp));
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
SetFocusBehavior(FocusBehavior::ALWAYS);
// The icon size has to be defined later if the image will be visible.
message_icon_ = AddChildView(std::make_unique<views::ImageView>());
message_icon_->SetImageSize(gfx::Size(kDisabledAuthMessageIconSizeDp,
kDisabledAuthMessageIconSizeDp));
auto decorate_label = [](views::Label* label) {
label->SetSubpixelRenderingEnabled(false);
label->SetAutoColorReadabilityEnabled(false);
label->SetFocusBehavior(FocusBehavior::ALWAYS);
};
message_title_ = AddChildView(std::make_unique<views::Label>(
std::u16string(), views::style::CONTEXT_LABEL,
views::style::STYLE_PRIMARY));
message_title_->SetFontList(
gfx::FontList().Derive(kDisabledAuthMessageTitleFontSizeDeltaDp,
gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM));
decorate_label(message_title_);
message_contents_ = AddChildView(std::make_unique<views::Label>(
std::u16string(), views::style::CONTEXT_LABEL,
views::style::STYLE_PRIMARY));
message_contents_->SetFontList(
gfx::FontList().Derive(kDisabledAuthMessageContentsFontSizeDeltaDp,
gfx::Font::NORMAL, gfx::Font::Weight::NORMAL));
decorate_label(message_contents_);
message_contents_->SetMultiLine(true);
}
DisabledAuthMessageView(const DisabledAuthMessageView&) = delete;
DisabledAuthMessageView& operator=(const DisabledAuthMessageView&) = delete;
~DisabledAuthMessageView() override = default;
// Set the parameters needed to render the message.
void SetAuthDisabledMessage(const AuthDisabledData& auth_disabled_data,
bool use_24hour_clock) {
LockScreenMessage message = GetLockScreenMessage(
auth_disabled_data.reason, auth_disabled_data.auth_reenabled_time,
auth_disabled_data.device_used_time, use_24hour_clock);
SetPreferredSize(gfx::Size(kDisabledAuthMessageTimeWidthDp,
kDisabledAuthMessageHeightDp));
message_icon_->SetVisible(true);
message_vector_icon_ = message.icon;
message_title_->SetText(message.title);
message_contents_->SetText(message.content);
UpdateColors();
}
void SetAuthDisabledMessage(const std::u16string& title,
const std::u16string& content) {
SetPreferredSize(gfx::Size(kDisabledAuthMessageMultiprofileWidthDp,
kDisabledAuthMessageHeightDp));
message_icon_->SetVisible(false);
message_title_->SetText(title);
message_contents_->SetText(content);
UpdateColors();
}
// views::View:
void OnPaint(gfx::Canvas* canvas) override {
views::View::OnPaint(canvas);
cc::PaintFlags flags;
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setColor(
PinRequestView::GetChildUserDialogColor(false /*using blur*/));
canvas->DrawRoundRect(GetContentsBounds(),
kDisabledAuthMessageRoundedCornerRadiusDp, flags);
}
// views::View:
void RequestFocus() override { message_title_->RequestFocus(); }
// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
// Any view which claims to be focusable is expected to have an accessible
// name and accessible role so that screen readers know what to present to
// the user when it gains focus. In the case of this particular view,
// `RequestFocus` gives focus to the `message_title_` label. As a result,
// this view is not end-user focusable. However, its official focusability
// will cause the accessibility paint checks to fail. Give this view a
// container role. If the `message_title_` has text, set the accessible
// name to that text; otherwise set the name explicitly empty to prevent
// the paint check from failing during tests.
node_data->role = ax::mojom::Role::kPane;
if (message_title_->GetText().empty()) {
node_data->SetNameExplicitlyEmpty();
} else {
node_data->SetNameChecked(message_title_->GetText());
}
}
private:
void UpdateColors() {
message_title_->SetEnabledColorId(kColorAshTextColorPrimary);
message_contents_->SetEnabledColorId(kColorAshTextColorPrimary);
if (message_vector_icon_) {
message_icon_->SetImage(ui::ImageModel::FromVectorIcon(
*message_vector_icon_, kColorAshIconColorPrimary,
kDisabledAuthMessageIconSizeDp));
}
}
raw_ptr<views::Label, ExperimentalAsh> message_title_;
raw_ptr<views::Label, ExperimentalAsh> message_contents_;
raw_ptr<views::ImageView, ExperimentalAsh> message_icon_;
raw_ptr<const gfx::VectorIcon, ExperimentalAsh> message_vector_icon_ =
nullptr;
};
// The message shown to user when TPM is locked.
class LoginAuthUserView::LockedTpmMessageView : public views::View {
public:
LockedTpmMessageView() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
gfx::Insets::VH(kLockedTpmMessageVerticalBorderDp,
kLockedTpmMessageHorizontalBorderDp),
kLockedTpmMessageChildrenSpacingDp));
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
SetPreferredSize(
gfx::Size(kLockedTpmMessageWidthDp, kLockedTpmMessageHeightDp));
SetFocusBehavior(FocusBehavior::ALWAYS);
message_icon_ = AddChildView(std::make_unique<views::ImageView>());
message_icon_->SetImage(ui::ImageModel::FromVectorIcon(
kLockScreenAlertIcon, kColorAshIconColorPrimary,
kLockedTpmMessageIconSizeDp));
message_warning_ = CreateLabel();
message_warning_->SetEnabledColorId(kColorAshTextColorPrimary);
message_description_ = CreateLabel();
// Set content.
std::u16string message_description = l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_POD_TPM_LOCKED_ISSUE_DESCRIPTION);
message_description_->SetText(message_description);
message_description_->SetEnabledColorId(kColorAshTextColorPrimary);
}
LockedTpmMessageView(const LockedTpmMessageView&) = delete;
LockedTpmMessageView& operator=(const LockedTpmMessageView&) = delete;
~LockedTpmMessageView() override = default;
// Set the parameters needed to render the message.
void SetRemainingTime(base::TimeDelta time_left) {
std::u16string time_left_message;
if (base::TimeDurationFormatWithSeconds(
time_left, base::DurationFormatWidth::DURATION_WIDTH_WIDE,
&time_left_message)) {
std::u16string message_warning = l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_POD_TPM_LOCKED_ISSUE_WARNING, time_left_message);
message_warning_->SetText(message_warning);
if (time_left.InMinutes() != prev_time_left_.InMinutes()) {
message_warning_->SetAccessibleName(message_warning);
}
prev_time_left_ = time_left;
}
}
// views::View:
void OnPaint(gfx::Canvas* canvas) override {
views::View::OnPaint(canvas);
cc::PaintFlags flags;
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setColor(
PinRequestView::GetChildUserDialogColor(false /*using blur*/));
canvas->DrawRoundRect(GetContentsBounds(),
kLockedTpmMessageRoundedCornerRadiusDp, flags);
}
// views::View:
void RequestFocus() override { message_warning_->RequestFocus(); }
private:
views::Label* CreateLabel() {
auto label = std::make_unique<views::Label>(std::u16string(),
views::style::CONTEXT_LABEL,
views::style::STYLE_PRIMARY);
label->SetFontList(gfx::FontList().Derive(kLockedTpmMessageDeltaDp,
gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL));
label->SetSubpixelRenderingEnabled(false);
label->SetAutoColorReadabilityEnabled(false);
label->SetFocusBehavior(FocusBehavior::ALWAYS);
label->SetMultiLine(true);
return AddChildView(std::move(label));
}
base::TimeDelta prev_time_left_;
raw_ptr<views::Label, ExperimentalAsh> message_warning_;
raw_ptr<views::Label, ExperimentalAsh> message_description_;
raw_ptr<views::ImageView, ExperimentalAsh> message_icon_;
};
LoginAuthUserView::AuthMethodsMetadata::AuthMethodsMetadata() = default;
LoginAuthUserView::AuthMethodsMetadata::~AuthMethodsMetadata() = default;
LoginAuthUserView::AuthMethodsMetadata::AuthMethodsMetadata(
const AuthMethodsMetadata&) = default;
struct LoginAuthUserView::UiState {
explicit UiState(const LoginAuthUserView* view) {
has_password = view->ShouldShowPasswordField();
has_pin_input = view->ShouldShowPinInputField();
has_pinpad = view->ShouldShowPinPad();
has_toggle = view->ShouldShowToggle();
has_fingerprint = view->HasAuthMethod(LoginAuthUserView::AUTH_FINGERPRINT);
has_smart_lock = view->HasAuthMethod(LoginAuthUserView::AUTH_SMART_LOCK);
has_challenge_response =
view->HasAuthMethod(LoginAuthUserView::AUTH_CHALLENGE_RESPONSE);
auth_disabled = view->HasAuthMethod(LoginAuthUserView::AUTH_DISABLED);
tpm_is_locked =
view->HasAuthMethod(LoginAuthUserView::AUTH_DISABLED_TPM_LOCKED);
force_online_sign_in =
view->HasAuthMethod(LoginAuthUserView::AUTH_ONLINE_SIGN_IN);
auth_factor_is_hiding_password = view->HasAuthMethod(
LoginAuthUserView::AUTH_AUTH_FACTOR_IS_HIDING_PASSWORD);
non_pin_y_start_in_screen = view->GetBoundsInScreen().y();
pin_start_in_screen = view->pin_view_->GetBoundsInScreen().origin();
}
bool has_password = false;
bool has_pin_input = false;
bool has_pinpad = false;
bool has_toggle = false;
bool has_fingerprint = false;
bool has_smart_lock = false;
bool has_challenge_response = false;
bool auth_disabled = false;
bool tpm_is_locked = false;
bool force_online_sign_in = false;
bool auth_factor_is_hiding_password = false;
// Used for this view's animation in `ApplyAnimationPostLayout`.
int non_pin_y_start_in_screen = 0;
gfx::Point pin_start_in_screen;
};
LoginAuthUserView::TestApi::TestApi(LoginAuthUserView* view) : view_(view) {}
LoginAuthUserView::TestApi::~TestApi() = default;
LoginUserView* LoginAuthUserView::TestApi::user_view() const {
return view_->user_view_;
}
LoginPasswordView* LoginAuthUserView::TestApi::password_view() const {
return view_->password_view_;
}
LoginPinView* LoginAuthUserView::TestApi::pin_view() const {
return view_->pin_view_;
}
LoginPinInputView* LoginAuthUserView::TestApi::pin_input_view() const {
return view_->pin_input_view_;
}
views::Button* LoginAuthUserView::TestApi::pin_password_toggle() const {
return view_->pin_password_toggle_;
}
views::Button* LoginAuthUserView::TestApi::online_sign_in_message() const {
return view_->online_sign_in_button_;
}
views::View* LoginAuthUserView::TestApi::disabled_auth_message() const {
return view_->disabled_auth_message_;
}
views::Button* LoginAuthUserView::TestApi::challenge_response_button() {
return view_->challenge_response_view_->GetButtonForTesting();
}
views::Label* LoginAuthUserView::TestApi::challenge_response_label() {
return view_->challenge_response_view_->GetLabelForTesting();
}
LoginAuthFactorsView* LoginAuthUserView::TestApi::auth_factors_view() const {
return view_->auth_factors_view_;
}
AuthFactorModel* LoginAuthUserView::TestApi::fingerprint_auth_factor_model()
const {
return view_->fingerprint_auth_factor_model_;
}
AuthFactorModel* LoginAuthUserView::TestApi::smart_lock_auth_factor_model()
const {
return view_->smart_lock_auth_factor_model_;
}
bool LoginAuthUserView::TestApi::HasAuthMethod(AuthMethods auth_method) const {
return view_->HasAuthMethod(auth_method);
}
void LoginAuthUserView::TestApi::SetFingerprintState(
FingerprintState state) const {
return view_->SetFingerprintState(state);
}
void LoginAuthUserView::TestApi::SetSmartLockState(SmartLockState state) const {
return view_->SetSmartLockState(state);
}
const std::u16string&
LoginAuthUserView::TestApi::GetDisabledAuthMessageContent() const {
return LoginAuthUserView::DisabledAuthMessageView::TestApi(
view_->disabled_auth_message_)
.GetDisabledAuthMessageContent();
}
LoginAuthUserView::Callbacks::Callbacks() = default;
LoginAuthUserView::Callbacks::Callbacks(const Callbacks& other) = default;
LoginAuthUserView::Callbacks::~Callbacks() = default;
LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
const Callbacks& callbacks)
: NonAccessibleView(kLoginAuthUserViewClassName),
on_auth_(callbacks.on_auth),
on_tap_(callbacks.on_tap) {
DCHECK(callbacks.on_auth);
DCHECK(callbacks.on_tap);
DCHECK(callbacks.on_remove_warning_shown);
DCHECK(callbacks.on_remove);
DCHECK(callbacks.on_easy_unlock_icon_hovered);
DCHECK(callbacks.on_auth_factor_is_hiding_password_changed);
DCHECK_NE(user.basic_user_info.type, user_manager::USER_TYPE_PUBLIC_ACCOUNT);
if (Shell::Get()->login_screen_controller()->IsAuthenticating()) {
// TODO(b/276246832): We should avoid re-layouting during Authentication.
LOG(WARNING)
<< "LoginAuthUserView::LoginAuthUserView called during Authentication.";
}
// Build child views.
auto user_view = std::make_unique<LoginUserView>(
LoginDisplayStyle::kLarge, true /*show_dropdown*/,
base::BindRepeating(&LoginAuthUserView::OnUserViewTap,
base::Unretained(this)),
callbacks.on_remove_warning_shown, callbacks.on_remove);
user_view_ = user_view.get();
auto password_view = std::make_unique<LoginPasswordView>();
password_view_ = password_view.get();
password_view->SetPaintToLayer(); // Needed for opacity animation.
password_view->layer()->SetFillsBoundsOpaquely(false);
password_view_->SetDisplayPasswordButtonVisible(
user.show_display_password_button);
password_view->Init(
base::BindRepeating(&LoginAuthUserView::OnAuthSubmit,
base::Unretained(this)),
base::BindRepeating(&LoginAuthUserView::OnPasswordTextChanged,
base::Unretained(this)),
callbacks.on_easy_unlock_icon_hovered);
auto pin_input_view = std::make_unique<LoginPinInputView>();
pin_input_view_ = pin_input_view.get();
pin_input_view->Init(base::BindRepeating(&LoginAuthUserView::OnAuthSubmit,
base::Unretained(this)),
base::BindRepeating(&LoginAuthUserView::OnPinTextChanged,
base::Unretained(this)));
auto toggle_container = std::make_unique<NonAccessibleView>();
toggle_container->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
gfx::Insets::TLBR(kPinPasswordToggleButtonPaddingTop, 0,
kPinPasswordToggleButtonPaddingBottom, 0)));
pin_password_toggle_ =
toggle_container->AddChildView(std::make_unique<PillButton>(
base::BindRepeating(&LoginAuthUserView::OnSwitchButtonClicked,
base::Unretained(this)),
GetPinPasswordToggleText()));
pin_password_toggle_->SetMaxSize(
gfx::Size(/*ignored*/ 0, kPinPasswordToggleButtonHeight));
if (chromeos::features::IsJellyrollEnabled()) {
pin_password_toggle_->SetBackgroundColorId(kPinPasswordToggleColorId);
}
auto pin_view = std::make_unique<LoginPinView>(
LoginPinView::Style::kNumeric,
base::BindRepeating(&LoginAuthUserView::OnPinPadInsertDigit,
base::Unretained(this)),
base::BindRepeating(&LoginAuthUserView::OnPinPadBackspace,
base::Unretained(this)));
pin_view_ = pin_view.get();
DCHECK(pin_view_->layer());
auto padding_below_password_view = std::make_unique<NonAccessibleView>();
padding_below_password_view->SetPreferredSize(gfx::Size(
kNonEmptyWidthDp, kDistanceBetweenPasswordFieldAndPinKeyboardDp));
padding_below_password_view_ = padding_below_password_view.get();
auto padding_below_user_view = std::make_unique<NonAccessibleView>();
padding_below_user_view->SetPreferredSize(
gfx::Size(kNonEmptyWidthDp, kDistanceBetweenUserViewAndPasswordDp));
padding_below_user_view_ = padding_below_user_view.get();
std::u16string button_message =
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_ONLINE_SIGN_IN_MESSAGE);
if (user.is_signed_in) {
button_message =
l10n_util::GetStringUTF16(IDS_ASH_LOCK_SCREEN_VERIFY_ACCOUNT_MESSAGE);
}
auto online_sign_in_button = std::make_unique<PillButton>(
base::BindRepeating(&LoginAuthUserView::OnOnlineSignInMessageTap,
base::Unretained(this)),
button_message);
online_sign_in_button_ = online_sign_in_button.get();
auto disabled_auth_message = std::make_unique<DisabledAuthMessageView>();
disabled_auth_message_ = disabled_auth_message.get();
auto locked_tpm_message_view = std::make_unique<LockedTpmMessageView>();
locked_tpm_message_view_ = locked_tpm_message_view.get();
auto fingerprint_auth_factor_model =
FingerprintAuthFactorModel::Factory::Create(user.fingerprint_state);
fingerprint_auth_factor_model_ = fingerprint_auth_factor_model.get();
auto smart_lock_auth_factor_model = SmartLockAuthFactorModel::Factory::Create(
user.smart_lock_state,
base::BindRepeating(&LoginAuthUserView::OnSmartLockArrowButtonTapped,
base::Unretained(this)));
smart_lock_auth_factor_model_ = smart_lock_auth_factor_model.get();
// Note: at the moment, between Fingerprint and Smart Lock, Smart Lock
// is the only auth factor which considers an "arrow button" tap event.
auto auth_factors_view = std::make_unique<LoginAuthFactorsView>(
base::BindRepeating(
&SmartLockAuthFactorModel::OnArrowButtonTapOrClickEvent,
base::Unretained(smart_lock_auth_factor_model_)),
callbacks.on_auth_factor_is_hiding_password_changed);
auth_factors_view_ = auth_factors_view.get();
auth_factors_view_->AddAuthFactor(std::move(fingerprint_auth_factor_model));
auth_factors_view_->AddAuthFactor(std::move(smart_lock_auth_factor_model));
// Needed for up/down sliding animation.
auth_factors_view_->SetPaintToLayer();
auth_factors_view_->layer()->SetFillsBoundsOpaquely(false);
auto challenge_response_view =
std::make_unique<ChallengeResponseView>(base::BindRepeating(
&LoginAuthUserView::AttemptAuthenticateWithChallengeResponse,
weak_factory_.GetWeakPtr()));
challenge_response_view_ = challenge_response_view.get();
SetPaintToLayer(ui::LayerType::LAYER_NOT_DRAWN);
// Build layout.
auto wrapped_password_view =
login_views_utils::WrapViewForPreferredSize(std::move(password_view));
auto wrapped_online_sign_in_message_view =
login_views_utils::WrapViewForPreferredSize(
std::move(online_sign_in_button));
auto wrapped_disabled_auth_message_view =
login_views_utils::WrapViewForPreferredSize(
std::move(disabled_auth_message));
auto wrapped_locked_tpm_message_view =
login_views_utils::WrapViewForPreferredSize(
std::move(locked_tpm_message_view));
auto wrapped_user_view =
login_views_utils::WrapViewForPreferredSize(std::move(user_view));
auto wrapped_pin_view =
login_views_utils::WrapViewForPreferredSize(std::move(pin_view));
auto wrapped_pin_input_view =
login_views_utils::WrapViewForPreferredSize(std::move(pin_input_view));
auto wrapped_pin_password_toggle_view =
login_views_utils::WrapViewForPreferredSize(std::move(toggle_container));
auto wrapped_auth_factors_view =
login_views_utils::WrapViewForPreferredSize(std::move(auth_factors_view));
auto wrapped_challenge_response_view =
login_views_utils::WrapViewForPreferredSize(
std::move(challenge_response_view));
auto wrapped_padding_below_password_view =
login_views_utils::WrapViewForPreferredSize(
std::move(padding_below_password_view));
auto wrapped_padding_below_user_view =
login_views_utils::WrapViewForPreferredSize(
std::move(padding_below_user_view));
auto* box_layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
gfx::Insets::TLBR(kDistanceFromTopOfBigUserViewToUserIconDp, 0,
kDistanceFromPinKeyboardToBigUserViewBottomDp, 0)));
box_layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
// Add views in rendering order.
auto* user_ptr = AddChildView(std::move(wrapped_user_view));
AddChildView(std::move(wrapped_padding_below_user_view));
auto* tpm_message_ptr =
AddChildView(std::move(wrapped_locked_tpm_message_view));
AddChildView(std::move(wrapped_password_view));
AddChildView(std::move(wrapped_online_sign_in_message_view));
auto* auth_message_ptr =
AddChildView(std::move(wrapped_disabled_auth_message_view));
AddChildView(std::move(wrapped_pin_input_view));
AddChildView(std::move(wrapped_padding_below_password_view));
AddChildView(std::move(wrapped_pin_view));
AddChildView(std::move(wrapped_pin_password_toggle_view));
AddChildView(std::move(wrapped_auth_factors_view));
auto* challenge_ptr =
AddChildView(std::move(wrapped_challenge_response_view));
// Set up taborder.
tpm_message_ptr->InsertAfterInFocusList(auth_message_ptr);
user_ptr->InsertAfterInFocusList(challenge_ptr);
// The user needs to be set before SetAuthMethods is called.
user_view_->UpdateForUser(user, /*animate*/ false);
// Update authentication UI.
CaptureStateForAnimationPreLayout();
SetAuthMethods(auth_methods_);
ApplyAnimationPostLayout(/*animate*/ false);
}
LoginAuthUserView::~LoginAuthUserView() = default;
void LoginAuthUserView::SetAuthMethods(
uint32_t auth_methods,
const AuthMethodsMetadata& auth_metadata) {
// It is an error to call this method without storing the previous state.
DCHECK(previous_state_);
// Apply changes and determine the new state of input fields.
auth_methods_ = static_cast<AuthMethods>(auth_methods);
auth_metadata_ = auth_metadata;