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
|
// 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_ANDROID_PAYMENT_HANDLER_HOST_H_
#define COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_HANDLER_HOST_H_
#include <jni.h>
#include "base/android/scoped_java_ref.h"
#include "base/memory/weak_ptr.h"
#include "components/payments/content/android/payment_request_update_event_listener.h"
#include "components/payments/content/payment_handler_host.h"
namespace payments {
namespace android {
// The native bridge for Java to interact with the payment handler host.
// Object relationship diagram:
//
// ChromePaymentRequestService.java --- implements --->
// PaymentRequestUpdateEventListener
// | ^
// owns |________________________
// | |
// v |
// PaymentHandlerHost.java |
// | |
// owns |
// | listener
// v |
// android/payment_handler_host.h |
// | | |
// owns | |
// | owns |
// | | |
// | v |
// | android/payment_request_update_event_listener.h
// | ^ \ ---- implements ---> PaymentHandlerHost::Delegate
// | |
// | delegate
// v |
// payment_handler_host.h
class PaymentHandlerHost {
public:
// Converts a Java PaymentHandlerHost object into a C++ cross-platform
// payments::PaymentHandlerHost object. The returned object is ultimately
// owned by the Java PaymentHandlerHost.
static base::WeakPtr<payments::PaymentHandlerHost> FromJavaPaymentHandlerHost(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& payment_handler_host);
// The |listener| must implement PaymentRequestUpdateEventListener. The
// |web_contents| should be from the same browser context as the payment
// handler and are used for logging in developr tools.
PaymentHandlerHost(const base::android::JavaParamRef<jobject>& web_contents,
const base::android::JavaParamRef<jobject>& listener);
PaymentHandlerHost(const PaymentHandlerHost&) = delete;
PaymentHandlerHost& operator=(const PaymentHandlerHost&) = delete;
~PaymentHandlerHost();
// Checks whether any payment method, shipping address or shipping option
// change is currently in progress.
jboolean IsWaitingForPaymentDetailsUpdate(JNIEnv* env) const;
// Destroys this object.
void Destroy(JNIEnv* env);
// Notifies the payment handler that the merchant has updated the payment
// details. The |response_buffer| should be a serialization of a valid
// PaymentRequestDetailsUpdate.java object.
void UpdateWith(JNIEnv* env,
const base::android::JavaParamRef<jobject>& response_buffer);
// Notifies the payment handler that the merchant ignored the payment
// method change event.
void OnPaymentDetailsNotUpdated(JNIEnv* env);
private:
PaymentRequestUpdateEventListener listener_;
payments::PaymentHandlerHost payment_handler_host_;
};
} // namespace android
} // namespace payments
#endif // COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_HANDLER_HOST_H_
|