[Apple Pay] Stop maintaining a list of payment networks
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2017 17:49:29 +0000 (17:49 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2017 17:49:29 +0000 (17:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180965
<rdar://problem/34696560>

Reviewed by Tim Horton.

Source/WebCore:

Instead of maintaining the list of valid payment networks in WebCore, allow the client to
provide the list when constructing a PaymentCoordinator. Then, use PaymentCoordinator's list
to validate ApplePaySessionPaymentRequests.

Validation will now be done case-insensitively since Cocoa clients will provide a list of
network names that differ in capitalization from the names formerly accepted by WebCore.

Added new test cases to http/tests/ssl/applepay/ApplePaySession.html.

* Modules/applepay/ApplePayRequestBase.cpp:
(WebCore::convertAndValidate): Changed to return a Vector of validated strings.
(WebCore::validate): Renamed to convertAndValidate.
* Modules/applepay/ApplePayRequestBase.h:
* Modules/applepay/ApplePaySession.cpp:
(WebCore::convertAndValidate):
(WebCore::ApplePaySession::create):
* Modules/applepay/ApplePaySessionPaymentRequest.cpp:
(WebCore::ApplePaySessionPaymentRequest::isValidSupportedNetwork): Deleted.
* Modules/applepay/ApplePaySessionPaymentRequest.h:
* Modules/applepay/PaymentCoordinator.cpp:
(WebCore::toHashSet):
(WebCore::PaymentCoordinator::PaymentCoordinator): Converted availablePaymentNetworks to a
case-insensitive HashSet and stored in m_availablePaymentNetworks.
(WebCore::PaymentCoordinator::validatedPaymentNetwork const): Added special cases for "jcb"
and "carteBancaire" for API compatibility. For other networks, checked m_availablePaymentNetworks.
* Modules/applepay/PaymentCoordinator.h:
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::show):
* page/MainFrame.cpp:
(WebCore::MainFrame::MainFrame): Constructed m_paymentCoordinator with configuration.availablePaymentNetworks.
* page/PageConfiguration.h:
* testing/Internals.cpp:
(WebCore::Internals::Internals):
* testing/MockPaymentCoordinator.cpp:
* testing/MockPaymentCoordinator.h:

Source/WebCore/PAL:

* pal/spi/cocoa/PassKitSPI.h: Defined +[PKPaymentRequest availableNetworks].

Source/WebKit:

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h: Defined availablePaymentNetworks.
* UIProcess/ApplePay/WebPaymentCoordinatorProxy.h:
* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::toSupportedNetworks):
(WebKit::WebPaymentCoordinatorProxy::availablePaymentNetworks): Called
+[PKPaymentRequest availableNetworks].
(WebKit::toSupportedNetwork): Deleted.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters): Set parameters.availablePaymentNetworks by
calling WebPaymentCoordinatorProxy::availablePaymentNetworks.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage): Set pageConfiguration.availablePaymentNetworks to
parameters.availablePaymentNetworks.

LayoutTests:

* http/tests/ssl/applepay/ApplePaySession-expected.txt:
* http/tests/ssl/applepay/ApplePaySession.html: Added a test case for network names with
varying capitalization.

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

26 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt
LayoutTests/http/tests/ssl/applepay/ApplePaySession.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/ApplePayRequestBase.cpp
Source/WebCore/Modules/applepay/ApplePayRequestBase.h
Source/WebCore/Modules/applepay/ApplePaySession.cpp
Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.cpp
Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.h
Source/WebCore/Modules/applepay/PaymentCoordinator.cpp
Source/WebCore/Modules/applepay/PaymentCoordinator.h
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h
Source/WebCore/page/MainFrame.cpp
Source/WebCore/page/PageConfiguration.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/MockPaymentCoordinator.cpp
Source/WebCore/testing/MockPaymentCoordinator.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h
Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp

index 09044bd..a6a3303 100644 (file)
@@ -1,3 +1,15 @@
+2017-12-19  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Stop maintaining a list of payment networks
+        https://bugs.webkit.org/show_bug.cgi?id=180965
+        <rdar://problem/34696560>
+
+        Reviewed by Tim Horton.
+
+        * http/tests/ssl/applepay/ApplePaySession-expected.txt:
+        * http/tests/ssl/applepay/ApplePaySession.html: Added a test case for network names with
+        varying capitalization.
+
 2017-12-19  Ms2ger  <Ms2ger@igalia.com>
 
         [WPE] Enable the rest of the wpt html tests.
index 805fe00..5c63b9d 100644 (file)
@@ -82,6 +82,9 @@ PASS new ApplePaySession(2, request) threw exception TypeError: "carteBancaire"
 SETUP: request = validRequest(); request.supportedNetworks = ['visa', 'visa'];
 PASS new ApplePaySession(2, request) did not throw exception.
 
+SETUP: request = validRequest(); request.supportedNetworks = ['vIsa', 'MasterCard', 'JCB'];
+PASS new ApplePaySession(2, request) did not throw exception.
+
 Testing PaymentRequest.merchantCapabilities
 
 SETUP: request = validRequest(); delete request.merchantCapabilities;
index 97df234..efec091 100644 (file)
@@ -75,6 +75,7 @@ function go() {
     logAndShouldThrow("request = validRequest(); request.supportedNetworks = ['carteBancaire'];", "new ApplePaySession(2, request)")
     // FIXME: Should duplicate supportedNetworks be allowed?
     logAndShouldNotThrow("request = validRequest(); request.supportedNetworks = ['visa', 'visa'];", "new ApplePaySession(2, request)")
+    logAndShouldNotThrow("request = validRequest(); request.supportedNetworks = ['vIsa', 'MasterCard', 'JCB'];", "new ApplePaySession(2, request)")
     
     debug("Testing PaymentRequest.merchantCapabilities")
     debug("");
index c902096..1dde104 100644 (file)
@@ -1,3 +1,47 @@
+2017-12-19  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Stop maintaining a list of payment networks
+        https://bugs.webkit.org/show_bug.cgi?id=180965
+        <rdar://problem/34696560>
+
+        Reviewed by Tim Horton.
+
+        Instead of maintaining the list of valid payment networks in WebCore, allow the client to
+        provide the list when constructing a PaymentCoordinator. Then, use PaymentCoordinator's list
+        to validate ApplePaySessionPaymentRequests.
+
+        Validation will now be done case-insensitively since Cocoa clients will provide a list of
+        network names that differ in capitalization from the names formerly accepted by WebCore.
+
+        Added new test cases to http/tests/ssl/applepay/ApplePaySession.html.
+
+        * Modules/applepay/ApplePayRequestBase.cpp:
+        (WebCore::convertAndValidate): Changed to return a Vector of validated strings.
+        (WebCore::validate): Renamed to convertAndValidate.
+        * Modules/applepay/ApplePayRequestBase.h:
+        * Modules/applepay/ApplePaySession.cpp:
+        (WebCore::convertAndValidate):
+        (WebCore::ApplePaySession::create):
+        * Modules/applepay/ApplePaySessionPaymentRequest.cpp:
+        (WebCore::ApplePaySessionPaymentRequest::isValidSupportedNetwork): Deleted.
+        * Modules/applepay/ApplePaySessionPaymentRequest.h:
+        * Modules/applepay/PaymentCoordinator.cpp:
+        (WebCore::toHashSet):
+        (WebCore::PaymentCoordinator::PaymentCoordinator): Converted availablePaymentNetworks to a
+        case-insensitive HashSet and stored in m_availablePaymentNetworks.
+        (WebCore::PaymentCoordinator::validatedPaymentNetwork const): Added special cases for "jcb"
+        and "carteBancaire" for API compatibility. For other networks, checked m_availablePaymentNetworks.
+        * Modules/applepay/PaymentCoordinator.h:
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+        (WebCore::ApplePayPaymentHandler::show):
+        * page/MainFrame.cpp:
+        (WebCore::MainFrame::MainFrame): Constructed m_paymentCoordinator with configuration.availablePaymentNetworks.
+        * page/PageConfiguration.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::Internals):
+        * testing/MockPaymentCoordinator.cpp:
+        * testing/MockPaymentCoordinator.h:
+
 2017-12-19  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Unreviewed, try to fix the Windows build after r226097.
index c7bb70d..4b772f2 100644 (file)
 
 #if ENABLE(APPLE_PAY)
 
+#include "PaymentCoordinator.h"
+
 namespace WebCore {
 
-static ExceptionOr<void> validate(unsigned version, const Vector<String>& supportedNetworks)
+static ExceptionOr<Vector<String>> convertAndValidate(unsigned version, const Vector<String>& supportedNetworks, const PaymentCoordinator& paymentCoordinator)
 {
     if (supportedNetworks.isEmpty())
         return Exception { TypeError, "At least one supported network must be provided." };
 
+    Vector<String> result;
+    result.reserveInitialCapacity(supportedNetworks.size());
     for (auto& supportedNetwork : supportedNetworks) {
-        if (!ApplePaySessionPaymentRequest::isValidSupportedNetwork(version, supportedNetwork))
-            return Exception { TypeError, makeString("\"" + supportedNetwork, "\" is not a valid payment network.") };
+        auto validatedNetwork = paymentCoordinator.validatedPaymentNetwork(version, supportedNetwork);
+        if (!validatedNetwork)
+            return Exception { TypeError, makeString("\"", supportedNetwork, "\" is not a valid payment network.") };
+        result.uncheckedAppend(*validatedNetwork);
     }
 
-    return { };
+    return WTFMove(result);
 }
 
-ExceptionOr<ApplePaySessionPaymentRequest> convertAndValidate(unsigned version, ApplePayRequestBase& request)
+ExceptionOr<ApplePaySessionPaymentRequest> convertAndValidate(unsigned version, ApplePayRequestBase& request, const PaymentCoordinator& paymentCoordinator)
 {
     ApplePaySessionPaymentRequest result;
     result.setCountryCode(request.countryCode);
@@ -53,10 +59,10 @@ ExceptionOr<ApplePaySessionPaymentRequest> convertAndValidate(unsigned version,
         return merchantCapabilities.releaseException();
     result.setMerchantCapabilities(merchantCapabilities.releaseReturnValue());
 
-    auto exception = validate(version, WTFMove(request.supportedNetworks));
-    if (exception.hasException())
-        return exception.releaseException();
-    result.setSupportedNetworks(request.supportedNetworks);
+    auto supportedNetworks = convertAndValidate(version, request.supportedNetworks, paymentCoordinator);
+    if (supportedNetworks.hasException())
+        return supportedNetworks.releaseException();
+    result.setSupportedNetworks(supportedNetworks.releaseReturnValue());
 
     if (request.requiredBillingContactFields) {
         auto requiredBillingContactFields = convertAndValidate(version, *request.requiredBillingContactFields);
index d164482..bc89ccd 100644 (file)
@@ -33,6 +33,8 @@
 
 namespace WebCore {
 
+class PaymentCoordinator;
+
 struct ApplePayRequestBase {
     Vector<ApplePayMerchantCapability> merchantCapabilities;
     Vector<String> supportedNetworks;
@@ -45,7 +47,7 @@ struct ApplePayRequestBase {
     Vector<String> supportedCountries;
 };
 
-ExceptionOr<ApplePaySessionPaymentRequest> convertAndValidate(unsigned version, ApplePayRequestBase&);
+ExceptionOr<ApplePaySessionPaymentRequest> convertAndValidate(unsigned version, ApplePayRequestBase&, const PaymentCoordinator&);
 
 } // namespace WebCore
 
index 29c06b4..37da5c8 100644 (file)
@@ -207,9 +207,9 @@ static ExceptionOr<Vector<ApplePaySessionPaymentRequest::ShippingMethod>> conver
     return WTFMove(result);
 }
 
-static ExceptionOr<ApplePaySessionPaymentRequest> convertAndValidate(unsigned version, ApplePayPaymentRequest&& paymentRequest)
+static ExceptionOr<ApplePaySessionPaymentRequest> convertAndValidate(unsigned version, ApplePayPaymentRequest&& paymentRequest, const PaymentCoordinator& paymentCoordinator)
 {
-    auto convertedRequest = convertAndValidate(version, paymentRequest);
+    auto convertedRequest = convertAndValidate(version, paymentRequest, paymentCoordinator);
     if (convertedRequest.hasException())
         return convertedRequest.releaseException();
 
@@ -413,7 +413,7 @@ ExceptionOr<Ref<ApplePaySession>> ApplePaySession::create(Document& document, un
     if (!version || !paymentCoordinator.supportsVersion(version))
         return Exception { InvalidAccessError, makeString("\"" + String::number(version), "\" is not a supported version.") };
 
-    auto convertedPaymentRequest = convertAndValidate(version, WTFMove(paymentRequest));
+    auto convertedPaymentRequest = convertAndValidate(version, WTFMove(paymentRequest), paymentCoordinator);
     if (convertedPaymentRequest.hasException())
         return convertedPaymentRequest.releaseException();
 
index aebf861..aa7b869 100644 (file)
@@ -37,30 +37,6 @@ ApplePaySessionPaymentRequest::ApplePaySessionPaymentRequest() = default;
 
 ApplePaySessionPaymentRequest::~ApplePaySessionPaymentRequest() = default;
 
-bool ApplePaySessionPaymentRequest::isValidSupportedNetwork(unsigned version, const String& supportedNetwork)
-{
-    if (supportedNetwork == "amex")
-        return true;
-    if (supportedNetwork == "chinaUnionPay")
-        return true;
-    if (supportedNetwork == "discover")
-        return true;
-    if (supportedNetwork == "interac")
-        return true;
-    if (supportedNetwork == "masterCard")
-        return true;
-    if (supportedNetwork == "privateLabel")
-        return true;
-    if (supportedNetwork == "visa")
-        return true;
-    if (version >= 2 && supportedNetwork == "jcb")
-        return true;
-    if (version >= 3 && supportedNetwork == "carteBancaire")
-        return true;
-
-    return false;
-}
-
 bool isFinalStateResult(const std::optional<PaymentAuthorizationResult>& result)
 {
     if (!result)
index 1a62c12..ecf4ed0 100644 (file)
@@ -68,8 +68,6 @@ public:
     const PaymentContact& shippingContact() const { return m_shippingContact; }
     void setShippingContact(const PaymentContact& shippingContact) { m_shippingContact = shippingContact; }
 
-    static bool isValidSupportedNetwork(unsigned version, const String&);
-
     const Vector<String>& supportedNetworks() const { return m_supportedNetworks; }
     void setSupportedNetworks(const Vector<String>& supportedNetworks) { m_supportedNetworks = supportedNetworks; }
 
index 8111cf5..025e803 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 namespace WebCore {
 
-PaymentCoordinator::PaymentCoordinator(PaymentCoordinatorClient& client)
-    : m_client(client)
+static HashSet<String, ASCIICaseInsensitiveHash> toHashSet(const Vector<String>& values)
+{
+    HashSet<String, ASCIICaseInsensitiveHash> result;
+    for (auto& value : values)
+        result.add(value);
+    return result;
+}
+
+PaymentCoordinator::PaymentCoordinator(PaymentCoordinatorClient& client, const Vector<String>& availablePaymentNetworks)
+    : m_client { client }
+    , m_availablePaymentNetworks { toHashSet(availablePaymentNetworks) }
 {
 }
 
@@ -194,6 +203,21 @@ void PaymentCoordinator::didCancelPaymentSession()
     m_activeSession = nullptr;
 }
 
+std::optional<String> PaymentCoordinator::validatedPaymentNetwork(unsigned version, const String& paymentNetwork) const
+{
+    if (version < 2 && equalIgnoringASCIICase(paymentNetwork, "jcb"))
+        return std::nullopt;
+
+    if (version < 3 && equalIgnoringASCIICase(paymentNetwork, "carteBancaire"))
+        return std::nullopt;
+
+    auto result = m_availablePaymentNetworks.find(paymentNetwork);
+    if (result == m_availablePaymentNetworks.end())
+        return std::nullopt;
+
+    return *result;
 }
 
-#endif
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)
index af8779b..1d19100 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "ApplePaySessionPaymentRequest.h"
 #include <wtf/Function.h>
+#include <wtf/text/StringHash.h>
 
 namespace WebCore {
 
@@ -47,7 +48,7 @@ struct ShippingMethodUpdate;
 
 class PaymentCoordinator {
 public:
-    WEBCORE_EXPORT explicit PaymentCoordinator(PaymentCoordinatorClient&);
+    WEBCORE_EXPORT PaymentCoordinator(PaymentCoordinatorClient&, const Vector<String>& availablePaymentNetworks);
     WEBCORE_EXPORT ~PaymentCoordinator();
 
     bool supportsVersion(unsigned version) const;
@@ -73,10 +74,13 @@ public:
     WEBCORE_EXPORT void didSelectShippingContact(const PaymentContact&);
     WEBCORE_EXPORT void didCancelPaymentSession();
 
+    std::optional<String> validatedPaymentNetwork(unsigned version, const String&) const;
+
 private:
     PaymentCoordinatorClient& m_client;
 
     RefPtr<PaymentSession> m_activeSession;
+    HashSet<String, ASCIICaseInsensitiveHash> m_availablePaymentNetworks;
 };
 
 }
index 0fb8155..df2b1f5 100644 (file)
@@ -174,7 +174,7 @@ ExceptionOr<void> ApplePayPaymentHandler::convertData(JSC::JSValue&& data)
 
 ExceptionOr<void> ApplePayPaymentHandler::show()
 {
-    auto validatedRequest = convertAndValidate(m_applePayRequest->version, *m_applePayRequest);
+    auto validatedRequest = convertAndValidate(m_applePayRequest->version, *m_applePayRequest, paymentCoordinator());
     if (validatedRequest.hasException())
         return validatedRequest.releaseException();
 
index cbce07a..c2633ee 100644 (file)
@@ -1,3 +1,13 @@
+2017-12-19  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Stop maintaining a list of payment networks
+        https://bugs.webkit.org/show_bug.cgi?id=180965
+        <rdar://problem/34696560>
+
+        Reviewed by Tim Horton.
+
+        * pal/spi/cocoa/PassKitSPI.h: Defined +[PKPaymentRequest availableNetworks].
+
 2017-12-14  David Kilzer  <ddkilzer@apple.com>
 
         Fix 32-bit build: Enable -Wstrict-prototypes for WebKit
index 83cea54..8aad22f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -176,6 +176,7 @@ typedef NSString * PKPaymentNetwork NS_EXTENSIBLE_STRING_ENUM;
 @end
 
 @interface PKPaymentRequest : NSObject
++ (NSArray<PKPaymentNetwork> *)availableNetworks;
 @property (nonatomic, copy) NSString *countryCode;
 @property (nonatomic, copy) NSArray<PKPaymentNetwork> *supportedNetworks;
 @property (nonatomic, assign) PKMerchantCapability merchantCapabilities;
index 56f99de..c122f27 100644 (file)
@@ -49,7 +49,7 @@ inline MainFrame::MainFrame(Page& page, PageConfiguration& configuration)
     , m_recentWheelEventDeltaFilter(WheelEventDeltaFilter::create())
     , m_pageOverlayController(std::make_unique<PageOverlayController>(*this))
 #if ENABLE(APPLE_PAY)
-    , m_paymentCoordinator(std::make_unique<PaymentCoordinator>(*configuration.paymentCoordinatorClient))
+    , m_paymentCoordinator(std::make_unique<PaymentCoordinator>(*configuration.paymentCoordinatorClient, configuration.availablePaymentNetworks))
 #endif
 #if ENABLE(APPLICATION_MANIFEST)
     , m_applicationManifest(configuration.applicationManifest)
index bd071b3..718d8ae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -78,6 +78,7 @@ public:
     InspectorClient* inspectorClient { nullptr };
 #if ENABLE(APPLE_PAY)
     PaymentCoordinatorClient* paymentCoordinatorClient { nullptr };
+    Vector<String> availablePaymentNetworks;
 #endif
 
 #if ENABLE(APPLICATION_MANIFEST)
index 467aa45..177438a 100644 (file)
@@ -520,7 +520,7 @@ Internals::Internals(Document& document)
     auto* frame = document.frame();
     if (frame && frame->isMainFrame()) {
         m_mockPaymentCoordinator = new MockPaymentCoordinator(frame->mainFrame());
-        frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*m_mockPaymentCoordinator));
+        frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*m_mockPaymentCoordinator, m_mockPaymentCoordinator->availablePaymentNetworks()));
     }
 #endif
 }
index a21cb1f..40221e9 100644 (file)
@@ -41,6 +41,15 @@ namespace WebCore {
 MockPaymentCoordinator::MockPaymentCoordinator(MainFrame& mainFrame)
     : m_mainFrame { mainFrame }
 {
+    m_availablePaymentNetworks.append("amex");
+    m_availablePaymentNetworks.append("carteBancaire");
+    m_availablePaymentNetworks.append("chinaUnionPay");
+    m_availablePaymentNetworks.append("discover");
+    m_availablePaymentNetworks.append("interac");
+    m_availablePaymentNetworks.append("jcb");
+    m_availablePaymentNetworks.append("masterCard");
+    m_availablePaymentNetworks.append("privateLabel");
+    m_availablePaymentNetworks.append("visa");
 }
 
 bool MockPaymentCoordinator::supportsVersion(unsigned version)
index 3214631..f17649b 100644 (file)
@@ -48,6 +48,7 @@ public:
 
     const ApplePayLineItem& total() const { return m_total; }
     const Vector<ApplePayLineItem>& lineItems() const { return m_lineItems; }
+    const Vector<String>& availablePaymentNetworks() const { return m_availablePaymentNetworks; }
 
     void ref() const { }
     void deref() const { }
@@ -73,6 +74,7 @@ private:
     MockPaymentAddress m_shippingAddress;
     ApplePayLineItem m_total;
     Vector<ApplePayLineItem> m_lineItems;
+    Vector<String> m_availablePaymentNetworks;
 };
 
 } // namespace WebCore
index 6e8c144..1079346 100644 (file)
@@ -1,3 +1,28 @@
+2017-12-19  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Stop maintaining a list of payment networks
+        https://bugs.webkit.org/show_bug.cgi?id=180965
+        <rdar://problem/34696560>
+
+        Reviewed by Tim Horton.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h: Defined availablePaymentNetworks.
+        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h:
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
+        (WebKit::toSupportedNetworks):
+        (WebKit::WebPaymentCoordinatorProxy::availablePaymentNetworks): Called
+        +[PKPaymentRequest availableNetworks].
+        (WebKit::toSupportedNetwork): Deleted.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters): Set parameters.availablePaymentNetworks by
+        calling WebPaymentCoordinatorProxy::availablePaymentNetworks.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage): Set pageConfiguration.availablePaymentNetworks to
+        parameters.availablePaymentNetworks.
+
 2017-12-18  Brady Eidson  <beidson@apple.com>
 
         Add ability to API test Service Workers via a custom protocol.
index 6e4a0ae..e533a4d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010, 2011, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -110,6 +110,9 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
 #if ENABLE(CONTENT_EXTENSIONS)
     encoder << contentRuleLists;
 #endif
+#if ENABLE(APPLE_PAY)
+    encoder << availablePaymentNetworks;
+#endif
 }
 
 std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder)
@@ -311,6 +314,15 @@ std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::
         return std::nullopt;
     parameters.contentRuleLists = WTFMove(*contentRuleLists);
 #endif
+
+#if ENABLE(APPLE_PAY)
+    std::optional<Vector<String>> availablePaymentNetworks;
+    decoder >> availablePaymentNetworks;
+    if (!availablePaymentNetworks)
+        return std::nullopt;
+    parameters.availablePaymentNetworks = WTFMove(*availablePaymentNetworks);
+#endif
+
     return WTFMove(parameters);
 }
 
index 00a78a2..7150352 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010, 2011, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -175,6 +175,10 @@ struct WebPageCreationParameters {
 #if ENABLE(CONTENT_EXTENSIONS)
     Vector<std::pair<String, WebCompiledContentRuleListData>> contentRuleLists;
 #endif
+
+#if ENABLE(APPLE_PAY)
+    Vector<String> availablePaymentNetworks;
+#endif
 };
 
 } // namespace WebKit
index bc02ef3..520fb20 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -69,6 +69,8 @@ public:
 
     void hidePaymentUI();
 
+    static Vector<String> availablePaymentNetworks();
+
 private:
     // IPC::MessageReceiver.
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
index d3c8cbe..ce85e57 100644 (file)
@@ -50,15 +50,6 @@ 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, PKPaymentNetworkCarteBancaire, NSString *);
-SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkChinaUnionPay, NSString *);
-SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkDiscover, NSString *);
-SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkInterac, NSString *);
-SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkJCB, NSString *);
-SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkMasterCard, NSString *);
-SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkPrivateLabel, NSString *);
-SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkVisa, NSString *);
 
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
 SOFT_LINK_FRAMEWORK(Contacts)
@@ -440,39 +431,11 @@ static PKMerchantCapability toPKMerchantCapabilities(const WebCore::ApplePaySess
     return result;
 }
 
-static NSString *toSupportedNetwork(const String& supportedNetwork)
-{
-    if (supportedNetwork == "amex")
-        return getPKPaymentNetworkAmex();
-    if (supportedNetwork == "carteBancaire")
-        return getPKPaymentNetworkCarteBancaire();
-    if (supportedNetwork == "chinaUnionPay")
-        return getPKPaymentNetworkChinaUnionPay();
-    if (supportedNetwork == "discover")
-        return getPKPaymentNetworkDiscover();
-    if (supportedNetwork == "interac")
-        return getPKPaymentNetworkInterac();
-    if (supportedNetwork == "jcb")
-        return getPKPaymentNetworkJCB();
-    if (supportedNetwork == "masterCard")
-        return getPKPaymentNetworkMasterCard();
-    if (supportedNetwork == "privateLabel")
-        return getPKPaymentNetworkPrivateLabel();
-    if (supportedNetwork == "visa")
-        return getPKPaymentNetworkVisa();
-
-    return nil;
-}
-
 static RetainPtr<NSArray> toSupportedNetworks(const Vector<String>& supportedNetworks)
 {
-    auto result = adoptNS([[NSMutableArray alloc] init]);
-
-    for (auto& supportedNetwork : supportedNetworks) {
-        if (auto network = toSupportedNetwork(supportedNetwork))
-            [result addObject:network];
-    }
-
+    auto result = adoptNS([[NSMutableArray alloc] initWithCapacity:supportedNetworks.size()]);
+    for (auto& supportedNetwork : supportedNetworks)
+        [result addObject:supportedNetwork];
     return result;
 }
 
@@ -866,7 +829,16 @@ void WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection(const st
     m_paymentAuthorizationViewControllerDelegate->_didSelectPaymentMethodCompletion = nullptr;
 }
 
+Vector<String> WebPaymentCoordinatorProxy::availablePaymentNetworks()
+{
+    NSArray<PKPaymentNetwork> *availableNetworks = [getPKPaymentRequestClass() availableNetworks];
+    Vector<String> result;
+    result.reserveInitialCapacity(availableNetworks.count);
+    for (PKPaymentNetwork network in availableNetworks)
+        result.uncheckedAppend(network);
+    return result;
 }
 
-#endif
+} // namespace WebKit
 
+#endif // ENABLE(APPLE_PAY)
index a9b43c2..e0061dc 100644 (file)
@@ -5846,6 +5846,10 @@ WebPageCreationParameters WebPageProxy::creationParameters()
     parameters.applicationManifest = m_configuration->applicationManifest() ? std::optional<WebCore::ApplicationManifest>(m_configuration->applicationManifest()->applicationManifest()) : std::nullopt;
 #endif
 
+#if ENABLE(APPLE_PAY)
+    parameters.availablePaymentNetworks = WebPaymentCoordinatorProxy::availablePaymentNetworks();
+#endif
+
     m_process->addWebUserContentControllerProxy(m_userContentController, parameters);
 
     return parameters;
index b8b0f9a..c302c59 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
  * Copyright (C) 2012 Intel Corporation. All rights reserved.
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  *
@@ -418,6 +418,7 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
 
 #if ENABLE(APPLE_PAY)
     pageConfiguration.paymentCoordinatorClient = new WebPaymentCoordinator(*this);
+    pageConfiguration.availablePaymentNetworks = WTFMove(parameters.availablePaymentNetworks);
 #endif
 
 #if ENABLE(APPLICATION_MANIFEST)