Move WebKit2 Apple Pay code to the open source repository
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jun 2016 18:31:05 +0000 (18:31 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Jun 2016 18:31:05 +0000 (18:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159041

Reviewed by Sam Weinig.

* DerivedSources.make:
* Shared/Cocoa/WebCoreArgumentCodersCocoa.h: Added.
* Shared/Cocoa/WebCoreArgumentCodersCocoa.mm: Added.
* UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: Added.
* UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: Added.
* UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in: Added.
* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h: Added.
* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm: Added.
* UIProcess/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm: Added.
* UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: Added.
* UIProcess/WebPageProxy.cpp:
* UIProcess/WebPageProxy.h:
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/ApplePay/WebPaymentCoordinator.cpp: Added.
* WebProcess/ApplePay/WebPaymentCoordinator.h: Added.
* WebProcess/ApplePay/WebPaymentCoordinator.messages.in: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202432 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/DerivedSources.make
Source/WebKit2/Shared/Cocoa/WebCoreArgumentCodersCocoa.h [new file with mode: 0644]
Source/WebKit2/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm [new file with mode: 0644]
Source/WebKit2/Shared/Cocoa/WebKitAdditions.mm [deleted file]
Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h [new file with mode: 0644]
Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in [new file with mode: 0644]
Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h [new file with mode: 0644]
Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm [new file with mode: 0644]
Source/WebKit2/UIProcess/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm [new file with mode: 0644]
Source/WebKit2/UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm [new file with mode: 0644]
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.h [new file with mode: 0644]
Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.messages.in [new file with mode: 0644]

index 4a416eb..cef9e8d 100644 (file)
@@ -29,6 +29,7 @@ set(WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/UIProcess/API"
     "${WEBKIT2_DIR}/UIProcess/API/C"
     "${WEBKIT2_DIR}/UIProcess/API/cpp"
+    "${WEBKIT2_DIR}/UIProcess/ApplePay"
     "${WEBKIT2_DIR}/UIProcess/Authentication"
     "${WEBKIT2_DIR}/UIProcess/Automation"
     "${WEBKIT2_DIR}/UIProcess/Databases"
@@ -43,6 +44,7 @@ set(WebKit2_INCLUDE_DIRECTORIES
     "${WEBKIT2_DIR}/UIProcess/UserContent"
     "${WEBKIT2_DIR}/UIProcess/WebsiteData"
     "${WEBKIT2_DIR}/WebProcess"
+    "${WEBKIT2_DIR}/WebProcess/ApplePay"
     "${WEBKIT2_DIR}/WebProcess/ApplicationCache"
     "${WEBKIT2_DIR}/WebProcess/Automation"
     "${WEBKIT2_DIR}/WebProcess/Battery"
index 58295bc..12cc65a 100644 (file)
@@ -1,3 +1,27 @@
+2016-06-22  Anders Carlsson  <andersca@apple.com>
+
+        Move WebKit2 Apple Pay code to the open source repository
+        https://bugs.webkit.org/show_bug.cgi?id=159041
+
+        Reviewed by Sam Weinig.
+
+        * DerivedSources.make:
+        * Shared/Cocoa/WebCoreArgumentCodersCocoa.h: Added.
+        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm: Added.
+        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: Added.
+        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: Added.
+        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in: Added.
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h: Added.
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm: Added.
+        * UIProcess/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm: Added.
+        * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: Added.
+        * UIProcess/WebPageProxy.cpp:
+        * UIProcess/WebPageProxy.h:
+        * WebKit2.xcodeproj/project.pbxproj:
+        * WebProcess/ApplePay/WebPaymentCoordinator.cpp: Added.
+        * WebProcess/ApplePay/WebPaymentCoordinator.h: Added.
+        * WebProcess/ApplePay/WebPaymentCoordinator.messages.in: Added.
+
 2016-06-24  Chris Dumez  <cdumez@apple.com>
 
         [WK2] PageConfiguration.m_relatedPage keeps WebPageProxy alive after its WebView has been destroyed
index a15bbfb..220b8a8 100644 (file)
@@ -35,6 +35,7 @@ VPATH = \
     $(WebKit2)/Shared/API/Cocoa \
     $(WebKit2)/Shared/Authentication \
     $(WebKit2)/Shared/mac \
+    $(WebKit2)/WebProcess/ApplePay \
     $(WebKit2)/WebProcess/ApplicationCache \
     $(WebKit2)/WebProcess/Automation \
     $(WebKit2)/WebProcess/Cookies \
@@ -57,6 +58,7 @@ VPATH = \
     $(WebKit2)/WebProcess/ios \
     $(WebKit2)/WebProcess \
     $(WebKit2)/UIProcess \
+    $(WebKit2)/UIProcess/ApplePay \
     $(WebKit2)/UIProcess/Automation \
     $(WebKit2)/UIProcess/Cocoa \
     $(WebKit2)/UIProcess/Databases \
@@ -138,6 +140,8 @@ MESSAGE_RECEIVERS = \
     WebPage \
     WebPageProxy \
     WebPasteboardProxy \
+    WebPaymentCoordinator \
+    WebPaymentCoordinatorProxy \
     WebPlaybackSessionManager \
     WebPlaybackSessionManagerProxy \
     WebProcess \
diff --git a/Source/WebKit2/Shared/Cocoa/WebCoreArgumentCodersCocoa.h b/Source/WebKit2/Shared/Cocoa/WebCoreArgumentCodersCocoa.h
new file mode 100644 (file)
index 0000000..b94af4c
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(APPLE_PAY)
+
+#include <WebCore/PaymentHeaders.h>
+
+namespace IPC {
+
+template<> struct ArgumentCoder<WebCore::Payment> {
+    static void encode(ArgumentEncoder&, const WebCore::Payment&);
+    static bool decode(ArgumentDecoder&, WebCore::Payment&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentContact> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentContact&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentContact&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentMerchantSession> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentMerchantSession&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentMerchantSession&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentMethod> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentMethod&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentMethod&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentRequest> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentRequest&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentRequest&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentRequest::AddressFields> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentRequest::AddressFields&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentRequest::AddressFields&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentRequest::LineItem> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentRequest::LineItem&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentRequest::LineItem&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentRequest::MerchantCapabilities> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentRequest::MerchantCapabilities&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentRequest::MerchantCapabilities&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentRequest::ShippingMethod> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentRequest::ShippingMethod&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentRequest::ShippingMethod&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentRequest::SupportedNetworks> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentRequest::SupportedNetworks&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentRequest::SupportedNetworks&);
+};
+
+template<> struct ArgumentCoder<WebCore::PaymentRequest::TotalAndLineItems> {
+    static void encode(ArgumentEncoder&, const WebCore::PaymentRequest::TotalAndLineItems&);
+    static bool decode(ArgumentDecoder&, WebCore::PaymentRequest::TotalAndLineItems&);
+};
+
+}
+
+#endif
diff --git a/Source/WebKit2/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm b/Source/WebKit2/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm
new file mode 100644 (file)
index 0000000..6b5b2e5
--- /dev/null
@@ -0,0 +1,398 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebCoreArgumentCoders.h"
+
+#if ENABLE(APPLE_PAY)
+
+#import "DataReference.h"
+#import <PassKit/PassKit.h>
+#import <WebCore/SoftLinking.h>
+
+#if PLATFORM(MAC)
+SOFT_LINK_PRIVATE_FRAMEWORK(PassKit)
+#else
+SOFT_LINK_FRAMEWORK(PassKit)
+#endif
+
+SOFT_LINK_CLASS(PassKit, PKContact);
+SOFT_LINK_CLASS(PassKit, PKPayment);
+SOFT_LINK_CLASS(PassKit, PKPaymentMethod);
+
+using namespace WebCore;
+
+namespace IPC {
+
+void ArgumentCoder<WebCore::Payment>::encode(ArgumentEncoder& encoder, const WebCore::Payment& payment)
+{
+    auto data = adoptNS([[NSMutableData alloc] init]);
+    auto archiver = adoptNS([[NSKeyedArchiver alloc] initForWritingWithMutableData:data.get()]);
+
+    [archiver setRequiresSecureCoding:YES];
+
+    [archiver encodeObject:payment.pkPayment() forKey:NSKeyedArchiveRootObjectKey];
+    [archiver finishEncoding];
+
+    encoder << DataReference(static_cast<const uint8_t*>([data bytes]), [data length]);
+}
+
+bool ArgumentCoder<WebCore::Payment>::decode(ArgumentDecoder& decoder, WebCore::Payment& payment)
+{
+    IPC::DataReference dataReference;
+    if (!decoder.decode(dataReference))
+        return false;
+
+    auto data = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(dataReference.data())) length:dataReference.size() freeWhenDone:NO]);
+    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:data.get()]);
+    [unarchiver setRequiresSecureCoding:YES];
+    @try {
+        PKPayment *pkPayment = [unarchiver decodeObjectOfClass:getPKPaymentClass() forKey:NSKeyedArchiveRootObjectKey];
+        payment = Payment(pkPayment);
+    } @catch (NSException *exception) {
+        LOG_ERROR("Failed to decode PKPayment: %@", exception);
+        return false;
+    }
+
+    [unarchiver finishDecoding];
+    return true;
+}
+
+void ArgumentCoder<WebCore::PaymentContact>::encode(ArgumentEncoder& encoder, const WebCore::PaymentContact& paymentContact)
+{
+    auto data = adoptNS([[NSMutableData alloc] init]);
+    auto archiver = adoptNS([[NSKeyedArchiver alloc] initForWritingWithMutableData:data.get()]);
+
+    [archiver setRequiresSecureCoding:YES];
+
+    [archiver encodeObject:paymentContact.pkContact() forKey:NSKeyedArchiveRootObjectKey];
+    [archiver finishEncoding];
+
+    encoder << DataReference(static_cast<const uint8_t*>([data bytes]), [data length]);
+}
+
+bool ArgumentCoder<WebCore::PaymentContact>::decode(ArgumentDecoder& decoder, WebCore::PaymentContact& paymentContact)
+{
+    IPC::DataReference dataReference;
+    if (!decoder.decode(dataReference))
+        return false;
+
+    auto data = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(dataReference.data())) length:dataReference.size() freeWhenDone:NO]);
+    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:data.get()]);
+    [unarchiver setRequiresSecureCoding:YES];
+    @try {
+        PKContact *pkContact = [unarchiver decodeObjectOfClass:getPKContactClass() forKey:NSKeyedArchiveRootObjectKey];
+        paymentContact = PaymentContact(pkContact);
+    } @catch (NSException *exception) {
+        LOG_ERROR("Failed to decode PKContact: %@", exception);
+        return false;
+    }
+
+    [unarchiver finishDecoding];
+    return true;
+}
+
+void ArgumentCoder<WebCore::PaymentMerchantSession>::encode(ArgumentEncoder& encoder, const WebCore::PaymentMerchantSession& paymentMerchantSession)
+{
+    encoder << paymentMerchantSession.merchantIdentifier;
+    encoder << paymentMerchantSession.sessionIdentifier;
+    encoder << paymentMerchantSession.nonce;
+    encoder << paymentMerchantSession.domainName;
+    encoder << paymentMerchantSession.epochTimestamp;
+    encoder << paymentMerchantSession.signature;
+}
+
+bool ArgumentCoder<WebCore::PaymentMerchantSession>::decode(ArgumentDecoder& decoder, WebCore::PaymentMerchantSession& paymentMerchantSession)
+{
+    if (!decoder.decode(paymentMerchantSession.merchantIdentifier))
+        return false;
+    if (!decoder.decode(paymentMerchantSession.sessionIdentifier))
+        return false;
+    if (!decoder.decode(paymentMerchantSession.nonce))
+        return false;
+    if (!decoder.decode(paymentMerchantSession.domainName))
+        return false;
+    if (!decoder.decode(paymentMerchantSession.epochTimestamp))
+        return false;
+    if (!decoder.decode(paymentMerchantSession.signature))
+        return false;
+
+    return true;
+}
+
+void ArgumentCoder<WebCore::PaymentMethod>::encode(ArgumentEncoder& encoder, const WebCore::PaymentMethod& paymentMethod)
+{
+    auto data = adoptNS([[NSMutableData alloc] init]);
+    auto archiver = adoptNS([[NSKeyedArchiver alloc] initForWritingWithMutableData:data.get()]);
+
+    [archiver setRequiresSecureCoding:YES];
+
+    [archiver encodeObject:paymentMethod.pkPaymentMethod() forKey:NSKeyedArchiveRootObjectKey];
+    [archiver finishEncoding];
+
+    encoder << DataReference(static_cast<const uint8_t*>([data bytes]), [data length]);
+}
+
+bool ArgumentCoder<WebCore::PaymentMethod>::decode(ArgumentDecoder& decoder, WebCore::PaymentMethod& paymentMethod)
+{
+    IPC::DataReference dataReference;
+    if (!decoder.decode(dataReference))
+        return false;
+
+    auto data = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(dataReference.data())) length:dataReference.size() freeWhenDone:NO]);
+    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:data.get()]);
+    [unarchiver setRequiresSecureCoding:YES];
+    @try {
+        PKPaymentMethod *pkPaymentMethod = [unarchiver decodeObjectOfClass:getPKPaymentMethodClass() forKey:NSKeyedArchiveRootObjectKey];
+        paymentMethod = PaymentMethod(pkPaymentMethod);
+    } @catch (NSException *exception) {
+        LOG_ERROR("Failed to decode PKPayment: %@", exception);
+        return false;
+    }
+
+    [unarchiver finishDecoding];
+    return true;
+}
+
+void ArgumentCoder<PaymentRequest>::encode(ArgumentEncoder& encoder, const PaymentRequest& request)
+{
+    encoder << request.countryCode();
+    encoder << request.currencyCode();
+    encoder << request.requiredBillingAddressFields();
+    encoder << request.billingContact();
+    encoder << request.requiredShippingAddressFields();
+    encoder << request.shippingContact();
+    encoder << request.merchantCapabilities();
+    encoder << request.supportedNetworks();
+    encoder.encodeEnum(request.shippingType());
+    encoder << request.shippingMethods();
+    encoder << request.lineItems();
+    encoder << request.total();
+    encoder << request.applicationData();
+}
+
+bool ArgumentCoder<PaymentRequest>::decode(ArgumentDecoder& decoder, PaymentRequest& request)
+{
+    String countryCode;
+    if (!decoder.decode(countryCode))
+        return false;
+    request.setCountryCode(countryCode);
+
+    String currencyCode;
+    if (!decoder.decode(currencyCode))
+        return false;
+    request.setCurrencyCode(currencyCode);
+
+    PaymentRequest::AddressFields requiredBillingAddressFields;
+    if (!decoder.decode((requiredBillingAddressFields)))
+        return false;
+    request.setRequiredBillingAddressFields(requiredBillingAddressFields);
+
+    PaymentContact billingContact;
+    if (!decoder.decode(billingContact))
+        return false;
+    request.setBillingContact(billingContact);
+
+    PaymentRequest::AddressFields requiredShippingAddressFields;
+    if (!decoder.decode((requiredShippingAddressFields)))
+        return false;
+    request.setRequiredShippingAddressFields(requiredShippingAddressFields);
+
+    PaymentContact shippingContact;
+    if (!decoder.decode(shippingContact))
+        return false;
+    request.setShippingContact(shippingContact);
+
+    PaymentRequest::MerchantCapabilities merchantCapabilities;
+    if (!decoder.decode(merchantCapabilities))
+        return false;
+    request.setMerchantCapabilities(merchantCapabilities);
+
+    PaymentRequest::SupportedNetworks supportedNetworks;
+    if (!decoder.decode(supportedNetworks))
+        return false;
+    request.setSupportedNetworks(supportedNetworks);
+
+    PaymentRequest::ShippingType shippingType;
+    if (!decoder.decodeEnum(shippingType))
+        return false;
+    request.setShippingType(shippingType);
+
+    Vector<PaymentRequest::ShippingMethod> shippingMethods;
+    if (!decoder.decode(shippingMethods))
+        return false;
+    request.setShippingMethods(shippingMethods);
+
+    Vector<PaymentRequest::LineItem> lineItems;
+    if (!decoder.decode(lineItems))
+        return false;
+    request.setLineItems(lineItems);
+
+    PaymentRequest::LineItem total;
+    if (!decoder.decode(total))
+        return false;
+    request.setTotal(total);
+
+    String applicationData;
+    if (!decoder.decode(applicationData))
+        return false;
+    request.setApplicationData(applicationData);
+
+    return true;
+}
+
+void ArgumentCoder<PaymentRequest::AddressFields>::encode(ArgumentEncoder& encoder, const PaymentRequest::AddressFields& addressFields)
+{
+    encoder << addressFields.postalAddress;
+    encoder << addressFields.phone;
+    encoder << addressFields.email;
+    encoder << addressFields.name;
+}
+
+bool ArgumentCoder<PaymentRequest::AddressFields>::decode(ArgumentDecoder& decoder, PaymentRequest::AddressFields& addressFields)
+{
+    if (!decoder.decode(addressFields.postalAddress))
+        return false;
+    if (!decoder.decode(addressFields.phone))
+        return false;
+    if (!decoder.decode(addressFields.email))
+        return false;
+    if (!decoder.decode(addressFields.name))
+        return false;
+
+    return true;
+}
+
+void ArgumentCoder<PaymentRequest::LineItem>::encode(ArgumentEncoder& encoder, const PaymentRequest::LineItem& lineItem)
+{
+    encoder.encodeEnum(lineItem.type);
+    encoder << lineItem.label;
+    encoder << lineItem.amount;
+}
+
+bool ArgumentCoder<PaymentRequest::LineItem>::decode(ArgumentDecoder& decoder, PaymentRequest::LineItem& lineItem)
+{
+    if (!decoder.decodeEnum(lineItem.type))
+        return false;
+    if (!decoder.decode(lineItem.label))
+        return false;
+    if (!decoder.decode(lineItem.amount))
+        return false;
+
+    return true;
+}
+
+void ArgumentCoder<PaymentRequest::MerchantCapabilities>::encode(ArgumentEncoder& encoder, const PaymentRequest::MerchantCapabilities& merchantCapabilities)
+{
+    encoder << merchantCapabilities.supports3DS;
+    encoder << merchantCapabilities.supportsEMV;
+    encoder << merchantCapabilities.supportsCredit;
+    encoder << merchantCapabilities.supportsDebit;
+}
+
+bool ArgumentCoder<PaymentRequest::MerchantCapabilities>::decode(ArgumentDecoder& decoder, PaymentRequest::MerchantCapabilities& merchantCapabilities)
+{
+    if (!decoder.decode(merchantCapabilities.supports3DS))
+        return false;
+    if (!decoder.decode(merchantCapabilities.supportsEMV))
+        return false;
+    if (!decoder.decode(merchantCapabilities.supportsCredit))
+        return false;
+    if (!decoder.decode(merchantCapabilities.supportsDebit))
+        return false;
+
+    return true;
+}
+
+void ArgumentCoder<PaymentRequest::SupportedNetworks>::encode(ArgumentEncoder& encoder, const PaymentRequest::SupportedNetworks& supportedNetworks)
+{
+    encoder << supportedNetworks.amex;
+    encoder << supportedNetworks.chinaUnionPay;
+    encoder << supportedNetworks.discover;
+    encoder << supportedNetworks.interac;
+    encoder << supportedNetworks.masterCard;
+    encoder << supportedNetworks.privateLabel;
+    encoder << supportedNetworks.visa;
+}
+
+bool ArgumentCoder<PaymentRequest::SupportedNetworks>::decode(ArgumentDecoder& decoder, PaymentRequest::SupportedNetworks& supportedNetworks)
+{
+    if (!decoder.decode(supportedNetworks.amex))
+        return false;
+    if (!decoder.decode(supportedNetworks.chinaUnionPay))
+        return false;
+    if (!decoder.decode(supportedNetworks.discover))
+        return false;
+    if (!decoder.decode(supportedNetworks.interac))
+        return false;
+    if (!decoder.decode(supportedNetworks.masterCard))
+        return false;
+    if (!decoder.decode(supportedNetworks.privateLabel))
+        return false;
+    if (!decoder.decode(supportedNetworks.visa))
+        return false;
+
+    return true;
+}
+
+void ArgumentCoder<PaymentRequest::ShippingMethod>::encode(ArgumentEncoder& encoder, const PaymentRequest::ShippingMethod& shippingMethod)
+{
+    encoder << shippingMethod.label;
+    encoder << shippingMethod.detail;
+    encoder << shippingMethod.amount;
+    encoder << shippingMethod.identifier;
+}
+
+bool ArgumentCoder<PaymentRequest::ShippingMethod>::decode(ArgumentDecoder& decoder, PaymentRequest::ShippingMethod& shippingMethod)
+{
+    if (!decoder.decode(shippingMethod.label))
+        return false;
+    if (!decoder.decode(shippingMethod.detail))
+        return false;
+    if (!decoder.decode(shippingMethod.amount))
+        return false;
+    if (!decoder.decode(shippingMethod.identifier))
+        return false;
+    return true;
+}
+
+void ArgumentCoder<PaymentRequest::TotalAndLineItems>::encode(ArgumentEncoder& encoder, const PaymentRequest::TotalAndLineItems& totalAndLineItems)
+{
+    encoder << totalAndLineItems.total;
+    encoder << totalAndLineItems.lineItems;
+}
+
+bool ArgumentCoder<PaymentRequest::TotalAndLineItems>::decode(ArgumentDecoder& decoder, PaymentRequest::TotalAndLineItems& totalAndLineItems)
+{
+    if (!decoder.decode(totalAndLineItems.total))
+        return false;
+    if (!decoder.decode(totalAndLineItems.lineItems))
+        return false;
+    return true;
+}
+
+}
+
+#endif
diff --git a/Source/WebKit2/Shared/Cocoa/WebKitAdditions.mm b/Source/WebKit2/Shared/Cocoa/WebKitAdditions.mm
deleted file mode 100644 (file)
index 0a5e845..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebKitAdditions.mm>
-#endif
diff --git a/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp b/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp
new file mode 100644 (file)
index 0000000..adbfdb1
--- /dev/null
@@ -0,0 +1,322 @@
+/*
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebPaymentCoordinatorProxy.h"
+
+#if ENABLE(APPLE_PAY)
+
+#include "WebPageProxy.h"
+#include "WebPaymentCoordinatorMessages.h"
+#include "WebPaymentCoordinatorProxyMessages.h"
+#include "WebProcessProxy.h"
+#include <WebCore/PaymentAuthorizationStatus.h>
+
+namespace WebKit {
+
+WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy(WebPageProxy& webPageProxy)
+    : m_webPageProxy(webPageProxy)
+    , m_weakPtrFactory(this)
+    , m_state(State::Idle)
+    , m_merchantValidationState(MerchantValidationState::Idle)
+{
+    m_webPageProxy.process().addMessageReceiver(Messages::WebPaymentCoordinatorProxy::messageReceiverName(), m_webPageProxy.pageID(), *this);
+}
+
+WebPaymentCoordinatorProxy::~WebPaymentCoordinatorProxy()
+{
+    if (m_state != State::Idle)
+        hidePaymentUI();
+
+    m_webPageProxy.process().removeMessageReceiver(Messages::WebPaymentCoordinatorProxy::messageReceiverName(), m_webPageProxy.pageID());
+}
+
+void WebPaymentCoordinatorProxy::canMakePayments(bool& reply)
+{
+    reply = platformCanMakePayments();
+}
+
+void WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, uint64_t requestID)
+{
+    auto weakThis = m_weakPtrFactory.createWeakPtr();
+    platformCanMakePaymentsWithActiveCard(merchantIdentifier, domainName, [weakThis, requestID](bool canMakePayments) {
+        auto paymentCoordinatorProxy = weakThis.get();
+        if (!paymentCoordinatorProxy)
+            return;
+
+        paymentCoordinatorProxy->m_webPageProxy.send(Messages::WebPaymentCoordinator::CanMakePaymentsWithActiveCardReply(requestID, canMakePayments));
+    });
+}
+
+void WebPaymentCoordinatorProxy::showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::PaymentRequest& paymentRequest)
+{
+    // FIXME: Make this a message check.
+    ASSERT(canBegin());
+
+    m_state = State::Activating;
+
+    WebCore::URL originatingURL(WebCore::URL(), originatingURLString);
+
+    Vector<WebCore::URL> linkIconURLs;
+    for (const auto& linkIconURLString : linkIconURLStrings)
+        linkIconURLs.append(WebCore::URL(WebCore::URL(), linkIconURLString));
+
+    platformShowPaymentUI(originatingURL, linkIconURLs, paymentRequest, [this](bool result) {
+        ASSERT(m_state == State::Activating);
+        if (!result) {
+            didCancelPayment();
+            return;
+        }
+
+        m_state = State::Active;
+    });
+}
+
+static bool isValidEnum(WebCore::PaymentAuthorizationStatus status)
+{
+    switch (status) {
+    case WebCore::PaymentAuthorizationStatus::Success:
+    case WebCore::PaymentAuthorizationStatus::Failure:
+    case WebCore::PaymentAuthorizationStatus::InvalidBillingPostalAddress:
+    case WebCore::PaymentAuthorizationStatus::InvalidShippingPostalAddress:
+    case WebCore::PaymentAuthorizationStatus::InvalidShippingContact:
+    case WebCore::PaymentAuthorizationStatus::PINRequired:
+    case WebCore::PaymentAuthorizationStatus::PINIncorrect:
+    case WebCore::PaymentAuthorizationStatus::PINLockout:
+        return true;
+    }
+
+    return false;
+}
+
+void WebPaymentCoordinatorProxy::completeMerchantValidation(const WebCore::PaymentMerchantSession& paymentMerchantSession)
+{
+    // It's possible that the payment has been canceled already.
+    if (m_state == State::Idle)
+        return;
+
+    // FIXME: This should be a MESSAGE_CHECK.
+    ASSERT(m_merchantValidationState == MerchantValidationState::Validating);
+
+    platformCompleteMerchantValidation(paymentMerchantSession);
+    m_merchantValidationState = MerchantValidationState::ValidationComplete;
+}
+
+void WebPaymentCoordinatorProxy::completeShippingMethodSelection(uint32_t opaqueStatus, const Optional<WebCore::PaymentRequest::TotalAndLineItems>& newTotalAndLineItems)
+{
+    // It's possible that the payment has been canceled already.
+    if (m_state == State::Idle)
+        return;
+
+    // FIXME: This should be a MESSAGE_CHECK.
+    ASSERT(m_state == State::ShippingMethodSelected);
+
+    auto status = static_cast<WebCore::PaymentAuthorizationStatus>(opaqueStatus);
+
+    // FIXME: Make this a message check.
+    RELEASE_ASSERT(isValidEnum(status));
+
+    platformCompleteShippingMethodSelection(status, newTotalAndLineItems);
+    m_state = State::Active;
+}
+
+void WebPaymentCoordinatorProxy::completeShippingContactSelection(uint32_t opaqueStatus, const Vector<WebCore::PaymentRequest::ShippingMethod>& newShippingMethods, const Optional<WebCore::PaymentRequest::TotalAndLineItems>& newTotalAndLineItems)
+{
+    // It's possible that the payment has been canceled already.
+    if (m_state == State::Idle)
+        return;
+
+    // FIXME: This should be a MESSAGE_CHECK.
+    ASSERT(m_state == State::ShippingContactSelected);
+
+    auto status = static_cast<WebCore::PaymentAuthorizationStatus>(opaqueStatus);
+
+    // FIXME: Make this a message check.
+    RELEASE_ASSERT(isValidEnum(status));
+
+    platformCompleteShippingContactSelection(status, newShippingMethods, newTotalAndLineItems);
+    m_state = State::Active;
+}
+
+void WebPaymentCoordinatorProxy::completePaymentMethodSelection(const Optional<WebCore::PaymentRequest::TotalAndLineItems>& newTotalAndLineItems)
+{
+    // It's possible that the payment has been canceled already.
+    if (m_state == State::Idle)
+        return;
+
+    // FIXME: This should be a MESSAGE_CHECK.
+    ASSERT(m_state == State::PaymentMethodSelected);
+
+    platformCompletePaymentMethodSelection(newTotalAndLineItems);
+    m_state = State::Active;
+}
+
+void WebPaymentCoordinatorProxy::completePaymentSession(uint32_t opaqueStatus)
+{
+    // It's possible that the payment has been canceled already.
+    if (!canCompletePayment())
+        return;
+
+    auto status = static_cast<WebCore::PaymentAuthorizationStatus>(opaqueStatus);
+
+    // FIXME: Make this a message check.
+    RELEASE_ASSERT(isValidEnum(status));
+
+    platformCompletePaymentSession(status);
+
+    didReachFinalState();
+}
+
+void WebPaymentCoordinatorProxy::abortPaymentSession()
+{
+    // It's possible that the payment has been canceled already.
+    if (!canAbort())
+        return;
+
+    hidePaymentUI();
+
+    didReachFinalState();
+}
+
+void WebPaymentCoordinatorProxy::didCancelPayment()
+{
+    ASSERT(canCancel());
+
+    m_webPageProxy.send(Messages::WebPaymentCoordinator::DidCancelPayment());
+
+    didReachFinalState();
+}
+
+void WebPaymentCoordinatorProxy::validateMerchant(const WebCore::URL& url)
+{
+    ASSERT(m_merchantValidationState == MerchantValidationState::Idle);
+
+    m_merchantValidationState = MerchantValidationState::Validating;
+    m_webPageProxy.send(Messages::WebPaymentCoordinator::ValidateMerchant(url.string()));
+}
+
+void WebPaymentCoordinatorProxy::didAuthorizePayment(const WebCore::Payment& payment)
+{
+    m_state = State::Authorized;
+    m_webPageProxy.send(Messages::WebPaymentCoordinator::DidAuthorizePayment(payment));
+}
+
+void WebPaymentCoordinatorProxy::didSelectShippingMethod(const WebCore::PaymentRequest::ShippingMethod& shippingMethod)
+{
+    ASSERT(m_state == State::Active);
+
+    m_state = State::ShippingMethodSelected;
+    m_webPageProxy.send(Messages::WebPaymentCoordinator::DidSelectShippingMethod(shippingMethod));
+}
+
+void WebPaymentCoordinatorProxy::didSelectShippingContact(const WebCore::PaymentContact& shippingContact)
+{
+    ASSERT(m_state == State::Active);
+
+    m_state = State::ShippingContactSelected;
+    m_webPageProxy.send(Messages::WebPaymentCoordinator::DidSelectShippingContact(shippingContact));
+}
+
+void WebPaymentCoordinatorProxy::didSelectPaymentMethod(const WebCore::PaymentMethod& paymentMethod)
+{
+    ASSERT(m_state == State::Active);
+
+    m_state = State::PaymentMethodSelected;
+    m_webPageProxy.send(Messages::WebPaymentCoordinator::DidSelectPaymentMethod(paymentMethod));
+}
+
+bool WebPaymentCoordinatorProxy::canBegin() const
+{
+    switch (m_state) {
+    case State::Idle:
+        return true;
+
+    case State::Activating:
+    case State::Active:
+    case State::Authorized:
+    case State::ShippingMethodSelected:
+    case State::ShippingContactSelected:
+    case State::PaymentMethodSelected:
+        return false;
+    }
+}
+
+bool WebPaymentCoordinatorProxy::canCancel() const
+{
+    switch (m_state) {
+    case State::Activating:
+    case State::Active:
+    case State::Authorized:
+    case State::ShippingMethodSelected:
+    case State::ShippingContactSelected:
+    case State::PaymentMethodSelected:
+        return true;
+
+    case State::Idle:
+        return false;
+    }
+}
+
+bool WebPaymentCoordinatorProxy::canCompletePayment() const
+{
+    switch (m_state) {
+    case State::Authorized:
+        return true;
+
+    case State::Idle:
+    case State::Activating:
+    case State::Active:
+    case State::ShippingMethodSelected:
+    case State::ShippingContactSelected:
+    case State::PaymentMethodSelected:
+        return false;
+    }
+}
+
+bool WebPaymentCoordinatorProxy::canAbort() const
+{
+    switch (m_state) {
+    case State::Activating:
+    case State::Active:
+    case State::Authorized:
+    case State::ShippingMethodSelected:
+    case State::ShippingContactSelected:
+    case State::PaymentMethodSelected:
+        return true;
+
+    case State::Idle:
+        return false;
+    }
+}
+
+void WebPaymentCoordinatorProxy::didReachFinalState()
+{
+    m_state = State::Idle;
+    m_merchantValidationState = MerchantValidationState::Idle;
+}
+
+}
+
+#endif
diff --git a/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h b/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h
new file mode 100644 (file)
index 0000000..2c2d61e
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(APPLE_PAY)
+
+#include "MessageReceiver.h"
+#include <WebCore/PaymentHeaders.h>
+#include <wtf/Forward.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
+
+namespace IPC {
+class DataReference;
+}
+
+namespace WebCore {
+enum class PaymentAuthorizationStatus;
+class Payment;
+class PaymentContact;
+class PaymentMethod;
+class URL;
+struct PaymentMerchantSession;
+}
+
+OBJC_CLASS NSWindow;
+OBJC_CLASS PKPaymentAuthorizationViewController;
+OBJC_CLASS WKPaymentAuthorizationViewControllerDelegate;
+
+namespace WebKit {
+
+class WebPageProxy;
+
+class WebPaymentCoordinatorProxy : private IPC::MessageReceiver {
+public:
+    explicit WebPaymentCoordinatorProxy(WebPageProxy&);
+    ~WebPaymentCoordinatorProxy();
+
+    void didCancelPayment();
+    void validateMerchant(const WebCore::URL&);
+    void didAuthorizePayment(const WebCore::Payment&);
+    void didSelectShippingMethod(const WebCore::PaymentRequest::ShippingMethod&);
+    void didSelectShippingContact(const WebCore::PaymentContact&);
+    void didSelectPaymentMethod(const WebCore::PaymentMethod&);
+
+    void hidePaymentUI();
+
+private:
+    // IPC::MessageReceiver.
+    void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
+    void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
+
+    // Message handlers.
+    void canMakePayments(bool& reply);
+    void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, uint64_t requestID);
+    void showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::PaymentRequest&);
+    void completeMerchantValidation(const WebCore::PaymentMerchantSession&);
+    void completeShippingMethodSelection(uint32_t opaqueStatus, const Optional<WebCore::PaymentRequest::TotalAndLineItems>&);
+    void completeShippingContactSelection(uint32_t opaqueStatus, const Vector<WebCore::PaymentRequest::ShippingMethod>& newShippingMethods, const Optional<WebCore::PaymentRequest::TotalAndLineItems>&);
+    void completePaymentMethodSelection(const Optional<WebCore::PaymentRequest::TotalAndLineItems>&);
+    void completePaymentSession(uint32_t opaqueStatus);
+    void abortPaymentSession();
+
+    bool canBegin() const;
+    bool canCancel() const;
+    bool canCompletePayment() const;
+    bool canAbort() const;
+
+    void didReachFinalState();
+
+    bool platformCanMakePayments();
+    void platformCanMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler);
+    void platformShowPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest&, std::function<void (bool)> completionHandler);
+    void platformCompleteMerchantValidation(const WebCore::PaymentMerchantSession&);
+    void platformCompleteShippingMethodSelection(WebCore::PaymentAuthorizationStatus, const Optional<WebCore::PaymentRequest::TotalAndLineItems>&);
+    void platformCompleteShippingContactSelection(WebCore::PaymentAuthorizationStatus, const Vector<WebCore::PaymentRequest::ShippingMethod>& newShippingMethods, const Optional<WebCore::PaymentRequest::TotalAndLineItems>&);
+    void platformCompletePaymentMethodSelection(const Optional<WebCore::PaymentRequest::TotalAndLineItems>&);
+    void platformCompletePaymentSession(WebCore::PaymentAuthorizationStatus);
+
+    WebPageProxy& m_webPageProxy;
+    WeakPtrFactory<WebPaymentCoordinatorProxy> m_weakPtrFactory;
+
+    enum class State {
+        // Idle - Nothing's happening.
+        Idle,
+
+        // Activating - Waiting to show the payment UI.
+        Activating,
+
+        // Active - Showing payment UI.
+        Active,
+
+        // Authorized - Dispatching the authorized event and waiting for the paymentSessionCompleted message.
+        Authorized,
+
+        // ShippingMethodSelected - Dispatching the shippingmethodselected event and waiting for a reply.
+        ShippingMethodSelected,
+
+        // ShippingContactSelected - Dispatching the shippingcontactselected event and waiting for a reply.
+        ShippingContactSelected,
+
+        // PaymentMethodSelected - Dispatching the paymentmethodselected event and waiting for a reply.
+        PaymentMethodSelected,
+    } m_state;
+
+    enum class MerchantValidationState {
+        // Idle - Nothing's happening.
+        Idle,
+
+        // Validating - Dispatching the validatemerchant event and waiting for a reply.
+        Validating,
+
+        // ValidationComplete - A merchant session has been sent along to PassKit.
+        ValidationComplete
+    } m_merchantValidationState;
+
+    RetainPtr<PKPaymentAuthorizationViewController> m_paymentAuthorizationViewController;
+    RetainPtr<WKPaymentAuthorizationViewControllerDelegate> m_paymentAuthorizationViewControllerDelegate;
+
+#if PLATFORM(MAC)
+    uint64_t m_showPaymentUIRequestSeed { 0 };
+    RetainPtr<NSWindow> m_sheetWindow;
+#endif
+};
+
+}
+
+#endif
diff --git a/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in b/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in
new file mode 100644 (file)
index 0000000..538cb5d
--- /dev/null
@@ -0,0 +1,41 @@
+# Copyright (C) 2015 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+#/
+
+#if ENABLE(APPLE_PAY)
+
+messages -> WebPaymentCoordinatorProxy {
+
+    CanMakePayments() -> (bool result)
+    CanMakePaymentsWithActiveCard(String merchantIdentifier, String domainName, uint64_t requestID)
+
+    ShowPaymentUI(String originatingURLString, Vector<String> linkIconURLStrings, WebCore::PaymentRequest paymentRequest)
+    CompleteMerchantValidation(struct WebCore::PaymentMerchantSession paymentMerchantSession);
+    CompleteShippingMethodSelection(uint32_t opaqueStatus, Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems)
+    CompleteShippingContactSelection(uint32_t opaqueStatus, Vector<WebCore::PaymentRequest::ShippingMethod> newShippingMethods, Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems)
+    CompletePaymentMethodSelection(Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems)
+    CompletePaymentSession(uint32_t opaqueStatus)
+    AbortPaymentSession()
+}
+
+#endif
diff --git a/Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h b/Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h
new file mode 100644 (file)
index 0000000..7dd1474
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(APPLE_PAY)
+
+#import <PassKit/PKPaymentAuthorizationViewController.h>
+#import <PassKit/PKPaymentAuthorizationViewController_Private.h>
+#import <WebCore/PaymentHeaders.h>
+#import <wtf/BlockPtr.h>
+
+namespace WebCore {
+class URL;
+}
+
+namespace WebKit {
+class WebPaymentCoordinatorProxy;
+
+RetainPtr<PKPaymentRequest> toPKPaymentRequest(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest&);
+
+}
+
+@interface WKPaymentAuthorizationViewControllerDelegate : NSObject <PKPaymentAuthorizationViewControllerDelegate, PKPaymentAuthorizationViewControllerPrivateDelegate> {
+@package
+    WebKit::WebPaymentCoordinatorProxy* _webPaymentCoordinatorProxy;
+    RetainPtr<NSArray> _paymentSummaryItems;
+    RetainPtr<NSArray> _shippingMethods;
+
+    BlockPtr<void (PKPaymentMerchantSession *, NSError *)> _sessionBlock;
+
+    BOOL _authorized;
+    BlockPtr<void (PKPaymentAuthorizationStatus)> _paymentAuthorizedCompletion;
+    BlockPtr<void (NSArray *)> _didSelectPaymentMethodCompletion;
+    BlockPtr<void (PKPaymentAuthorizationStatus, NSArray *)> _didSelectShippingMethodCompletion;
+    BlockPtr<void (PKPaymentAuthorizationStatus, NSArray *, NSArray *)> _didSelectShippingContactCompletion;
+}
+
+- (instancetype)initWithPaymentCoordinatorProxy:(WebKit::WebPaymentCoordinatorProxy&)webPaymentCoordinatorProxy;
+
+- (void)invalidate;
+
+@end
+
+#endif
diff --git a/Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm b/Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm
new file mode 100644 (file)
index 0000000..27f8a65
--- /dev/null
@@ -0,0 +1,515 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebPaymentCoordinatorProxyCocoa.h"
+
+#if ENABLE(APPLE_PAY)
+
+#import "WebPaymentCoordinatorProxy.h"
+#import <PassKit/PKPaymentAuthorizationViewController_Private.h>
+#import <PassKitCore/PKPaymentMerchantSession.h>
+#import <WebCore/PaymentAuthorizationStatus.h>
+#import <WebCore/PaymentHeaders.h>
+#import <WebCore/SoftLinking.h>
+#import <WebCore/URL.h>
+#import <wtf/RunLoop.h>
+
+#if PLATFORM(MAC)
+SOFT_LINK_PRIVATE_FRAMEWORK(PassKit)
+#else
+SOFT_LINK_FRAMEWORK(PassKit)
+#endif
+
+#if PLATFORM(MAC)
+// FIXME: Once <rdar://problem/26074851> has been fixed we no longer
+// have to fall back to PKInAppPaymentService.
+#import <PassKitCore/PKInAppPaymentService.h>
+SOFT_LINK_CLASS(PassKit, PKInAppPaymentService)
+#endif
+
+SOFT_LINK_CLASS(PassKit, PKPaymentAuthorizationViewController);
+SOFT_LINK_CLASS(PassKit, PKPaymentMerchantSession);
+SOFT_LINK_CLASS(PassKit, PKPaymentRequest);
+SOFT_LINK_CLASS(PassKit, PKPaymentSummaryItem);
+SOFT_LINK_CLASS(PassKit, PKShippingMethod);
+SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkAmex, NSString *);
+SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkChinaUnionPay, NSString *);
+SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkDiscover, NSString *);
+SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkInterac, NSString *);
+SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkMasterCard, NSString *);
+SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkPrivateLabel, NSString *);
+SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkVisa, NSString *);
+
+typedef void (^PKCanMakePaymentsCompletion)(BOOL isValid, NSError *error);
+extern "C" void PKCanMakePaymentsWithMerchantIdentifierAndDomain(NSString *identifier, NSString *domain, PKCanMakePaymentsCompletion completion);
+
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebKit, PassKit, PKCanMakePaymentsWithMerchantIdentifierAndDomain, void, (NSString *identifier, NSString *domain, PKCanMakePaymentsCompletion completion), (identifier, domain, completion));
+
+@implementation WKPaymentAuthorizationViewControllerDelegate
+
+- (instancetype)initWithPaymentCoordinatorProxy:(WebKit::WebPaymentCoordinatorProxy&)webPaymentCoordinatorProxy
+{
+    if (!(self = [super init]))
+        return nullptr;
+
+    _webPaymentCoordinatorProxy = &webPaymentCoordinatorProxy;
+
+    return self;
+}
+
+- (void)invalidate
+{
+    _webPaymentCoordinatorProxy = nullptr;
+    if (_paymentAuthorizedCompletion) {
+        _paymentAuthorizedCompletion(PKPaymentAuthorizationStatusFailure);
+        _paymentAuthorizedCompletion = nullptr;
+    }
+}
+
+- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller willFinishWithError:(NSError *)error
+{
+}
+
+- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didRequestMerchantSession:(void(^)(PKPaymentMerchantSession *, NSError *))sessionBlock
+{
+    ASSERT(!_sessionBlock);
+    _sessionBlock = sessionBlock;
+
+    [getPKPaymentAuthorizationViewControllerClass() paymentServicesMerchantURL:^(NSURL *merchantURL, NSError *error) {
+        if (error)
+            LOG_ERROR("PKCanMakePaymentsWithMerchantIdentifierAndDomain error %@", error);
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            ASSERT(_sessionBlock);
+
+            if (!_webPaymentCoordinatorProxy) {
+                _sessionBlock(nullptr, nullptr);
+                return;
+            }
+
+            _webPaymentCoordinatorProxy->validateMerchant(merchantURL);
+        });
+    }];
+}
+
+- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion
+{
+    if (!_webPaymentCoordinatorProxy) {
+        completion(PKPaymentAuthorizationStatusFailure);
+        return;
+    }
+
+    ASSERT(!_paymentAuthorizedCompletion);
+    _paymentAuthorizedCompletion = completion;
+
+    _webPaymentCoordinatorProxy->didAuthorizePayment(WebCore::Payment(payment));
+}
+
+- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
+{
+    if (!_webPaymentCoordinatorProxy)
+        return;
+
+    if (!_authorized)
+        _webPaymentCoordinatorProxy->didCancelPayment();
+
+    _webPaymentCoordinatorProxy->hidePaymentUI();
+}
+
+static WebCore::PaymentRequest::ShippingMethod toShippingMethod(PKShippingMethod *shippingMethod)
+{
+    ASSERT(shippingMethod);
+
+    WebCore::PaymentRequest::ShippingMethod result;
+    result.label = shippingMethod.label;
+    result.detail = shippingMethod.detail;
+    result.amount = [shippingMethod.amount decimalNumberByMultiplyingByPowerOf10:2].integerValue;
+    result.identifier = shippingMethod.identifier;
+
+    return result;
+}
+
+- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKPaymentSummaryItem *> *summaryItems))completion
+{
+    if (!_webPaymentCoordinatorProxy) {
+        completion(PKPaymentAuthorizationStatusFailure, @[]);
+        return;
+    }
+
+    ASSERT(!_didSelectShippingMethodCompletion);
+    _didSelectShippingMethodCompletion = completion;
+    _webPaymentCoordinatorProxy->didSelectShippingMethod(toShippingMethod(shippingMethod));
+}
+
+- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> *shippingMethods, NSArray<PKPaymentSummaryItem *> *summaryItems))completion
+{
+    if (!_webPaymentCoordinatorProxy) {
+        completion(PKPaymentAuthorizationStatusFailure, @[], @[]);
+        return;
+    }
+
+    ASSERT(!_didSelectShippingContactCompletion);
+    _didSelectShippingContactCompletion = completion;
+    _webPaymentCoordinatorProxy->didSelectShippingContact(WebCore::PaymentContact(contact));
+}
+
+- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectPaymentMethod:(PKPaymentMethod *)paymentMethod completion:(void (^)(NSArray<PKPaymentSummaryItem *> *summaryItems))completion
+{
+    if (!_webPaymentCoordinatorProxy) {
+        completion(@[]);
+        return;
+    }
+
+    ASSERT(!_didSelectPaymentMethodCompletion);
+    _didSelectPaymentMethodCompletion = completion;
+
+    _webPaymentCoordinatorProxy->didSelectPaymentMethod(WebCore::PaymentMethod(paymentMethod));
+}
+
+@end
+
+// FIXME: Once rdar://problem/24420024 has been fixed, import PKPaymentRequest_Private.h instead.
+@interface PKPaymentRequest ()
+@property (nonatomic, retain) NSURL *originatingURL;
+@end
+
+@interface PKPaymentRequest ()
+// FIXME: Remove this once it's in an SDK.
+@property (nonatomic, strong) NSArray *thumbnailURLs;
+@property (nonatomic, strong) NSURL *thumbnailURL;
+
+@property (nonatomic, assign) BOOL expectsMerchantSession;
+@end
+
+namespace WebKit {
+
+bool WebPaymentCoordinatorProxy::platformCanMakePayments()
+{
+    return [getPKPaymentAuthorizationViewControllerClass() canMakePayments];
+}
+
+void WebPaymentCoordinatorProxy::platformCanMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler)
+{
+    if (!canLoad_PassKit_PKCanMakePaymentsWithMerchantIdentifierAndDomain()) {
+        RunLoop::main().dispatch([completionHandler] {
+            completionHandler(false);
+        });
+        return;
+    }
+
+    softLink_PassKit_PKCanMakePaymentsWithMerchantIdentifierAndDomain(merchantIdentifier, domainName, [completionHandler](BOOL canMakePayments, NSError *error) {
+        if (error)
+            LOG_ERROR("PKCanMakePaymentsWithMerchantIdentifierAndDomain error %@", error);
+
+        RunLoop::main().dispatch([completionHandler, canMakePayments] {
+            completionHandler(canMakePayments);
+        });
+    });
+}
+
+static PKAddressField toPKAddressField(const WebCore::PaymentRequest::AddressFields& addressFields)
+{
+    PKAddressField result = 0;
+
+    if (addressFields.postalAddress)
+        result |= PKAddressFieldPostalAddress;
+    if (addressFields.phone)
+        result |= PKAddressFieldPhone;
+    if (addressFields.email)
+        result |= PKAddressFieldEmail;
+    if (addressFields.name)
+        result |= PKAddressFieldName;
+
+    return result;
+}
+
+static PKPaymentSummaryItemType toPKPaymentSummaryItemType(WebCore::PaymentRequest::LineItem::Type type)
+{
+    switch (type) {
+    case WebCore::PaymentRequest::LineItem::Type::Final:
+        return PKPaymentSummaryItemTypeFinal;
+
+    case WebCore::PaymentRequest::LineItem::Type::Pending:
+        return PKPaymentSummaryItemTypePending;
+    }
+}
+
+static RetainPtr<PKPaymentSummaryItem> toPKPaymentSummaryItem(const WebCore::PaymentRequest::LineItem& lineItem)
+{
+    auto amount = adoptNS([[NSDecimalNumber alloc] initWithMantissa:lineItem.amount.valueOr(0) exponent:-2 isNegative:*lineItem.amount < 0]);
+
+    return [getPKPaymentSummaryItemClass() summaryItemWithLabel:lineItem.label amount:amount.get() type:toPKPaymentSummaryItemType(lineItem.type)];
+}
+
+static PKMerchantCapability toPKMerchantCapabilities(const WebCore::PaymentRequest::MerchantCapabilities& merchantCapabilities)
+{
+    PKMerchantCapability result = 0;
+    if (merchantCapabilities.supports3DS)
+        result |= PKMerchantCapability3DS;
+    if (merchantCapabilities.supportsEMV)
+        result |= PKMerchantCapabilityEMV;
+    if (merchantCapabilities.supportsCredit)
+        result |= PKMerchantCapabilityCredit;
+    if (merchantCapabilities.supportsDebit)
+        result |= PKMerchantCapabilityDebit;
+
+    return result;
+}
+
+static RetainPtr<NSArray> toSupportedNetworks(const WebCore::PaymentRequest::SupportedNetworks& supportedNetworks)
+{
+    auto result = adoptNS([[NSMutableArray alloc] init]);
+
+    if (supportedNetworks.amex)
+        [result addObject:getPKPaymentNetworkAmex()];
+    if (supportedNetworks.chinaUnionPay)
+        [result addObject:getPKPaymentNetworkChinaUnionPay()];
+    if (supportedNetworks.discover)
+        [result addObject:getPKPaymentNetworkDiscover()];
+    if (supportedNetworks.interac)
+        [result addObject:getPKPaymentNetworkInterac()];
+    if (supportedNetworks.masterCard)
+        [result addObject:getPKPaymentNetworkMasterCard()];
+    if (supportedNetworks.privateLabel)
+        [result addObject:getPKPaymentNetworkPrivateLabel()];
+    if (supportedNetworks.visa)
+        [result addObject:getPKPaymentNetworkVisa()];
+
+    return result;
+}
+
+static PKShippingType toPKShippingType(WebCore::PaymentRequest::ShippingType shippingType)
+{
+    switch (shippingType) {
+    case WebCore::PaymentRequest::ShippingType::Shipping:
+        return PKShippingTypeShipping;
+
+    case WebCore::PaymentRequest::ShippingType::Delivery:
+        return PKShippingTypeDelivery;
+
+    case WebCore::PaymentRequest::ShippingType::StorePickup:
+        return PKShippingTypeStorePickup;
+
+    case WebCore::PaymentRequest::ShippingType::ServicePickup:
+        return PKShippingTypeServicePickup;
+    }
+}
+
+static RetainPtr<PKShippingMethod> toPKShippingMethod(const WebCore::PaymentRequest::ShippingMethod& shippingMethod)
+{
+    auto amount = adoptNS([[NSDecimalNumber alloc] initWithMantissa:shippingMethod.amount exponent:-2 isNegative:NO]);
+
+    RetainPtr<PKShippingMethod> result = [getPKShippingMethodClass() summaryItemWithLabel:shippingMethod.label amount:amount.get()];
+    [result setIdentifier:shippingMethod.identifier];
+    [result setDetail:shippingMethod.detail];
+
+    return result;
+}
+
+static RetainPtr<PKPaymentMerchantSession> toPKPaymentMerchantSession(const WebCore::PaymentMerchantSession& paymentMerchantSession)
+{
+    NSDictionary *dictionary = @{
+        @"merchantSessionIdentifier" : paymentMerchantSession.sessionIdentifier,
+        @"merchantIdentifier" : paymentMerchantSession.merchantIdentifier,
+        @"nOnce" : paymentMerchantSession.nonce,
+        @"epochTimestamp" : @(static_cast<NSUInteger>(paymentMerchantSession.epochTimestamp)),
+        @"FQDN" : paymentMerchantSession.domainName,
+        @"signature" : paymentMerchantSession.signature,
+    };
+
+    return adoptNS([allocPKPaymentMerchantSessionInstance() initWithDictionary:dictionary]);
+}
+
+RetainPtr<PKPaymentRequest> toPKPaymentRequest(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest& paymentRequest)
+{
+    auto result = adoptNS([allocPKPaymentRequestInstance() init]);
+
+    [result setOriginatingURL:originatingURL];
+
+    if ([result respondsToSelector:@selector(setThumbnailURLs:)]) {
+        auto thumbnailURLs = adoptNS([[NSMutableArray alloc] init]);
+        for (auto& linkIconURL : linkIconURLs)
+            [thumbnailURLs addObject:static_cast<NSURL *>(linkIconURL)];
+
+        [result setThumbnailURLs:thumbnailURLs.get()];
+    } else if (!linkIconURLs.isEmpty())
+        [result setThumbnailURL:linkIconURLs[0]];
+
+    [result setCountryCode:paymentRequest.countryCode()];
+    [result setCurrencyCode:paymentRequest.currencyCode()];
+    [result setRequiredBillingAddressFields:toPKAddressField(paymentRequest.requiredBillingAddressFields())];
+    [result setBillingContact:paymentRequest.billingContact().pkContact()];
+    [result setRequiredShippingAddressFields:toPKAddressField(paymentRequest.requiredShippingAddressFields())];
+    [result setShippingContact:paymentRequest.shippingContact().pkContact()];
+
+    [result setSupportedNetworks:toSupportedNetworks(paymentRequest.supportedNetworks()).get()];
+    [result setMerchantCapabilities:toPKMerchantCapabilities(paymentRequest.merchantCapabilities())];
+
+    [result setShippingType:toPKShippingType(paymentRequest.shippingType())];
+
+    auto shippingMethods = adoptNS([[NSMutableArray alloc] init]);
+    for (auto& shippingMethod : paymentRequest.shippingMethods())
+        [shippingMethods addObject:toPKShippingMethod(shippingMethod).get()];
+    [result setShippingMethods:shippingMethods.get()];
+
+    auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
+    for (auto& lineItem : paymentRequest.lineItems()) {
+        if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
+            [paymentSummaryItems addObject:summaryItem.get()];
+    }
+
+    if (auto totalItem = toPKPaymentSummaryItem(paymentRequest.total()))
+        [paymentSummaryItems addObject:totalItem.get()];
+
+    [result setPaymentSummaryItems:paymentSummaryItems.get()];
+
+    [result setExpectsMerchantSession:YES];
+
+    if (!paymentRequest.applicationData().isNull()) {
+        auto applicationData = adoptNS([[NSData alloc] initWithBase64EncodedString:paymentRequest.applicationData() options:0]);
+        [result setApplicationData:applicationData.get()];
+    }
+
+    return result;
+}
+
+static PKPaymentAuthorizationStatus toPKPaymentAuthorizationStatus(WebCore::PaymentAuthorizationStatus status)
+{
+    switch (status) {
+    case WebCore::PaymentAuthorizationStatus::Success:
+        return PKPaymentAuthorizationStatusSuccess;
+    case WebCore::PaymentAuthorizationStatus::Failure:
+        return PKPaymentAuthorizationStatusFailure;
+    case WebCore::PaymentAuthorizationStatus::InvalidBillingPostalAddress:
+        return PKPaymentAuthorizationStatusInvalidBillingPostalAddress;
+    case WebCore::PaymentAuthorizationStatus::InvalidShippingPostalAddress:
+        return PKPaymentAuthorizationStatusInvalidShippingPostalAddress;
+    case WebCore::PaymentAuthorizationStatus::InvalidShippingContact:
+        return PKPaymentAuthorizationStatusInvalidShippingContact;
+    case WebCore::PaymentAuthorizationStatus::PINRequired:
+        return PKPaymentAuthorizationStatusPINRequired;
+    case WebCore::PaymentAuthorizationStatus::PINIncorrect:
+        return PKPaymentAuthorizationStatusPINIncorrect;
+    case WebCore::PaymentAuthorizationStatus::PINLockout:
+        return PKPaymentAuthorizationStatusPINLockout;
+    }
+}
+
+void WebPaymentCoordinatorProxy::platformCompletePaymentSession(WebCore::PaymentAuthorizationStatus status)
+{
+    ASSERT(m_paymentAuthorizationViewController);
+    ASSERT(m_paymentAuthorizationViewControllerDelegate);
+
+    m_paymentAuthorizationViewControllerDelegate->_authorized = YES;
+    m_paymentAuthorizationViewControllerDelegate->_paymentAuthorizedCompletion(toPKPaymentAuthorizationStatus(status));
+    m_paymentAuthorizationViewControllerDelegate->_paymentAuthorizedCompletion = nullptr;
+}
+
+void WebPaymentCoordinatorProxy::platformCompleteMerchantValidation(const WebCore::PaymentMerchantSession& paymentMerchantSession)
+{
+    ASSERT(m_paymentAuthorizationViewController);
+    ASSERT(m_paymentAuthorizationViewControllerDelegate);
+
+    m_paymentAuthorizationViewControllerDelegate->_sessionBlock(toPKPaymentMerchantSession(paymentMerchantSession).get(), nullptr);
+    m_paymentAuthorizationViewControllerDelegate->_sessionBlock = nullptr;
+}
+
+void WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection(WebCore::PaymentAuthorizationStatus status, const Optional<WebCore::PaymentRequest::TotalAndLineItems>& newTotalAndLineItems)
+{
+    ASSERT(m_paymentAuthorizationViewController);
+    ASSERT(m_paymentAuthorizationViewControllerDelegate);
+
+    if (newTotalAndLineItems) {
+        auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
+        for (auto& lineItem : newTotalAndLineItems->lineItems) {
+            if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
+                [paymentSummaryItems addObject:summaryItem.get()];
+        }
+
+        if (auto totalItem = toPKPaymentSummaryItem(newTotalAndLineItems->total))
+            [paymentSummaryItems addObject:totalItem.get()];
+
+        m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = WTFMove(paymentSummaryItems);
+    }
+
+    m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion(toPKPaymentAuthorizationStatus(status), m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
+    m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion = nullptr;
+}
+
+void WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection(WebCore::PaymentAuthorizationStatus status, const Vector<WebCore::PaymentRequest::ShippingMethod>& newShippingMethods, const Optional<WebCore::PaymentRequest::TotalAndLineItems>& newTotalAndLineItems)
+{
+    ASSERT(m_paymentAuthorizationViewController);
+    ASSERT(m_paymentAuthorizationViewControllerDelegate);
+
+    if (newTotalAndLineItems) {
+        auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
+        for (auto& lineItem : newTotalAndLineItems->lineItems) {
+            if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
+                [paymentSummaryItems addObject:summaryItem.get()];
+        }
+
+        if (auto totalItem = toPKPaymentSummaryItem(newTotalAndLineItems->total))
+            [paymentSummaryItems addObject:totalItem.get()];
+
+        m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = WTFMove(paymentSummaryItems);
+
+        auto shippingMethods = adoptNS([[NSMutableArray alloc] init]);
+        for (auto& shippingMethod : newShippingMethods)
+            [shippingMethods addObject:toPKShippingMethod(shippingMethod).get()];
+
+        m_paymentAuthorizationViewControllerDelegate->_shippingMethods = WTFMove(shippingMethods);
+    }
+
+    m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion(toPKPaymentAuthorizationStatus(status), m_paymentAuthorizationViewControllerDelegate->_shippingMethods.get(), m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
+    m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion = nullptr;
+}
+
+void WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection(const Optional<WebCore::PaymentRequest::TotalAndLineItems>& newTotalAndLineItems)
+{
+    ASSERT(m_paymentAuthorizationViewController);
+    ASSERT(m_paymentAuthorizationViewControllerDelegate);
+
+    if (newTotalAndLineItems) {
+        auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
+        for (auto& lineItem : newTotalAndLineItems->lineItems) {
+            if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
+                [paymentSummaryItems addObject:summaryItem.get()];
+        }
+
+        if (auto totalItem = toPKPaymentSummaryItem(newTotalAndLineItems->total))
+            [paymentSummaryItems addObject:totalItem.get()];
+
+        m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = WTFMove(paymentSummaryItems);
+    }
+
+    m_paymentAuthorizationViewControllerDelegate->_didSelectPaymentMethodCompletion(m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
+    m_paymentAuthorizationViewControllerDelegate->_didSelectPaymentMethodCompletion = nullptr;
+}
+
+}
+
+#endif
+
diff --git a/Source/WebKit2/UIProcess/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm b/Source/WebKit2/UIProcess/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm
new file mode 100644 (file)
index 0000000..7757a52
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebPaymentCoordinatorProxy.h"
+
+#if PLATFORM(IOS) && ENABLE(APPLE_PAY)
+
+#import "APIUIClient.h"
+#import "WebPageProxy.h"
+#import "WebPaymentCoordinatorProxyCocoa.h"
+#import <PassKit/PassKit.h>
+#import <PassKitCore/PKPaymentMerchantSession.h>
+#import <UIKit/UIViewController.h>
+#import <WebCore/PaymentAuthorizationStatus.h>
+#import <WebCore/SoftLinking.h>
+#import <wtf/BlockPtr.h>
+
+SOFT_LINK_FRAMEWORK(PassKit)
+SOFT_LINK_CLASS(PassKit, PKPaymentAuthorizationViewController);
+
+namespace WebKit {
+
+void WebPaymentCoordinatorProxy::platformShowPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLStrings, const WebCore::PaymentRequest& request, std::function<void (bool)> completionHandler)
+{
+    UIViewController *presentingViewController = m_webPageProxy.uiClient().presentingViewController();
+
+    if (!presentingViewController) {
+        completionHandler(false);
+        return;
+    }
+
+    ASSERT(!m_paymentAuthorizationViewController);
+
+    auto paymentRequest = toPKPaymentRequest(originatingURL, linkIconURLStrings, request);
+
+    m_paymentAuthorizationViewController = adoptNS([allocPKPaymentAuthorizationViewControllerInstance() initWithPaymentRequest:paymentRequest.get()]);
+    if (!m_paymentAuthorizationViewController) {
+        completionHandler(false);
+        return;
+    }
+
+    m_paymentAuthorizationViewControllerDelegate = adoptNS([[WKPaymentAuthorizationViewControllerDelegate alloc] initWithPaymentCoordinatorProxy:*this]);
+    m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = [paymentRequest paymentSummaryItems];
+    m_paymentAuthorizationViewControllerDelegate->_shippingMethods = [paymentRequest shippingMethods];
+
+    [m_paymentAuthorizationViewController setDelegate:m_paymentAuthorizationViewControllerDelegate.get()];
+    [m_paymentAuthorizationViewController setPrivateDelegate:m_paymentAuthorizationViewControllerDelegate.get()];
+
+    [presentingViewController presentViewController:m_paymentAuthorizationViewController.get() animated:YES completion:nullptr];
+
+    completionHandler(true);
+}
+
+void WebPaymentCoordinatorProxy::hidePaymentUI()
+{
+    ASSERT(m_paymentAuthorizationViewController);
+    ASSERT(m_paymentAuthorizationViewControllerDelegate);
+
+    [[m_paymentAuthorizationViewController presentingViewController] dismissViewControllerAnimated:YES completion:nullptr];
+    [m_paymentAuthorizationViewController setDelegate:nil];
+    [m_paymentAuthorizationViewController setPrivateDelegate:nil];
+    m_paymentAuthorizationViewController = nullptr;
+
+    [m_paymentAuthorizationViewControllerDelegate invalidate];
+    m_paymentAuthorizationViewControllerDelegate = nullptr;
+}
+
+}
+
+#endif
diff --git a/Source/WebKit2/UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm b/Source/WebKit2/UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm
new file mode 100644 (file)
index 0000000..2fc974e
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebPaymentCoordinatorProxy.h"
+
+#if PLATFORM(MAC) && ENABLE(APPLE_PAY)
+
+#import "WebPageProxy.h"
+#import "WebPaymentCoordinatorProxyCocoa.h"
+#import <Foundation/NSExtension.h>
+#import <PassKit/PKPaymentAuthorizationViewController_Private.h>
+#import <WebCore/SoftLinking.h>
+
+SOFT_LINK_PRIVATE_FRAMEWORK(PassKit)
+
+SOFT_LINK_CLASS(PassKit, PKPaymentAuthorizationViewController);
+SOFT_LINK_CONSTANT(PassKit, PKExtensionPaymentAuthorizationUIExtensionPointName, NSString *);
+
+namespace WebKit {
+
+void WebPaymentCoordinatorProxy::platformShowPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLStrings, const WebCore::PaymentRequest& request, std::function<void (bool)> completionHandler)
+{
+    auto paymentRequest = toPKPaymentRequest(originatingURL, linkIconURLStrings, request);
+
+    auto showPaymentUIRequestSeed = m_showPaymentUIRequestSeed;
+    auto weakThis = m_weakPtrFactory.createWeakPtr();
+    [getPKPaymentAuthorizationViewControllerClass() requestViewControllerWithPaymentRequest:paymentRequest.get() completion:[paymentRequest, showPaymentUIRequestSeed, weakThis, completionHandler](PKPaymentAuthorizationViewController *viewController, NSError *error) {
+        auto paymentCoordinatorProxy = weakThis.get();
+        if (!paymentCoordinatorProxy)
+            return;
+
+        if (error) {
+            LOG_ERROR("+[PKPaymentAuthorizationViewController requestViewControllerWithPaymentRequest:completion:] error %@", error);
+
+            completionHandler(false);
+            return;
+        }
+
+        if (showPaymentUIRequestSeed != paymentCoordinatorProxy->m_showPaymentUIRequestSeed) {
+            // We've already been asked to hide the payment UI. Don't attempt to show it.
+            return;
+        }
+
+        ASSERT(viewController);
+
+        paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate = adoptNS([[WKPaymentAuthorizationViewControllerDelegate alloc] initWithPaymentCoordinatorProxy:*paymentCoordinatorProxy]);
+        paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = [paymentRequest paymentSummaryItems];
+        paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate->_shippingMethods = [paymentRequest shippingMethods];
+        paymentCoordinatorProxy->m_paymentAuthorizationViewController = viewController;
+        [paymentCoordinatorProxy->m_paymentAuthorizationViewController setDelegate:paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate.get()];
+        [paymentCoordinatorProxy->m_paymentAuthorizationViewController setPrivateDelegate:paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate.get()];
+
+        ASSERT(!paymentCoordinatorProxy->m_sheetWindow);
+        paymentCoordinatorProxy->m_sheetWindow = [NSWindow windowWithContentViewController:viewController];
+        [paymentCoordinatorProxy->m_webPageProxy.platformWindow() beginSheet:paymentCoordinatorProxy->m_sheetWindow.get() completionHandler:nullptr];
+
+        completionHandler(true);
+    }];
+}
+
+void WebPaymentCoordinatorProxy::hidePaymentUI()
+{
+    if (m_state == State::Activating) {
+        ++m_showPaymentUIRequestSeed;
+
+        ASSERT(!m_paymentAuthorizationViewController);
+        ASSERT(!m_paymentAuthorizationViewControllerDelegate);
+        ASSERT(!m_sheetWindow);
+        return;
+    }
+
+    ASSERT(m_paymentAuthorizationViewController);
+    ASSERT(m_paymentAuthorizationViewControllerDelegate);
+    ASSERT(m_sheetWindow);
+
+    [[m_sheetWindow sheetParent] endSheet:m_sheetWindow.get()];
+    [m_paymentAuthorizationViewController setDelegate:nil];
+    [m_paymentAuthorizationViewController setPrivateDelegate:nil];
+    m_paymentAuthorizationViewController = nullptr;
+
+    [m_paymentAuthorizationViewControllerDelegate invalidate];
+    m_paymentAuthorizationViewControllerDelegate = nullptr;
+
+    m_sheetWindow = nullptr;
+}
+
+}
+
+extern "C" {
+WK_EXPORT bool WKPreferencesGetApplePayEnabled(WKPreferencesRef preferencesRef);
+WK_EXPORT void WKPreferencesSetApplePayEnabled(WKPreferencesRef preferencesRef, bool enabled);
+
+WK_EXPORT bool WKPreferencesGetApplePayCapabilityDisclosureAllowed(WKPreferencesRef preferencesRef);
+WK_EXPORT void WKPreferencesSetApplePayCapabilityDisclosureAllowed(WKPreferencesRef preferencesRef, bool allowed);
+
+// FIXME: Get rid of these in favor of the ones that mention Apple Pay.
+WK_EXPORT bool WKPreferencesGetPaymentsEnabled(WKPreferencesRef preferencesRef);
+WK_EXPORT void WKPreferencesSetPaymentsEnabled(WKPreferencesRef preferencesRef, bool enabled);
+}
+
+WK_EXPORT bool WKPreferencesGetApplePayEnabled(WKPreferencesRef preferencesRef)
+{
+    return WebKit::toImpl(preferencesRef)->applePayEnabled();
+}
+
+void WKPreferencesSetApplePayEnabled(WKPreferencesRef preferencesRef, bool enabled)
+{
+    WebKit::toImpl(preferencesRef)->setApplePayEnabled(enabled);
+}
+
+bool WKPreferencesGetApplePayCapabilityDisclosureAllowed(WKPreferencesRef preferencesRef)
+{
+    return WebKit::toImpl(preferencesRef)->applePayCapabilityDisclosureAllowed();
+}
+
+void WKPreferencesSetApplePayCapabilityDisclosureAllowed(WKPreferencesRef preferencesRef, bool allowed)
+{
+    WebKit::toImpl(preferencesRef)->setApplePayCapabilityDisclosureAllowed(allowed);
+}
+
+bool WKPreferencesGetPaymentsEnabled(WKPreferencesRef preferencesRef)
+{
+    return WKPreferencesGetApplePayEnabled(preferencesRef);
+}
+
+void WKPreferencesSetPaymentsEnabled(WKPreferencesRef preferencesRef, bool enabled)
+{
+    WKPreferencesSetApplePayEnabled(preferencesRef, enabled);
+}
+#endif
index 5cff824..f303b5c 100644 (file)
@@ -97,6 +97,7 @@
 #include "WebPageGroupData.h"
 #include "WebPageMessages.h"
 #include "WebPageProxyMessages.h"
+#include "WebPaymentCoordinatorProxy.h"
 #include "WebPopupItem.h"
 #include "WebPopupMenuProxy.h"
 #include "WebPreferences.h"
 #include <WebCore/MediaSessionMetadata.h>
 #endif
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <WebKitAdditions/WebPageProxyIncludes.h>
-#endif
-
 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
 #include "WebPlaybackSessionManagerProxy.h"
 #endif
index f4dde36..22dc7f9 100644 (file)
@@ -55,6 +55,7 @@
 #include "WebPageCreationParameters.h"
 #include "WebPageDiagnosticLoggingClient.h"
 #include "WebPageInjectedBundleClient.h"
+#include "WebPaymentCoordinatorProxy.h"
 #include "WebPreferences.h"
 #include <WebCore/AlternativeTextClient.h> // FIXME: Needed by WebPageProxyMessages.h for DICTATION_ALTERNATIVES.
 #include "WebPageProxyMessages.h"
@@ -116,10 +117,6 @@ OBJC_CLASS _WKRemoteObjectRegistry;
 #include <WebCore/WebMediaSessionManagerClient.h>
 #endif
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <WebKitAdditions/WebPageProxyIncludes.h>
-#endif
-
 #if ENABLE(MEDIA_SESSION)
 namespace WebCore {
 class MediaSessionMetadata;
index cb550c8..1c1a856 100644 (file)
                1A6FBD2811E69BC200DB1371 /* NetscapePlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6FBD2611E69BC200DB1371 /* NetscapePlugin.h */; };
                1A6FBD2911E69BC200DB1371 /* NetscapePlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A6FBD2711E69BC200DB1371 /* NetscapePlugin.cpp */; };
                1A7284481959F8040007BCE5 /* SessionStateConversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7284441959ED100007BCE5 /* SessionStateConversion.cpp */; };
-               1A781AE71C5714DA00FB96DD /* WebKitAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A781AE51C5714DA00FB96DD /* WebKitAdditions.mm */; };
                1A7865B916CAC71500ACE83A /* PluginProcessConnectionManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7865B716CAC71500ACE83A /* PluginProcessConnectionManagerMessageReceiver.cpp */; };
                1A7865BA16CAC71500ACE83A /* PluginProcessConnectionManagerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7865B816CAC71500ACE83A /* PluginProcessConnectionManagerMessages.h */; };
                1A7C0DF61B7D1F1000A9B848 /* WKWindowFeaturesRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7C0DF41B7D1F1000A9B848 /* WKWindowFeaturesRef.cpp */; };
                1AB16AE21648656D00290D62 /* RemoteLayerTreeDrawingAreaProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB16AE01648656D00290D62 /* RemoteLayerTreeDrawingAreaProxy.h */; };
                1AB16AE9164B3A8800290D62 /* RemoteLayerTreeContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AB16AE7164B3A8800290D62 /* RemoteLayerTreeContext.mm */; };
                1AB16AEA164B3A8800290D62 /* RemoteLayerTreeContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB16AE8164B3A8800290D62 /* RemoteLayerTreeContext.h */; };
+               1AB1F7741D1B2F8A007C9BD1 /* WebPaymentCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F7711D1B2F7E007C9BD1 /* WebPaymentCoordinator.cpp */; };
+               1AB1F77E1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB1F7781D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h */; };
+               1AB1F77F1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F7791D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.mm */; };
+               1AB1F7801D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F77B1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyIOS.mm */; };
+               1AB1F7811D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F77D1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyMac.mm */; };
+               1AB1F78B1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F7881D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.cpp */; };
+               1AB1F78C1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB1F7891D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h */; };
+               1AB1F7901D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F78E1D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.mm */; };
+               1AB1F7911D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB1F78F1D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.h */; };
+               1AB1F7961D1B3613007C9BD1 /* WebPaymentCoordinatorMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F7921D1B3613007C9BD1 /* WebPaymentCoordinatorMessageReceiver.cpp */; };
+               1AB1F7971D1B3613007C9BD1 /* WebPaymentCoordinatorMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB1F7931D1B3613007C9BD1 /* WebPaymentCoordinatorMessages.h */; };
+               1AB1F7981D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F7941D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessageReceiver.cpp */; };
+               1AB1F7991D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB1F7951D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessages.h */; };
                1AB31A9616BC688100F6DBC9 /* StorageManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB31A9416BC688100F6DBC9 /* StorageManagerMessageReceiver.cpp */; };
                1AB31A9716BC688100F6DBC9 /* StorageManagerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB31A9516BC688100F6DBC9 /* StorageManagerMessages.h */; };
                1AB40EE51BF677E300BA81BE /* WKMenuItemIdentifiers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AB40EE31BF677E300BA81BE /* WKMenuItemIdentifiers.mm */; };
                1A6FBD2711E69BC200DB1371 /* NetscapePlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetscapePlugin.cpp; sourceTree = "<group>"; };
                1A7284441959ED100007BCE5 /* SessionStateConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SessionStateConversion.cpp; sourceTree = "<group>"; };
                1A7284451959ED100007BCE5 /* SessionStateConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SessionStateConversion.h; sourceTree = "<group>"; };
-               1A781AE51C5714DA00FB96DD /* WebKitAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKitAdditions.mm; sourceTree = "<group>"; };
                1A7865B616CAC6FD00ACE83A /* PluginProcessConnectionManager.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = PluginProcessConnectionManager.messages.in; sourceTree = "<group>"; };
                1A7865B716CAC71500ACE83A /* PluginProcessConnectionManagerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginProcessConnectionManagerMessageReceiver.cpp; sourceTree = "<group>"; };
                1A7865B816CAC71500ACE83A /* PluginProcessConnectionManagerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginProcessConnectionManagerMessages.h; sourceTree = "<group>"; };
                1AB16AE01648656D00290D62 /* RemoteLayerTreeDrawingAreaProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteLayerTreeDrawingAreaProxy.h; sourceTree = "<group>"; };
                1AB16AE7164B3A8800290D62 /* RemoteLayerTreeContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteLayerTreeContext.mm; sourceTree = "<group>"; };
                1AB16AE8164B3A8800290D62 /* RemoteLayerTreeContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteLayerTreeContext.h; sourceTree = "<group>"; };
+               1AB1F7711D1B2F7E007C9BD1 /* WebPaymentCoordinator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPaymentCoordinator.cpp; sourceTree = "<group>"; };
+               1AB1F7721D1B2F7E007C9BD1 /* WebPaymentCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPaymentCoordinator.h; sourceTree = "<group>"; };
+               1AB1F7731D1B2F7E007C9BD1 /* WebPaymentCoordinator.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebPaymentCoordinator.messages.in; sourceTree = "<group>"; };
+               1AB1F7781D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPaymentCoordinatorProxyCocoa.h; sourceTree = "<group>"; };
+               1AB1F7791D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPaymentCoordinatorProxyCocoa.mm; sourceTree = "<group>"; };
+               1AB1F77B1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPaymentCoordinatorProxyIOS.mm; sourceTree = "<group>"; };
+               1AB1F77D1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPaymentCoordinatorProxyMac.mm; sourceTree = "<group>"; };
+               1AB1F7881D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPaymentCoordinatorProxy.cpp; sourceTree = "<group>"; };
+               1AB1F7891D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPaymentCoordinatorProxy.h; sourceTree = "<group>"; };
+               1AB1F78A1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebPaymentCoordinatorProxy.messages.in; sourceTree = "<group>"; };
+               1AB1F78E1D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreArgumentCodersCocoa.mm; sourceTree = "<group>"; };
+               1AB1F78F1D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreArgumentCodersCocoa.h; sourceTree = "<group>"; };
+               1AB1F7921D1B3613007C9BD1 /* WebPaymentCoordinatorMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebPaymentCoordinatorMessageReceiver.cpp; path = WebPaymentCoordinatorMessageReceiver.cpp; sourceTree = "<group>"; };
+               1AB1F7931D1B3613007C9BD1 /* WebPaymentCoordinatorMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebPaymentCoordinatorMessages.h; path = WebPaymentCoordinatorMessages.h; sourceTree = "<group>"; };
+               1AB1F7941D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebPaymentCoordinatorProxyMessageReceiver.cpp; path = WebPaymentCoordinatorProxyMessageReceiver.cpp; sourceTree = "<group>"; };
+               1AB1F7951D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebPaymentCoordinatorProxyMessages.h; path = WebPaymentCoordinatorProxyMessages.h; sourceTree = "<group>"; };
                1AB31A9316BC65AB00F6DBC9 /* StorageManager.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = StorageManager.messages.in; sourceTree = "<group>"; };
                1AB31A9416BC688100F6DBC9 /* StorageManagerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageManagerMessageReceiver.cpp; sourceTree = "<group>"; };
                1AB31A9516BC688100F6DBC9 /* StorageManagerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageManagerMessages.h; sourceTree = "<group>"; };
                                518E8EF116B208F000E91429 /* Authentication */,
                                1AAF0C4712B16328008E49E2 /* cf */,
                                C01A25FF12662F2100C9ED55 /* cg */,
-                               37C4C0901814B37B003688B9 /* Cocoa */,
+                               37C4C0901814B37B003688B9 /* cocoa */,
                                51E351C2180F2C8500E53BE9 /* Databases */,
                                BC82836816B3587900A278FE /* EntryPointUtilities */,
                                E170877216D6CFEC00F99226 /* FileAPI */,
                        path = cf;
                        sourceTree = "<group>";
                };
+               1AB1F7701D1B2F5D007C9BD1 /* ApplePay */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1AB1F7711D1B2F7E007C9BD1 /* WebPaymentCoordinator.cpp */,
+                               1AB1F7721D1B2F7E007C9BD1 /* WebPaymentCoordinator.h */,
+                               1AB1F7731D1B2F7E007C9BD1 /* WebPaymentCoordinator.messages.in */,
+                       );
+                       path = ApplePay;
+                       sourceTree = "<group>";
+               };
+               1AB1F7761D1B30A9007C9BD1 /* ApplePay */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1AB1F7771D1B30A9007C9BD1 /* cocoa */,
+                               1AB1F77A1D1B30A9007C9BD1 /* ios */,
+                               1AB1F77C1D1B30A9007C9BD1 /* mac */,
+                               1AB1F7881D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.cpp */,
+                               1AB1F7891D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h */,
+                               1AB1F78A1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.messages.in */,
+                       );
+                       path = ApplePay;
+                       sourceTree = "<group>";
+               };
+               1AB1F7771D1B30A9007C9BD1 /* cocoa */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1AB1F7781D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h */,
+                               1AB1F7791D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.mm */,
+                       );
+                       path = cocoa;
+                       sourceTree = "<group>";
+               };
+               1AB1F77A1D1B30A9007C9BD1 /* ios */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1AB1F77B1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyIOS.mm */,
+                       );
+                       path = ios;
+                       sourceTree = "<group>";
+               };
+               1AB1F77C1D1B30A9007C9BD1 /* mac */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1AB1F77D1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyMac.mm */,
+                       );
+                       path = mac;
+                       sourceTree = "<group>";
+               };
                1AB7D4C71288AA9A00CFD08C /* Downloads */ = {
                        isa = PBXGroup;
                        children = (
                        path = Cocoa;
                        sourceTree = "<group>";
                };
-               37C4C0901814B37B003688B9 /* Cocoa */ = {
+               37C4C0901814B37B003688B9 /* cocoa */ = {
                        isa = PBXGroup;
                        children = (
+                               1AB1F78E1D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.mm */,
+                               1AB1F78F1D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.h */,
                                1A1EF1971A1D5B420023200A /* APIDataCocoa.mm */,
                                378E1A3B181ED6FF0031007A /* APIObject.mm */,
                                37BEC4DF19491486008B4286 /* CompletionHandlerCallChecker.h */,
                                37BEC4DE19491486008B4286 /* CompletionHandlerCallChecker.mm */,
                                C55F916C1C595E440029E92D /* DataDetectionResult.h */,
                                C55F916D1C595E440029E92D /* DataDetectionResult.mm */,
-                               1A781AE51C5714DA00FB96DD /* WebKitAdditions.mm */,
                                37C4C0921814B3AF003688B9 /* WKNSArray.h */,
                                37C4C0911814B3AF003688B9 /* WKNSArray.mm */,
                                373CEAD4185417AE008C363D /* WKNSData.h */,
                                378E1A3F181EDA010031007A /* WKObject.h */,
                                374436871820E7240049579F /* WKObject.mm */,
                        );
+                       name = cocoa;
                        path = Cocoa;
                        sourceTree = "<group>";
                };
                BC032D5C10F436D50058C15A /* WebProcess */ = {
                        isa = PBXGroup;
                        children = (
+                               1AB1F7701D1B2F5D007C9BD1 /* ApplePay */,
                                1C0A19431C8FF1A800FE0EBB /* Automation */,
                                7C6E70F818B2D47E00F24E2E /* cocoa */,
                                3309344B1315B93A0097A7BC /* Cookies */,
                        isa = PBXGroup;
                        children = (
                                BC032DC410F4387C0058C15A /* API */,
+                               1AB1F7761D1B30A9007C9BD1 /* ApplePay */,
                                512F588D12A8836F00629530 /* Authentication */,
                                9955A6E81C79809000EB6A93 /* Automation */,
                                1ABC3DF21899E415004F0626 /* Cocoa */,
                C0CE729D1247E71D00BC0EC4 /* Derived Sources */ = {
                        isa = PBXGroup;
                        children = (
+                               1AB1F7921D1B3613007C9BD1 /* WebPaymentCoordinatorMessageReceiver.cpp */,
+                               1AB1F7931D1B3613007C9BD1 /* WebPaymentCoordinatorMessages.h */,
+                               1AB1F7941D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessageReceiver.cpp */,
+                               1AB1F7951D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessages.h */,
                                512F58A012A883AD00629530 /* AuthenticationManagerMessageReceiver.cpp */,
                                512F58A112A883AD00629530 /* AuthenticationManagerMessages.h */,
                                9955A6F01C79866400EB6A93 /* AutomationBackendDispatchers.cpp */,
                                9391F2CB121B67AD00EBF7E8 /* WebFrameNetworkingContext.h in Headers */,
                                BCB9F6A01123A84B00A137E0 /* WebFramePolicyListenerProxy.h in Headers */,
                                BC9B38A110F538BE00443A15 /* WebFrameProxy.h in Headers */,
+                               1AB1F7991D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessages.h in Headers */,
                                BC1BE1E012D54A410004A228 /* WebGeolocationClient.h in Headers */,
                                BC0E5FE512D697160012A72A /* WebGeolocationManager.h in Headers */,
                                BC0E606212D6BA910012A72A /* WebGeolocationManagerMessages.h in Headers */,
                                BC306824125A6B9400E71278 /* WebProcessCreationParameters.h in Headers */,
                                1AFA4B901A65A9E2006C4AB4 /* WebProcessLifetimeObserver.h in Headers */,
                                1AFA4B8C1A65A1D0006C4AB4 /* WebProcessLifetimeTracker.h in Headers */,
+                               1AB1F78C1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h in Headers */,
                                BC3066BF125A442100E71278 /* WebProcessMessages.h in Headers */,
                                7CE4D21B1A4914A300C7F152 /* WebProcessPool.h in Headers */,
                                7CE4D2281A4916C200C7F152 /* WebProcessPoolMessages.h in Headers */,
                                3309345B1315B9980097A7BC /* WKCookieManager.h in Headers */,
                                512F58FA12A88A5400629530 /* WKCredential.h in Headers */,
                                518ACF1112B015F800B04B83 /* WKCredentialTypes.h in Headers */,
+                               1AB1F7971D1B3613007C9BD1 /* WebPaymentCoordinatorMessages.h in Headers */,
                                BC4075F8124FF0270068F20A /* WKData.h in Headers */,
                                377EAD4517E2C51A002D193D /* WKDeclarationSpecifiers.h in Headers */,
                                8372DB2F1A677D4A00C697C5 /* WKDiagnosticLoggingResultType.h in Headers */,
                                1AD01BCD1905D54900C9C45F /* WKReloadFrameErrorRecoveryAttempter.h in Headers */,
                                1A9E329B1822E1CC00F5D04C /* WKRemoteObject.h in Headers */,
                                1A9E329F1822FEDD00F5D04C /* WKRemoteObjectCoder.h in Headers */,
+                               1AB1F7911D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.h in Headers */,
                                37948409150C4B9700E52CE9 /* WKRenderLayer.h in Headers */,
                                37608823150414F700FC82C7 /* WKRenderObject.h in Headers */,
                                3336763B130C99DC006C9DE2 /* WKResourceCacheManager.h in Headers */,
                                A19DD3C01D07D16800AC823B /* _WKWebViewPrintFormatterInternal.h in Headers */,
+                               1AB1F77E1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h in Headers */,
                                BC8A501511765F5600757573 /* WKRetainPtr.h in Headers */,
                                1A7E377918E4A4FE003D0FFF /* WKScriptMessage.h in Headers */,
                                1A7E377518E4A33A003D0FFF /* WKScriptMessageHandler.h in Headers */,
                                BCC43ABA127B95DC00317F16 /* PlatformPopupMenuData.cpp in Sources */,
                                1A6FB7D211E651E200DB1371 /* Plugin.cpp in Sources */,
                                31A67E0C165B2A99006CBA66 /* PlugInAutoStartProvider.cpp in Sources */,
+                               1AB1F7961D1B3613007C9BD1 /* WebPaymentCoordinatorMessageReceiver.cpp in Sources */,
                                1A8EF4CC1252403700F7067F /* PluginControllerProxy.cpp in Sources */,
                                1A2D91A61281D739001EB962 /* PluginControllerProxyMac.mm in Sources */,
                                1A8EF96E1252AF6B00F7067F /* PluginControllerProxyMessageReceiver.cpp in Sources */,
                                1A0EC75F124BC7B2007EF4A5 /* PluginProcessProxy.cpp in Sources */,
                                1A2D90BB1281C931001EB962 /* PluginProcessProxyMac.mm in Sources */,
                                1A043B5D124D5E9D00FFBFB5 /* PluginProcessProxyMessageReceiver.cpp in Sources */,
+                               1AB1F7741D1B2F8A007C9BD1 /* WebPaymentCoordinator.cpp in Sources */,
                                1A043DC2124FF87500FFBFB5 /* PluginProxy.cpp in Sources */,
                                1A2D92211281DC1B001EB962 /* PluginProxyMac.mm in Sources */,
                                1A8EFA701252B84100F7067F /* PluginProxyMessageReceiver.cpp in Sources */,
                                51834592134532E90092B696 /* WebIconDatabaseClient.cpp in Sources */,
                                51D02F64132EC5B900BEAA96 /* WebIconDatabaseMessageReceiver.cpp in Sources */,
                                511B24A6132E095700065A0C /* WebIconDatabaseProxy.cpp in Sources */,
+                               1AB1F77F1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.mm in Sources */,
                                51D02F6B132EC73700BEAA96 /* WebIconDatabaseProxyMessageReceiver.cpp in Sources */,
                                5105236F1C739D42007993CB /* WebIDBConnectionToClient.cpp in Sources */,
                                510523791C73DA77007993CB /* WebIDBConnectionToClientMessageReceiver.cpp in Sources */,
                                C0337DD3127A2A0E008FF4F4 /* WebKeyboardEvent.cpp in Sources */,
                                1A6280F31919982A006AD9F9 /* WebKit.m in Sources */,
                                BC9BA5041697C45300E44616 /* WebKit2Initialize.cpp in Sources */,
-                               1A781AE71C5714DA00FB96DD /* WebKitAdditions.mm in Sources */,
                                51FB08FF1639DE1A00EC324A /* WebLoaderStrategy.cpp in Sources */,
                                CD003A5219D49B5D005ABCE0 /* WebMediaKeyStorageManager.cpp in Sources */,
                                C98C48A51B6FD4C300145103 /* WebMediaSessionFocusManager.cpp in Sources */,
                                BC857F8612B82D0B00EDEB2E /* WebOpenPanelResultListener.cpp in Sources */,
                                BC857F7E12B82CEE00EDEB2E /* WebOpenPanelResultListenerProxy.cpp in Sources */,
                                BC963D6B113DD19200574BE2 /* WebPage.cpp in Sources */,
+                               1AB1F78B1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.cpp in Sources */,
                                C06C6095124C144B0001682F /* WebPageCreationParameters.cpp in Sources */,
                                8372DB281A67562800C697C5 /* WebPageDiagnosticLoggingClient.cpp in Sources */,
+                               1AB1F7981D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessageReceiver.cpp in Sources */,
                                BC7B6207129A0A6700D174A4 /* WebPageGroup.cpp in Sources */,
                                BC7B625312A43C9600D174A4 /* WebPageGroupData.cpp in Sources */,
                                BC7B621612A4219A00D174A4 /* WebPageGroupProxy.cpp in Sources */,
                                EDCA71B7128DDA8C00201B26 /* WKBundlePageOverlay.cpp in Sources */,
                                BC60C57A1240A546008C5E29 /* WKBundleRangeHandle.cpp in Sources */,
                                BC14DF9E120B635F00826C0C /* WKBundleScriptWorld.cpp in Sources */,
+                               1AB1F7801D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyIOS.mm in Sources */,
                                BC4075F5124FF0270068F20A /* WKCertificateInfo.cpp in Sources */,
                                BC407628124FF0400068F20A /* WKCertificateInfoMac.mm in Sources */,
                                BCA284D61492F2C7001F9042 /* WKConnection.mm in Sources */,
                                3309345A1315B9980097A7BC /* WKCookieManager.cpp in Sources */,
                                512F58F912A88A5400629530 /* WKCredential.cpp in Sources */,
                                BC4075F7124FF0270068F20A /* WKData.cpp in Sources */,
+                               1AB1F7901D1B34A6007C9BD1 /* WebCoreArgumentCodersCocoa.mm in Sources */,
                                1AFF49001833DE78009AB15A /* WKDeprecatedFunctions.cpp in Sources */,
                                BC4075F9124FF0270068F20A /* WKDictionary.cpp in Sources */,
                                BC017D0816260FF4007054F5 /* WKDOMDocument.mm in Sources */,
                                0FCB4E6918BBE3D9000FCFC9 /* WKTextInputWindowController.mm in Sources */,
                                BC407607124FF0270068F20A /* WKType.cpp in Sources */,
                                7CD5EBBE1746B04C000C1C45 /* WKTypeRefWrapper.mm in Sources */,
+                               1AB1F7811D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyMac.mm in Sources */,
                                BC407609124FF0270068F20A /* WKURL.cpp in Sources */,
                                BC40761B124FF0370068F20A /* WKURLCF.mm in Sources */,
                                BC40760B124FF0270068F20A /* WKURLRequest.cpp in Sources */,
diff --git a/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.cpp b/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.cpp
new file mode 100644 (file)
index 0000000..c7b2a9d
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebPaymentCoordinator.h"
+
+#if ENABLE(APPLE_PAY)
+
+#include "DataReference.h"
+#include "WebPage.h"
+#include "WebPaymentCoordinatorMessages.h"
+#include "WebPaymentCoordinatorProxyMessages.h"
+#include "WebProcess.h"
+#include <WebCore/MainFrame.h>
+#include <WebCore/PaymentCoordinator.h>
+#include <WebCore/URL.h>
+
+namespace WebKit {
+
+WebPaymentCoordinator::WebPaymentCoordinator(WebPage& webPage)
+    : m_webPage(webPage)
+{
+    WebProcess::singleton().addMessageReceiver(Messages::WebPaymentCoordinator::messageReceiverName(), m_webPage.pageID(), *this);
+}
+
+WebPaymentCoordinator::~WebPaymentCoordinator()
+{
+    WebProcess::singleton().removeMessageReceiver(Messages::WebPaymentCoordinator::messageReceiverName(), m_webPage.pageID());
+}
+
+bool WebPaymentCoordinator::supportsVersion(unsigned version)
+{
+    ASSERT(version > 0);
+
+    if (version == 1)
+        return true;
+
+    return false;
+}
+
+bool WebPaymentCoordinator::canMakePayments()
+{
+    bool canMakePayments;
+    if (!m_webPage.sendSync(Messages::WebPaymentCoordinatorProxy::CanMakePayments(), Messages::WebPaymentCoordinatorProxy::CanMakePayments::Reply(canMakePayments)))
+        return false;
+
+    return canMakePayments;
+}
+
+static uint64_t generateCanMakePaymentsWithActiveCardReplyID()
+{
+    static uint64_t canMakePaymentsWithActiveCardReplyID;
+
+    return ++canMakePaymentsWithActiveCardReplyID;
+}
+
+void WebPaymentCoordinator::canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler)
+{
+    auto replyID = generateCanMakePaymentsWithActiveCardReplyID();
+
+    m_pendingCanMakePaymentsWithActiveCardCallbacks.add(replyID, WTFMove(completionHandler));
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::CanMakePaymentsWithActiveCard(merchantIdentifier, domainName, replyID));
+}
+
+void WebPaymentCoordinator::showPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest& paymentRequest)
+{
+    Vector<String> linkIconURLStrings;
+    for (const auto& linkIconURL : linkIconURLs)
+        linkIconURLStrings.append(linkIconURL.string());
+
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::ShowPaymentUI(originatingURL.string(), linkIconURLStrings, paymentRequest));
+}
+
+void WebPaymentCoordinator::completeMerchantValidation(const WebCore::PaymentMerchantSession& paymentMerchantSession)
+{
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::CompleteMerchantValidation(paymentMerchantSession));
+}
+
+void WebPaymentCoordinator::completeShippingMethodSelection(WebCore::PaymentAuthorizationStatus status, Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems)
+{
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::CompleteShippingMethodSelection(static_cast<uint32_t>(status), newTotalAndItems));
+}
+
+void WebPaymentCoordinator::completeShippingContactSelection(WebCore::PaymentAuthorizationStatus status, const Vector<WebCore::PaymentRequest::ShippingMethod>& newShippingMethods, Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems)
+{
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::CompleteShippingContactSelection(static_cast<uint32_t>(status), newShippingMethods, newTotalAndItems));
+}
+
+void WebPaymentCoordinator::completePaymentMethodSelection(Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems)
+{
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::CompletePaymentMethodSelection(newTotalAndItems));
+}
+
+void WebPaymentCoordinator::completePaymentSession(WebCore::PaymentAuthorizationStatus status)
+{
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::CompletePaymentSession(static_cast<uint32_t>(status)));
+}
+
+void WebPaymentCoordinator::abortPaymentSession()
+{
+    m_webPage.send(Messages::WebPaymentCoordinatorProxy::AbortPaymentSession());
+}
+
+void WebPaymentCoordinator::mainFrameDestroyed()
+{
+    delete this;
+}
+
+void WebPaymentCoordinator::validateMerchant(const String& validationURLString)
+{
+    paymentCoordinator().validateMerchant(WebCore::URL(WebCore::URL(), validationURLString));
+}
+
+void WebPaymentCoordinator::didAuthorizePayment(const WebCore::Payment& payment)
+{
+    paymentCoordinator().didAuthorizePayment(payment);
+}
+
+void WebPaymentCoordinator::didSelectShippingMethod(const WebCore::PaymentRequest::ShippingMethod& shippingMethod)
+{
+    paymentCoordinator().didSelectShippingMethod(shippingMethod);
+}
+
+void WebPaymentCoordinator::didSelectShippingContact(const WebCore::PaymentContact& shippingContact)
+{
+    paymentCoordinator().didSelectShippingContact(shippingContact);
+}
+
+void WebPaymentCoordinator::didSelectPaymentMethod(const WebCore::PaymentMethod& paymentMethod)
+{
+    paymentCoordinator().didSelectPaymentMethod(paymentMethod);
+}
+
+void WebPaymentCoordinator::didCancelPayment()
+{
+    paymentCoordinator().didCancelPayment();
+}
+
+void WebPaymentCoordinator::canMakePaymentsWithActiveCardReply(uint64_t requestID, bool canMakePayments)
+{
+    auto callback = m_pendingCanMakePaymentsWithActiveCardCallbacks.take(requestID);
+    callback(canMakePayments);
+}
+
+WebCore::PaymentCoordinator& WebPaymentCoordinator::paymentCoordinator()
+{
+    return m_webPage.mainFrame()->paymentCoordinator();
+}
+
+}
+
+#endif
diff --git a/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.h b/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.h
new file mode 100644 (file)
index 0000000..d362e22
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(APPLE_PAY)
+
+#include "MessageReceiver.h"
+#include <WebCore/PaymentCoordinatorClient.h>
+#include <WebCore/PaymentHeaders.h>
+#include <wtf/Forward.h>
+#include <wtf/HashMap.h>
+
+namespace IPC {
+class DataReference;
+}
+
+namespace WebCore {
+class PaymentCoordinator;
+class PaymentContact;
+}
+
+namespace WebKit {
+
+class WebPage;
+
+class WebPaymentCoordinator final : public WebCore::PaymentCoordinatorClient, private IPC::MessageReceiver {
+public:
+    explicit WebPaymentCoordinator(WebPage&);
+    ~WebPaymentCoordinator();
+
+private:
+    // WebCore::PaymentCoordinatorClient.
+    bool supportsVersion(unsigned version) override;
+    bool canMakePayments() override;
+    void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) override;
+    void showPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest&) override;
+    void completeMerchantValidation(const WebCore::PaymentMerchantSession&) override;
+    void completeShippingMethodSelection(WebCore::PaymentAuthorizationStatus, Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems) override;
+    void completeShippingContactSelection(WebCore::PaymentAuthorizationStatus, const Vector<WebCore::PaymentRequest::ShippingMethod>&, Optional<WebCore::PaymentRequest::TotalAndLineItems> newTotalAndItems) override;
+    void completePaymentMethodSelection(Optional<WebCore::PaymentRequest::TotalAndLineItems>) override;
+    void completePaymentSession(WebCore::PaymentAuthorizationStatus) override;
+    void abortPaymentSession() override;
+
+    void mainFrameDestroyed() override;
+
+    // IPC::MessageReceiver.
+    void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
+
+    // Message handlers.
+    void validateMerchant(const String& validationURLString);
+    void didAuthorizePayment(const WebCore::Payment&);
+    void didSelectShippingMethod(const WebCore::PaymentRequest::ShippingMethod&);
+    void didSelectShippingContact(const WebCore::PaymentContact&);
+    void didSelectPaymentMethod(const WebCore::PaymentMethod&);
+    void didCancelPayment();
+    void canMakePaymentsWithActiveCardReply(uint64_t requestID, bool canMakePayments);
+
+    WebCore::PaymentCoordinator& paymentCoordinator();
+
+    WebPage& m_webPage;
+
+    HashMap<uint64_t, std::function<void (bool)>> m_pendingCanMakePaymentsWithActiveCardCallbacks;
+};
+
+}
+#endif
diff --git a/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.messages.in b/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.messages.in
new file mode 100644 (file)
index 0000000..f53797d
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright (C) 2016 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+#/
+
+#if ENABLE(APPLE_PAY)
+
+messages -> WebPaymentCoordinator {
+
+    ValidateMerchant(String validationURLString)
+    DidAuthorizePayment(WebCore::Payment payment)
+    DidSelectShippingMethod(WebCore::PaymentRequest::ShippingMethod shippingMethod)
+    DidSelectShippingContact(WebCore::PaymentContact shippingContact)
+    DidSelectPaymentMethod(WebCore::PaymentMethod paymentMethod)
+    DidCancelPayment()
+    CanMakePaymentsWithActiveCardReply(uint64_t requestID, bool canMakePayments)
+}
+
+#endif