Commit b8c1836d authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert PaymentHandlerHost to new Mojo types

This CL converts PaymentHandlerHost{Ptr, PtrInfo} in blink and
components to the new Mojo types.

Bug: 955171, 978694
Change-Id: I903ce85df7ca3d221fcff3c64c366ba1e107d2ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1782199Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#692927}
parent 9836d9ac
......@@ -40,23 +40,23 @@ content::DevToolsBackgroundServicesContext* GetDevTools(
PaymentHandlerHost::PaymentHandlerHost(content::WebContents* web_contents,
Delegate* delegate)
: binding_(this), web_contents_(web_contents), delegate_(delegate) {
: web_contents_(web_contents), delegate_(delegate) {
DCHECK(web_contents_);
DCHECK(delegate_);
}
PaymentHandlerHost::~PaymentHandlerHost() {}
mojom::PaymentHandlerHostPtrInfo PaymentHandlerHost::Bind() {
mojom::PaymentHandlerHostPtrInfo host_ptr_info;
binding_.Close();
binding_.Bind(mojo::MakeRequest(&host_ptr_info));
mojo::PendingRemote<mojom::PaymentHandlerHost> PaymentHandlerHost::Bind() {
receiver_.reset();
mojo::PendingRemote<mojom::PaymentHandlerHost> host =
receiver_.BindNewPipeAndPassRemote();
// Connection error handler can be set only after the Bind() call.
binding_.set_connection_error_handler(base::BindOnce(
receiver_.set_disconnect_handler(base::BindOnce(
&PaymentHandlerHost::Disconnect, weak_ptr_factory_.GetWeakPtr()));
return host_ptr_info;
return host;
}
void PaymentHandlerHost::UpdateWith(
......@@ -115,7 +115,7 @@ void PaymentHandlerHost::NoUpdatedPaymentDetails() {
}
void PaymentHandlerHost::Disconnect() {
binding_.Close();
receiver_.reset();
}
base::WeakPtr<PaymentHandlerHost> PaymentHandlerHost::AsWeakPtr() {
......
......@@ -11,7 +11,8 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/blink/public/mojom/payments/payment_handler_host.mojom.h"
#include "url/origin.h"
......@@ -69,7 +70,7 @@ class PaymentHandlerHost : public mojom::PaymentHandlerHost {
}
// Binds to an IPC endpoint and returns it.
mojom::PaymentHandlerHostPtrInfo Bind();
mojo::PendingRemote<mojom::PaymentHandlerHost> Bind();
// Notifies the payment handler of the updated details, such as updated total,
// in response to the change of the payment method.
......@@ -97,7 +98,7 @@ class PaymentHandlerHost : public mojom::PaymentHandlerHost {
// The end-point for the payment handler renderer process to call into the
// browser process.
mojo::Binding<mojom::PaymentHandlerHost> binding_;
mojo::Receiver<mojom::PaymentHandlerHost> receiver_{this};
// The merchant page that invoked the Payment Request API.
content::WebContents* web_contents_;
......
......@@ -12,6 +12,7 @@
#include "components/payments/content/web_app_manifest.h"
#include "components/payments/core/payment_instrument.h"
#include "content/public/browser/stored_payment_app.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/mojom/payments/payment_app.mojom.h"
#include "third_party/blink/public/mojom/payments/payment_handler_host.mojom.h"
#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
......@@ -110,7 +111,7 @@ class ServiceWorkerPaymentInstrument : public PaymentInstrument {
gfx::ImageSkia icon_image_skia() const override;
void set_payment_handler_host(
mojom::PaymentHandlerHostPtrInfo payment_handler_host) {
mojo::PendingRemote<mojom::PaymentHandlerHost> payment_handler_host) {
payment_handler_host_ = std::move(payment_handler_host);
}
......@@ -143,7 +144,7 @@ class ServiceWorkerPaymentInstrument : public PaymentInstrument {
// the service worker is installed.
base::WeakPtr<IdentityObserver> identity_observer_;
mojom::PaymentHandlerHostPtrInfo payment_handler_host_;
mojo::PendingRemote<mojom::PaymentHandlerHost> payment_handler_host_;
// PaymentAppProvider::CanMakePayment result of this payment instrument.
bool can_make_payment_result_;
......
......@@ -27,25 +27,24 @@ PaymentRequestEvent* PaymentRequestEvent::Create(
const AtomicString& type,
const PaymentRequestEventInit* initializer) {
return MakeGarbageCollected<PaymentRequestEvent>(
type, initializer, payments::mojom::blink::PaymentHandlerHostPtrInfo(),
nullptr, nullptr);
type, initializer, mojo::NullRemote(), nullptr, nullptr);
}
PaymentRequestEvent* PaymentRequestEvent::Create(
const AtomicString& type,
const PaymentRequestEventInit* initializer,
payments::mojom::blink::PaymentHandlerHostPtrInfo host_info,
mojo::PendingRemote<payments::mojom::blink::PaymentHandlerHost> host,
RespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer) {
return MakeGarbageCollected<PaymentRequestEvent>(
type, initializer, std::move(host_info), respond_with_observer,
type, initializer, std::move(host), respond_with_observer,
wait_until_observer);
}
PaymentRequestEvent::PaymentRequestEvent(
const AtomicString& type,
const PaymentRequestEventInit* initializer,
payments::mojom::blink::PaymentHandlerHostPtrInfo host_info,
mojo::PendingRemote<payments::mojom::blink::PaymentHandlerHost> host,
RespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer)
: ExtendableEvent(type, initializer, wait_until_observer),
......@@ -62,11 +61,11 @@ PaymentRequestEvent::PaymentRequestEvent(
: HeapVector<Member<PaymentDetailsModifier>>()),
instrument_key_(initializer->instrumentKey()),
observer_(respond_with_observer) {
if (!host_info.is_valid())
if (!host.is_valid())
return;
payment_handler_host_.Bind(std::move(host_info));
payment_handler_host_.set_connection_error_handler(WTF::Bind(
payment_handler_host_.Bind(std::move(host));
payment_handler_host_.set_disconnect_handler(WTF::Bind(
&PaymentRequestEvent::OnHostConnectionError, WrapWeakPersistent(this)));
}
......
......@@ -6,6 +6,8 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_REQUEST_EVENT_H_
#include "base/macros.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/payments/payment_handler_host.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/modules/event_modules.h"
......@@ -33,14 +35,14 @@ class MODULES_EXPORT PaymentRequestEvent final : public ExtendableEvent {
static PaymentRequestEvent* Create(
const AtomicString& type,
const PaymentRequestEventInit*,
payments::mojom::blink::PaymentHandlerHostPtrInfo host_info,
mojo::PendingRemote<payments::mojom::blink::PaymentHandlerHost> host,
RespondWithObserver*,
WaitUntilObserver*);
PaymentRequestEvent(
const AtomicString& type,
const PaymentRequestEventInit*,
payments::mojom::blink::PaymentHandlerHostPtrInfo host_info,
mojo::PendingRemote<payments::mojom::blink::PaymentHandlerHost> host,
RespondWithObserver*,
WaitUntilObserver*);
~PaymentRequestEvent() override;
......@@ -82,7 +84,8 @@ class MODULES_EXPORT PaymentRequestEvent final : public ExtendableEvent {
Member<ScriptPromiseResolver> change_payment_method_resolver_;
Member<RespondWithObserver> observer_;
payments::mojom::blink::PaymentHandlerHostPtr payment_handler_host_;
mojo::Remote<payments::mojom::blink::PaymentHandlerHost>
payment_handler_host_;
DISALLOW_COPY_AND_ASSIGN(PaymentRequestEvent);
};
......
......@@ -36,6 +36,7 @@
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h"
......@@ -1879,8 +1880,8 @@ void ServiceWorkerGlobalScope::DispatchPaymentRequestEvent(
PaymentRequestRespondWithObserver* respond_with_observer =
PaymentRequestRespondWithObserver::Create(this, event_id,
wait_until_observer);
payments::mojom::blink::PaymentHandlerHostPtrInfo payment_handler_host =
std::move(event_data->payment_handler_host);
mojo::PendingRemote<payments::mojom::blink::PaymentHandlerHost>
payment_handler_host = std::move(event_data->payment_handler_host);
Event* event = PaymentRequestEvent::Create(
event_type_names::kPaymentrequest,
PaymentEventDataConversion::ToPaymentRequestEventInit(
......
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