Title: [220718] trunk
Revision
220718
Author
aes...@apple.com
Date
2017-08-14 15:03:56 -0700 (Mon, 14 Aug 2017)

Log Message

[Apple Pay] Add support for phonetic contact names
https://bugs.webkit.org/show_bug.cgi?id=175537
<rdar://problem/32002644>

Reviewed by Tim Horton.

Source/WebCore:

* Modules/applepay/ApplePayError.idl: Defined "phoneticName" in ApplePayErrorContactField.
* Modules/applepay/ApplePayPaymentContact.h: Defined phoneticGivenName and phoneticFamilyName
in ApplePayPaymentContact.
* Modules/applepay/ApplePayPaymentContact.idl: Ditto.
* Modules/applepay/ApplePayPaymentRequest.h: Defined PhoneticName in
ApplePayPaymentRequest::ContactField.
* Modules/applepay/ApplePayPaymentRequest.idl: Defined "phoneticName" in ApplePayContactField.
* Modules/applepay/ApplePaySession.cpp:
(WebCore::convertAndValidate): Added a version parameter. Added code to convert
ContactField::PhoneticName, throwing an exception if version is less than 3.
* Modules/applepay/PaymentContact.h: Added a version parameter to fromApplePayPaymentContact().
* Modules/applepay/PaymentRequest.h: Defined phoneticName in PaymentRequest::ContactFields
and defined PhoneticName in PaymentError::ContactField.
* Modules/applepay/cocoa/PaymentContactCocoa.mm:
(WebCore::convert): Added a version parameter. Set a phoneticRepresentation on the
PKContact's name if there are non-empty phonetic names and version is 3 or greater.
(WebCore::PaymentContact::fromApplePayPaymentContact): Passed version to convert().

Source/WebKit:

* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm: Soft-linked PKContactFieldPhoneticName.
(WebKit::toPKContactFields): Added code to append PKContactFieldPhoneticName to result if
contactFields.phoneticName is true.
(WebKit::toNSError): Specified PKContactFieldPhoneticName as the contact field for
PaymentError::ContactField::PhoneticName.

LayoutTests:

* http/tests/ssl/applepay/ApplePayError-expected.txt:
* http/tests/ssl/applepay/ApplePayError.html:
* http/tests/ssl/applepay/ApplePaySession-expected.txt:
* http/tests/ssl/applepay/ApplePaySession.html:
* http/tests/ssl/applepay/ApplePaySessionV3-expected.txt:
* http/tests/ssl/applepay/ApplePaySessionV3.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (220717 => 220718)


--- trunk/LayoutTests/ChangeLog	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/LayoutTests/ChangeLog	2017-08-14 22:03:56 UTC (rev 220718)
@@ -1,3 +1,18 @@
+2017-08-14  Andy Estes  <aes...@apple.com>
+
+        [Apple Pay] Add support for phonetic contact names
+        https://bugs.webkit.org/show_bug.cgi?id=175537
+        <rdar://problem/32002644>
+
+        Reviewed by Tim Horton.
+
+        * http/tests/ssl/applepay/ApplePayError-expected.txt:
+        * http/tests/ssl/applepay/ApplePayError.html:
+        * http/tests/ssl/applepay/ApplePaySession-expected.txt:
+        * http/tests/ssl/applepay/ApplePaySession.html:
+        * http/tests/ssl/applepay/ApplePaySessionV3-expected.txt:
+        * http/tests/ssl/applepay/ApplePaySessionV3.html:
+
 2017-08-14  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         The none smooth stroke applied to an SVG shape breaks its hit testing

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePayError-expected.txt (220717 => 220718)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePayError-expected.txt	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePayError-expected.txt	2017-08-14 22:03:56 UTC (rev 220718)
@@ -27,10 +27,10 @@
 PASS new ApplePayError('addressUnserviceable') did not throw exception.
 
 SETUP: 
-PASS new ApplePayError('unknown', []) threw exception TypeError: Argument 2 ('contactField') to the ApplePayError constructor must be one of: "phoneNumber", "emailAddress", "name", "postalAddress", "addressLines", "locality", "postalCode", "administrativeArea", "country", "countryCode".
+PASS new ApplePayError('unknown', []) threw exception TypeError: Argument 2 ('contactField') to the ApplePayError constructor must be one of: "phoneNumber", "emailAddress", "name", "phoneticName", "postalAddress", "addressLines", "locality", "postalCode", "administrativeArea", "country", "countryCode".
 
 SETUP: 
-PASS new ApplePayError('unknown', '') threw exception TypeError: Argument 2 ('contactField') to the ApplePayError constructor must be one of: "phoneNumber", "emailAddress", "name", "postalAddress", "addressLines", "locality", "postalCode", "administrativeArea", "country", "countryCode".
+PASS new ApplePayError('unknown', '') threw exception TypeError: Argument 2 ('contactField') to the ApplePayError constructor must be one of: "phoneNumber", "emailAddress", "name", "phoneticName", "postalAddress", "addressLines", "locality", "postalCode", "administrativeArea", "country", "countryCode".
 
 SETUP: 
 PASS new ApplePayError('unknown', 'phoneNumber') did not throw exception.
@@ -42,6 +42,9 @@
 PASS new ApplePayError('unknown', 'name') did not throw exception.
 
 SETUP: 
+PASS new ApplePayError('unknown', 'phoneticName') did not throw exception.
+
+SETUP: 
 PASS new ApplePayError('unknown', 'postalAddress') did not throw exception.
 
 SETUP: 

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePayError.html (220717 => 220718)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePayError.html	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePayError.html	2017-08-14 22:03:56 UTC (rev 220718)
@@ -40,6 +40,7 @@
         logAndShouldNotThrow("", "new ApplePayError('unknown', 'phoneNumber')")
         logAndShouldNotThrow("", "new ApplePayError('unknown', 'emailAddress')")
         logAndShouldNotThrow("", "new ApplePayError('unknown', 'name')")
+        logAndShouldNotThrow("", "new ApplePayError('unknown', 'phoneticName')")
         logAndShouldNotThrow("", "new ApplePayError('unknown', 'postalAddress')")
         logAndShouldNotThrow("", "new ApplePayError('unknown', 'addressLines')")
         logAndShouldNotThrow("", "new ApplePayError('unknown', 'locality')")

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt (220717 => 220718)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt	2017-08-14 22:03:56 UTC (rev 220718)
@@ -231,6 +231,9 @@
 SETUP: request = validRequest(); request.requiredBillingContactFields = ['invalid'];
 PASS new ApplePaySession(2, request) threw exception TypeError: Type error.
 
+SETUP: request = validRequest(); request.requiredBillingContactFields = ['phoneticName'];
+PASS new ApplePaySession(2, request) threw exception TypeError: "phoneticName" is not a valid contact field..
+
 SETUP: request = validRequest(); request.requiredBillingContactFields = ['email', 'name', 'phone', 'postalAddress'];
 PASS new ApplePaySession(2, request) did not throw exception.
 
@@ -289,6 +292,9 @@
 SETUP: request = validRequest(); request.requiredShippingContactFields = ['invalid'];
 PASS new ApplePaySession(2, request) threw exception TypeError: Type error.
 
+SETUP: request = validRequest(); request.requiredShippingContactFields = ['phoneticName'];
+PASS new ApplePaySession(2, request) threw exception TypeError: "phoneticName" is not a valid contact field..
+
 SETUP: request = validRequest(); request.requiredShippingContactFields = ['email', 'name', 'phone', 'postalAddress'];
 PASS new ApplePaySession(2, request) did not throw exception.
 

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession.html (220717 => 220718)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession.html	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySession.html	2017-08-14 22:03:56 UTC (rev 220718)
@@ -135,6 +135,7 @@
     logAndShouldThrow("request = validRequest(); request.requiredBillingContactFields = [undefined];", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.requiredBillingContactFields = [{}];", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.requiredBillingContactFields = ['invalid'];", "new ApplePaySession(2, request)")
+    logAndShouldThrow("request = validRequest(); request.requiredBillingContactFields = ['phoneticName'];", "new ApplePaySession(2, request)")
     logAndShouldNotThrow("request = validRequest(); request.requiredBillingContactFields = ['email', 'name', 'phone', 'postalAddress'];", "new ApplePaySession(2, request)")
     // FIXME: Should duplicate contactFields be allowed?
     logAndShouldNotThrow("request = validRequest(); request.requiredBillingContactFields = ['email', 'email'];", "new ApplePaySession(2, request)")
@@ -160,6 +161,7 @@
     logAndShouldThrow("request = validRequest(); request.requiredShippingContactFields = [undefined];", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.requiredShippingContactFields = [{}];", "new ApplePaySession(2, request)")
     logAndShouldThrow("request = validRequest(); request.requiredShippingContactFields = ['invalid'];", "new ApplePaySession(2, request)")
+    logAndShouldThrow("request = validRequest(); request.requiredShippingContactFields = ['phoneticName'];", "new ApplePaySession(2, request)")
     logAndShouldNotThrow("request = validRequest(); request.requiredShippingContactFields = ['email', 'name', 'phone', 'postalAddress'];", "new ApplePaySession(2, request)")
     // FIXME: Should duplicate contactFields be allowed?
     logAndShouldNotThrow("request = validRequest(); request.requiredShippingContactFields = ['email', 'email'];", "new ApplePaySession(2, request)")

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySessionV3-expected.txt (220717 => 220718)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySessionV3-expected.txt	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySessionV3-expected.txt	2017-08-14 22:03:56 UTC (rev 220718)
@@ -43,7 +43,13 @@
 SETUP: request = validRequest(); request.supportedCountries = ['US', 'US'];
 PASS new ApplePaySession(3, request) did not throw exception.
 
+SETUP: request = validRequest(); request.requiredBillingContactFields = ['phoneticName'];
+PASS new ApplePaySession(3, request) did not throw exception.
 
+SETUP: request = validRequest(); request.requiredShippingContactFields = ['phoneticName'];
+PASS new ApplePaySession(3, request) did not throw exception.
+
+
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySessionV3.html (220717 => 220718)


--- trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySessionV3.html	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/LayoutTests/http/tests/ssl/applepay/ApplePaySessionV3.html	2017-08-14 22:03:56 UTC (rev 220718)
@@ -56,6 +56,8 @@
     logAndShouldNotThrow("request = validRequest(); request.supportedCountries = [];", "new ApplePaySession(3, request)");
     logAndShouldNotThrow("request = validRequest(); request.supportedCountries = ['US'];", "new ApplePaySession(3, request)");
     logAndShouldNotThrow("request = validRequest(); request.supportedCountries = ['US', 'US'];", "new ApplePaySession(3, request)");
+    logAndShouldNotThrow("request = validRequest(); request.requiredBillingContactFields = ['phoneticName'];", "new ApplePaySession(3, request)")
+    logAndShouldNotThrow("request = validRequest(); request.requiredShippingContactFields = ['phoneticName'];", "new ApplePaySession(3, request)")
     debug("");
 
     document.querySelector("button").remove();

Modified: trunk/Source/WebCore/ChangeLog (220717 => 220718)


--- trunk/Source/WebCore/ChangeLog	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/ChangeLog	2017-08-14 22:03:56 UTC (rev 220718)
@@ -1,3 +1,29 @@
+2017-08-14  Andy Estes  <aes...@apple.com>
+
+        [Apple Pay] Add support for phonetic contact names
+        https://bugs.webkit.org/show_bug.cgi?id=175537
+        <rdar://problem/32002644>
+
+        Reviewed by Tim Horton.
+
+        * Modules/applepay/ApplePayError.idl: Defined "phoneticName" in ApplePayErrorContactField.
+        * Modules/applepay/ApplePayPaymentContact.h: Defined phoneticGivenName and phoneticFamilyName
+        in ApplePayPaymentContact.
+        * Modules/applepay/ApplePayPaymentContact.idl: Ditto.
+        * Modules/applepay/ApplePayPaymentRequest.h: Defined PhoneticName in
+        ApplePayPaymentRequest::ContactField.
+        * Modules/applepay/ApplePayPaymentRequest.idl: Defined "phoneticName" in ApplePayContactField.
+        * Modules/applepay/ApplePaySession.cpp:
+        (WebCore::convertAndValidate): Added a version parameter. Added code to convert
+        ContactField::PhoneticName, throwing an exception if version is less than 3.
+        * Modules/applepay/PaymentContact.h: Added a version parameter to fromApplePayPaymentContact().
+        * Modules/applepay/PaymentRequest.h: Defined phoneticName in PaymentRequest::ContactFields
+        and defined PhoneticName in PaymentError::ContactField.
+        * Modules/applepay/cocoa/PaymentContactCocoa.mm:
+        (WebCore::convert): Added a version parameter. Set a phoneticRepresentation on the
+        PKContact's name if there are non-empty phonetic names and version is 3 or greater.
+        (WebCore::PaymentContact::fromApplePayPaymentContact): Passed version to convert().
+
 2017-08-14  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         The none smooth stroke applied to an SVG shape breaks its hit testing

Modified: trunk/Source/WebCore/Modules/applepay/ApplePayError.idl (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/ApplePayError.idl	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayError.idl	2017-08-14 22:03:56 UTC (rev 220718)
@@ -38,6 +38,7 @@
     "phoneNumber",
     "emailAddress",
     "name",
+    "phoneticName",
     "postalAddress",
     "addressLines",
     "locality",

Modified: trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -38,6 +38,8 @@
     String emailAddress;
     String givenName;
     String familyName;
+    String phoneticGivenName;
+    String phoneticFamilyName;
     std::optional<Vector<String>> addressLines;
     String locality;
     String postalCode;

Modified: trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.idl (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.idl	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.idl	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -31,6 +31,8 @@
     DOMString emailAddress;
     DOMString givenName;
     DOMString familyName;
+    [Conditional=APPLE_PAY_SESSION_V3] DOMString phoneticGivenName;
+    [Conditional=APPLE_PAY_SESSION_V3] DOMString phoneticFamilyName;
     sequence<DOMString> addressLines;
     DOMString locality;
     DOMString postalCode;

Modified: trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -36,7 +36,7 @@
 
 struct ApplePayPaymentRequest {
     enum class MerchantCapability { Supports3DS, SupportsEMV, SupportsCredit, SupportsDebit };
-    enum class ContactField { Email, Name, Phone, PostalAddress };
+    enum class ContactField { Email, Name, PhoneticName, Phone, PostalAddress };
 
     using ShippingType = PaymentRequest::ShippingType;
 

Modified: trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -37,6 +37,7 @@
 ] enum ApplePayContactField {
     "email",
     "name",
+    "phoneticName",
     "phone",
     "postalAddress"
 };

Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -257,7 +257,7 @@
     return WTFMove(supportedNetworks);
 }
 
-static ExceptionOr<PaymentRequest::ContactFields> convertAndValidate(Vector<ApplePayPaymentRequest::ContactField>&& contactFields)
+static ExceptionOr<PaymentRequest::ContactFields> convertAndValidate(unsigned version, Vector<ApplePayPaymentRequest::ContactField>&& contactFields)
 {
     PaymentRequest::ContactFields result;
 
@@ -269,6 +269,11 @@
         case ApplePayPaymentRequest::ContactField::Name:
             result.name = true;
             break;
+        case ApplePayPaymentRequest::ContactField::PhoneticName:
+            if (version < 3)
+                return Exception { TypeError, "\"phoneticName\" is not a valid contact field." };
+            result.phoneticName = true;
+            break;
         case ApplePayPaymentRequest::ContactField::Phone:
             result.phone = true;
             break;
@@ -339,7 +344,7 @@
     result.setSupportedNetworks(supportedNetworks.releaseReturnValue());
 
     if (paymentRequest.requiredBillingContactFields) {
-        auto requiredBillingContactFields = convertAndValidate(WTFMove(*paymentRequest.requiredBillingContactFields));
+        auto requiredBillingContactFields = convertAndValidate(version, WTFMove(*paymentRequest.requiredBillingContactFields));
         if (requiredBillingContactFields.hasException())
             return requiredBillingContactFields.releaseException();
         result.setRequiredBillingContactFields(requiredBillingContactFields.releaseReturnValue());
@@ -346,10 +351,10 @@
     }
 
     if (paymentRequest.billingContact)
-        result.setBillingContact(PaymentContact::fromApplePayPaymentContact(paymentRequest.billingContact.value()));
+        result.setBillingContact(PaymentContact::fromApplePayPaymentContact(version, paymentRequest.billingContact.value()));
 
     if (paymentRequest.requiredShippingContactFields) {
-        auto requiredShippingContactFields = convertAndValidate(WTFMove(*paymentRequest.requiredShippingContactFields));
+        auto requiredShippingContactFields = convertAndValidate(version, WTFMove(*paymentRequest.requiredShippingContactFields));
         if (requiredShippingContactFields.hasException())
             return requiredShippingContactFields.releaseException();
         result.setRequiredShippingContactFields(requiredShippingContactFields.releaseReturnValue());
@@ -356,7 +361,7 @@
     }
 
     if (paymentRequest.shippingContact)
-        result.setShippingContact(PaymentContact::fromApplePayPaymentContact(paymentRequest.shippingContact.value()));
+        result.setShippingContact(PaymentContact::fromApplePayPaymentContact(version, paymentRequest.shippingContact.value()));
 
     result.setShippingType(paymentRequest.shippingType);
 

Modified: trunk/Source/WebCore/Modules/applepay/PaymentContact.h (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/PaymentContact.h	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/PaymentContact.h	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -44,7 +44,7 @@
     {
     }
 
-    static PaymentContact fromApplePayPaymentContact(const ApplePayPaymentContact&);
+    static PaymentContact fromApplePayPaymentContact(unsigned version, const ApplePayPaymentContact&);
     ApplePayPaymentContact toApplePayPaymentContact() const;
 
     PKContact *pkContact() const { return m_pkContact.get(); }

Modified: trunk/Source/WebCore/Modules/applepay/PaymentRequest.h (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/PaymentRequest.h	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/PaymentRequest.h	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -53,6 +53,7 @@
         bool phone { false };
         bool email { false };
         bool name { false };
+        bool phoneticName { false };
     };
 
     const ContactFields& requiredBillingContactFields() const { return m_requiredBillingContactFields; }
@@ -166,6 +167,7 @@
         PhoneNumber,
         EmailAddress,
         Name,
+        PhoneticName,
         PostalAddress,
         AddressLines,
         Locality,

Modified: trunk/Source/WebCore/Modules/applepay/cocoa/PaymentContactCocoa.mm (220717 => 220718)


--- trunk/Source/WebCore/Modules/applepay/cocoa/PaymentContactCocoa.mm	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebCore/Modules/applepay/cocoa/PaymentContactCocoa.mm	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -48,14 +48,36 @@
 
 namespace WebCore {
 
-static RetainPtr<PKContact> convert(const ApplePayPaymentContact& contact)
+static RetainPtr<PKContact> convert(unsigned version, const ApplePayPaymentContact& contact)
 {
     auto result = adoptNS([allocPKContactInstance() init]);
 
-    if (!contact.familyName.isEmpty() || !contact.givenName.isEmpty()) {
+    NSString *familyName = nil;
+    NSString *phoneticFamilyName = nil;
+    if (!contact.familyName.isEmpty()) {
+        familyName = contact.familyName;
+        if (version >= 3 && !contact.phoneticFamilyName.isEmpty())
+            phoneticFamilyName = contact.phoneticFamilyName;
+    }
+
+    NSString *givenName = nil;
+    NSString *phoneticGivenName = nil;
+    if (!contact.givenName.isEmpty()) {
+        givenName = contact.givenName;
+        if (version >= 3 && !contact.phoneticGivenName.isEmpty())
+            phoneticGivenName = contact.phoneticGivenName;
+    }
+
+    if (familyName || givenName) {
         auto name = adoptNS([[NSPersonNameComponents alloc] init]);
-        [name setFamilyName:contact.familyName];
-        [name setGivenName:contact.givenName];
+        [name setFamilyName:familyName];
+        [name setGivenName:givenName];
+        if (phoneticFamilyName || phoneticGivenName) {
+            auto phoneticName = adoptNS([[NSPersonNameComponents alloc] init]);
+            [phoneticName setFamilyName:phoneticFamilyName];
+            [phoneticName setGivenName:phoneticGivenName];
+            [name setPhoneticRepresentation:phoneticName.get()];
+        }
         [result setName:name.get()];
     }
 
@@ -74,7 +96,7 @@
             if (i != contact.addressLines->size() - 1)
                 builder.append('\n');
         }
-        
+
         // FIXME: StringBuilder should hava a toNSString() function to avoid the extra String allocation.
         [address setStreet:builder.toString()];
 
@@ -101,36 +123,35 @@
 
     ApplePayPaymentContact result;
 
-    if (contact.phoneNumber)
-        result.phoneNumber = contact.phoneNumber.stringValue;
-    if (contact.emailAddress)
-        result.emailAddress = contact.emailAddress;
-    if (contact.name.givenName)
-        result.givenName = contact.name.givenName;
-    if (contact.name.familyName)
-        result.familyName = contact.name.familyName;
-    if (contact.postalAddress.street.length) {
+    result.phoneNumber = contact.phoneNumber.stringValue;
+    result.emailAddress = contact.emailAddress;
+
+    NSPersonNameComponents *name = contact.name;
+    result.givenName = name.givenName;
+    result.familyName = name.familyName;
+
+    NSPersonNameComponents *phoneticName = name.phoneticRepresentation;
+    result.phoneticGivenName = phoneticName.givenName;
+    result.phoneticFamilyName = phoneticName.familyName;
+
+    CNPostalAddress *postalAddress = contact.postalAddress;
+    if (postalAddress.street.length) {
         Vector<String> addressLines;
-        String(contact.postalAddress.street).split("\n", addressLines);
+        String(postalAddress.street).split("\n", addressLines);
         result.addressLines = WTFMove(addressLines);
     }
-    if (contact.postalAddress.city)
-        result.locality = contact.postalAddress.city;
-    if (contact.postalAddress.postalCode)
-        result.postalCode = contact.postalAddress.postalCode;
-    if (contact.postalAddress.state)
-        result.administrativeArea = contact.postalAddress.state;
-    if (contact.postalAddress.country)
-        result.country = contact.postalAddress.country;
-    if (contact.postalAddress.ISOCountryCode)
-        result.countryCode = contact.postalAddress.ISOCountryCode;
+    result.locality = postalAddress.city;
+    result.postalCode = postalAddress.postalCode;
+    result.administrativeArea = postalAddress.state;
+    result.country = postalAddress.country;
+    result.countryCode = postalAddress.ISOCountryCode;
 
     return result;
 }
 
-PaymentContact PaymentContact::fromApplePayPaymentContact(const ApplePayPaymentContact& contact)
+PaymentContact PaymentContact::fromApplePayPaymentContact(unsigned version, const ApplePayPaymentContact& contact)
 {
-    return PaymentContact(convert(contact).get());
+    return PaymentContact(convert(version, contact).get());
 }
 
 ApplePayPaymentContact PaymentContact::toApplePayPaymentContact() const

Modified: trunk/Source/WebKit/ChangeLog (220717 => 220718)


--- trunk/Source/WebKit/ChangeLog	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebKit/ChangeLog	2017-08-14 22:03:56 UTC (rev 220718)
@@ -1,3 +1,17 @@
+2017-08-14  Andy Estes  <aes...@apple.com>
+
+        [Apple Pay] Add support for phonetic contact names
+        https://bugs.webkit.org/show_bug.cgi?id=175537
+        <rdar://problem/32002644>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm: Soft-linked PKContactFieldPhoneticName.
+        (WebKit::toPKContactFields): Added code to append PKContactFieldPhoneticName to result if
+        contactFields.phoneticName is true.
+        (WebKit::toNSError): Specified PKContactFieldPhoneticName as the contact field for
+        PaymentError::ContactField::PhoneticName.
+
 2017-08-14  Tim Horton  <timothy_hor...@apple.com>
 
         Only create directory and sandbox extension handle for storage directories if they are set

Modified: trunk/Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm (220717 => 220718)


--- trunk/Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm	2017-08-14 22:00:27 UTC (rev 220717)
+++ trunk/Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm	2017-08-14 22:03:56 UTC (rev 220718)
@@ -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
@@ -77,6 +77,7 @@
 SOFT_LINK_CONSTANT(PassKit, PKContactFieldEmailAddress, NSString *);
 SOFT_LINK_CONSTANT(PassKit, PKContactFieldPhoneNumber, NSString *);
 SOFT_LINK_CONSTANT(PassKit, PKContactFieldName, NSString *);
+SOFT_LINK_CONSTANT(PassKit, PKContactFieldPhoneticName, NSString *);
 SOFT_LINK_CONSTANT(PassKit, PKPaymentErrorContactFieldUserInfoKey, NSString *);
 SOFT_LINK_CONSTANT(PassKit, PKPaymentErrorPostalAddressUserInfoKey, NSString *);
 #endif
@@ -362,6 +363,8 @@
         result.append(getPKContactFieldEmailAddress());
     if (contactFields.name)
         result.append(getPKContactFieldName());
+    if (contactFields.phoneticName)
+        result.append(getPKContactFieldPhoneticName());
 
     return adoptNS([[NSSet alloc] initWithObjects:result.data() count:result.size()]);
 }
@@ -638,6 +641,10 @@
             pkContactField = getPKContactFieldName();
             break;
 
+        case WebCore::PaymentError::ContactField::PhoneticName:
+            pkContactField = getPKContactFieldPhoneticName();
+            break;
+
         case WebCore::PaymentError::ContactField::PostalAddress:
             pkContactField = getPKContactFieldPostalAddress();
             break;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to