Diff
Modified: trunk/Source/WebCore/ChangeLog (250178 => 250179)
--- trunk/Source/WebCore/ChangeLog 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/ChangeLog 2019-09-21 06:37:34 UTC (rev 250179)
@@ -1,3 +1,44 @@
+2019-09-19 Andy Estes <[email protected]>
+
+ [Apple Pay] Clean up handling of summary items and payment method updates
+ https://bugs.webkit.org/show_bug.cgi?id=202018
+ <rdar://problem/55470632>
+
+ Reviewed by Tim Horton.
+
+ Replaced the PaymentMethodUpdate struct with a class that knows how to convert from
+ ApplePayPaymentMethodUpdate structs to PKPaymentRequestPaymentMethodUpdate instances.
+
+ Moved some scattered-around free functions for converting payment summary items into
+ PaymentSummaryItems{.h,Cocoa.mm}.
+
+ * Modules/applepay/ApplePayPaymentMethodUpdate.h:
+ * Modules/applepay/ApplePaySession.cpp:
+ (WebCore::finishConverting):
+ (WebCore::convertAndValidateTotal):
+ (WebCore::convertAndValidate):
+ * Modules/applepay/ApplePaySessionPaymentRequest.h:
+ * Modules/applepay/PaymentCoordinator.h:
+ * Modules/applepay/PaymentCoordinatorClient.h:
+ * Modules/applepay/PaymentHeaders.h:
+ * Modules/applepay/PaymentMethodUpdate.h: Added.
+ * Modules/applepay/PaymentSummaryItems.h: Added.
+ * Modules/applepay/cocoa/PaymentMethodUpdateCocoa.mm: Added.
+ (WebCore::PaymentMethodUpdate::PaymentMethodUpdate):
+ (WebCore::PaymentMethodUpdate::totalAndLineItems const):
+ (WebCore::PaymentMethodUpdate::platformUpdate const):
+ * Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm: Added.
+ (WebCore::toDecimalNumber):
+ (WebCore::toPKPaymentSummaryItemType):
+ (WebCore::toPKPaymentSummaryItem):
+ (WebCore::platformSummaryItems):
+ * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+ (WebCore::ApplePayPaymentHandler::paymentMethodUpdated):
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * testing/MockPaymentCoordinator.cpp:
+ (WebCore::MockPaymentCoordinator::completePaymentMethodSelection):
+
2019-09-20 Said Abou-Hallawa <[email protected]>
Assertion fires when animating a discrete property with values range and multiple animators
Modified: trunk/Source/WebCore/Modules/applepay/ApplePayPaymentMethodUpdate.h (250178 => 250179)
--- trunk/Source/WebCore/Modules/applepay/ApplePayPaymentMethodUpdate.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayPaymentMethodUpdate.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,11 +29,20 @@
#include "ApplePayLineItem.h"
+#if USE(APPLE_INTERNAL_SDK)
+#include <WebKitAdditions/ApplePayPaymentMethodUpdateAdditions.h>
+#endif
+
namespace WebCore {
struct ApplePayPaymentMethodUpdate {
ApplePayLineItem newTotal;
Vector<ApplePayLineItem> newLineItems;
+
+#if defined(APPLEPAYPAYMENTMETHODUPDATE_ADDITIONS)
+APPLEPAYPAYMENTMETHODUPDATE_ADDITIONS
+#undef APPLEPAYPAYMENTMETHODUPDATE_ADDITIONS
+#endif
};
}
Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp (250178 => 250179)
--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp 2019-09-21 06:37:34 UTC (rev 250179)
@@ -57,6 +57,7 @@
#include "PaymentCoordinator.h"
#include "PaymentMerchantSession.h"
#include "PaymentMethod.h"
+#include "PaymentMethodUpdate.h"
#include "PaymentRequestValidator.h"
#include "SecurityOrigin.h"
#include "Settings.h"
@@ -63,8 +64,16 @@
#include "UserGestureIndicator.h"
#include <wtf/IsoMallocInlines.h>
+#if USE(APPLE_INTERNAL_SDK)
+#include <WebKitAdditions/ApplePaySessionAdditions.cpp>
+#else
namespace WebCore {
+static void finishConverting(PaymentMethodUpdate&, ApplePayPaymentMethodUpdate&&) { }
+}
+#endif
+namespace WebCore {
+
WTF_MAKE_ISO_ALLOCATED_IMPL(ApplePaySession);
// The amount follows the regular _expression_ -?[0-9]+(\.[0-9][0-9])?.
@@ -139,12 +148,13 @@
if (!validateAmount(lineItem.amount))
return Exception { TypeError, makeString("\"" + lineItem.amount, "\" is not a valid amount.") };
- ApplePaySessionPaymentRequest::LineItem result;
- result.amount = lineItem.amount;
- result.type = lineItem.type;
- result.label = lineItem.label;
+ ApplePaySessionPaymentRequest::LineItem total { lineItem.type, lineItem.amount, lineItem.label };
- return WTFMove(result);
+ auto validatedTotal = PaymentRequestValidator::validateTotal(total);
+ if (validatedTotal.hasException())
+ return validatedTotal.releaseException();
+
+ return WTFMove(total);
}
static ExceptionOr<ApplePaySessionPaymentRequest::LineItem> convertAndValidate(ApplePayLineItem&& lineItem)
@@ -318,23 +328,16 @@
static ExceptionOr<PaymentMethodUpdate> convertAndValidate(ApplePayPaymentMethodUpdate&& update)
{
- PaymentMethodUpdate convertedUpdate;
-
auto convertedNewTotal = convertAndValidateTotal(WTFMove(update.newTotal));
if (convertedNewTotal.hasException())
return convertedNewTotal.releaseException();
- convertedUpdate.newTotalAndLineItems.total = convertedNewTotal.releaseReturnValue();
- // FIXME: Merge this validation into the validation we are doing above.
- auto validatedTotal = PaymentRequestValidator::validateTotal(convertedUpdate.newTotalAndLineItems.total);
- if (validatedTotal.hasException())
- return validatedTotal.releaseException();
-
auto convertedNewLineItems = convertAndValidate(WTFMove(update.newLineItems));
if (convertedNewLineItems.hasException())
return convertedNewLineItems.releaseException();
- convertedUpdate.newTotalAndLineItems.lineItems = convertedNewLineItems.releaseReturnValue();
+ PaymentMethodUpdate convertedUpdate { convertedNewTotal.releaseReturnValue(), convertedNewLineItems.releaseReturnValue() };
+ finishConverting(convertedUpdate, WTFMove(update));
return WTFMove(convertedUpdate);
}
@@ -355,11 +358,6 @@
return convertedNewTotal.releaseException();
convertedUpdate.newTotalAndLineItems.total = convertedNewTotal.releaseReturnValue();
- // FIXME: Merge this validation into the validation we are doing above.
- auto validatedTotal = PaymentRequestValidator::validateTotal(convertedUpdate.newTotalAndLineItems.total);
- if (validatedTotal.hasException())
- return validatedTotal.releaseException();
-
auto convertedNewLineItems = convertAndValidate(WTFMove(update.newLineItems));
if (convertedNewLineItems.hasException())
return convertedNewLineItems.releaseException();
@@ -378,11 +376,6 @@
convertedUpdate.newTotalAndLineItems.total = convertedNewTotal.releaseReturnValue();
- // FIXME: Merge this validation into the validation we are doing above.
- auto validatedTotal = PaymentRequestValidator::validateTotal(convertedUpdate.newTotalAndLineItems.total);
- if (validatedTotal.hasException())
- return validatedTotal.releaseException();
-
auto convertedNewLineItems = convertAndValidate(WTFMove(update.newLineItems));
if (convertedNewLineItems.hasException())
return convertedNewLineItems.releaseException();
Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.h (250178 => 250179)
--- trunk/Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -212,10 +212,6 @@
Vector<PaymentError> errors;
};
-struct PaymentMethodUpdate {
- ApplePaySessionPaymentRequest::TotalAndLineItems newTotalAndLineItems;
-};
-
struct ShippingContactUpdate {
Vector<PaymentError> errors;
Modified: trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h (250178 => 250179)
--- trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -39,11 +39,11 @@
class PaymentContact;
class PaymentMerchantSession;
class PaymentMethod;
+class PaymentMethodUpdate;
class PaymentSession;
class PaymentSessionError;
enum class PaymentAuthorizationStatus;
struct PaymentAuthorizationResult;
-struct PaymentMethodUpdate;
struct ShippingContactUpdate;
struct ShippingMethodUpdate;
Modified: trunk/Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h (250178 => 250179)
--- trunk/Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -39,8 +39,8 @@
class Document;
class PaymentMerchantSession;
+class PaymentMethodUpdate;
struct PaymentAuthorizationResult;
-struct PaymentMethodUpdate;
struct ShippingContactUpdate;
struct ShippingMethodUpdate;
Modified: trunk/Source/WebCore/Modules/applepay/PaymentHeaders.h (250178 => 250179)
--- trunk/Source/WebCore/Modules/applepay/PaymentHeaders.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/Modules/applepay/PaymentHeaders.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,4 +30,6 @@
#include "PaymentContact.h"
#include "PaymentMerchantSession.h"
#include "PaymentMethod.h"
+#include "PaymentMethodUpdate.h"
#include "PaymentSessionError.h"
+#include "PaymentSummaryItems.h"
Copied: trunk/Source/WebCore/Modules/applepay/PaymentMethodUpdate.h (from rev 250176, trunk/Source/WebCore/Modules/applepay/ApplePayPaymentMethodUpdate.h) (0 => 250179)
--- trunk/Source/WebCore/Modules/applepay/PaymentMethodUpdate.h (rev 0)
+++ trunk/Source/WebCore/Modules/applepay/PaymentMethodUpdate.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2019 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 "ApplePaySessionPaymentRequest.h"
+#include <wtf/RetainPtr.h>
+
+#if USE(APPLE_INTERNAL_SDK)
+#include <WebKitAdditions/PaymentMethodUpdateAdditions.h>
+#endif
+
+OBJC_CLASS PKPaymentRequestPaymentMethodUpdate;
+
+namespace WebCore {
+
+class WEBCORE_EXPORT PaymentMethodUpdate {
+public:
+ using LineItem = ApplePaySessionPaymentRequest::LineItem;
+ using TotalAndLineItems = ApplePaySessionPaymentRequest::TotalAndLineItems;
+
+ PaymentMethodUpdate(LineItem&& total, Vector<LineItem>&&);
+ explicit PaymentMethodUpdate(RetainPtr<PKPaymentRequestPaymentMethodUpdate>&&);
+ explicit PaymentMethodUpdate(TotalAndLineItems&&);
+
+ const TotalAndLineItems& totalAndLineItems() const;
+ PKPaymentRequestPaymentMethodUpdate *platformUpdate() const;
+
+#if defined(PAYMENTMETHODUPDATE_PUBLIC_ADDITIONS)
+PAYMENTMETHODUPDATE_PUBLIC_ADDITIONS
+#undef PAYMENTMETHODUPDATE_PUBLIC_ADDITIONS
+#endif
+
+private:
+ Optional<TotalAndLineItems> m_totalAndLineItems;
+ RetainPtr<PKPaymentRequestPaymentMethodUpdate> m_platformUpdate;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)
Copied: trunk/Source/WebCore/Modules/applepay/PaymentSummaryItems.h (from rev 250176, trunk/Source/WebCore/Modules/applepay/ApplePayPaymentMethodUpdate.h) (0 => 250179)
--- trunk/Source/WebCore/Modules/applepay/PaymentSummaryItems.h (rev 0)
+++ trunk/Source/WebCore/Modules/applepay/PaymentSummaryItems.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2019 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 "ApplePaySessionPaymentRequest.h"
+
+OBJC_CLASS NSArray;
+
+namespace WebCore {
+
+WEBCORE_EXPORT NSArray *platformSummaryItems(const ApplePaySessionPaymentRequest::TotalAndLineItems&);
+WEBCORE_EXPORT NSArray *platformSummaryItems(const ApplePaySessionPaymentRequest::LineItem& total, const Vector<ApplePaySessionPaymentRequest::LineItem>&);
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)
Copied: trunk/Source/WebCore/Modules/applepay/cocoa/PaymentMethodUpdateCocoa.mm (from rev 250176, trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h) (0 => 250179)
--- trunk/Source/WebCore/Modules/applepay/cocoa/PaymentMethodUpdateCocoa.mm (rev 0)
+++ trunk/Source/WebCore/Modules/applepay/cocoa/PaymentMethodUpdateCocoa.mm 2019-09-21 06:37:34 UTC (rev 250179)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2019 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 "PaymentMethodUpdate.h"
+
+#if ENABLE(APPLE_PAY)
+
+#import "PaymentSummaryItems.h"
+#import <pal/cocoa/PassKitSoftLink.h>
+
+namespace WebCore {
+
+PaymentMethodUpdate::PaymentMethodUpdate(LineItem&& total, Vector<LineItem>&& lineItems)
+ : m_totalAndLineItems { { WTFMove(total), WTFMove(lineItems) } }
+ , m_platformUpdate { adoptNS([PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:platformSummaryItems(*m_totalAndLineItems)]) }
+{
+}
+
+PaymentMethodUpdate::PaymentMethodUpdate(RetainPtr<PKPaymentRequestPaymentMethodUpdate>&& platformUpdate)
+ : m_platformUpdate { WTFMove(platformUpdate) }
+{
+}
+
+PaymentMethodUpdate::PaymentMethodUpdate(TotalAndLineItems&& totalAndLineItems)
+ : PaymentMethodUpdate { WTFMove(totalAndLineItems.total), WTFMove(totalAndLineItems.lineItems) }
+{
+}
+
+const PaymentMethodUpdate::TotalAndLineItems& PaymentMethodUpdate::totalAndLineItems() const
+{
+ return *m_totalAndLineItems;
+}
+
+PKPaymentRequestPaymentMethodUpdate *PaymentMethodUpdate::platformUpdate() const
+{
+ return m_platformUpdate.get();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)
Added: trunk/Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm (0 => 250179)
--- trunk/Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm (rev 0)
+++ trunk/Source/WebCore/Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm 2019-09-21 06:37:34 UTC (rev 250179)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016-2019 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 "PaymentSummaryItems.h"
+
+#if ENABLE(APPLE_PAY)
+
+#import <pal/cocoa/PassKitSoftLink.h>
+
+namespace WebCore {
+
+static NSDecimalNumber *toDecimalNumber(const String& amount)
+{
+ if (!amount)
+ return [NSDecimalNumber zero];
+ return [NSDecimalNumber decimalNumberWithString:amount locale:@{ NSLocaleDecimalSeparator : @"." }];
+}
+
+static PKPaymentSummaryItemType toPKPaymentSummaryItemType(ApplePaySessionPaymentRequest::LineItem::Type type)
+{
+ switch (type) {
+ case ApplePaySessionPaymentRequest::LineItem::Type::Final:
+ return PKPaymentSummaryItemTypeFinal;
+ case ApplePaySessionPaymentRequest::LineItem::Type::Pending:
+ return PKPaymentSummaryItemTypePending;
+ }
+}
+
+static PKPaymentSummaryItem *toPKPaymentSummaryItem(const ApplePaySessionPaymentRequest::LineItem& lineItem)
+{
+ return [PAL::getPKPaymentSummaryItemClass() summaryItemWithLabel:lineItem.label amount:toDecimalNumber(lineItem.amount) type:toPKPaymentSummaryItemType(lineItem.type)];
+}
+
+NSArray *platformSummaryItems(const ApplePaySessionPaymentRequest::TotalAndLineItems& totalAndLineItems)
+{
+ return platformSummaryItems(totalAndLineItems.total, totalAndLineItems.lineItems);
+}
+
+NSArray *platformSummaryItems(const ApplePaySessionPaymentRequest::LineItem& total, const Vector<ApplePaySessionPaymentRequest::LineItem>& lineItems)
+{
+ NSMutableArray *paymentSummaryItems = [NSMutableArray arrayWithCapacity:lineItems.size() + 1];
+ for (auto& lineItem : lineItems) {
+ if (PKPaymentSummaryItem *summaryItem = toPKPaymentSummaryItem(lineItem))
+ [paymentSummaryItems addObject:summaryItem];
+ }
+
+ if (PKPaymentSummaryItem *totalItem = toPKPaymentSummaryItem(total))
+ [paymentSummaryItems addObject:totalItem];
+
+ return adoptNS([paymentSummaryItems copy]).autorelease();
+}
+
+} // namespace WebbCore
+
+#endif // ENABLE(APPLE_PAY)
Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp (250178 => 250179)
--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp 2019-09-21 06:37:34 UTC (rev 250179)
@@ -51,6 +51,7 @@
#include "PaymentCoordinator.h"
#include "PaymentMerchantSession.h"
#include "PaymentMethod.h"
+#include "PaymentMethodUpdate.h"
#include "PaymentRequestValidator.h"
#include "PaymentResponse.h"
#include "PaymentValidationErrors.h"
@@ -473,14 +474,11 @@
ASSERT(m_isUpdating);
m_isUpdating = false;
- PaymentMethodUpdate update;
-
auto newTotalAndLineItems = computeTotalAndLineItems();
if (newTotalAndLineItems.hasException())
return newTotalAndLineItems.releaseException();
- update.newTotalAndLineItems = newTotalAndLineItems.releaseReturnValue();
- paymentCoordinator().completePaymentMethodSelection(WTFMove(update));
+ paymentCoordinator().completePaymentMethodSelection(PaymentMethodUpdate { newTotalAndLineItems.releaseReturnValue() });
return { };
}
Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h (250178 => 250179)
--- trunk/Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -348,18 +348,22 @@
@property (nonatomic, assign) PKPaymentAuthorizationStatus status;
@end
-@interface PKPaymentRequestPaymentMethodUpdate : NSObject
-- (instancetype)initWithPaymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)paymentSummaryItems;
+@interface PKPaymentRequestUpdate : NSObject
+- (instancetype)initWithPaymentSummaryItems:(NSArray<PKPaymentSummaryItem *> *)paymentSummaryItems;
+@property (nonatomic, copy) NSArray<PKPaymentSummaryItem *> *paymentSummaryItems;
@end
-@interface PKPaymentRequestUpdate : NSObject
+@interface PKPaymentRequestPaymentMethodUpdate : PKPaymentRequestUpdate
@end
@interface PKPaymentRequestShippingContactUpdate : PKPaymentRequestUpdate
-- (instancetype)initWithPaymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)summaryItems shippingMethods:(nonnull NSArray<PKShippingMethod *> *)shippingMethods;
- (instancetype)initWithErrors:(nullable NSArray<NSError *> *)errors paymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)summaryItems shippingMethods:(nonnull NSArray<PKShippingMethod *> *)shippingMethods;
+@property (nonatomic, copy) NSArray<PKShippingMethod *> *shippingMethods;
@end
+@interface PKPaymentRequestShippingMethodUpdate : PKPaymentRequestUpdate
+@end
+
NS_ASSUME_NONNULL_END
#endif
Modified: trunk/Source/WebCore/SourcesCocoa.txt (250178 => 250179)
--- trunk/Source/WebCore/SourcesCocoa.txt 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2019-09-21 06:37:34 UTC (rev 250179)
@@ -592,7 +592,9 @@
Modules/applepay/cocoa/PaymentContactCocoa.mm
Modules/applepay/cocoa/PaymentMerchantSessionCocoa.mm
Modules/applepay/cocoa/PaymentMethodCocoa.mm
+ Modules/applepay/cocoa/PaymentMethodUpdateCocoa.mm
Modules/applepay/cocoa/PaymentSessionErrorCocoa.mm
+ Modules/applepay/cocoa/PaymentSummaryItemsCocoa.mm
Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (250178 => 250179)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-09-21 06:37:34 UTC (rev 250179)
@@ -3004,6 +3004,8 @@
A1DF5AA61F7F64BB0058A477 /* PaymentHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DF5AA41F7F64BB0058A477 /* PaymentHandler.h */; };
A1DF5AAD1F8075F00058A477 /* ApplePayRequestBase.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DF5AAA1F8075F00058A477 /* ApplePayRequestBase.h */; };
A1DF5AB31F8077530058A477 /* JSApplePayRequestBase.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DF5AB11F8077520058A477 /* JSApplePayRequestBase.h */; };
+ A1DFD5252334593F0042FCDB /* PaymentMethodUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DFD5242334593A0042FCDB /* PaymentMethodUpdate.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ A1DFD526233459480042FCDB /* PaymentSummaryItems.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DFD5222334593A0042FCDB /* PaymentSummaryItems.h */; settings = {ATTRIBUTES = (Private, ); }; };
A1ED778D1BE3294000DC1791 /* Device.h in Headers */ = {isa = PBXBuildFile; fileRef = A1ED778B1BE3294000DC1791 /* Device.h */; settings = {ATTRIBUTES = (Private, ); }; };
A1F600441F4757A90077E83F /* PaymentRequestUpdateEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A1F600411F4757A90077E83F /* PaymentRequestUpdateEvent.h */; };
A1F600491F47594E0077E83F /* PaymentDetailsUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = A1F600471F47594E0077E83F /* PaymentDetailsUpdate.h */; };
@@ -11308,6 +11310,10 @@
A1DF5AB01F8077520058A477 /* JSApplePayRequestBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSApplePayRequestBase.cpp; sourceTree = "<group>"; };
A1DF5AB11F8077520058A477 /* JSApplePayRequestBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSApplePayRequestBase.h; sourceTree = "<group>"; };
A1DF5AB41F8078F30058A477 /* ApplePayContactField.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ApplePayContactField.cpp; sourceTree = "<group>"; };
+ A1DFD5222334593A0042FCDB /* PaymentSummaryItems.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentSummaryItems.h; sourceTree = "<group>"; };
+ A1DFD5242334593A0042FCDB /* PaymentMethodUpdate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentMethodUpdate.h; sourceTree = "<group>"; };
+ A1DFD527233459730042FCDB /* PaymentSummaryItemsCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PaymentSummaryItemsCocoa.mm; sourceTree = "<group>"; };
+ A1DFD528233459740042FCDB /* PaymentMethodUpdateCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PaymentMethodUpdateCocoa.mm; sourceTree = "<group>"; };
A1E1154313015C3D0054AC8C /* DistantLightSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DistantLightSource.cpp; sourceTree = "<group>"; };
A1E1154513015C4E0054AC8C /* PointLightSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PointLightSource.cpp; sourceTree = "<group>"; };
A1E1154713015C5D0054AC8C /* SpotLightSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpotLightSource.cpp; sourceTree = "<group>"; };
@@ -16783,11 +16789,13 @@
7CF930E61E01F9AD00BAFFBE /* PaymentHeaders.h */,
1AE96A871D1A0CEB00B86768 /* PaymentMerchantSession.h */,
1A8A64391D19FC5300D0E00F /* PaymentMethod.h */,
+ A1DFD5242334593A0042FCDB /* PaymentMethodUpdate.h */,
1A8A64661D19FDFF00D0E00F /* PaymentRequestValidator.h */,
1A8A64651D19FDFF00D0E00F /* PaymentRequestValidator.mm */,
A1C2C5751FA2851600BA46FA /* PaymentSession.cpp */,
A1491DA21F859D870095F5D4 /* PaymentSession.h */,
A113E02723318293009C33A0 /* PaymentSessionError.h */,
+ A1DFD5222334593A0042FCDB /* PaymentSummaryItems.h */,
);
path = applepay;
sourceTree = "<group>";
@@ -16799,7 +16807,9 @@
1A8A646A1D19FF8700D0E00F /* PaymentContactCocoa.mm */,
1ADA4A1B1D22F2C0005A9A15 /* PaymentMerchantSessionCocoa.mm */,
1A8A646B1D19FF8700D0E00F /* PaymentMethodCocoa.mm */,
+ A1DFD528233459740042FCDB /* PaymentMethodUpdateCocoa.mm */,
A113E02A23318EBC009C33A0 /* PaymentSessionErrorCocoa.mm */,
+ A1DFD527233459730042FCDB /* PaymentSummaryItemsCocoa.mm */,
);
path = cocoa;
sourceTree = "<group>";
@@ -31083,6 +31093,7 @@
1A8A643C1D19FC5300D0E00F /* PaymentMethod.h in Headers */,
A164A2472134BC7100509156 /* PaymentMethodChangeEvent.h in Headers */,
A1F76B191F44C3900014C318 /* PaymentMethodData.h in Headers */,
+ A1DFD5252334593F0042FCDB /* PaymentMethodUpdate.h in Headers */,
A1F76B2B1F44C4EF0014C318 /* PaymentOptions.h in Headers */,
A1F76B131F44C2450014C318 /* PaymentRequest.h in Headers */,
A1F600441F4757A90077E83F /* PaymentRequestUpdateEvent.h in Headers */,
@@ -31094,6 +31105,7 @@
A113E02823318293009C33A0 /* PaymentSessionError.h in Headers */,
A1F76B551F44D2C70014C318 /* PaymentShippingOption.h in Headers */,
A1F76B491F44D07A0014C318 /* PaymentShippingType.h in Headers */,
+ A1DFD526233459480042FCDB /* PaymentSummaryItems.h in Headers */,
A1677DFD213E006600A08C34 /* PaymentValidationErrors.h in Headers */,
B27535650B053814002CE64F /* PDFDocumentImage.h in Headers */,
5E2C43511BCEE2F60001E2BC /* PeerConnectionBackend.h in Headers */,
Modified: trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp (250178 => 250179)
--- trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp 2019-09-21 06:37:34 UTC (rev 250179)
@@ -34,6 +34,7 @@
#include "MockPaymentMethod.h"
#include "Page.h"
#include "PaymentCoordinator.h"
+#include "PaymentMethodUpdate.h"
#include "PaymentSessionError.h"
#include <wtf/CompletionHandler.h>
#include <wtf/RunLoop.h>
@@ -160,7 +161,7 @@
void MockPaymentCoordinator::completePaymentMethodSelection(Optional<PaymentMethodUpdate>&& paymentMethodUpdate)
{
if (paymentMethodUpdate)
- updateTotalAndLineItems(paymentMethodUpdate->newTotalAndLineItems);
+ updateTotalAndLineItems(paymentMethodUpdate->totalAndLineItems());
}
void MockPaymentCoordinator::changeShippingOption(String&& shippingOption)
Modified: trunk/Source/WebKit/ChangeLog (250178 => 250179)
--- trunk/Source/WebKit/ChangeLog 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/ChangeLog 2019-09-21 06:37:34 UTC (rev 250179)
@@ -1,3 +1,42 @@
+2019-09-19 Andy Estes <[email protected]>
+
+ [Apple Pay] Clean up handling of summary items and payment method updates
+ https://bugs.webkit.org/show_bug.cgi?id=202018
+ <rdar://problem/55470632>
+
+ Reviewed by Tim Horton.
+
+ Now that PaymentMethodUpdate knows how to convert itself to a
+ PKPaymentRequestPaymentMethodUpdate, PaymentAuthorizationPresenter can merely pass the
+ converted update directly to the platform delegate rather than passing the individual
+ components and relying on the delegate to instantiate the platform update itself. Added
+ FIXMEs for applying a similar treatment to ShippingContactUpdate and ShippingMethodUpdate.
+
+ * Platform/cocoa/PaymentAuthorizationPresenter.h:
+ * Platform/cocoa/PaymentAuthorizationPresenter.mm:
+ (WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection):
+ (WebKit::PaymentAuthorizationPresenter::completeShippingContactSelection):
+ (WebKit::PaymentAuthorizationPresenter::completeShippingMethodSelection):
+ * Platform/cocoa/WKPaymentAuthorizationDelegate.h:
+ * Platform/cocoa/WKPaymentAuthorizationDelegate.mm:
+ (-[WKPaymentAuthorizationDelegate completePaymentMethodSelection:]):
+ (-[WKPaymentAuthorizationDelegate completeShippingContactSelection:]):
+ (-[WKPaymentAuthorizationDelegate completeShippingMethodSelection:]):
+ (-[WKPaymentAuthorizationDelegate _didSelectPaymentMethod:completion:]):
+ (-[WKPaymentAuthorizationDelegate _didSelectShippingContact:completion:]):
+ (-[WKPaymentAuthorizationDelegate _didSelectShippingMethod:completion:]):
+ (-[WKPaymentAuthorizationDelegate completeShippingContactSelection:summaryItems:shippingMethods:errors:]): Deleted.
+ * Shared/ApplePay/WebPaymentCoordinatorProxy.h:
+ * Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h:
+ * Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
+ (WebKit::WebPaymentCoordinatorProxy::platformPaymentRequest):
+ (WebKit::toPKPaymentSummaryItemType): Deleted.
+ (WebKit::toPKPaymentSummaryItem): Deleted.
+ (WebKit::toPKPaymentSummaryItems): Deleted.
+ * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+ (IPC::ArgumentCoder<WebCore::PaymentMethodUpdate>::encode):
+ (IPC::ArgumentCoder<WebCore::PaymentMethodUpdate>::decode):
+
2019-09-20 Keith Rollin <[email protected]>
Remove some support for < iOS 13
Modified: trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.h (250178 => 250179)
--- trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -41,6 +41,7 @@
class PaymentContact;
class PaymentMerchantSession;
class PaymentMethod;
+class PaymentMethodUpdate;
class PaymentSessionError;
}
Modified: trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.mm (250178 => 250179)
--- trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.mm 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.mm 2019-09-21 06:37:34 UTC (rev 250179)
@@ -32,6 +32,8 @@
#import "WebPaymentCoordinatorProxyCocoa.h"
#import <WebCore/PaymentAuthorizationStatus.h>
#import <WebCore/PaymentMerchantSession.h>
+#import <WebCore/PaymentMethodUpdate.h>
+#import <WebCore/PaymentSummaryItems.h>
#import <pal/cocoa/PassKitSoftLink.h>
SOFT_LINK_FRAMEWORK(Contacts);
@@ -185,8 +187,12 @@
void PaymentAuthorizationPresenter::completePaymentMethodSelection(const Optional<WebCore::PaymentMethodUpdate>& update)
{
ASSERT(platformDelegate());
- NSArray *summaryItems = update ? toPKPaymentSummaryItems(update->newTotalAndLineItems) : platformDelegate().summaryItems;
- [platformDelegate() completePaymentMethodSelection:summaryItems];
+ if (!update) {
+ [platformDelegate() completePaymentMethodSelection:nil];
+ return;
+ }
+
+ [platformDelegate() completePaymentMethodSelection:update->platformUpdate()];
}
void PaymentAuthorizationPresenter::completePaymentSession(const Optional<WebCore::PaymentAuthorizationResult>& result)
@@ -200,18 +206,27 @@
void PaymentAuthorizationPresenter::completeShippingContactSelection(const Optional<WebCore::ShippingContactUpdate>& update)
{
ASSERT(platformDelegate());
- NSArray *shippingMethods = update ? toPKShippingMethods(update->newShippingMethods) : platformDelegate().shippingMethods;
- NSArray *summaryItems = update ? toPKPaymentSummaryItems(update->newTotalAndLineItems) : platformDelegate().summaryItems;
- NSArray *errors = update ? toNSErrors(update->errors) : @[ ];
- auto status = PKPaymentAuthorizationStatusSuccess;
- [platformDelegate() completeShippingContactSelection:status summaryItems:summaryItems shippingMethods:shippingMethods errors:errors];
+ if (!update) {
+ [platformDelegate() completeShippingContactSelection:nil];
+ return;
+ }
+
+ // FIXME: WebCore::ShippingContactUpdate should know how to convert itself to a PKPaymentRequestShippingContactUpdate.
+ auto shippingContactUpdate = adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:toNSErrors(update->errors) paymentSummaryItems:WebCore::platformSummaryItems(update->newTotalAndLineItems) shippingMethods:toPKShippingMethods(update->newShippingMethods)]);
+ [platformDelegate() completeShippingContactSelection:shippingContactUpdate.get()];
}
void PaymentAuthorizationPresenter::completeShippingMethodSelection(const Optional<WebCore::ShippingMethodUpdate>& update)
{
ASSERT(platformDelegate());
- NSArray *summaryItems = update ? toPKPaymentSummaryItems(update->newTotalAndLineItems) : platformDelegate().summaryItems;
- [platformDelegate() completeShippingMethodSelection:summaryItems];
+ if (!update) {
+ [platformDelegate() completeShippingMethodSelection:nil];
+ return;
+ }
+
+ // FIXME: WebCore::ShippingMethodUpdate should know how to convert itself to a PKPaymentRequestShippingMethodUpdate.
+ auto shippingMethodUpdate = adoptNS([PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:WebCore::platformSummaryItems(update->newTotalAndLineItems)]);
+ [platformDelegate() completeShippingMethodSelection:shippingMethodUpdate.get()];
}
} // namespace WebKit
Modified: trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.h (250178 => 250179)
--- trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -52,15 +52,11 @@
- (instancetype)init NS_UNAVAILABLE;
-@property (nonatomic, readonly) BOOL didReachFinalState;
-@property (nonatomic, readonly) NSArray<PKPaymentSummaryItem *> *summaryItems;
-@property (nonatomic, readonly) NSArray<PKShippingMethod *> *shippingMethods;
-
- (void)completeMerchantValidation:(PKPaymentMerchantSession *)session error:(NSError *)error;
-- (void)completePaymentMethodSelection:(NSArray<PKPaymentSummaryItem *> *)summaryItems;
+- (void)completePaymentMethodSelection:(PKPaymentRequestPaymentMethodUpdate *)paymentMethodUpdate;
- (void)completePaymentSession:(PKPaymentAuthorizationStatus)status errors:(NSArray<NSError *> *)errors didReachFinalState:(BOOL)didReachFinalState;
-- (void)completeShippingContactSelection:(PKPaymentAuthorizationStatus)status summaryItems:(NSArray<PKPaymentSummaryItem *> *)summaryItems shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods errors:(NSArray<NSError *> *)errors;
-- (void)completeShippingMethodSelection:(NSArray<PKPaymentSummaryItem *> *)summaryItems;
+- (void)completeShippingContactSelection:(PKPaymentRequestShippingContactUpdate *)shippingContactUpdate;
+- (void)completeShippingMethodSelection:(PKPaymentRequestShippingMethodUpdate *)shippingMethodUpdate;
- (void)invalidate;
@end
Modified: trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.mm (250178 => 250179)
--- trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.mm 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Platform/cocoa/WKPaymentAuthorizationDelegate.mm 2019-09-21 06:37:34 UTC (rev 250179)
@@ -33,6 +33,7 @@
#import <WebCore/PaymentSessionError.h>
@implementation WKPaymentAuthorizationDelegate {
+ BOOL _didReachFinalState;
RetainPtr<NSArray<PKPaymentSummaryItem *>> _summaryItems;
RetainPtr<NSArray<PKShippingMethod *>> _shippingMethods;
RetainPtr<NSError> _sessionError;
@@ -59,11 +60,11 @@
std::exchange(_didRequestMerchantSessionCompletion, nil)(session, error);
}
-- (void)completePaymentMethodSelection:(NSArray<PKPaymentSummaryItem *> *)summaryItems
+- (void)completePaymentMethodSelection:(PKPaymentRequestPaymentMethodUpdate *)paymentMethodUpdate
{
- _summaryItems = summaryItems;
- auto update = adoptNS([PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
- std::exchange(_didSelectPaymentMethodCompletion, nil)(update.get());
+ PKPaymentRequestPaymentMethodUpdate *update = paymentMethodUpdate ?: [[PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()] autorelease];
+ _summaryItems = adoptNS([update.paymentSummaryItems copy]);
+ std::exchange(_didSelectPaymentMethodCompletion, nil)(update);
}
- (void)completePaymentSession:(PKPaymentAuthorizationStatus)status errors:(NSArray<NSError *> *)errors didReachFinalState:(BOOL)didReachFinalState
@@ -72,21 +73,19 @@
auto result = adoptNS([PAL::allocPKPaymentAuthorizationResultInstance() initWithStatus:status errors:errors]);
std::exchange(_didAuthorizePaymentCompletion, nil)(result.get());
}
-
-- (void)completeShippingContactSelection:(PKPaymentAuthorizationStatus)status summaryItems:(NSArray<PKPaymentSummaryItem *> *)summaryItems shippingMethods:(NSArray<PKShippingMethod *> *)shippingMethods errors:(NSArray<NSError *> *)errors
+- (void)completeShippingContactSelection:(PKPaymentRequestShippingContactUpdate *)shippingContactUpdate
{
- _summaryItems = summaryItems;
- _shippingMethods = shippingMethods;
- ASSERT(status == PKPaymentAuthorizationStatusSuccess);
- auto update = adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:errors paymentSummaryItems:_summaryItems.get() shippingMethods:_shippingMethods.get()]);
- std::exchange(_didSelectShippingContactCompletion, nil)(update.get());
+ PKPaymentRequestShippingContactUpdate *update = shippingContactUpdate ?: [[PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:@[] paymentSummaryItems:_summaryItems.get() shippingMethods:_shippingMethods.get()] autorelease];
+ _summaryItems = adoptNS([update.paymentSummaryItems copy]);
+ _shippingMethods = adoptNS([update.shippingMethods copy]);
+ std::exchange(_didSelectShippingContactCompletion, nil)(update);
}
-- (void)completeShippingMethodSelection:(NSArray<PKPaymentSummaryItem *> *)summaryItems
+- (void)completeShippingMethodSelection:(PKPaymentRequestShippingMethodUpdate *)shippingMethodUpdate
{
- _summaryItems = summaryItems;
- auto update = adoptNS([PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()]);
- std::exchange(_didSelectShippingMethodCompletion, nil)(update.get());
+ PKPaymentRequestShippingMethodUpdate *update = shippingMethodUpdate ?: [[PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:_summaryItems.get()] autorelease];
+ _summaryItems = adoptNS([update.paymentSummaryItems copy]);
+ std::exchange(_didSelectShippingMethodCompletion, nil)(update);
}
- (void)invalidate
@@ -159,7 +158,7 @@
auto presenter = _presenter.get();
if (!presenter)
- return [self completePaymentMethodSelection:@[ ]];
+ return [self completePaymentMethodSelection:nil];
presenter->client().presenterDidSelectPaymentMethod(*presenter, WebCore::PaymentMethod(paymentMethod));
}
@@ -171,7 +170,7 @@
auto presenter = _presenter.get();
if (!presenter)
- return [self completeShippingContactSelection:PKPaymentAuthorizationStatusFailure summaryItems:@[ ] shippingMethods:@[ ] errors:@[ ]];
+ return [self completeShippingContactSelection:nil];
presenter->client().presenterDidSelectShippingContact(*presenter, WebCore::PaymentContact(contact));
}
@@ -196,7 +195,7 @@
auto presenter = _presenter.get();
if (!presenter)
- return [self completeShippingMethodSelection:@[ ]];
+ return [self completeShippingMethodSelection:nil];
presenter->client().presenterDidSelectShippingMethod(*presenter, toShippingMethod(shippingMethod));
}
Modified: trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h (250178 => 250179)
--- trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -55,6 +55,7 @@
class PaymentContact;
class PaymentMerchantSession;
class PaymentMethod;
+class PaymentMethodUpdate;
}
OBJC_CLASS NSObject;
Modified: trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h (250178 => 250179)
--- trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h 2019-09-21 06:37:34 UTC (rev 250179)
@@ -33,10 +33,7 @@
// FIXME: Rather than having these free functions scattered about, Apple Pay data types should know
// how to convert themselves to and from their platform representations.
-NSArray *toPKPaymentSummaryItems(const WebCore::ApplePaySessionPaymentRequest::TotalAndLineItems&);
NSDecimalNumber *toDecimalNumber(const String& amount);
-PKPaymentSummaryItem *toPKPaymentSummaryItem(const WebCore::ApplePaySessionPaymentRequest::LineItem&);
-PKPaymentSummaryItemType toPKPaymentSummaryItemType(WebCore::ApplePaySessionPaymentRequest::LineItem::Type);
PKShippingMethod *toPKShippingMethod(const WebCore::ApplePaySessionPaymentRequest::ShippingMethod&);
} // namespace WebKit
Modified: trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm (250178 => 250179)
--- trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm 2019-09-21 06:37:34 UTC (rev 250179)
@@ -109,17 +109,6 @@
return adoptNS([[NSSet alloc] initWithObjects:result.data() count:result.size()]);
}
-PKPaymentSummaryItemType toPKPaymentSummaryItemType(WebCore::ApplePaySessionPaymentRequest::LineItem::Type type)
-{
- switch (type) {
- case WebCore::ApplePaySessionPaymentRequest::LineItem::Type::Final:
- return PKPaymentSummaryItemTypeFinal;
-
- case WebCore::ApplePaySessionPaymentRequest::LineItem::Type::Pending:
- return PKPaymentSummaryItemTypePending;
- }
-}
-
NSDecimalNumber *toDecimalNumber(const String& amount)
{
if (!amount)
@@ -127,25 +116,6 @@
return [NSDecimalNumber decimalNumberWithString:amount locale:@{ NSLocaleDecimalSeparator : @"." }];
}
-PKPaymentSummaryItem *toPKPaymentSummaryItem(const WebCore::ApplePaySessionPaymentRequest::LineItem& lineItem)
-{
- return [PAL::getPKPaymentSummaryItemClass() summaryItemWithLabel:lineItem.label amount:toDecimalNumber(lineItem.amount) type:toPKPaymentSummaryItemType(lineItem.type)];
-}
-
-NSArray *toPKPaymentSummaryItems(const WebCore::ApplePaySessionPaymentRequest::TotalAndLineItems& totalAndLineItems)
-{
- NSMutableArray *paymentSummaryItems = [NSMutableArray arrayWithCapacity:totalAndLineItems.lineItems.size() + 1];
- for (auto& lineItem : totalAndLineItems.lineItems) {
- if (PKPaymentSummaryItem *summaryItem = toPKPaymentSummaryItem(lineItem))
- [paymentSummaryItems addObject:summaryItem];
- }
-
- if (PKPaymentSummaryItem *totalItem = toPKPaymentSummaryItem(totalAndLineItems.total))
- [paymentSummaryItems addObject:totalItem];
-
- return paymentSummaryItems;
-}
-
static PKMerchantCapability toPKMerchantCapabilities(const WebCore::ApplePaySessionPaymentRequest::MerchantCapabilities& merchantCapabilities)
{
PKMerchantCapability result = 0;
@@ -256,17 +226,8 @@
[shippingMethods addObject:toPKShippingMethod(shippingMethod)];
[result setShippingMethods:shippingMethods.get()];
- auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
- for (auto& lineItem : paymentRequest.lineItems()) {
- if (PKPaymentSummaryItem *summaryItem = toPKPaymentSummaryItem(lineItem))
- [paymentSummaryItems addObject:summaryItem];
- }
+ [result setPaymentSummaryItems:WebCore::platformSummaryItems(paymentRequest.total(), paymentRequest.lineItems())];
- if (PKPaymentSummaryItem *totalItem = toPKPaymentSummaryItem(paymentRequest.total()))
- [paymentSummaryItems addObject:totalItem];
-
- [result setPaymentSummaryItems:paymentSummaryItems.get()];
-
[result setExpectsMerchantSession:YES];
if (!paymentRequest.applicationData().isNull()) {
Modified: trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm (250178 => 250179)
--- trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm 2019-09-21 05:29:17 UTC (rev 250178)
+++ trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm 2019-09-21 06:37:34 UTC (rev 250179)
@@ -161,16 +161,16 @@
void ArgumentCoder<WebCore::PaymentMethodUpdate>::encode(Encoder& encoder, const WebCore::PaymentMethodUpdate& update)
{
- encoder << update.newTotalAndLineItems;
+ encoder << update.platformUpdate();
}
Optional<WebCore::PaymentMethodUpdate> ArgumentCoder<WebCore::PaymentMethodUpdate>::decode(Decoder& decoder)
{
- Optional<ApplePaySessionPaymentRequest::TotalAndLineItems> newTotalAndLineItems;
- decoder >> newTotalAndLineItems;
- if (!newTotalAndLineItems)
+ auto update = IPC::decode<PKPaymentRequestPaymentMethodUpdate>(decoder, PAL::getPKPaymentRequestPaymentMethodUpdateClass());
+ if (!update)
return WTF::nullopt;
- return {{ WTFMove(*newTotalAndLineItems) }};
+
+ return PaymentMethodUpdate { WTFMove(*update) };
}
void ArgumentCoder<ApplePaySessionPaymentRequest>::encode(Encoder& encoder, const ApplePaySessionPaymentRequest& request)