File: profile_list_view_controller.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (115 lines) | stat: -rw-r--r-- 4,193 bytes parent folder | download | duplicates (5)
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
// 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.

#ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PROFILE_LIST_VIEW_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PROFILE_LIST_VIEW_CONTROLLER_H_

#include <memory>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/views/payments/payment_request_item_list.h"
#include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"

namespace autofill {
class AutofillProfile;
}

namespace views {
class Button;
class View;
}  // namespace views

namespace payments {

enum class DialogViewID;
class PaymentRequestSpec;
class PaymentRequestState;
class PaymentRequestDialogView;

// This base class encapsulates common view logic for contexts which display
// a list of profiles and allow exactly one of them to be selected.
class ProfileListViewController : public PaymentRequestSheetController {
 public:
  ProfileListViewController(const ProfileListViewController&) = delete;
  ProfileListViewController& operator=(const ProfileListViewController&) =
      delete;

  ~ProfileListViewController() override;

  // Creates a controller which lists and allows selection of profiles
  // for shipping address.
  static std::unique_ptr<ProfileListViewController>
  GetShippingProfileViewController(
      base::WeakPtr<PaymentRequestSpec> spec,
      base::WeakPtr<PaymentRequestState> state,
      base::WeakPtr<PaymentRequestDialogView> dialog);

  // Creates a controller which lists and allows selection of profiles
  // for contact info.
  static std::unique_ptr<ProfileListViewController>
  GetContactProfileViewController(
      base::WeakPtr<PaymentRequestSpec> spec,
      base::WeakPtr<PaymentRequestState> state,
      base::WeakPtr<PaymentRequestDialogView> dialog);

  // Returns a representation of the given profile appropriate for display
  // in this context. Populates |accessible_string|, which shouldn't be null,
  // with the screen reader string representing the returned label.
  virtual std::unique_ptr<views::View> GetLabel(
      autofill::AutofillProfile* profile,
      std::u16string* accessible_string) = 0;

  virtual void SelectProfile(autofill::AutofillProfile* profile) = 0;

  // Shows an editor for modifying |profile|, or for creating a new profile
  // if |profile| is null.
  virtual void ShowEditor(autofill::AutofillProfile* profile) = 0;

  virtual autofill::AutofillProfile* GetSelectedProfile() = 0;

  virtual bool IsValidProfile(const autofill::AutofillProfile& profile) = 0;

  // Whether |profile| should be displayed in an enabled state and selectable.
  virtual bool IsEnabled(autofill::AutofillProfile* profile);

 protected:
  // Does not take ownership of the arguments, which should outlive this object.
  ProfileListViewController(base::WeakPtr<PaymentRequestSpec> spec,
                            base::WeakPtr<PaymentRequestState> state,
                            base::WeakPtr<PaymentRequestDialogView> dialog);

  // Returns the profiles cached by |request| which are appropriate for display
  // in this context.
  virtual std::vector<raw_ptr<autofill::AutofillProfile, VectorExperimental>>
  GetProfiles() = 0;

  virtual DialogViewID GetDialogViewId() = 0;

  // Subclasses may choose to provide a header view to go on top of the item
  // list view.
  virtual std::unique_ptr<views::View> CreateHeaderView();

  void PopulateList();

  // PaymentRequestSheetController:
  bool ShouldShowPrimaryButton() override;
  ButtonCallback GetSecondaryButtonCallback() override;
  void FillContentView(views::View* content_view) override;
  base::WeakPtr<PaymentRequestSheetController> GetWeakPtr() override;

 private:
  void OnCreateNewProfileButtonClicked(const ui::Event& event);

  std::unique_ptr<views::Button> CreateRow(autofill::AutofillProfile* profile);
  PaymentRequestItemList list_;

  // Must be the last member of a leaf class.
  base::WeakPtrFactory<ProfileListViewController> weak_ptr_factory_{this};
};

}  // namespace payments

#endif  // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PROFILE_LIST_VIEW_CONTROLLER_H_