Clean up WebPaymentCoordinatorProxy
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Mar 2017 00:43:31 +0000 (00:43 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Mar 2017 00:43:31 +0000 (00:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169393
Part of rdar://problem/28880714.

Reviewed by Beth Dakin.

* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewControllerDidFinish:]):
Move this to where it belongs.

(WebKit::toPKPaymentSummaryItems):
Add a new helper function.

(WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection):
(WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection):
Use the new helper function.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm

index 0b0f660..3d53efe 100644 (file)
@@ -1,3 +1,22 @@
+2017-03-08  Anders Carlsson  <andersca@apple.com>
+
+        Clean up WebPaymentCoordinatorProxy
+        https://bugs.webkit.org/show_bug.cgi?id=169393
+        Part of rdar://problem/28880714.
+
+        Reviewed by Beth Dakin.
+
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
+        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewControllerDidFinish:]):
+        Move this to where it belongs.
+
+        (WebKit::toPKPaymentSummaryItems):
+        Add a new helper function.
+
+        (WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection):
+        (WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection):
+        Use the new helper function.
+
 2017-03-08  Brent Fulgham  <bfulgham@apple.com>
 
         [Mac][WK2] Whitelist a local cache needed by CFNetwork
index f188c7a..6925f37 100644 (file)
@@ -122,17 +122,6 @@ SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebKit, PassKit, PKCanMakePaymentsWithMer
     _webPaymentCoordinatorProxy->didAuthorizePayment(WebCore::Payment(payment));
 }
 
-- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
-{
-    if (!_webPaymentCoordinatorProxy)
-        return;
-
-    if (!_didReachFinalState)
-        _webPaymentCoordinatorProxy->didCancelPayment();
-
-    _webPaymentCoordinatorProxy->hidePaymentUI();
-}
-
 static WebCore::PaymentRequest::ShippingMethod toShippingMethod(PKShippingMethod *shippingMethod)
 {
     ASSERT(shippingMethod);
@@ -183,6 +172,17 @@ static WebCore::PaymentRequest::ShippingMethod toShippingMethod(PKShippingMethod
     _webPaymentCoordinatorProxy->didSelectPaymentMethod(WebCore::PaymentMethod(paymentMethod));
 }
 
+- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
+{
+    if (!_webPaymentCoordinatorProxy)
+        return;
+
+    if (!_didReachFinalState)
+        _webPaymentCoordinatorProxy->didCancelPayment();
+
+    _webPaymentCoordinatorProxy->hidePaymentUI();
+}
+
 @end
 
 // FIXME: Once rdar://problem/24420024 has been fixed, import PKPaymentRequest_Private.h instead.
@@ -274,6 +274,20 @@ static RetainPtr<PKPaymentSummaryItem> toPKPaymentSummaryItem(const WebCore::Pay
     return [getPKPaymentSummaryItemClass() summaryItemWithLabel:lineItem.label amount:toDecimalNumber(lineItem.amount.value_or(0)).get() type:toPKPaymentSummaryItemType(lineItem.type)];
 }
 
+static RetainPtr<NSArray> toPKPaymentSummaryItems(const WebCore::PaymentRequest::TotalAndLineItems& totalAndLineItems)
+{
+    auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
+    for (auto& lineItem : totalAndLineItems.lineItems) {
+        if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
+            [paymentSummaryItems addObject:summaryItem.get()];
+    }
+
+    if (auto totalItem = toPKPaymentSummaryItem(totalAndLineItems.total))
+        [paymentSummaryItems addObject:totalItem.get()];
+
+    return paymentSummaryItems;
+}
+
 static PKMerchantCapability toPKMerchantCapabilities(const WebCore::PaymentRequest::MerchantCapabilities& merchantCapabilities)
 {
     PKMerchantCapability result = 0;
@@ -479,18 +493,8 @@ void WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection(const s
 
     auto status = update ? update->status : WebCore::PaymentAuthorizationStatus::Success;
 
-    if (update) {
-        auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
-        for (auto& lineItem : update->newTotalAndLineItems.lineItems) {
-            if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
-                [paymentSummaryItems addObject:summaryItem.get()];
-        }
-
-        if (auto totalItem = toPKPaymentSummaryItem(update->newTotalAndLineItems.total))
-            [paymentSummaryItems addObject:totalItem.get()];
-
-        m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = WTFMove(paymentSummaryItems);
-    }
+    if (update)
+        m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = toPKPaymentSummaryItems(update->newTotalAndLineItems);
 
     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion(toPKPaymentAuthorizationStatus(status), m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion = nullptr;
@@ -504,16 +508,7 @@ void WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection(const
     auto status = update ? update->status : WebCore::PaymentAuthorizationStatus::Success;
 
     if (update) {
-        auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
-        for (auto& lineItem : update->newTotalAndLineItems.lineItems) {
-            if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
-                [paymentSummaryItems addObject:summaryItem.get()];
-        }
-
-        if (auto totalItem = toPKPaymentSummaryItem(update->newTotalAndLineItems.total))
-            [paymentSummaryItems addObject:totalItem.get()];
-
-        m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = WTFMove(paymentSummaryItems);
+        m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = toPKPaymentSummaryItems(update->newTotalAndLineItems);
 
         auto shippingMethods = adoptNS([[NSMutableArray alloc] init]);
         for (auto& shippingMethod : update->newShippingMethods)