Title: [286452] trunk
Revision
286452
Author
drou...@apple.com
Date
2021-12-02 14:21:46 -0800 (Thu, 02 Dec 2021)

Log Message

[Payment Request] Validate payment method data on construction
https://bugs.webkit.org/show_bug.cgi?id=233292
<rdar://problem/85736007>

Reviewed by Andy Estes.

Source/WebCore:

This will allow developers to replace any `ApplePaySession.supportsVersion` check(s) by
attempting to create a `PaymentRequest` object with data specific to Apple Pay. This is
actually an improvement, because it'll also allow developers to catch most errors in that
data earlier, as previously any errors would only be thrown when `show()` is called.

Spec: <https://github.com/w3c/payment-request/pull/976>

Test: http/tests/ssl/applepay/PaymentRequest.https.html

* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::show):
* Modules/paymentrequest/PaymentHandler.h:
Adjust `PaymentHandler::convertData` to take a `Document` so that additional validation
can be performed on the provided payment method(s) (e.g. check the Apple Pay version).

* Modules/applepay/PaymentRequestValidator.h:
* Modules/applepay/PaymentRequestValidator.mm:
(WebCore::PaymentRequestValidator::validate):
Allow callers to choose what fields to validate. This is needed because when the
`ApplePaySessionPaymentRequest` created/converted when validating the payment method data in
the `PaymentRequest` constructor isn't able to get fields from the `PaymentRequest` as it
hasn't been created yet.

* Modules/applepay/ApplePaySession.cpp:
(WebCore::convertAndValidate):
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::convertAndValidateApplePayRequest):
(WebCore::ApplePayPaymentHandler::convertData):
(WebCore::ApplePayPaymentHandler::show):
* Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.h:
* Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.cpp:
(WebCore::convertAndValidateApplePayAMSUIRequest):
(WebCore::ApplePayAMSUIPaymentHandler::convertData):

LayoutTests:

* http/tests/ssl/applepay/PaymentRequest.https.html:
* http/tests/ssl/applepay/PaymentRequest.https-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (286451 => 286452)


--- trunk/LayoutTests/ChangeLog	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/LayoutTests/ChangeLog	2021-12-02 22:21:46 UTC (rev 286452)
@@ -1,3 +1,14 @@
+2021-12-02  Devin Rousso  <drou...@apple.com>
+
+        [Payment Request] Validate payment method data on construction
+        https://bugs.webkit.org/show_bug.cgi?id=233292
+        <rdar://problem/85736007>
+
+        Reviewed by Andy Estes.
+
+        * http/tests/ssl/applepay/PaymentRequest.https.html:
+        * http/tests/ssl/applepay/PaymentRequest.https-expected.txt:
+
 2021-12-02  Fujii Hironori  <hironori.fu...@sony.com>
 
         [WinCairo] Unreviewed test gardening

Modified: trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https-expected.txt (286451 => 286452)


--- trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https-expected.txt	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https-expected.txt	2021-12-02 22:21:46 UTC (rev 286452)
@@ -10,32 +10,33 @@
 
 Testing ApplePayRequest.version
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.version = 0; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with InvalidAccessError: "0" is not a supported version..
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.version = 1000; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with InvalidAccessError: "1000" is not a supported version..
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.version = 0;
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception InvalidAccessError: "0" is not a supported version..
 
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.version = 1000;
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception InvalidAccessError: "1000" is not a supported version..
+
+
 Testing ApplePayRequest.countryCode
 
 SETUP: paymentMethod = validPaymentMethod(); delete paymentMethod.data.countryCode;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Member ApplePayRequest.countryCode is required and must be an instance of DOMString.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = undefined;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Member ApplePayRequest.countryCode is required and must be an instance of DOMString.
 
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 'invalid';
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: "invalid" is not a valid country code..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 'invalid'; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: "invalid" is not a valid country code..
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = '';
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: "" is not a valid country code..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = ''; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: "" is not a valid country code..
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = null;
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: "null" is not a valid country code..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = null; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: "null" is not a valid country code..
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 7;
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: "7" is not a valid country code..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 7; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: "7" is not a valid country code..
 
 Testing ApplePayRequest.supportedNetworks
 
@@ -42,31 +43,27 @@
 SETUP: paymentMethod = validPaymentMethod(); delete paymentMethod.data.supportedNetworks;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Member ApplePayRequest.supportedNetworks is required and must be an instance of sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = '';
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = null;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = undefined;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Member ApplePayRequest.supportedNetworks is required and must be an instance of sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = 7;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = [];
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: At least one supported network must be provided..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = []; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: At least one supported network must be provided..
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork'];
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: "invalidNetwork" is not a valid payment network..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork']; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: "invalidNetwork" is not a valid payment network..
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork', 'visa'];
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: "invalidNetwork" is not a valid payment network..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork', 'visa']; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: "invalidNetwork" is not a valid payment network..
 
 Testing ApplePayRequest.merchantCapabilities
 
@@ -73,33 +70,27 @@
 SETUP: paymentMethod = validPaymentMethod(); delete paymentMethod.data.merchantCapabilities;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Member ApplePayRequest.merchantCapabilities is required and must be an instance of sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = '';
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = null;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = undefined;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Member ApplePayRequest.merchantCapabilities is required and must be an instance of sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = 7;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = ['invalidCapability'];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = ['invalidCapability', 'supports3DS'];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
+SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = [];
+PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: At least one merchant capability must be provided..
 
-SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = []; request = new PaymentRequest([paymentMethod], validPaymentDetails())
-PASS request.show() rejected promise  with TypeError: At least one merchant capability must be provided..
 
 Testing ApplePayRequest.requiredBillingContactFields
 
@@ -106,35 +97,27 @@
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = '';
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = null;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = 7;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = { };
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [''];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [null];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [undefined];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [{}];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = ['invalid'];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
@@ -144,7 +127,6 @@
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.billingContact = '';
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.billingContact = 7;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
@@ -154,35 +136,27 @@
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = '';
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = null;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = 7;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Value is not a sequence.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = { };
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [''];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [null];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [undefined];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [{}];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = ['invalid'];
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
@@ -192,7 +166,6 @@
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.shippingContact = '';
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
-
 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.shippingContact = 7;
 PASS new PaymentRequest([paymentMethod], validPaymentDetails()) threw exception TypeError: Type error.
 
@@ -229,7 +202,6 @@
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: '', value: '0' } };
 PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception RangeError: "" is not a valid currency code..
 
-
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: 'USD', value:'-10.00'} };
 PASS new PaymentRequest([validPaymentMethod()], paymentDetails) threw exception TypeError: Total currency values cannot be negative..
 
@@ -236,6 +208,7 @@
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: 'USD', value: '10000000000.00' } }; request = new PaymentRequest([validPaymentMethod()], paymentDetails)
 PASS request.show() rejected promise  with TypeError: Total amount is too big..
 
+
 Testing PaymentDetails.displayItems
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.displayItems = '';
@@ -273,6 +246,8 @@
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: { currency: 'EUR', value: '10.00' } }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails)
 PASS request.show() rejected promise  with TypeError: "EUR" does not match the expected currency of "USD". Apple Pay requires all PaymentCurrencyAmounts to use the same currency code..
+
+
 Testing PaymentDetails.shippingOptions
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = '';
@@ -310,6 +285,8 @@
 
 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})
 PASS request.show() rejected promise  with TypeError: "EUR" does not match the expected currency of "USD". Apple Pay requires all PaymentCurrencyAmounts to use the same currency code..
+
+
 Testing PaymentOptions
 
 SETUP: paymentOptions = {}; paymentOptions.shippingType = '';

Modified: trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html (286451 => 286452)


--- trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html	2021-12-02 22:21:46 UTC (rev 286452)
@@ -58,81 +58,54 @@
     
     debug("Testing ApplePayRequest.version")
     debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.version = 0; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.version = 1000; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.version = 0;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.version = 1000;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
 
     debug("Testing ApplePayRequest.countryCode")
     debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); delete paymentMethod.data.countryCode;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = undefined;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 'invalid';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = '';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = null;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 'invalid'; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = ''; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = null; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 7; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
 
     debug("Testing ApplePayRequest.supportedNetworks")
     debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); delete paymentMethod.data.supportedNetworks;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = '';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = null;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = undefined;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = [];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork'];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork', 'visa'];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = []; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork']; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.supportedNetworks = ['invalidNetwork', 'visa']; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
 
     debug("Testing ApplePayRequest.merchantCapabilities")
     debug("");
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); delete paymentMethod.data.merchantCapabilities;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = '';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = null;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = undefined;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = ['invalidCapability'];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = ['invalidCapability', 'supports3DS'];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
+    await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = [];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
-    await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.merchantCapabilities = []; request = new PaymentRequest([paymentMethod], validPaymentDetails())", "request.show()")
-    debug("")
 
     debug("Testing ApplePayRequest.requiredBillingContactFields")
     debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = '';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = null;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = { };", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [''];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [null];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [undefined];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = [{}];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredBillingContactFields = ['invalid'];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
 
@@ -139,7 +112,6 @@
     debug("Testing ApplePayRequest.billingContact")
     debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.billingContact = '';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.billingContact = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
 
@@ -146,21 +118,13 @@
     debug("Testing ApplePayRequest.requiredShippingContactFields")
     debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = '';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = null;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = { };", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [''];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [null];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [undefined];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = [{}];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.requiredShippingContactFields = ['invalid'];", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
 
@@ -167,7 +131,6 @@
     debug("Testing ApplePayRequest.shippingContact")
     debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.shippingContact = '';", "new PaymentRequest([paymentMethod], validPaymentDetails())")
-    debug("")
     await logAndShouldThrow("paymentMethod = validPaymentMethod(); paymentMethod.data.shippingContact = 7;", "new PaymentRequest([paymentMethod], validPaymentDetails())")
     debug("")
 
@@ -183,10 +146,10 @@
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label' };", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: 'amount' };", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: '', value: '0' } };", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
-    debug("")
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: 'USD', value:'-10.00'} };", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
     await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.total = { label: 'label', amount: { currency: 'USD', value: '10000000000.00' } }; request = new PaymentRequest([validPaymentMethod()], paymentDetails)", "request.show()")
     debug("")
+    debug("")
 
     debug("Testing PaymentDetails.displayItems")
     debug("");
@@ -202,6 +165,8 @@
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: '10.00', type: 'invalid' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails)")
     await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: { currency: 'EUR', value: '10.00' } }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails)", "request.show()")
+    debug("")
+    debug("")
 
     debug("Testing PaymentDetails.shippingOptions")
     debug("");
@@ -217,6 +182,8 @@
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '', label: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
     await logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '-1', detail: '', identifier: '', label: '' }];", "new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})")
     await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }]; request = new PaymentRequest([validPaymentMethod()], paymentDetails, {requestShipping: true})", "request.show()")
+    debug("")
+    debug("")
 
     debug("Testing PaymentOptions")
     debug("");

Modified: trunk/Source/WebCore/ChangeLog (286451 => 286452)


--- trunk/Source/WebCore/ChangeLog	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/ChangeLog	2021-12-02 22:21:46 UTC (rev 286452)
@@ -1,3 +1,46 @@
+2021-12-02  Devin Rousso  <drou...@apple.com>
+
+        [Payment Request] Validate payment method data on construction
+        https://bugs.webkit.org/show_bug.cgi?id=233292
+        <rdar://problem/85736007>
+
+        Reviewed by Andy Estes.
+
+        This will allow developers to replace any `ApplePaySession.supportsVersion` check(s) by
+        attempting to create a `PaymentRequest` object with data specific to Apple Pay. This is
+        actually an improvement, because it'll also allow developers to catch most errors in that
+        data earlier, as previously any errors would only be thrown when `show()` is called.
+
+        Spec: <https://github.com/w3c/payment-request/pull/976>
+
+        Test: http/tests/ssl/applepay/PaymentRequest.https.html
+
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::PaymentRequest::show):
+        * Modules/paymentrequest/PaymentHandler.h:
+        Adjust `PaymentHandler::convertData` to take a `Document` so that additional validation
+        can be performed on the provided payment method(s) (e.g. check the Apple Pay version).
+
+        * Modules/applepay/PaymentRequestValidator.h:
+        * Modules/applepay/PaymentRequestValidator.mm:
+        (WebCore::PaymentRequestValidator::validate):
+        Allow callers to choose what fields to validate. This is needed because when the
+        `ApplePaySessionPaymentRequest` created/converted when validating the payment method data in
+        the `PaymentRequest` constructor isn't able to get fields from the `PaymentRequest` as it
+        hasn't been created yet.
+
+        * Modules/applepay/ApplePaySession.cpp:
+        (WebCore::convertAndValidate):
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+        (WebCore::convertAndValidateApplePayRequest):
+        (WebCore::ApplePayPaymentHandler::convertData):
+        (WebCore::ApplePayPaymentHandler::show):
+        * Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.h:
+        * Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.cpp:
+        (WebCore::convertAndValidateApplePayAMSUIRequest):
+        (WebCore::ApplePayAMSUIPaymentHandler::convertData):
+
 2021-12-02  Brandon Stewart  <brandonstew...@apple.com>
 
         Verify borderRect is Renderable

Modified: trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp (286451 => 286452)


--- trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp	2021-12-02 22:21:46 UTC (rev 286452)
@@ -179,7 +179,15 @@
         return mergeResult.releaseException();
 
     // FIXME: Merge this validation into the validation we are doing above.
-    auto validatedPaymentRequest = PaymentRequestValidator::validate(result);
+    constexpr OptionSet fieldsToValidate = {
+        PaymentRequestValidator::Field::MerchantCapabilities,
+        PaymentRequestValidator::Field::SupportedNetworks,
+        PaymentRequestValidator::Field::CountryCode,
+        PaymentRequestValidator::Field::CurrencyCode,
+        PaymentRequestValidator::Field::Total,
+        PaymentRequestValidator::Field::ShippingMethods,
+    };
+    auto validatedPaymentRequest = PaymentRequestValidator::validate(result, fieldsToValidate);
     if (validatedPaymentRequest.hasException())
         return validatedPaymentRequest.releaseException();
 

Modified: trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.h (286451 => 286452)


--- trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.h	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.h	2021-12-02 22:21:46 UTC (rev 286452)
@@ -29,12 +29,22 @@
 
 #include "ApplePaySessionPaymentRequest.h"
 #include "ExceptionOr.h"
+#include <wtf/OptionSet.h>
 
 namespace WebCore {
 
 class PaymentRequestValidator {
 public:
-    static ExceptionOr<void> validate(const ApplePaySessionPaymentRequest&);
+    enum class Field : uint8_t {
+        MerchantCapabilities = 1 << 0,
+        SupportedNetworks = 1 << 1,
+        CountryCode = 1 << 2,
+        CurrencyCode = 1 << 3,
+        Total = 1 << 4,
+        ShippingMethods = 1 << 5,
+    };
+
+    static ExceptionOr<void> validate(const ApplePaySessionPaymentRequest&, OptionSet<PaymentRequestValidator::Field>);
     static ExceptionOr<void> validateTotal(const ApplePayLineItem&);
 };
 

Modified: trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.mm (286451 => 286452)


--- trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.mm	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/applepay/PaymentRequestValidator.mm	2021-12-02 22:21:46 UTC (rev 286452)
@@ -43,36 +43,50 @@
 static ExceptionOr<void> validateShippingMethods(const Vector<ApplePayShippingMethod>&);
 static ExceptionOr<void> validateShippingMethod(const ApplePayShippingMethod&);
 
-ExceptionOr<void> PaymentRequestValidator::validate(const ApplePaySessionPaymentRequest& paymentRequest)
+ExceptionOr<void> PaymentRequestValidator::validate(const ApplePaySessionPaymentRequest& paymentRequest, OptionSet<Field> fieldsToValidate)
 {
-    auto validatedCountryCode = validateCountryCode(paymentRequest.countryCode());
-    if (validatedCountryCode.hasException())
-        return validatedCountryCode.releaseException();
+    if (fieldsToValidate.contains(Field::CountryCode)) {
+        auto validatedCountryCode = validateCountryCode(paymentRequest.countryCode());
+        if (validatedCountryCode.hasException())
+            return validatedCountryCode.releaseException();
+    }
 
-    auto validatedCurrencyCode = validateCurrencyCode(paymentRequest.currencyCode());
-    if (validatedCurrencyCode.hasException())
-        return validatedCurrencyCode.releaseException();
+    if (fieldsToValidate.contains(Field::CurrencyCode)) {
+        auto validatedCurrencyCode = validateCurrencyCode(paymentRequest.currencyCode());
+        if (validatedCurrencyCode.hasException())
+            return validatedCurrencyCode.releaseException();
+    }
 
-    auto validatedSupportedNetworks = validateSupportedNetworks(paymentRequest.supportedNetworks());
-    if (validatedSupportedNetworks.hasException())
-        return validatedSupportedNetworks.releaseException();
+    if (fieldsToValidate.contains(Field::SupportedNetworks)) {
+        auto validatedSupportedNetworks = validateSupportedNetworks(paymentRequest.supportedNetworks());
+        if (validatedSupportedNetworks.hasException())
+            return validatedSupportedNetworks.releaseException();
+    }
 
-    auto validatedMerchantCapabilities = validateMerchantCapabilities(paymentRequest.merchantCapabilities());
-    if (validatedMerchantCapabilities.hasException())
-        return validatedMerchantCapabilities.releaseException();
+    if (fieldsToValidate.contains(Field::MerchantCapabilities)) {
+        auto validatedMerchantCapabilities = validateMerchantCapabilities(paymentRequest.merchantCapabilities());
+        if (validatedMerchantCapabilities.hasException())
+            return validatedMerchantCapabilities.releaseException();
+    }
 
-    auto validatedTotal = validateTotal(paymentRequest.total());
-    if (validatedTotal.hasException())
-        return validatedTotal.releaseException();
+    if (fieldsToValidate.contains(Field::Total)) {
+        auto validatedTotal = validateTotal(paymentRequest.total());
+        if (validatedTotal.hasException())
+            return validatedTotal.releaseException();
+    }
 
-    auto validatedShippingMethods = validateShippingMethods(paymentRequest.shippingMethods());
-    if (validatedShippingMethods.hasException())
-        return validatedShippingMethods.releaseException();
+    if (fieldsToValidate.contains(Field::ShippingMethods)) {
+        auto validatedShippingMethods = validateShippingMethods(paymentRequest.shippingMethods());
+        if (validatedShippingMethods.hasException())
+            return validatedShippingMethods.releaseException();
+    }
 
-    for (auto& countryCode : paymentRequest.supportedCountries()) {
-        auto validatedCountryCode = validateCountryCode(countryCode);
-        if (validatedCountryCode.hasException())
-            return validatedCountryCode.releaseException();
+    if (fieldsToValidate.contains(Field::CountryCode)) {
+        for (auto& countryCode : paymentRequest.supportedCountries()) {
+            auto validatedCountryCode = validateCountryCode(countryCode);
+            if (validatedCountryCode.hasException())
+                return validatedCountryCode.releaseException();
+        }
     }
 
     return { };

Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp (286451 => 286452)


--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp	2021-12-02 22:21:46 UTC (rev 286452)
@@ -78,16 +78,35 @@
 
 namespace WebCore {
 
-static ExceptionOr<ApplePayRequest> convertAndValidateApplePayRequest(ScriptExecutionContext& context, JSC::JSValue data)
+static inline PaymentCoordinator& paymentCoordinator(Document& document)
 {
+    ASSERT(document.page());
+    return document.page()->paymentCoordinator();
+}
+
+static ExceptionOr<ApplePayRequest> convertAndValidateApplePayRequest(Document& document, JSC::JSValue data)
+{
     if (data.isEmpty())
         return Exception { TypeError, "Missing payment method data." };
 
-    auto throwScope = DECLARE_THROW_SCOPE(context.vm());
-    auto applePayRequest = convertDictionary<ApplePayRequest>(*context.globalObject(), data);
+    auto throwScope = DECLARE_THROW_SCOPE(document.vm());
+    auto applePayRequest = convertDictionary<ApplePayRequest>(*document.globalObject(), data);
     if (throwScope.exception())
         return Exception { ExistingExceptionError };
 
+    auto validatedRequest = convertAndValidate(document, applePayRequest.version, applePayRequest, paymentCoordinator(document));
+    if (validatedRequest.hasException())
+        return validatedRequest.releaseException();
+
+    constexpr OptionSet fieldsToValidate = {
+        PaymentRequestValidator::Field::MerchantCapabilities,
+        PaymentRequestValidator::Field::SupportedNetworks,
+        PaymentRequestValidator::Field::CountryCode,
+    };
+    auto exception = PaymentRequestValidator::validate(validatedRequest.releaseReturnValue(), fieldsToValidate);
+    if (exception.hasException())
+        return exception.releaseException();
+
     return WTFMove(applePayRequest);
 }
 
@@ -109,12 +128,6 @@
     return url.host() == "apple.com" && url.path() == "/apple-pay";
 }
 
-static inline PaymentCoordinator& paymentCoordinator(Document& document)
-{
-    ASSERT(document.page());
-    return document.page()->paymentCoordinator();
-}
-
 bool ApplePayPaymentHandler::hasActiveSession(Document& document)
 {
     return WebCore::paymentCoordinator(document).hasActiveSession();
@@ -200,9 +213,9 @@
     return { WTFMove(result) };
 }
 
-ExceptionOr<void> ApplePayPaymentHandler::convertData(JSC::JSValue data)
+ExceptionOr<void> ApplePayPaymentHandler::convertData(Document& document, JSC::JSValue data)
 {
-    auto requestOrException = convertAndValidateApplePayRequest(*scriptExecutionContext(), data);
+    auto requestOrException = convertAndValidateApplePayRequest(document, data);
     if (requestOrException.hasException())
         return requestOrException.releaseException();
 
@@ -269,7 +282,12 @@
     if (auto modifierData = modifierException.releaseReturnValue())
         merge(request, WTFMove(std::get<1>(*modifierData)));
 
-    auto exception = PaymentRequestValidator::validate(request);
+    constexpr OptionSet fieldsToValidate = {
+        PaymentRequestValidator::Field::CurrencyCode,
+        PaymentRequestValidator::Field::Total,
+        PaymentRequestValidator::Field::ShippingMethods,
+    };
+    auto exception = PaymentRequestValidator::validate(request, fieldsToValidate);
     if (exception.hasException())
         return exception.releaseException();
 

Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h (286451 => 286452)


--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h	2021-12-02 22:21:46 UTC (rev 286452)
@@ -71,7 +71,7 @@
     ExceptionOr<void> paymentMethodUpdated(Vector<RefPtr<ApplePayError>>&& errors);
 
     // PaymentHandler
-    ExceptionOr<void> convertData(JSC::JSValue) final;
+    ExceptionOr<void> convertData(Document&, JSC::JSValue) final;
     ExceptionOr<void> show(Document&) final;
     bool canAbortSession() final { return true; }
     void hide() final;

Modified: trunk/Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.cpp (286451 => 286452)


--- trunk/Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.cpp	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.cpp	2021-12-02 22:21:46 UTC (rev 286452)
@@ -36,13 +36,13 @@
 
 namespace WebCore {
 
-static ExceptionOr<ApplePayAMSUIRequest> convertAndValidateApplePayAMSUIRequest(ScriptExecutionContext& context, JSC::JSValue data)
+static ExceptionOr<ApplePayAMSUIRequest> convertAndValidateApplePayAMSUIRequest(Document& document, JSC::JSValue data)
 {
     if (data.isEmpty())
         return Exception { TypeError, "Missing payment method data." };
 
-    auto throwScope = DECLARE_THROW_SCOPE(context.vm());
-    auto applePayAMSUIRequest = convertDictionary<ApplePayAMSUIRequest>(*context.globalObject(), data);
+    auto throwScope = DECLARE_THROW_SCOPE(document.vm());
+    auto applePayAMSUIRequest = convertDictionary<ApplePayAMSUIRequest>(*document.globalObject(), data);
     if (throwScope.exception())
         return Exception { ExistingExceptionError };
 
@@ -118,9 +118,9 @@
     return *document().page();
 }
 
-ExceptionOr<void> ApplePayAMSUIPaymentHandler::convertData(JSC::JSValue data)
+ExceptionOr<void> ApplePayAMSUIPaymentHandler::convertData(Document& document, JSC::JSValue data)
 {
-    auto requestOrException = convertAndValidateApplePayAMSUIRequest(*scriptExecutionContext(), data);
+    auto requestOrException = convertAndValidateApplePayAMSUIRequest(document, data);
     if (requestOrException.hasException())
         return requestOrException.releaseException();
 

Modified: trunk/Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.h (286451 => 286452)


--- trunk/Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.h	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/applepay-ams-ui/ApplePayAMSUIPaymentHandler.h	2021-12-02 22:21:46 UTC (rev 286452)
@@ -68,7 +68,7 @@
     Page& page() const;
 
     // PaymentHandler
-    ExceptionOr<void> convertData(JSC::JSValue) final;
+    ExceptionOr<void> convertData(Document&, JSC::JSValue) final;
     ExceptionOr<void> show(Document&) final;
     bool canAbortSession() final { return false; }
     void hide() final;

Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h (286451 => 286452)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h	2021-12-02 22:21:46 UTC (rev 286452)
@@ -50,7 +50,7 @@
     static bool enabledForContext(ScriptExecutionContext&);
     static bool hasActiveSession(Document&);
 
-    virtual ExceptionOr<void> convertData(JSC::JSValue) = 0;
+    virtual ExceptionOr<void> convertData(Document&, JSC::JSValue) = 0;
     virtual ExceptionOr<void> show(Document&) = 0;
     virtual bool canAbortSession() = 0;
     virtual void hide() = 0;

Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp (286451 => 286452)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2021-12-02 21:51:08 UTC (rev 286451)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2021-12-02 22:21:46 UTC (rev 286452)
@@ -410,7 +410,7 @@
         if (!handler)
             continue;
 
-        auto result = handler->convertData(data.releaseReturnValue());
+        auto result = handler->convertData(document, data.releaseReturnValue());
         if (result.hasException()) {
             settleShowPromise(result.releaseException());
             return;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to