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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
// Copyright 2024 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_DESKTOP_PAYMENTS_WINDOW_MANAGER_H_
#define CHROME_BROWSER_UI_AUTOFILL_PAYMENTS_DESKTOP_PAYMENTS_WINDOW_MANAGER_H_
#include <memory>
#include <optional>
#include "base/memory/raw_ref.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/payments/payments_request_details.h"
#include "components/autofill/core/browser/payments/payments_window_manager.h"
#include "content/public/browser/web_contents_observer.h"
#if BUILDFLAG(IS_LINUX)
#include "base/scoped_observation.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
#endif // BUILDFLAG(IS_LINUX)
class GURL;
namespace content {
class NavigationHandle;
} // namespace content
namespace autofill {
class ContentAutofillClient;
namespace payments {
class PaymentsWindowUserConsentDialogControllerImpl;
// Desktop implementation of the PaymentsWindowManager interface. One per
// WebContents, owned by the ChromeAutofillClient associated with the
// WebContents of the original tab that the pop-up is created in. If there is a
// pop-up currently present, `this` will observe the WebContents of that pop-up.
class DesktopPaymentsWindowManager : public PaymentsWindowManager,
#if BUILDFLAG(IS_LINUX)
public BrowserListObserver,
#endif // BUILDFLAG(IS_LINUX)
public content::WebContentsObserver {
public:
explicit DesktopPaymentsWindowManager(ContentAutofillClient* client);
DesktopPaymentsWindowManager(const DesktopPaymentsWindowManager&) = delete;
DesktopPaymentsWindowManager& operator=(const DesktopPaymentsWindowManager&) =
delete;
~DesktopPaymentsWindowManager() override;
// PaymentsWindowManager:
void InitVcn3dsAuthentication(Vcn3dsContext context) override;
void InitBnplFlow(BnplContext context) override;
// content::WebContentsObserver:
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
void WebContentsDestroyed() override;
#if BUILDFLAG(IS_LINUX)
// BrowserListObserver:
void OnBrowserSetLastActive(Browser* browser) override;
#endif // BUILDFLAG(IS_LINUX)
private:
friend class DesktopPaymentsWindowManagerTestApi;
// Contains the possible flows that this class can support.
enum class FlowType {
kNoFlow = 0,
kVcn3ds = 1,
kBnpl = 2,
kMaxValue = kBnpl,
};
// Creates a pop-up for `flow_type_`, with an initial URL of `url` and size of
// `popup_size`. This pop-up will go through a couple of URL navigations
// specific to the flow that it is created for.
void CreatePopup(const GURL& url, gfx::Rect popup_size);
// Triggered when a pop-up navigation has finished, and the `flow_type_` is
// kVcn3ds.
void OnDidFinishNavigationForVcn3ds();
// Triggered when a pop-up navigation has finished, and the `flow_type_` is
// kBnpl.
void OnDidFinishNavigationForBnpl();
// Triggered when a pop-up is destroyed, and the `flow_type_` is kVcn3ds.
void OnWebContentsDestroyedForVcn3ds();
// Triggered when a pop-up is destroyed, and the `flow_type_` is kBnpl.
void OnWebContentsDestroyedForBnpl();
// Initiates the second UnmaskCardRequest in the VCN 3DS flow to attempt to
// retrieve the virtual card. This method is run once risk data is loaded for
// VCN 3DS.
void OnDidLoadRiskDataForVcn3ds(
RedirectCompletionResult redirect_completion_result,
const std::string& risk_data);
// Closes the progress dialog and runs the completion callback
// `vcn_3ds_context_`. Run once a response is received from the second
// UnmaskCardRequest, triggered after the authentication has completed.
void OnVcn3dsAuthenticationResponseReceived(
payments::PaymentsAutofillClient::PaymentsRpcResult result,
const UnmaskResponseDetails& response_details);
// Resets the state of `this` in relation to the ongoing UnmaskCardRequest.
// Called if the user clicks cancel on the progress dialog, which is shown
// after a pop-up with valid query params gets closed and the second
// UnmaskCardRequest is triggered.
void OnVcn3dsAuthenticationProgressDialogCancelled();
// Shows the VCN 3DS consent dialog, which the user must accept for the pop-up
// window to trigger. If the user cancels the dialog the flow will end.
void ShowVcn3dsConsentDialog();
// Handles the user accepting the VCN 3DS consent dialog.
void OnVcn3dsConsentDialogAccepted();
// Handles the user cancelling the VCN 3DS consent dialog.
void OnVcn3dsConsentDialogCancelled();
// Resets the state of `this` in relation to the ongoing flow.
void Reset();
// Only present if `flow_type_` is `kVcn3ds`.
std::optional<Vcn3dsContext> vcn_3ds_context_;
// Only present if `flow_type_` is `kBnpl`.
std::optional<BnplContext> bnpl_context_;
// The timestamp for when the VCN 3DS pop-up was shown to the user. Used for
// logging purposes.
std::optional<base::TimeTicks> vcn_3ds_popup_shown_timestamp_;
// The timestamp for when the BNPL payments window pop-up was shown to the
// user. Used for logging purposes.
std::optional<base::TimeTicks> bnpl_popup_shown_timestamp_;
// Set on every navigation inside of the observed pop-up. Used on pop-up
// destruction to understand the reason for destruction, and to notify the
// caller. This class variable is required because at the point where the most
// recent URL navigation needs to be known, accessing the observed web
// contents is unsafe. Thus it is preferred to cache this earlier and read
// from it when needed.
// TODO(crbug.com/388088113): Currently, only the BNPL flow uses this.
// Refactor the VCN 3DS flow to also use this.
GURL most_recent_url_navigation_;
// The type of flow that is currently ongoing. Set when a flow is initiated.
FlowType flow_type_ = FlowType::kNoFlow;
// ContentAutofillClient that owns `this`.
const raw_ref<ContentAutofillClient> client_;
// Controller for the VCN 3DS consent dialog. Set (and re-set if it was
// previously set) when the dialog is triggered.
std::unique_ptr<PaymentsWindowUserConsentDialogControllerImpl>
payments_window_user_consent_dialog_controller_;
// Used in tests to notify the test infrastructure that the pop-up has closed.
base::RepeatingClosure popup_closed_closure_for_testing_;
#if BUILDFLAG(IS_LINUX)
base::ScopedObservation<BrowserList, BrowserListObserver> scoped_observation_{
this};
#endif // BUILDFLAG(IS_LINUX)
base::WeakPtrFactory<DesktopPaymentsWindowManager> weak_ptr_factory_{this};
};
} // namespace payments
} // namespace autofill
#endif // CHROME_BROWSER_UI_AUTOFILL_PAYMENTS_DESKTOP_PAYMENTS_WINDOW_MANAGER_H_
|