[Apple Pay] Add subLocality and subAdministrativeArea to ApplePayPaymentContact and...
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Oct 2017 21:41:57 +0000 (21:41 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Oct 2017 21:41:57 +0000 (21:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178191
<rdar://problem/34906367>

Reviewed by Tim Horton.

Source/WebCore:

Added test cases to http/tests/ssl/applepay/ApplePaySession.html.

* Modules/applepay/ApplePayError.idl:
* Modules/applepay/ApplePayPaymentContact.h:
* Modules/applepay/ApplePayPaymentContact.idl:
* Modules/applepay/ApplePaySessionPaymentRequest.h:
* Modules/applepay/cocoa/PaymentContactCocoa.mm:
(WebCore::subLocality):
(WebCore::setSubLocality):
(WebCore::subAdministrativeArea):
(WebCore::setSubAdministrativeArea):
(WebCore::convert):

Source/WebKit:

* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::toNSError):

LayoutTests:

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

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

12 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/ssl/applepay/ApplePayError-expected.txt
LayoutTests/http/tests/ssl/applepay/ApplePaySession-expected.txt
LayoutTests/http/tests/ssl/applepay/ApplePaySession.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/ApplePayError.idl
Source/WebCore/Modules/applepay/ApplePayPaymentContact.h
Source/WebCore/Modules/applepay/ApplePayPaymentContact.idl
Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.h
Source/WebCore/Modules/applepay/cocoa/PaymentContactCocoa.mm
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm

index 8131e1f..ee843c1 100644 (file)
@@ -1,3 +1,15 @@
+2017-10-16  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Add subLocality and subAdministrativeArea to ApplePayPaymentContact and ApplePayError
+        https://bugs.webkit.org/show_bug.cgi?id=178191
+        <rdar://problem/34906367>
+
+        Reviewed by Tim Horton.
+
+        * http/tests/ssl/applepay/ApplePayError-expected.txt:
+        * http/tests/ssl/applepay/ApplePaySession-expected.txt:
+        * http/tests/ssl/applepay/ApplePaySession.html:
+
 2017-10-17  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Delete button doesn't fully delete certain emoji
index 5f1b3ed..6b40b07 100644 (file)
@@ -27,10 +27,10 @@ SETUP:
 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", "phoneticName", "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", "subLocality", "locality", "postalCode", "subAdministrativeArea", "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", "phoneticName", "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", "subLocality", "locality", "postalCode", "subAdministrativeArea", "administrativeArea", "country", "countryCode".
 
 SETUP: 
 PASS new ApplePayError('unknown', 'phoneNumber') did not throw exception.
index 551d4c1..805fe00 100644 (file)
@@ -260,6 +260,9 @@ PASS new ApplePaySession(2, request) did not throw exception.
 SETUP: request = validRequest(); request.billingContact = { };
 PASS new ApplePaySession(2, request) did not throw exception.
 
+SETUP: request = validRequest(); request.billingContact = { subLocality: '', subAdministrativeArea: '' };
+PASS new ApplePaySession(2, request) did not throw exception.
+
 Testing PaymentRequest.requiredShippingContactFields
 
 SETUP: request = validRequest(); request.requiredShippingContactFields = undefined;
@@ -321,6 +324,9 @@ PASS new ApplePaySession(2, request) did not throw exception.
 SETUP: request = validRequest(); request.shippingContact = { };
 PASS new ApplePaySession(2, request) did not throw exception.
 
+SETUP: request = validRequest(); request.shippingContact = { subLocality: '', subAdministrativeArea: '' };
+PASS new ApplePaySession(2, request) did not throw exception.
+
 Testing PaymentRequest.shippingType
 
 SETUP: request = validRequest(); request.shippingType = undefined;
index d822a99..97df234 100644 (file)
@@ -148,6 +148,7 @@ function go() {
     logAndShouldNotThrow("request = validRequest(); request.billingContact = null;", "new ApplePaySession(2, request)")
     logAndShouldNotThrow("request = validRequest(); request.billingContact = undefined;", "new ApplePaySession(2, request)")
     logAndShouldNotThrow("request = validRequest(); request.billingContact = { };", "new ApplePaySession(2, request)")
+    logAndShouldNotThrow("request = validRequest(); request.billingContact = { subLocality: '', subAdministrativeArea: '' };", "new ApplePaySession(2, request)")
     
     debug("Testing PaymentRequest.requiredShippingContactFields")
     debug("");
@@ -174,6 +175,7 @@ function go() {
     logAndShouldNotThrow("request = validRequest(); request.shippingContact = null;", "new ApplePaySession(2, request)")
     logAndShouldNotThrow("request = validRequest(); request.shippingContact = undefined;", "new ApplePaySession(2, request)")
     logAndShouldNotThrow("request = validRequest(); request.shippingContact = { };", "new ApplePaySession(2, request)")
+    logAndShouldNotThrow("request = validRequest(); request.shippingContact = { subLocality: '', subAdministrativeArea: '' };", "new ApplePaySession(2, request)")
     
     debug("Testing PaymentRequest.shippingType")
     debug("");
index 10ebbb4..d7e46e6 100644 (file)
@@ -1,3 +1,24 @@
+2017-10-16  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Add subLocality and subAdministrativeArea to ApplePayPaymentContact and ApplePayError
+        https://bugs.webkit.org/show_bug.cgi?id=178191
+        <rdar://problem/34906367>
+
+        Reviewed by Tim Horton.
+
+        Added test cases to http/tests/ssl/applepay/ApplePaySession.html.
+
+        * Modules/applepay/ApplePayError.idl:
+        * Modules/applepay/ApplePayPaymentContact.h:
+        * Modules/applepay/ApplePayPaymentContact.idl:
+        * Modules/applepay/ApplePaySessionPaymentRequest.h:
+        * Modules/applepay/cocoa/PaymentContactCocoa.mm:
+        (WebCore::subLocality):
+        (WebCore::setSubLocality):
+        (WebCore::subAdministrativeArea):
+        (WebCore::setSubAdministrativeArea):
+        (WebCore::convert):
+
 2017-10-17  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r223500.
index 402a017..f288150 100644 (file)
     "phoneticName",
     "postalAddress",
     "addressLines",
+    "subLocality",
     "locality",
     "postalCode",
+    "subAdministrativeArea",
     "administrativeArea",
     "country",
     "countryCode"
index 90238b4..eb6e28f 100644 (file)
@@ -41,8 +41,10 @@ struct ApplePayPaymentContact {
     String phoneticGivenName;
     String phoneticFamilyName;
     std::optional<Vector<String>> addressLines;
+    String subLocality;
     String locality;
     String postalCode;
+    String subAdministrativeArea;
     String administrativeArea;
     String country;
     String countryCode;
index cf079cd..9d5e62f 100644 (file)
     [Conditional=APPLE_PAY_SESSION_V3] DOMString phoneticGivenName;
     [Conditional=APPLE_PAY_SESSION_V3] DOMString phoneticFamilyName;
     sequence<DOMString> addressLines;
+    DOMString subLocality;
     DOMString locality;
     DOMString postalCode;
+    DOMString subAdministrativeArea;
     DOMString administrativeArea;
     DOMString country;
     DOMString countryCode;
index 95d14b0..7171f5e 100644 (file)
@@ -167,8 +167,10 @@ struct PaymentError {
         PhoneticName,
         PostalAddress,
         AddressLines,
+        SubLocality,
         Locality,
         PostalCode,
+        SubAdministrativeArea,
         AdministrativeArea,
         Country,
         CountryCode,
index 478dc08..e2cb7d8 100644 (file)
@@ -48,6 +48,54 @@ SOFT_LINK_CLASS(PassKit, PKContact)
 
 namespace WebCore {
 
+static NSString *subLocality(CNPostalAddress *address)
+{
+#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101204)
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+    if (![address respondsToSelector:@selector(subLocality)])
+        return nil;
+#endif
+    return address.subLocality;
+#else
+    return nil;
+#endif
+}
+
+static void setSubLocality(CNMutablePostalAddress *address, NSString *subLocality)
+{
+#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101204)
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+    if (![address respondsToSelector:@selector(setSubLocality:)])
+        return;
+#endif
+    address.subLocality = subLocality;
+#endif
+}
+
+static NSString *subAdministrativeArea(CNPostalAddress *address)
+{
+#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101204)
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+    if (![address respondsToSelector:@selector(subAdministrativeArea)])
+        return nil;
+#endif
+    return address.subAdministrativeArea;
+#else
+    return nil;
+#endif
+}
+
+static void setSubAdministrativeArea(CNMutablePostalAddress *address, NSString *subAdministrativeArea)
+{
+#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101204)
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+    if (![address respondsToSelector:@selector(setSubAdministrativeArea:)])
+        return;
+#endif
+    address.subAdministrativeArea = subAdministrativeArea;
+#endif
+}
+
 static RetainPtr<PKContact> convert(unsigned version, const ApplePayPaymentContact& contact)
 {
     auto result = adoptNS([allocPKContactInstance() init]);
@@ -100,10 +148,14 @@ static RetainPtr<PKContact> convert(unsigned version, const ApplePayPaymentConta
         // FIXME: StringBuilder should hava a toNSString() function to avoid the extra String allocation.
         [address setStreet:builder.toString()];
 
+        if (!contact.subLocality.isEmpty())
+            setSubLocality(address.get(), contact.subLocality);
         if (!contact.locality.isEmpty())
             [address setCity:contact.locality];
         if (!contact.postalCode.isEmpty())
             [address setPostalCode:contact.postalCode];
+        if (!contact.subAdministrativeArea.isEmpty())
+            setSubAdministrativeArea(address.get(), contact.subAdministrativeArea);
         if (!contact.administrativeArea.isEmpty())
             [address setState:contact.administrativeArea];
         if (!contact.country.isEmpty())
@@ -140,8 +192,10 @@ static ApplePayPaymentContact convert(PKContact *contact)
         String(postalAddress.street).split("\n", addressLines);
         result.addressLines = WTFMove(addressLines);
     }
+    result.subLocality = subLocality(postalAddress);
     result.locality = postalAddress.city;
     result.postalCode = postalAddress.postalCode;
+    result.subAdministrativeArea = subAdministrativeArea(postalAddress);
     result.administrativeArea = postalAddress.state;
     result.country = postalAddress.country;
     result.countryCode = postalAddress.ISOCountryCode;
index 7d38526..c0d9541 100644 (file)
@@ -1,3 +1,14 @@
+2017-10-16  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Add subLocality and subAdministrativeArea to ApplePayPaymentContact and ApplePayError
+        https://bugs.webkit.org/show_bug.cgi?id=178191
+        <rdar://problem/34906367>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
+        (WebKit::toNSError):
+
 2017-10-17  Sam Weinig  <sam@webkit.org>
 
         [Settings] Generate Settings.h/cpp
index 26b17e1..d3c8cbe 100644 (file)
@@ -63,7 +63,9 @@ SOFT_LINK_CONSTANT(PassKit, PKPaymentNetworkVisa, NSString *);
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
 SOFT_LINK_FRAMEWORK(Contacts)
 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressStreetKey, NSString *);
+SOFT_LINK_CONSTANT(Contacts, CNPostalAddressSubLocalityKey, NSString *);
 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressCityKey, NSString *);
+SOFT_LINK_CONSTANT(Contacts, CNPostalAddressSubAdministrativeAreaKey, NSString *);
 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressStateKey, NSString *);
 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressPostalCodeKey, NSString *);
 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressCountryKey, NSString *);
@@ -656,6 +658,11 @@ static RetainPtr<NSError> toNSError(const WebCore::PaymentError& error)
             postalAddressKey = getCNPostalAddressStreetKey();
             break;
 
+        case WebCore::PaymentError::ContactField::SubLocality:
+            pkContactField = getPKContactFieldPostalAddress();
+            postalAddressKey = getCNPostalAddressSubLocalityKey();
+            break;
+
         case WebCore::PaymentError::ContactField::Locality:
             pkContactField = getPKContactFieldPostalAddress();
             postalAddressKey = getCNPostalAddressCityKey();
@@ -666,6 +673,11 @@ static RetainPtr<NSError> toNSError(const WebCore::PaymentError& error)
             postalAddressKey = getCNPostalAddressPostalCodeKey();
             break;
 
+        case WebCore::PaymentError::ContactField::SubAdministrativeArea:
+            pkContactField = getPKContactFieldPostalAddress();
+            postalAddressKey = getCNPostalAddressSubAdministrativeAreaKey();
+            break;
+
         case WebCore::PaymentError::ContactField::AdministrativeArea:
             pkContactField = getPKContactFieldPostalAddress();
             postalAddressKey = getCNPostalAddressStateKey();