OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/payments/PaymentRequestProxy.h" |
| 6 |
| 7 #include "mojo/public/cpp/bindings/array.h" |
| 8 #include "mojo/public/cpp/bindings/string.h" |
| 9 #include "platform/payments/BlinkTypeConverters.h" |
| 10 #include "platform/payments/PlatformPaymentDetails.h" |
| 11 #include "platform/payments/PlatformPaymentOptions.h" |
| 12 #include "platform/payments/PlatformPaymentResponse.h" |
| 13 #include "platform/payments/PlatformShippingAddress.h" |
| 14 #include "public/platform/Platform.h" |
| 15 #include "wtf/Assertions.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 PaymentRequestProxy::PaymentRequestProxy(Listener* listener) |
| 20 : m_listener(listener) |
| 21 { |
| 22 ASSERT(m_listener); |
| 23 } |
| 24 |
| 25 PaymentRequestProxy::~PaymentRequestProxy() {} |
| 26 |
| 27 void PaymentRequestProxy::show(const Vector<String>& supportedMethods, |
| 28 const PlatformPaymentDetails& paymentDetails, |
| 29 const PlatformPaymentOptions& paymentOptions, |
| 30 const String& stringifiedData) |
| 31 { |
| 32 ASSERT(!m_provider.is_bound()); |
| 33 blink::Platform::current()->connectToRemoteService(mojo::GetProxy(&m_provide
r)); |
| 34 |
| 35 if (!m_provider) |
| 36 return; |
| 37 |
| 38 m_provider->Show(mojo::Array<mojo::String>::From(supportedMethods), |
| 39 payments::mojom::PaymentDetails::From(paymentDetails), |
| 40 payments::mojom::PaymentOptions::From(paymentOptions), |
| 41 mojo::String::From(stringifiedData)); |
| 42 } |
| 43 |
| 44 void PaymentRequestProxy::abort() |
| 45 { |
| 46 m_provider->Abort(); |
| 47 m_provider.reset(); |
| 48 } |
| 49 |
| 50 void PaymentRequestProxy::complete(bool success) |
| 51 { |
| 52 m_provider->Complete(success); |
| 53 } |
| 54 |
| 55 void PaymentRequestProxy::OnShippingAddressChange(payments::mojom::ShippingAddre
ssPtr shippingAddress) |
| 56 { |
| 57 m_listener->onShippingAddressChange(shippingAddress->To<PlatformShippingAddr
ess>()); |
| 58 } |
| 59 |
| 60 void PaymentRequestProxy::OnShippingOptionChange(const mojo::String& shippingOpt
ionId) |
| 61 { |
| 62 m_listener->onShippingOptionChange(shippingOptionId.To<String>()); |
| 63 } |
| 64 |
| 65 void PaymentRequestProxy::OnPaymentResponse(payments::mojom::PaymentResponsePtr
paymentResponse) |
| 66 { |
| 67 m_listener->onPaymentResponse(paymentResponse->To<PlatformPaymentResponse>()
); |
| 68 } |
| 69 |
| 70 void PaymentRequestProxy::OnError() |
| 71 { |
| 72 m_provider.reset(); |
| 73 m_listener->onError(); |
| 74 } |
| 75 |
| 76 void PaymentRequestProxy::OnComplete() |
| 77 { |
| 78 m_provider.reset(); |
| 79 m_listener->onComplete(); |
| 80 } |
| 81 |
| 82 } // namespace blink |
OLD | NEW |