Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Apple Pay] Deprecate enabled in favor of available in ApplePaySh…
…ippingContactEditingMode

https://bugs.webkit.org/show_bug.cgi?id=259659
rdar://113159800

Reviewed by Wenson Hsieh.

In iOS 17, PassKit is deprecating PKShippingContactEditingModeEnabled in
favor of PKShippingContactEditingModeAvailable in the
PKShippingContactEditingMode  enumeration. Reference: https://developer.apple.com/documentation/passkit/pkshippingcontacteditingmode/pkshippingcontacteditingmodeenabled?language=objc

Given our intention to reflect the PassKit public API in the Apple Pay
JS API, we should follow suit and perform a similar deprecation. We do
so by introducing `available`, the preferred enumeration value, and
logging a console warning whenever a PaymentSession is inititated with a
PaymentRequest containing the deprecated `shippingContactEditingMode`
value.

* LayoutTests/http/tests/paymentrequest/paymentrequest-shippingContactEditingMode.https.html:
* Source/WebCore/Modules/applepay/ApplePayShippingContactEditingMode.h:
* Source/WebCore/Modules/applepay/ApplePayShippingContactEditingMode.idl:
* Source/WebCore/Modules/applepay/PaymentCoordinator.cpp:
(WebCore::PaymentCoordinator::beginPaymentSession):
* Source/WebKit/Shared/ApplePay/PaymentSetupConfiguration.mm:

Drive-by fix of a mismatched namespace.

* Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::toPKShippingContactEditingMode):

Canonical link: https://commits.webkit.org/266493@main
  • Loading branch information
aprotyas committed Aug 1, 2023
1 parent 4b03459 commit 07b5559
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
Expand Up @@ -35,7 +35,7 @@

user_activation_test(async (test) => {
const method = validPaymentMethod();
method.data.shippingContactEditingMode = "enabled";
method.data.shippingContactEditingMode = "available";

let request = new PaymentRequest([method], validPaymentDetails());
request.addEventListener("merchantvalidation", (event) => {
Expand Down
Expand Up @@ -27,13 +27,29 @@

#if ENABLE(APPLE_PAY_SHIPPING_CONTACT_EDITING_MODE)

#include <wtf/EnumTraits.h>

namespace WebCore {

enum class ApplePayShippingContactEditingMode : bool {
Enabled,
enum class ApplePayShippingContactEditingMode : uint8_t {
Available,
Enabled, // Deprecated in favor of `Available`.
StorePickup,
};

} // namespace WebCore

namespace WTF {

template<> struct EnumTraits<WebCore::ApplePayShippingContactEditingMode> {
using values = EnumValues<
WebCore::ApplePayShippingContactEditingMode,
WebCore::ApplePayShippingContactEditingMode::Available,
WebCore::ApplePayShippingContactEditingMode::Enabled,
WebCore::ApplePayShippingContactEditingMode::StorePickup
>;
};

} // namespace WTF

#endif // ENABLE(APPLE_PAY_SHIPPING_CONTACT_EDITING_MODE)
Expand Up @@ -27,6 +27,7 @@
Conditional=APPLE_PAY_SHIPPING_CONTACT_EDITING_MODE,
ExportMacro=WEBCORE_EXPORT,
] enum ApplePayShippingContactEditingMode {
"available",
"enabled",
"storePickup"
};
5 changes: 5 additions & 0 deletions Source/WebCore/Modules/applepay/PaymentCoordinator.cpp
Expand Up @@ -107,6 +107,11 @@ bool PaymentCoordinator::beginPaymentSession(Document& document, PaymentSession&
if (!showPaymentUI)
return false;

#if ENABLE(APPLE_PAY_SHIPPING_CONTACT_EDITING_MODE)
if (paymentRequest.shippingContactEditingMode() == ApplePayShippingContactEditingMode::Enabled)
document.addConsoleMessage(MessageSource::PaymentRequest, MessageLevel::Warning, "`enabled` is a deprecated value for `shippingContactEditingMode`. Please use `available` instead."_s);
#endif

m_activeSession = &paymentSession;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/Shared/ApplePay/PaymentSetupConfiguration.mm
Expand Up @@ -78,6 +78,6 @@ @interface PKPaymentSetupConfiguration (WebKit)
{
}

} // namespace WebKitAdditions
} // namespace WebKit

#endif // ENABLE(APPLE_PAY)
Expand Up @@ -216,6 +216,7 @@ static PKShippingType toPKShippingType(WebCore::ApplePaySessionPaymentRequest::S
static PKShippingContactEditingMode toPKShippingContactEditingMode(WebCore::ApplePayShippingContactEditingMode shippingContactEditingMode)
{
switch (shippingContactEditingMode) {
case WebCore::ApplePayShippingContactEditingMode::Available:
case WebCore::ApplePayShippingContactEditingMode::Enabled:
#if USE(PKSHIPPINGCONTACTEDITINGMODEENABLED)
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
Expand Down

0 comments on commit 07b5559

Please sign in to comment.