File: password_change_ui_controller.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 (83 lines) | stat: -rw-r--r-- 2,976 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
// 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

// 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_; }
#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 ShowNothingChangedToast();

  void OpenPasswordChangeTab();
  void StartPasswordChangeFlow();
  void ShowPasswordDetails();
  void CancelPasswordChange();
  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_