Stop using deprecated APIs, part 2
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Apr 2017 22:22:06 +0000 (22:22 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Apr 2017 22:22:06 +0000 (22:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170965
Source/WebCore:

rdar://problem/31589635

Reviewed by Tim Horton.

* Modules/applepay/ApplePaySession.cpp:
(WebCore::convertAndValidate):
No need to convert the status anymore.

(WebCore::ApplePaySession::completeShippingContactSelection):
Create an ApplePayError given the status.

* Modules/applepay/ApplePayShippingContactUpdate.h:
Remove the status member variable.

* Modules/applepay/PaymentRequest.h:
Remove the status member variable.

Source/WebKit2:

Reviewed by Tim Horton.

* Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
(IPC::ArgumentCoder<WebCore::ShippingContactUpdate>::encode):
(IPC::ArgumentCoder<WebCore::ShippingContactUpdate>::decode):
Remove the status member variable.

* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::status):
New function to be used by older OSes. This will recreate a PKPaymentAuthorizationStatus given a ShippingContactUpdate.

(WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection):
Stop using the deprecated API.

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/ApplePaySession.cpp
Source/WebCore/Modules/applepay/ApplePayShippingContactUpdate.h
Source/WebCore/Modules/applepay/PaymentRequest.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm
Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm

index 9d61708..ed865cd 100644 (file)
@@ -1,3 +1,24 @@
+2017-04-18  Anders Carlsson  <andersca@apple.com>
+
+        Stop using deprecated APIs, part 2
+        https://bugs.webkit.org/show_bug.cgi?id=170965
+        rdar://problem/31589635
+
+        Reviewed by Tim Horton.
+
+        * Modules/applepay/ApplePaySession.cpp:
+        (WebCore::convertAndValidate):
+        No need to convert the status anymore.
+
+        (WebCore::ApplePaySession::completeShippingContactSelection):
+        Create an ApplePayError given the status.
+
+        * Modules/applepay/ApplePayShippingContactUpdate.h:
+        Remove the status member variable.
+
+        * Modules/applepay/PaymentRequest.h:
+        Remove the status member variable.
+
 2017-04-18  Tim Horton  <timothy_horton@apple.com>
 
         Safari crash when clicking phone number data detector popover button
index ec0f965..652dbcd 100644 (file)
@@ -467,21 +467,7 @@ static ExceptionOr<ShippingContactUpdate> convertAndValidate(ApplePayShippingCon
 {
     ShippingContactUpdate convertedUpdate;
 
-    if (!update.status) {
-        convertedUpdate.errors = convert(update.errors);
-        if (convertedUpdate.errors.isEmpty())
-            convertedUpdate.status = PaymentAuthorizationStatus::Success;
-        else
-            convertedUpdate.status = PaymentAuthorizationStatus::Failure;
-    } else {
-        ASSERT(update.errors.isEmpty());
-
-        auto authorizationStatus = toPaymentAuthorizationStatus(*update.status);
-        if (!authorizationStatus)
-            return Exception { INVALID_ACCESS_ERR };
-
-        convertedUpdate.status = *authorizationStatus;
-    }
+    convertedUpdate.errors = convert(update.errors);
 
     auto convertedNewShippingMethods = convertAndValidate(WTFMove(update.newShippingMethods));
     if (convertedNewShippingMethods.hasException())
@@ -829,7 +815,41 @@ ExceptionOr<void> ApplePaySession::completeShippingContactSelection(unsigned sho
 {
     ApplePayShippingContactUpdate update;
 
-    update.status = status;
+    auto authorizationStatus = toPaymentAuthorizationStatus(status);
+    if (!authorizationStatus)
+        return Exception { INVALID_ACCESS_ERR };
+
+    std::optional<ApplePayError::Code> errorCode;
+    std::optional<ApplePayError::ContactField> contactField;
+
+    switch (*authorizationStatus) {
+    case PaymentAuthorizationStatus::Success:
+        break;
+
+    case PaymentAuthorizationStatus::Failure:
+    case PaymentAuthorizationStatus::PINRequired:
+    case PaymentAuthorizationStatus::PINIncorrect:
+    case PaymentAuthorizationStatus::PINLockout:
+        errorCode = ApplePayError::Code::Unknown;
+        break;
+
+    case PaymentAuthorizationStatus::InvalidBillingPostalAddress:
+        errorCode = ApplePayError::Code::BillingContactInvalid;
+        break;
+
+    case PaymentAuthorizationStatus::InvalidShippingPostalAddress:
+        errorCode = ApplePayError::Code::ShippingContactInvalid;
+        contactField = ApplePayError::ContactField::PostalAddress;
+        break;
+
+    case PaymentAuthorizationStatus::InvalidShippingContact:
+        errorCode = ApplePayError::Code::ShippingContactInvalid;
+        break;
+    }
+
+    if (errorCode)
+        update.errors = { ApplePayError::create(*errorCode, contactField, { }) };
+
     update.newShippingMethods = WTFMove(newShippingMethods);
     update.newTotal = WTFMove(newTotal);
     update.newLineItems = WTFMove(newLineItems);
index 0aacb6c..7259778 100644 (file)
@@ -34,7 +34,6 @@
 namespace WebCore {
 
 struct ApplePayShippingContactUpdate {
-    std::optional<unsigned short> status;
     Vector<RefPtr<ApplePayError>> errors;
 
     Vector<ApplePayShippingMethod> newShippingMethods;
index 08e1b4b..9d8d362 100644 (file)
@@ -185,7 +185,6 @@ struct PaymentMethodUpdate {
 };
 
 struct ShippingContactUpdate {
-    PaymentAuthorizationStatus status;
     Vector<PaymentError> errors;
 
     Vector<PaymentRequest::ShippingMethod> newShippingMethods;
index c3a131c..320612c 100644 (file)
@@ -1,3 +1,22 @@
+2017-04-18  Anders Carlsson  <andersca@apple.com>
+
+        Stop using deprecated APIs, part 2
+        https://bugs.webkit.org/show_bug.cgi?id=170965
+
+        Reviewed by Tim Horton.
+
+        * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+        (IPC::ArgumentCoder<WebCore::ShippingContactUpdate>::encode):
+        (IPC::ArgumentCoder<WebCore::ShippingContactUpdate>::decode):
+        Remove the status member variable.
+
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
+        (WebKit::status):
+        New function to be used by older OSes. This will recreate a PKPaymentAuthorizationStatus given a ShippingContactUpdate.
+
+        (WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection):
+        Stop using the deprecated API.
+
 2017-04-18  Timothy Horton  <timothy_horton@apple.com>
 
         Force scroll view insets to be respected regardless of rubber-banding state
index fb19e44..ebe0e0d 100644 (file)
@@ -421,7 +421,6 @@ bool ArgumentCoder<PaymentRequest::TotalAndLineItems>::decode(Decoder& decoder,
 
 void ArgumentCoder<WebCore::ShippingContactUpdate>::encode(Encoder& encoder, const WebCore::ShippingContactUpdate& update)
 {
-    encoder << update.status;
     encoder << update.errors;
     encoder << update.newShippingMethods;
     encoder << update.newTotalAndLineItems;
@@ -429,8 +428,6 @@ void ArgumentCoder<WebCore::ShippingContactUpdate>::encode(Encoder& encoder, con
 
 bool ArgumentCoder<WebCore::ShippingContactUpdate>::decode(Decoder& decoder, WebCore::ShippingContactUpdate& update)
 {
-    if (!decoder.decode(update.status))
-        return false;
     if (!decoder.decode(update.errors))
         return false;
     if (!decoder.decode(update.newShippingMethods))
index 0f14b4a..7c277c8 100644 (file)
@@ -724,13 +724,39 @@ void WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection(const s
     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion = nullptr;
 }
 
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000)
+static PKPaymentAuthorizationStatus status(const std::optional<WebCore::ShippingContactUpdate>& update)
+{
+    if (!update)
+        return PKPaymentAuthorizationStatusSuccess;
+
+    if (update->errors.size() == 1) {
+        auto& error = update->errors[0];
+        switch (error.code) {
+        case WebCore::PaymentError::Code::Unknown:
+        case WebCore::PaymentError::Code::AddressUnservicable:
+            return PKPaymentAuthorizationStatusFailure;
+
+        case WebCore::PaymentError::Code::BillingContactInvalid:
+            return PKPaymentAuthorizationStatusInvalidBillingPostalAddress;
+
+        case WebCore::PaymentError::Code::ShippingContactInvalid:
+            if (error.contactField && error.contactField == WebCore::PaymentError::ContactField::PostalAddress)
+                return PKPaymentAuthorizationStatusInvalidShippingPostalAddress;
+
+            return PKPaymentAuthorizationStatusInvalidShippingContact;
+        }
+    }
+
+    return PKPaymentAuthorizationStatusFailure;
+}
+#endif
+
 void WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection(const std::optional<WebCore::ShippingContactUpdate>& update)
 {
     ASSERT(m_paymentAuthorizationViewController);
     ASSERT(m_paymentAuthorizationViewControllerDelegate);
 
-    auto status = update ? update->status : WebCore::PaymentAuthorizationStatus::Success;
-
     if (update) {
         m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = toPKPaymentSummaryItems(update->newTotalAndLineItems);
 
@@ -742,13 +768,12 @@ void WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection(const
     }
 
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-    auto pkShippingContactUpdate = adoptNS([allocPKPaymentRequestShippingContactUpdateInstance() initWithStatus:toPKPaymentAuthorizationStatus(status) errors:update ? toNSErrors(update->errors).get() : @[ ] paymentSummaryItems:m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get() shippingMethods:m_paymentAuthorizationViewControllerDelegate->_shippingMethods.get()]);
-#pragma clang diagnostic pop
+    auto pkShippingContactUpdate = adoptNS([allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:update ? toNSErrors(update->errors).get() : @[ ] paymentSummaryItems:m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get() shippingMethods:m_paymentAuthorizationViewControllerDelegate->_shippingMethods.get()]);
+    if ([pkShippingContactUpdate errors].count)
+        [pkShippingContactUpdate setStatus:PKPaymentAuthorizationStatusFailure];
     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion(pkShippingContactUpdate.get());
 #else
-    m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion(toPKPaymentAuthorizationStatus(status), m_paymentAuthorizationViewControllerDelegate->_shippingMethods.get(), m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
+    m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion(status(update), m_paymentAuthorizationViewControllerDelegate->_shippingMethods.get(), m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
 #endif
     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion = nullptr;
 }