1 | /* |
2 | * Copyright (C) 2015-2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(APPLE_PAY) |
29 | |
30 | #include "MessageReceiver.h" |
31 | #include "MessageSender.h" |
32 | #include <WebCore/PaymentCoordinatorClient.h> |
33 | #include <WebCore/PaymentHeaders.h> |
34 | #include <wtf/Forward.h> |
35 | #include <wtf/HashMap.h> |
36 | #include <wtf/HashSet.h> |
37 | #include <wtf/text/StringHash.h> |
38 | |
39 | namespace IPC { |
40 | class DataReference; |
41 | } |
42 | |
43 | namespace WebCore { |
44 | class PaymentCoordinator; |
45 | class PaymentContact; |
46 | } |
47 | |
48 | namespace WebKit { |
49 | |
50 | class NetworkProcessConnection; |
51 | class WebPage; |
52 | |
53 | class WebPaymentCoordinator final : public WebCore::PaymentCoordinatorClient, private IPC::MessageReceiver, private IPC::MessageSender { |
54 | public: |
55 | friend class NetworkProcessConnection; |
56 | explicit WebPaymentCoordinator(WebPage&); |
57 | ~WebPaymentCoordinator(); |
58 | |
59 | void networkProcessConnectionClosed(); |
60 | |
61 | private: |
62 | // WebCore::PaymentCoordinatorClient. |
63 | Optional<String> validatedPaymentNetwork(const String&) override; |
64 | bool canMakePayments() override; |
65 | void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, CompletionHandler<void(bool)>&&) override; |
66 | void openPaymentSetup(const String& merchantIdentifier, const String& domainName, CompletionHandler<void(bool)>&&) override; |
67 | bool showPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLs, const WebCore::ApplePaySessionPaymentRequest&) override; |
68 | void completeMerchantValidation(const WebCore::PaymentMerchantSession&) override; |
69 | void completeShippingMethodSelection(Optional<WebCore::ShippingMethodUpdate>&&) override; |
70 | void completeShippingContactSelection(Optional<WebCore::ShippingContactUpdate>&&) override; |
71 | void completePaymentMethodSelection(Optional<WebCore::PaymentMethodUpdate>&&) override; |
72 | void completePaymentSession(Optional<WebCore::PaymentAuthorizationResult>&&) override; |
73 | |
74 | void abortPaymentSession() override; |
75 | void cancelPaymentSession() override; |
76 | |
77 | void paymentCoordinatorDestroyed() override; |
78 | |
79 | bool isWebPaymentCoordinator() const override { return true; } |
80 | |
81 | bool isAlwaysOnLoggingAllowed() const override; |
82 | bool supportsUnrestrictedApplePay() const override; |
83 | |
84 | // IPC::MessageReceiver. |
85 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
86 | |
87 | // IPC::MessageSender. |
88 | IPC::Connection* messageSenderConnection() const final; |
89 | uint64_t messageSenderDestinationID() const final; |
90 | |
91 | // Message handlers. |
92 | void validateMerchant(const String& validationURLString); |
93 | void didAuthorizePayment(const WebCore::Payment&); |
94 | void didSelectShippingMethod(const WebCore::ApplePaySessionPaymentRequest::ShippingMethod&); |
95 | void didSelectShippingContact(const WebCore::PaymentContact&); |
96 | void didSelectPaymentMethod(const WebCore::PaymentMethod&); |
97 | void didCancelPaymentSession(); |
98 | |
99 | WebCore::PaymentCoordinator& paymentCoordinator(); |
100 | |
101 | #if ENABLE(APPLE_PAY_REMOTE_UI) |
102 | bool remoteUIEnabled() const; |
103 | #endif |
104 | |
105 | using AvailablePaymentNetworksSet = HashSet<String, ASCIICaseInsensitiveHash>; |
106 | static AvailablePaymentNetworksSet platformAvailablePaymentNetworks(); |
107 | |
108 | WebPage& m_webPage; |
109 | |
110 | Optional<AvailablePaymentNetworksSet> m_availablePaymentNetworks; |
111 | |
112 | #if USE(APPLE_INTERNAL_SDK) |
113 | #import <WebKitAdditions/WebPaymentCoordinatorAdditions.h> |
114 | #endif |
115 | }; |
116 | |
117 | } // namespace WebKit |
118 | |
119 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::WebPaymentCoordinator) |
120 | static bool isType(const WebCore::PaymentCoordinatorClient& paymentCoordinatorClient) { return paymentCoordinatorClient.isWebPaymentCoordinator(); } |
121 | SPECIALIZE_TYPE_TRAITS_END() |
122 | |
123 | #endif |
124 | |