File: payment_app_factory.h

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; 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 (158 lines) | stat: -rw-r--r-- 5,887 bytes parent folder | download | duplicates (7)
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
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_APP_FACTORY_H_
#define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_APP_FACTORY_H_

#include <memory>
#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "components/payments/content/payment_app.h"
#include "components/payments/content/service_worker_payment_app_finder.h"
#include "content/public/browser/payment_app_provider.h"
#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"

class GURL;

namespace content {
class RenderFrameHost;
class WebContents;
}  // namespace content

namespace url {
class Origin;
}  // namespace url

namespace webauthn {
class InternalAuthenticator;
}  // namespace webauthn

namespace payments {

// Known reasons why an app may fail to be created. Passed to a
// PaymentAppFactory Delegate to allow it to better handle the lack of creation
// of an app, if appropriate.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.payments
enum class AppCreationFailureReason {
  UNKNOWN,
  ICON_DOWNLOAD_FAILED,
};

class ContentPaymentRequestDelegate;
class CSPChecker;
class PaymentManifestWebDataService;
class PaymentRequestSpec;

// Base class for a factory that can create instances of payment apps.
class PaymentAppFactory {
 public:
  class Delegate {
   public:
    using GetTwaPackageNameCallback =
        base::OnceCallback<void(const std::string& twa_package_name)>;

    virtual ~Delegate() = default;

    // Returns the WebContents that initiated the PaymentRequest API, or null if
    // the RenderFrameHost or WebContents has been deleted, which can happen
    // when the page is being closed, for example.
    virtual content::WebContents* GetWebContents() = 0;

    virtual const GURL& GetTopOrigin() = 0;
    virtual const GURL& GetFrameOrigin() = 0;
    virtual const url::Origin& GetFrameSecurityOrigin() = 0;

    // Returns the RenderFrameHost that initiated the PaymentRequest API, or
    // null if the RenderFrameHost has been deleted, which can happen when the
    // RenderFrameHost is being unloaded, for example.
    virtual content::RenderFrameHost* GetInitiatorRenderFrameHost() const = 0;

    virtual content::GlobalRenderFrameHostId GetInitiatorRenderFrameHostId()
        const = 0;

    virtual const std::vector<mojom::PaymentMethodDataPtr>& GetMethodData()
        const = 0;
    virtual std::unique_ptr<webauthn::InternalAuthenticator>
    CreateInternalAuthenticator() const = 0;
    virtual scoped_refptr<PaymentManifestWebDataService>
    GetPaymentManifestWebDataService() const = 0;
    virtual bool IsOffTheRecord() const = 0;

    // Returns the merchant provided information, or null if the payment is
    // being aborted.
    virtual base::WeakPtr<PaymentRequestSpec> GetSpec() const = 0;

    // Obtains the Android package name of the Trusted Web Activity that invoked
    // this browser, if any. Otherwise, calls `callback` with an empty string.
    virtual void GetTwaPackageName(GetTwaPackageNameCallback callback) = 0;

    // Tells the UI to show the processing spinner. Only desktop UI needs this
    // notification.
    virtual void ShowProcessingSpinner() = 0;

    virtual base::WeakPtr<ContentPaymentRequestDelegate>
    GetPaymentRequestDelegate() const = 0;

    // Called when an app is created.
    virtual void OnPaymentAppCreated(std::unique_ptr<PaymentApp> app) = 0;

    // Called when there is an error creating a payment app. Called when unable
    // to download a web app manifest, for example.
    virtual void OnPaymentAppCreationError(
        const std::string& error_message,
        AppCreationFailureReason failure_reason =
            AppCreationFailureReason::UNKNOWN) = 0;

    // Called when all apps of this factory have been created.
    virtual void OnDoneCreatingPaymentApps() = 0;

    // Make both canMakePayment() and hasEnrolledInstrument() return true,
    // regardless of presence of payment apps. This is used by secure payment
    // confirmation method, which returns true for canMakePayment() and
    // hasEnrolledInstrument() regardless of presence of credentials in user
    // profile or the authenticator device, as long as a user-verifying platform
    // authenticator device is available.
    virtual void SetCanMakePaymentEvenWithoutApps() = 0;

    // Return a Content Security Policy checker that should be used before
    // downloading payment manifests and following their redirects.
    virtual base::WeakPtr<CSPChecker> GetCSPChecker() = 0;

    // Records that an Opt Out experience will be offered to the user in the
    // current UI flow.
    virtual void SetOptOutOffered() = 0;

    // Return the app instance id for the TWA that invokes the payment request.
    // The instance id is used to find the TWA window in the ash so that we can
    // attach the payment dialog to it. This interface should only be used
    // in ChromeOS.
    // At the moment, this interface is only implemented in Lacros and for all
    // other platforms this will return std::nullopt. In addition to that, if
    // for any reason, we failed to find the app instance, this method will
    // also return std::nullopt.
    virtual std::optional<base::UnguessableToken> GetChromeOSTWAInstanceId()
        const = 0;
  };

  explicit PaymentAppFactory(PaymentApp::Type type);

  PaymentAppFactory(const PaymentAppFactory&) = delete;
  PaymentAppFactory& operator=(const PaymentAppFactory&) = delete;

  virtual ~PaymentAppFactory();

  PaymentApp::Type type() const { return type_; }

  virtual void Create(base::WeakPtr<Delegate> delegate) = 0;

 private:
  const PaymentApp::Type type_;
};

}  // namespace payments

#endif  // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_APP_FACTORY_H_