File: sheet_models.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (874 lines) | stat: -rw-r--r-- 30,756 bytes parent folder | download | duplicates (3)
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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBAUTHN_SHEET_MODELS_H_
#define CHROME_BROWSER_UI_WEBAUTHN_SHEET_MODELS_H_

#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "chrome/browser/ui/webauthn/authenticator_request_sheet_model.h"
#include "chrome/browser/webauthn/authenticator_request_dialog_model.h"
#include "chrome/browser/webauthn/local_authentication_token.h"
#include "device/fido/pin.h"

namespace gfx {
class Image;
}  // namespace gfx

// Base class for sheets, implementing the shared behavior used on most sheets,
// as well as maintaining a weak pointer to the dialog model.
class AuthenticatorSheetModelBase
    : public AuthenticatorRequestSheetModel,
      public AuthenticatorRequestDialogModel::Observer {
 public:
  // Determines whether the button in the lower-left corner of the dialog, to
  // display other available mechanisms, is shown on a sheet.
  enum class OtherMechanismButtonVisibility {
    // The button is not shown (default).
    kHidden,
    // The button is shown if there is more than one mechanism to choose from.
    kVisible,
  };

  explicit AuthenticatorSheetModelBase(
      AuthenticatorRequestDialogModel* dialog_model);
  AuthenticatorSheetModelBase(
      AuthenticatorRequestDialogModel* dialog_model,
      OtherMechanismButtonVisibility other_mechanism_button_visibility);

  AuthenticatorSheetModelBase(const AuthenticatorSheetModelBase&) = delete;
  AuthenticatorSheetModelBase& operator=(const AuthenticatorSheetModelBase&) =
      delete;

  ~AuthenticatorSheetModelBase() override;

  AuthenticatorRequestDialogModel* dialog_model() const {
    return dialog_model_;
  }

  // Returns a string containing the RP ID, styled as an origin, truncated to a
  // reasonable width.
  static std::u16string GetRelyingPartyIdString(
      const AuthenticatorRequestDialogModel* dialog_model);

 protected:
  // AuthenticatorRequestSheetModel:
  bool IsActivityIndicatorVisible() const override;
  bool IsCancelButtonVisible() const override;
  bool IsOtherMechanismButtonVisible() const override;
  std::u16string GetOtherMechanismButtonLabel() const override;
  std::u16string GetCancelButtonLabel() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnBack() override;
  void OnAccept() override;
  void OnCancel() override;

  // AuthenticatorRequestDialogModel::Observer:
  void OnModelDestroyed(AuthenticatorRequestDialogModel* model) override;

 private:
  raw_ptr<AuthenticatorRequestDialogModel> dialog_model_;
  OtherMechanismButtonVisibility other_mechanism_button_visibility_ =
      OtherMechanismButtonVisibility::kHidden;
};

// The sheet shown for selecting the transport over which the security key
// should be accessed.
class AuthenticatorMechanismSelectorSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorMechanismSelectorSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorInsertAndActivateUsbSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorInsertAndActivateUsbSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  // AuthenticatorSheetModelBase:
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  std::vector<std::u16string> GetAdditionalDescriptions() const override;
};

class AuthenticatorTimeoutErrorModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorTimeoutErrorModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetCancelButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorNoAvailableTransportsErrorModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorNoAvailableTransportsErrorModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetCancelButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorNoPasskeysErrorModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorNoPasskeysErrorModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetCancelButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorNotRegisteredErrorModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorNotRegisteredErrorModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetCancelButtonLabel() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  void OnAccept() override;
};

class AuthenticatorAlreadyRegisteredErrorModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorAlreadyRegisteredErrorModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetCancelButtonLabel() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  void OnAccept() override;
};

class AuthenticatorInternalUnrecognizedErrorSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorInternalUnrecognizedErrorSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  void OnAccept() override;
};

class AuthenticatorChallengeFetchErrorModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorChallengeFetchErrorModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetCancelButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorBlePowerOnManualSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorBlePowerOnManualSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;

  // AuthenticatorRequestDialogModel::Observer:
  void OnBluetoothPoweredStateChanged() override;
};

class AuthenticatorBlePowerOnAutomaticSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorBlePowerOnAutomaticSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;

  bool busy_powering_on_ble_ = false;
};

#if BUILDFLAG(IS_MAC)

class AuthenticatorBlePermissionMacSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorBlePermissionMacSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  bool IsCancelButtonVisible() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;
};

class AuthenticatorTouchIdSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorTouchIdSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  // Called after the user taps their Touch ID sensor.
  void OnTouchIDSensorTapped(
      std::optional<webauthn::LocalAuthenticationToken> local_auth_token);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  bool IsCancelButtonVisible() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetCancelButtonLabel() const override;
  void OnAccept() override;

  bool touch_id_completed_ = false;
};

#endif  // IS_MAC

class AuthenticatorOffTheRecordInterstitialSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorOffTheRecordInterstitialSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetCancelButtonLabel() const override;
  void OnAccept() override;
};

class AuthenticatorPaaskSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorPaaskSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorPaaskSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorClientPinEntrySheetModel
    : public AuthenticatorSheetModelBase {
 public:
  // Indicates whether the view should accommodate changing an existing PIN,
  // setting up a new PIN or entering an existing one.
  enum class Mode { kPinChange, kPinEntry, kPinSetup };
  AuthenticatorClientPinEntrySheetModel(
      AuthenticatorRequestDialogModel* dialog_model,
      Mode mode,
      device::pin::PINEntryError error);
  ~AuthenticatorClientPinEntrySheetModel() override;

  void SetPinCode(std::u16string pin_code);
  void SetPinConfirmation(std::u16string pin_confirmation);

  Mode mode() const { return mode_; }

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  std::u16string GetError() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;
  bool IsOtherMechanismButtonVisible() const override;

  std::u16string pin_code_;
  std::u16string pin_confirmation_;
  std::u16string error_;
  const Mode mode_;
};

class AuthenticatorClientPinTapAgainSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorClientPinTapAgainSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorClientPinTapAgainSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  std::vector<std::u16string> GetAdditionalDescriptions() const override;
};

class AuthenticatorBioEnrollmentSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorBioEnrollmentSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorBioEnrollmentSheetModel() override;

  int max_bio_samples() { return dialog_model()->max_bio_samples.value_or(1); }
  int bio_samples_remaining() {
    return dialog_model()->bio_samples_remaining.value_or(1);
  }

 private:
  // AuthenticatorSheetModelBase:
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  bool IsCancelButtonVisible() const override;
  std::u16string GetCancelButtonLabel() const override;
  void OnAccept() override;
  void OnCancel() override;

  bool HasBioSamplesRemaining() const;
};

class AuthenticatorRetryUvSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorRetryUvSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorRetryUvSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  std::u16string GetError() const override;
};

// Generic error dialog that allows starting the request over.
class AuthenticatorGenericErrorSheetModel : public AuthenticatorSheetModelBase {
 public:
  static std::unique_ptr<AuthenticatorGenericErrorSheetModel>
  ForClientPinErrorSoftBlock(AuthenticatorRequestDialogModel* dialog_model);
  static std::unique_ptr<AuthenticatorGenericErrorSheetModel>
  ForClientPinErrorHardBlock(AuthenticatorRequestDialogModel* dialog_model);
  static std::unique_ptr<AuthenticatorGenericErrorSheetModel>
  ForClientPinErrorAuthenticatorRemoved(
      AuthenticatorRequestDialogModel* dialog_model);
  static std::unique_ptr<AuthenticatorGenericErrorSheetModel>
  ForMissingCapability(AuthenticatorRequestDialogModel* dialog_model);
  static std::unique_ptr<AuthenticatorGenericErrorSheetModel> ForStorageFull(
      AuthenticatorRequestDialogModel* dialog_model);
  static std::unique_ptr<AuthenticatorGenericErrorSheetModel>
  ForWindowsHelloNotEnabled(AuthenticatorRequestDialogModel* dialog_model);

 private:
  AuthenticatorGenericErrorSheetModel(
      AuthenticatorRequestDialogModel* dialog_model,
      std::u16string title,
      std::u16string description);

  // AuthenticatorSheetModelBase:
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetCancelButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  void OnAccept() override;

  std::u16string title_;
  std::u16string description_;
};

class AuthenticatorResidentCredentialConfirmationSheetView
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorResidentCredentialConfirmationSheetView(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorResidentCredentialConfirmationSheetView() override;

 private:
  // AuthenticatorSheetModelBase:
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  void OnAccept() override;
};

// The sheet shown when the user needs to select an account.
class AuthenticatorSelectAccountSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  // Indicates whether the corresponding view is presented before or after
  // gathering user verification and generating an assertion signature.
  // `kPreUserVerification` is only possible with platform authenticators
  // for which we can silently enumerate credentials.
  enum UserVerificationMode {
    kPreUserVerification,
    kPostUserVerification,
  };

  AuthenticatorSelectAccountSheetModel(
      AuthenticatorRequestDialogModel* dialog_model,
      UserVerificationMode mode);
  ~AuthenticatorSelectAccountSheetModel() override;

  // Set the index of the currently selected row. Only valid to call for
  // `kMultipleAccount`.
  void SetCurrentSelection(int selected);

  // AuthenticatorSheetModelBase:
  void OnAccept() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;

  const UserVerificationMode user_verification_mode_;
  size_t selected_ = 0;
};

class AuthenticatorHybridAndSecurityKeySheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorHybridAndSecurityKeySheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorHybridAndSecurityKeySheetModel() override;

  // Returns the attestation warning for the security key.
  std::optional<std::u16string> GetAttestationWarning() const;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  std::u16string GetOtherMechanismButtonLabel() const override;
};

class AuthenticatorConnectingSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorConnectingSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorConnectingSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorConnectedSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorConnectedSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorConnectedSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorCableErrorSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorCableErrorSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorCableErrorSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  std::u16string GetCancelButtonLabel() const override;
};

class AuthenticatorCreatePasskeySheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorCreatePasskeySheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorCreatePasskeySheetModel() override;

  // An additional label that `AuthenticatorCreatePasskeySheetView` includes in
  // the `BuildStepSpecificContent()` view.
  std::u16string passkey_storage_description() const;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  void OnAccept() override;
  std::u16string GetAcceptButtonLabel() const override;
};

class AuthenticatorGPMErrorSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorGPMErrorSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorGPMErrorSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

class AuthenticatorGPMConnectingSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorGPMConnectingSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorGPMConnectingSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
};

// An account and mechanism picker that combines passkeys from multiple sources.
// Passkeys are grouped in two lists:
// * "Primary" passkeys. These are local passkeys if available, or GPM passkeys
//   if no local passkeys are available. Can be empty.
// * "Secondary" passkeys. These are all the other passkeys & mechanisms.
// AuthenticatorMultiSourcePickerSheetModel will filter these lists and
// present them as indices of AuthenticatorRequestDialogModel's
// `mechanisms()` member.
class AuthenticatorMultiSourcePickerSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorMultiSourcePickerSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorMultiSourcePickerSheetModel() override;

  // Returns a vector of indices to the "Primary" passkey mechanisms. Indices
  // correspond to AuthenticatorRequestDialogModel's mechanisms().
  std::vector<int>& primary_passkey_indices() {
    return primary_passkey_indices_;
  }

  // Returns a vector of indices to the "Secondary" passkey mechanisms. Indices
  // correspond to AuthenticatorRequestDialogModel's mechanisms().
  std::vector<int>& secondary_passkey_indices() {
    return secondary_passkey_indices_;
  }

  // Returns the user-visible label for the "Primary" passkey mechanisms.
  std::u16string& primary_passkeys_label() { return primary_passkeys_label_; }

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;

  std::vector<int> primary_passkey_indices_;
  std::vector<int> secondary_passkey_indices_;
  std::u16string primary_passkeys_label_;
  bool has_passwords_ = false;
};

class AuthenticatorPriorityMechanismSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorPriorityMechanismSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);
  ~AuthenticatorPriorityMechanismSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;
};

class AuthenticatorGpmPinSheetModelBase : public AuthenticatorSheetModelBase {
 public:
  // Indicates whether the view should accommodate creating a new pin or
  // entering an existing one.
  enum class Mode { kPinCreate, kPinEntry };

  explicit AuthenticatorGpmPinSheetModelBase(
      AuthenticatorRequestDialogModel* dialog_model,
      Mode mode);
  ~AuthenticatorGpmPinSheetModelBase() override;

  std::u16string GetGpmAccountEmail() const;
  std::u16string GetGpmAccountName() const;
  gfx::Image GetGpmAccountImage() const;
  std::u16string GetAccessibleDescription() const;

  std::u16string pin() const { return pin_; }
  Mode mode() const { return mode_; }
  bool ui_disabled() const;

  // Sets currently typed pin in the sheet.
  virtual void SetPin(std::u16string pin) = 0;

  // Returns the accessibility label of the pin view based on its type and mode.
  virtual std::u16string GetAccessibleName() const = 0;

 protected:
  std::u16string pin_;
  const Mode mode_;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  std::u16string GetError() const override;
  bool IsForgotGPMPinButtonVisible() const override;
  bool IsGPMPinOptionsButtonVisible() const override;
  void OnAccept() override;
  void OnCancel() override;
  void OnForgotGPMPin() const override;
  void OnGPMPinOptionChosen(bool is_arbitrary) const override;
};

// The sheet shown when the user is entering a digit-only GPM pin.
class AuthenticatorGpmPinSheetModel : public AuthenticatorGpmPinSheetModelBase {
 public:
  explicit AuthenticatorGpmPinSheetModel(
      AuthenticatorRequestDialogModel* dialog_model,
      int pin_digits_count,
      Mode mode);
  ~AuthenticatorGpmPinSheetModel() override;

  void PinCharTyped(bool is_digit);

  int pin_digits_count() const;

  // AuthenticatorGpmPinSheetModelBase:
  void SetPin(std::u16string pin) override;
  std::u16string GetAccessibleName() const override;

 private:
  bool FullPinTyped() const;

  // AuthenticatorSheetModelBase:
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetHint() const override;

  const int pin_digits_count_;

  // Whether a hint explaining that only digits are allowed should be shown.
  bool show_digit_hint_ = false;
};

// The sheet shown when the user is entering an arbitrary (alphanumeric) pin.
class AuthenticatorGpmArbitraryPinSheetModel
    : public AuthenticatorGpmPinSheetModelBase {
 public:
  explicit AuthenticatorGpmArbitraryPinSheetModel(
      AuthenticatorRequestDialogModel* dialog_model,
      Mode mode);
  ~AuthenticatorGpmArbitraryPinSheetModel() override;

  // AuthenticatorGpmPinSheetModelBase:
  void SetPin(std::u16string pin) override;
  std::u16string GetAccessibleName() const override;

 private:
  // AuthenticatorSheetModelBase:
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  std::u16string GetHint() const override;
};

// The sheet shown for bootstrapping Google Password Manager passkeys during
// sign-in.
class AuthenticatorTrustThisComputerAssertionSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorTrustThisComputerAssertionSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  ~AuthenticatorTrustThisComputerAssertionSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  bool IsCancelButtonVisible() const override;
  std::u16string GetCancelButtonLabel() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  bool IsOtherMechanismButtonVisible() const override;
  std::u16string GetOtherMechanismButtonLabel() const override;
  void OnAccept() override;
};

// The sheet shown for creating a passkey in Google Password Manager.
class AuthenticatorCreateGpmPasskeySheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorCreateGpmPasskeySheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  ~AuthenticatorCreateGpmPasskeySheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  bool IsCancelButtonVisible() const override;
  std::u16string GetCancelButtonLabel() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;
  // "Save another way" button handler.
  void OnBack() override;
  void OnCancel() override;
};

// The sheet shown for warning a user about creating a Google Password Manager
// passkey in incognito mode.
class AuthenticatorGpmIncognitoCreateSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorGpmIncognitoCreateSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  ~AuthenticatorGpmIncognitoCreateSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  bool IsCancelButtonVisible() const override;
  std::u16string GetCancelButtonLabel() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;
};

// The sheet shown for bootstrapping Google Password Manager passkeys during
// passkey creation.
class AuthenticatorTrustThisComputerCreationSheetModel
    : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorTrustThisComputerCreationSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  ~AuthenticatorTrustThisComputerCreationSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  bool IsCancelButtonVisible() const override;
  std::u16string GetCancelButtonLabel() const override;
  std::u16string GetOtherMechanismButtonLabel() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;
};

// The sheet shown when the maximum amount of GPM pin entry attempts has been
// reached informing that the PIN needs to be reset.
class AuthenticatorGPMLockedPinSheetModel : public AuthenticatorSheetModelBase {
 public:
  explicit AuthenticatorGPMLockedPinSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  ~AuthenticatorGPMLockedPinSheetModel() override;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;
};

class CombinedSelectorSheetModel : public AuthenticatorSheetModelBase {
 public:
  enum class SelectionStatus {
    kNone,
    kNotSelected,
    kSelected,
  };
  explicit CombinedSelectorSheetModel(
      AuthenticatorRequestDialogModel* dialog_model);

  SelectionStatus GetSelectionStatus(size_t index) const;
  size_t GetSelectionIndex() const;
  void SetSelectionIndex(size_t index);

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override;
  std::u16string GetStepDescription() const override;
  AcceptButtonState GetAcceptButtonState() const override;
  bool IsCancelButtonVisible() const override;
  bool IsActivityIndicatorVisible() const override;
  std::u16string GetCancelButtonLabel() const override;
  std::u16string GetAcceptButtonLabel() const override;
  void OnAccept() override;

  size_t selection_index_ = 0;
};

#endif  // CHROME_BROWSER_UI_WEBAUTHN_SHEET_MODELS_H_