File: virtual_card_enroll_bubble_controller_impl.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 (148 lines) | stat: -rw-r--r-- 5,643 bytes parent folder | download | duplicates (6)
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
// Copyright 2022 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_AUTOFILL_PAYMENTS_VIRTUAL_CARD_ENROLL_BUBBLE_CONTROLLER_IMPL_H_
#define CHROME_BROWSER_UI_AUTOFILL_PAYMENTS_VIRTUAL_CARD_ENROLL_BUBBLE_CONTROLLER_IMPL_H_

#include <memory>

#include "chrome/browser/ui/autofill/autofill_bubble_controller_base.h"
#include "components/autofill/core/browser/metrics/payments/virtual_card_enrollment_metrics.h"
#include "components/autofill/core/browser/payments/legal_message_line.h"
#include "components/autofill/core/browser/payments/virtual_card_enrollment_manager.h"
#include "components/autofill/core/browser/ui/payments/virtual_card_enroll_bubble_controller.h"
#include "content/public/browser/visibility.h"
#include "content/public/browser/web_contents_user_data.h"

namespace autofill {

#if BUILDFLAG(IS_ANDROID)
class AutofillVCNEnrollBottomSheetBridge;
#endif

class VirtualCardEnrollBubbleControllerImpl
    : public AutofillBubbleControllerBase,
      public VirtualCardEnrollBubbleController,
      public content::WebContentsUserData<
          VirtualCardEnrollBubbleControllerImpl> {
 public:
  // Virtual card enrollment status
  enum class EnrollmentStatus {
    kNone,
    kPaymentsServerRequestInFlight,
    kCompleted,
  };
  VirtualCardEnrollBubbleControllerImpl(
      const VirtualCardEnrollBubbleControllerImpl&) = delete;
  VirtualCardEnrollBubbleControllerImpl& operator=(
      const VirtualCardEnrollBubbleControllerImpl&) = delete;
  ~VirtualCardEnrollBubbleControllerImpl() override;

  // Displays both the virtual card enroll bubble and its associated omnibox
  // icon. Sets virtual card enrollment fields as well as the closure for the
  // accept and decline bubble events.
  void ShowBubble(
      const VirtualCardEnrollmentFields& virtual_card_enrollment_fields,
      base::OnceClosure accept_virtual_card_callback,
      base::OnceClosure decline_virtual_card_callback);

  // Shows the bubble again if the users clicks the omnibox icon.
  void ReshowBubble();

  // Shows the confirmation bubble view after the virtual card enrollment
  // process has completed.
  virtual void ShowConfirmationBubbleView(
      payments::PaymentsAutofillClient::PaymentsRpcResult result);

  // VirtualCardEnrollBubbleController:
  const VirtualCardEnrollUiModel& GetUiModel() const override;
  VirtualCardEnrollmentBubbleSource GetVirtualCardEnrollmentBubbleSource()
      const override;
  AutofillBubbleBase* GetVirtualCardBubbleView() const override;

#if !BUILDFLAG(IS_ANDROID)
  void HideIconAndBubble() override;
  bool IsEnrollmentInProgress() const override;
  bool IsEnrollmentComplete() const override;
#endif

  void OnAcceptButton(bool did_switch_to_loading_state) override;
  void OnDeclineButton() override;
  void OnLinkClicked(VirtualCardEnrollmentLinkType link_type,
                     const GURL& url) override;
  void OnBubbleClosed(PaymentsUiClosedReason closed_reason) override;
  base::OnceCallback<void(PaymentsUiClosedReason)> GetOnBubbleClosedCallback()
      override;
  const SavePaymentMethodAndVirtualCardEnrollConfirmationUiParams&
  GetConfirmationUiParams() const override;
  bool IsIconVisible() const override;

 protected:
  explicit VirtualCardEnrollBubbleControllerImpl(
      content::WebContents* web_contents);

  // AutofillBubbleControllerBase::
  void OnVisibilityChanged(content::Visibility visibility) override;
  PageActionIconType GetPageActionIconType() override;
  void DoShowBubble() override;

 private:
  friend class VirtualCardEnrollBubbleControllerImplTestApi;

  friend class content::WebContentsUserData<
      VirtualCardEnrollBubbleControllerImpl>;

  // Contains the UI assets shown in the virtual card enrollment view.
  std::unique_ptr<VirtualCardEnrollUiModel> ui_model_;

  // Whether we should re-show the dialog when users return to the tab.
  bool reprompt_required_ = false;

#if BUILDFLAG(IS_ANDROID)
  // A Java bridge for the bottom sheet version of the virtual card enrollment
  // UI.
  std::unique_ptr<AutofillVCNEnrollBottomSheetBridge>
      autofill_vcn_enroll_bottom_sheet_bridge_;
#else
  // Returns whether the web content associated with this controller is active.
  virtual bool IsWebContentsActive();

  // Resets bubble to its initial state.
  void ResetBubble();

  // Represents the current status of virtual card enrollment.
  EnrollmentStatus enrollment_status_ = EnrollmentStatus::kNone;

  // Represents the current state of icon and bubble.
  BubbleState bubble_state_ = BubbleState::kHidden;
#endif

  // Denotes whether the bubble is shown due to user gesture. If this is true,
  // it means the bubble is a reshown bubble.
  bool is_user_gesture_ = false;

  // Closure invoked when the user agrees to enroll in a virtual card.
  base::OnceClosure accept_virtual_card_callback_;

  // Closure invoked when the user rejects enrolling in a virtual card.
  base::OnceClosure decline_virtual_card_callback_;

  // Closure used for testing purposes that notifies that the enrollment bubble
  // has been shown.
  base::RepeatingClosure bubble_shown_closure_for_testing_;

  // UI parameters needed to display the virtual card enrollment confirmation
  // view.
  std::optional<SavePaymentMethodAndVirtualCardEnrollConfirmationUiParams>
      confirmation_ui_params_;

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

  WEB_CONTENTS_USER_DATA_KEY_DECL();
};

}  // namespace autofill

#endif  // CHROME_BROWSER_UI_AUTOFILL_PAYMENTS_VIRTUAL_CARD_ENROLL_BUBBLE_CONTROLLER_IMPL_H_