auth_dialog_contents_view.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_IN_SESSION_AUTH_AUTH_DIALOG_CONTENTS_VIEW_H_
  5. #define ASH_IN_SESSION_AUTH_AUTH_DIALOG_CONTENTS_VIEW_H_
  6. #include <string>
  7. #include "ash/login/ui/login_palette.h"
  8. #include "ash/public/cpp/login_types.h"
  9. #include "ui/views/view.h"
  10. namespace views {
  11. class BoxLayout;
  12. class Label;
  13. class LabelButton;
  14. class MdTextButton;
  15. } // namespace views
  16. namespace ash {
  17. class AnimatedRoundedImageView;
  18. class LoginPasswordView;
  19. class LoginPinView;
  20. class LoginPinInputView;
  21. // Contains the debug views that allows the developer to interact with the
  22. // AuthDialogController.
  23. class AuthDialogContentsView : public views::View {
  24. public:
  25. // Flags which describe the set of currently visible auth methods.
  26. enum AuthMethods {
  27. kAuthNone = 0, // No auth methods.
  28. kAuthPassword = 1 << 0, // Display password.
  29. kAuthPin = 1 << 1, // Display PIN keyboard.
  30. kAuthFingerprint = 1 << 2, // Use fingerprint to unlock.
  31. };
  32. // Extra control parameters to be passed when setting the auth methods.
  33. struct AuthMethodsMetadata {
  34. // User's pin length to use for autosubmit.
  35. size_t autosubmit_pin_length = 0;
  36. };
  37. AuthDialogContentsView(uint32_t auth_methods,
  38. const std::string& origin_name,
  39. const AuthMethodsMetadata& auth_metadata,
  40. const UserAvatar& avatar);
  41. AuthDialogContentsView(const AuthDialogContentsView&) = delete;
  42. AuthDialogContentsView& operator=(const AuthDialogContentsView&) = delete;
  43. ~AuthDialogContentsView() override;
  44. // views::Views:
  45. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  46. void RequestFocus() override;
  47. uint32_t auth_methods() const { return auth_methods_; }
  48. private:
  49. class TitleLabel;
  50. class FingerprintView;
  51. // views::View:
  52. void AddedToWidget() override;
  53. // Add a view for user avatar.
  54. void AddAvatarView(const UserAvatar& avatar);
  55. // Add a view for dialog title.
  56. void AddTitleView();
  57. // Add a view that shows which website/app we are authenticating for.
  58. void AddOriginNameView();
  59. // Add a view for entering PIN (if autosubmit is off).
  60. void AddPinTextInputView();
  61. // Add a view for entering password.
  62. void AddPasswordView();
  63. // Add a PIN pad view.
  64. void AddPinPadView();
  65. // Add a PIN input view that automatically submits PIN.
  66. void AddPinDigitInputView();
  67. // Add a vertical spacing view.
  68. void AddVerticalSpacing(int height);
  69. // Add a view for action buttons.
  70. void AddActionButtonsView();
  71. // Called when the user taps a digit on the PIN pad.
  72. void OnInsertDigitFromPinPad(int digit);
  73. // Called when the user taps backspace on the PIN pad.
  74. void OnBackspaceFromPinPad();
  75. // Called when either:
  76. // 1. the user inserts or deletes a character in
  77. // |pin_text_input_view_| or |pin_digit_input_view_| without using the PIN
  78. // pad, or
  79. // 2. the user inserts or deletes a character in |password_view_|, or
  80. // 3. contents of |pin_text_input_view_|, |password_view_|, or
  81. // |pin_digit_input_view_| are cleared by a Reset() call.
  82. void OnInputTextChanged(bool is_empty);
  83. // Called when the user submits password or PIN. If authenticated_by_pin is
  84. // false, the user authenticated by password.
  85. void OnAuthSubmit(bool authenticated_by_pin, const std::u16string& password);
  86. // Called when password or PIN authentication of the user completes. If
  87. // authenticated_by_pin is false, the user authenticated by password.
  88. // |can_use_pin| specifies whether PIN is available after the authentication,
  89. // as it might be locked out.
  90. void OnPasswordOrPinAuthComplete(bool authenticated_by_pin,
  91. bool success,
  92. bool can_use_pin);
  93. // Called when fingerprint authentication completes.
  94. void OnFingerprintAuthComplete(bool success,
  95. FingerprintState fingerprint_state);
  96. // Called when the cancel button is pressed.
  97. void OnCancelButtonPressed(const ui::Event& event);
  98. // Called when the "Need help?" button is pressed.
  99. void OnNeedHelpButtonPressed(const ui::Event& event);
  100. // Debug container which holds the entire debug UI.
  101. views::View* container_ = nullptr;
  102. // Layout for |container_|.
  103. views::BoxLayout* main_layout_ = nullptr;
  104. // User avatar to indicate this is an OS dialog.
  105. AnimatedRoundedImageView* avatar_view_ = nullptr;
  106. // Title of the auth dialog, also used to show PIN auth error message..
  107. TitleLabel* title_ = nullptr;
  108. // Prompt message to the user.
  109. views::Label* origin_name_view_ = nullptr;
  110. // Whether PIN can be auto submitted.
  111. bool pin_autosubmit_on_ = false;
  112. // Whether PIN is locked out.
  113. bool pin_locked_out_ = false;
  114. // Text input field for PIN if PIN cannot be auto submitted.
  115. LoginPasswordView* pin_text_input_view_ = nullptr;
  116. // PIN input view that's shown if PIN can be auto submitted.
  117. LoginPinInputView* pin_digit_input_view_ = nullptr;
  118. // Text input field for password.
  119. LoginPasswordView* password_view_ = nullptr;
  120. // PIN pad view.
  121. LoginPinView* pin_pad_view_ = nullptr;
  122. FingerprintView* fingerprint_view_ = nullptr;
  123. // A button to cancel authentication and close the dialog.
  124. views::MdTextButton* cancel_button_ = nullptr;
  125. // A button to show a help center article.
  126. views::LabelButton* help_button_ = nullptr;
  127. // Flags of auth methods that should be visible.
  128. uint32_t auth_methods_ = 0u;
  129. const std::string origin_name_;
  130. // Extra parameters to control the UI.
  131. AuthMethodsMetadata auth_metadata_;
  132. LoginPalette palette_ = CreateInSessionAuthPalette();
  133. // Container which holds action buttons.
  134. views::View* action_view_container_ = nullptr;
  135. base::WeakPtrFactory<AuthDialogContentsView> weak_factory_{this};
  136. };
  137. } // namespace ash
  138. #endif // ASH_IN_SESSION_AUTH_AUTH_DIALOG_CONTENTS_VIEW_H_