Commit 47f109e4 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] PaymentHandlerHost for all payment apps.

Before this patch, PaymentHandlerHost was passed only to
ServiceWorkerPaymentApps, which are based on payment handlers.
This prevented introducing more types of payment apps which may be based
on payment handler, such as a JNI wrapper on top of C++ payment app
interface.

This patch sends the PaymentHandlerHost to all payment apps, so it's up
to the payment app implementation to determine whether the Host should
be used.

After this patch, it's easier to add a JNI wrapper on top of a C++
payment app, regardless of whether that app is backed by a payment
handler.

Design: https://bit.ly/cross-platform-pay-app-factory

Bug: 1083242
Change-Id: Ibf785fd665691a402500705c5b6d39061c904f73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207290
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770605}
parent 84743c7b
......@@ -2104,14 +2104,7 @@ public class PaymentRequestImpl
}
}
if (mInvokedPaymentApp instanceof ServiceWorkerPaymentApp) {
if (mPaymentHandlerHost == null) {
mPaymentHandlerHost = new PaymentHandlerHost(mWebContents, this /* delegate */);
}
((ServiceWorkerPaymentApp) mInvokedPaymentApp)
.setPaymentHandlerHost(mPaymentHandlerHost);
}
mInvokedPaymentApp.setPaymentHandlerHost(getPaymentHandlerHost());
// Create payment options for the invoked payment app.
PaymentOptions paymentOptions = new PaymentOptions();
......@@ -2151,6 +2144,13 @@ public class PaymentRequestImpl
return !isAutofillCard;
}
private PaymentHandlerHost getPaymentHandlerHost() {
if (mPaymentHandlerHost == null) {
mPaymentHandlerHost = new PaymentHandlerHost(mWebContents, /*delegate=*/this);
}
return mPaymentHandlerHost;
}
@Override
public void onDismiss() {
mJourneyLogger.setAborted(AbortReason.ABORTED_BY_USER);
......@@ -2984,7 +2984,10 @@ public class PaymentRequestImpl
}
mJourneyLogger.destroy();
if (mPaymentHandlerHost != null) mPaymentHandlerHost.destroy();
if (mPaymentHandlerHost != null) {
mPaymentHandlerHost.destroy();
mPaymentHandlerHost = null;
}
}
private void closeClient() {
......
......@@ -199,12 +199,8 @@ public class ServiceWorkerPaymentApp extends PaymentApp {
mUkmSourceId = 0;
}
/**
* Sets the endpoint for payment handler communication. Must be called before invoking this
* payment handler.
* @param host The endpoint for payment handler communication. Should not be null.
*/
/* package */ void setPaymentHandlerHost(PaymentHandlerHost host) {
@Override
public void setPaymentHandlerHost(PaymentHandlerHost host) {
assert host != null;
mPaymentHandlerHost = host;
}
......
......@@ -305,4 +305,11 @@ public abstract class PaymentApp extends EditableOption {
public long getUkmSourceId() {
return 0;
}
/**
* Sets the endpoint for payment handler communication. Must be called before invoking this
* payment app. Used only by payment apps that are backed by a payment handler.
* @param host The endpoint for payment handler communication. Should not be null.
*/
public void setPaymentHandlerHost(PaymentHandlerHost host) {}
}
......@@ -765,10 +765,8 @@ void PaymentRequest::OnConnectionTerminated() {
void PaymentRequest::Pay() {
journey_logger_.SetEventOccurred(JourneyLogger::EVENT_PAY_CLICKED);
DCHECK(state_->selected_app());
if (state_->selected_app()->type() == PaymentApp::Type::SERVICE_WORKER_APP) {
static_cast<ServiceWorkerPaymentApp*>(state_->selected_app())
->set_payment_handler_host(payment_handler_host_.Bind());
}
state_->selected_app()->SetPaymentHandlerHost(
payment_handler_host_.AsWeakPtr());
state_->GeneratePaymentResponse();
}
......
......@@ -14,6 +14,7 @@
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/payments/content/payment_event_response_util.h"
#include "components/payments/content/payment_handler_host.h"
#include "components/payments/content/payment_request_converter.h"
#include "components/payments/core/features.h"
#include "components/payments/core/method_strings.h"
......@@ -549,4 +550,9 @@ ukm::SourceId ServiceWorkerPaymentApp::UkmSourceId() {
return ukm_source_id_;
}
void ServiceWorkerPaymentApp::SetPaymentHandlerHost(
base::WeakPtr<PaymentHandlerHost> payment_handler_host) {
payment_handler_host_ = payment_handler_host->Bind();
}
} // namespace payments
......@@ -98,11 +98,8 @@ class ServiceWorkerPaymentApp : public PaymentApp {
bool HandlesPayerEmail() const override;
bool HandlesPayerPhone() const override;
ukm::SourceId UkmSourceId() override;
void set_payment_handler_host(
mojo::PendingRemote<mojom::PaymentHandlerHost> payment_handler_host) {
payment_handler_host_ = std::move(payment_handler_host);
}
void SetPaymentHandlerHost(
base::WeakPtr<PaymentHandlerHost> payment_handler_host) override;
private:
friend class ServiceWorkerPaymentAppTest;
......
......@@ -20,6 +20,8 @@
namespace payments {
class PaymentHandlerHost;
// Base class which represents a payment app in Payment Request.
class PaymentApp {
public:
......@@ -113,6 +115,11 @@ class PaymentApp {
virtual ukm::SourceId UkmSourceId();
// Optionally bind to the Mojo pipe for receiving events generated by the
// invoked payment handler.
virtual void SetPaymentHandlerHost(
base::WeakPtr<PaymentHandlerHost> payment_handler_host) {}
protected:
PaymentApp(int icon_resource_id, Type type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment