File: password_change_ui_controller.h

package info (click to toggle)
chromium 140.0.7339.127-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,192,880 kB
  • sloc: cpp: 35,093,808; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,503; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (108 lines) | stat: -rw-r--r-- 3,977 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
// Copyright 2025 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_PASSWORDS_PASSWORD_CHANGE_UI_CONTROLLER_H_
#define CHROME_BROWSER_UI_PASSWORDS_PASSWORD_CHANGE_UI_CONTROLLER_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/password_manager/password_change_delegate.h"
#include "chrome/browser/ui/views/passwords/password_change/password_change_toast.h"
#include "ui/views/widget/widget.h"

namespace tabs {
class TabInterface;
}  // namespace tabs

namespace ui {
class DialogModel;
}  // namespace ui

// Possible actions that the user can take in dialogs displayed by this
// controller. These values are persisted to logs. Entries should not be
// renumbered and numeric values should never be reused.
// LINT.IfChange(PasswordChangeDialogAction)
enum class PasswordChangeDialogAction {
  kCancelButtonClicked = 0,
  kAcceptButtonClicked = 1,
  kLinkClicked = 2,
  kMaxValue = kLinkClicked,
};
// LINT.ThenChange(/tools/metrics/histograms/metadata/password/enums.xml:PasswordChangeDialogAction)

// Events happening for toasts displayed by this controller. These values are
// persisted to logs. Entries should not be renumbered and numeric values should
// never be reused.
// LINT.IfChange(PasswordChangeToastEvent)
enum class PasswordChangeToastEvent {
  kShown = 0,
  kCanceled = 1,
  kMaxValue = kCanceled,
};
// LINT.ThenChange(/tools/metrics/histograms/metadata/password/enums.xml:PasswordChangeToastEvent)

// Responsible for creating and displaying appropriate views based on the
// current state of the password change flow.
class PasswordChangeUIController {
 public:
  PasswordChangeUIController(PasswordChangeDelegate* password_change_delegate,
                             tabs::TabInterface* tab_interface);
  virtual ~PasswordChangeUIController();

  // Updates the `state_` and the UI.
  virtual void UpdateState(PasswordChangeDelegate::State state);

#if defined(UNIT_TEST)
  const views::Widget* dialog_widget() const { return dialog_widget_.get(); }
  PasswordChangeToast* toast_view() const { return toast_view_; }
  void CallOnDialogCanceledForTesting() { OnDialogCanceled(); }
#endif

 private:
  std::variant<PasswordChangeToast::ToastOptions,
               std::unique_ptr<ui::DialogModel>>
  GetDialogOrToastConfiguration(PasswordChangeDelegate::State state);

  void ShowToast(PasswordChangeToast::ToastOptions options);
  void ShowDialog(std::unique_ptr<ui::DialogModel> dialog_model);

  void OnToastCanceled();
  void OnDialogCanceled();
  void OpenPasswordChangeTab();
  void StartPasswordChangeFlow();
  void OnPrivacyNoticeAccepted();
  void ShowPasswordDetails();
  void NavigateToPasswordChangeSettings();

  // Closes the dialog or widget and logs the `reason`.
  // TODO(crbug.com/407504591): Actually log the reason.
  void CloseDialogWidget(views::Widget::ClosedReason reason);
  void CloseToastWidget(views::Widget::ClosedReason reason);

  // Controls password change process. Owns this class.
  const raw_ptr<PasswordChangeDelegate> password_change_delegate_;

  // A tab where a toast and a modal dialog is displayed.
  const raw_ptr<tabs::TabInterface> tab_interface_;

  // View displaying the progress of password change.
  raw_ptr<PasswordChangeToast> toast_view_;

  // Delegate for the `toast_widget_`.
  std::unique_ptr<views::WidgetDelegate> toast_delegate_;

  // Widget containing the currently open toast, if any.
  std::unique_ptr<views::Widget> toast_widget_;

  // Widget containing the currently open dialog, if any.
  std::unique_ptr<views::Widget> dialog_widget_;

  // Current state of the password change flow.
  PasswordChangeDelegate::State state_ =
      static_cast<PasswordChangeDelegate::State>(-1);

  base::WeakPtrFactory<PasswordChangeUIController> weak_ptr_factory_{this};
};

#endif  // CHROME_BROWSER_UI_PASSWORDS_PASSWORD_CHANGE_UI_CONTROLLER_H_