Diff
Modified: trunk/LayoutTests/ChangeLog (223159 => 223160)
--- trunk/LayoutTests/ChangeLog 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/ChangeLog 2017-10-11 00:37:49 UTC (rev 223160)
@@ -1,3 +1,16 @@
+2017-10-10 Andy Estes <aes...@apple.com>
+
+ [Payment Request] Implement PaymentRequest.canMakePayment()
+ https://bugs.webkit.org/show_bug.cgi?id=178048
+
+ Reviewed by Youenn Fablet.
+
+ * http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt: Added.
+ * http/tests/paymentrequest/payment-request-canmakepayment-method.https.html: Added.
+ * http/tests/ssl/applepay/PaymentRequest.https.html:
+ * platform/ios-wk2/TestExpectations:
+ * platform/mac-wk2/TestExpectations:
+
2017-10-10 Joanmarie Diggs <jdi...@igalia.com>
AX: [ATK] ARIA form role should be mapped to ATK_ROLE_LANDMARK; not ATK_ROLE_FORM
Modified: trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html (223159 => 223160)
--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html 2017-10-11 00:37:49 UTC (rev 223160)
@@ -18,6 +18,7 @@
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 2,
+ merchantIdentifier: '',
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['visa', 'masterCard'],
countryCode: 'US',
Added: trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt (0 => 223160)
--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt 2017-10-11 00:37:49 UTC (rev 223160)
@@ -0,0 +1,8 @@
+
+PASS If request.[[state]] is "created", then return a promise that resolves to true for known method.
+PASS If request.[[state]] is "interactive", then return a promise rejected with an "InvalidStateError" DOMException.
+PASS If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.
+PASS If payment method identifier and serialized parts are supported, resolve promise with true.
+PASS If payment method identifier is unknown, resolve promise with false.
+PASS Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.
+
Added: trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html (0 => 223160)
--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html (rev 0)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html 2017-10-11 00:37:49 UTC (rev 223160)
@@ -0,0 +1,174 @@
+<!DOCTYPE html>
+<!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
+<!-- Copyright (C) 2017 Apple Inc. All rights reserved. -->
+<!-- FIXME: Upstream this test to web-platform-tests/payment-request/. -->
+<meta charset="utf-8">
+<title>Tests for PaymentRequest.canMakePayment() method</title>
+<link rel="help" href=""
+<script src=""
+<script src=""
+<script>
+ const applePay = Object.freeze({
+ supportedMethods: "https://apple.com/apple-pay",
+ data: {
+ version: 2,
+ merchantIdentifier: "",
+ merchantCapabilities: ["supports3DS"],
+ supportedNetworks: ["visa", "masterCard"],
+ countryCode: "US",
+ currencyCode: "USD",
+ }
+});
+const defaultMethods = Object.freeze([applePay]);
+const defaultDetails = Object.freeze({
+ total: {
+ label: "Total",
+ amount: {
+ currency: "USD",
+ value: "1.00",
+ },
+ },
+});
+
+promise_test(async t => {
+ const request = new PaymentRequest(defaultMethods, defaultDetails);
+ try {
+ assert_true(
+ await request.canMakePayment(),
+ `canMakePaymentPromise should be true`
+ );
+ assert_true(
+ await request.canMakePayment(),
+ `canMakePaymentPromise should be true`
+ );
+ } catch (err) {
+ assert_equals(
+ err.name,
+ "NotAllowedError",
+ "if it throws, then it must be a NotAllowedError."
+ );
+ }
+}, `If request.[[state]] is "created", then return a promise that resolves to true for known method.`);
+
+promise_test(async t => {
+ const request = new PaymentRequest(defaultMethods, defaultDetails);
+ const acceptPromise = request.show(); // Sets state to "interactive"
+ const canMakePaymentPromise = request.canMakePayment();
+ try {
+ const result = await canMakePaymentPromise;
+ assert_true(
+ false,
+ `canMakePaymentPromise should have thrown InvalidStateError`
+ );
+ } catch (err) {
+ await promise_rejects(t, "InvalidStateError", canMakePaymentPromise);
+ } finally {
+ await request.abort();
+ await promise_rejects(t, "AbortError", acceptPromise);
+ }
+ // The state should be "closed"
+ await promise_rejects(t, "InvalidStateError", request.canMakePayment());
+}, `If request.[[state]] is "interactive", then return a promise rejected with an "InvalidStateError" DOMException.`);
+
+promise_test(async t => {
+ const request = new PaymentRequest(defaultMethods, defaultDetails);
+ const acceptPromise = request.show(); // The state is now "interactive"
+ acceptPromise.catch(() => {}); // no-op, just to silence unhandled rejection in devtools.
+ await request.abort(); // The state is now "closed"
+ await promise_rejects(t, "InvalidStateError", request.canMakePayment());
+ try {
+ const result = await request.canMakePayment();
+ assert_true(
+ false,
+ `should have thrown InvalidStateError, but instead returned "${result}"`
+ );
+ } catch (err) {
+ assert_equals(
+ err.name,
+ "InvalidStateError",
+ "must be an InvalidStateError."
+ );
+ }
+}, `If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.`);
+
+promise_test(async t => {
+ const request = new PaymentRequest(defaultMethods, defaultDetails);
+ assert_true(await request.canMakePayment(), "basic-card should be supported");
+}, `If payment method identifier and serialized parts are supported, resolve promise with true.`);
+
+promise_test(async t => {
+ const unsupportedMethods = [
+ "this-is-not-supported",
+ "https://not.supported",
+ "e",
+ "n6jzof05mk2g4lhxr-u-q-w1-c-i-pa-ty-bdvs9-ho-ae7-p-md8-s-wq3-h-qd-e-q-sa",
+ "a-b-q-n-s-pw0",
+ "m-u",
+ "s-l5",
+ "k9-f",
+ "m-l",
+ "u4-n-t",
+ "i488jh6-g18-fck-yb-v7-i",
+ "x-x-t-t-c34-o",
+ "https://wpt",
+ "https://wpt.fyi/",
+ "https://wpt.fyi/payment",
+ "https://wpt.fyi/payment-request",
+ "https://wpt.fyi/payment-request?",
+ "https://wpt.fyi/payment-request?this=is",
+ "https://wpt.fyi/payment-request?this=is&totally",
+ "https://wpt.fyi:443/payment-request?this=is&totally",
+ "https://wpt.fyi:443/payment-request?this=is&totally#fine",
+ "https://:@wpt.fyi:443/payment-request?this=is&totally#👍",
+ " \thttps://wpt\n ",
+ "https://xn--c1yn36f",
+ "https://點看",
+ ];
+ for (const method of unsupportedMethods) {
+ try {
+ const request = new PaymentRequest(
+ [{ supportedMethods: method }],
+ defaultDetails
+ );
+ assert_false(
+ await request.canMakePayment(),
+ `method "${method}" must not be supported`
+ );
+ } catch (err) {
+ assert_true(
+ false,
+ `Unexpected exception testing method ${method}, expected false. See error console.`
+ );
+ }
+ }
+}, `If payment method identifier is unknown, resolve promise with false.`);
+
+promise_test(async t => {
+ // This test might never actually hit its assertion, but that's allowed.
+ const request = new PaymentRequest(defaultMethods, defaultDetails);
+ for (let i = 0; i < 1000; i++) {
+ try {
+ await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ "NotAllowedError",
+ "if it throws, then it must be a NotAllowedError."
+ );
+ break;
+ }
+ }
+ for (let i = 0; i < 1000; i++) {
+ try {
+ await new PaymentRequest(defaultMethods, defaultDetails).canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ "NotAllowedError",
+ "if it throws, then it must be a NotAllowedError."
+ );
+ break;
+ }
+ }
+}, `Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.`);
+</script>
Modified: trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html (223159 => 223160)
--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html 2017-10-11 00:37:49 UTC (rev 223160)
@@ -13,6 +13,7 @@
supportedMethods: "https://apple.com/apple-pay",
data: {
version: 2,
+ merchantIdentifier: '',
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['visa', 'masterCard'],
countryCode: 'US',
Modified: trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html (223159 => 223160)
--- trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html 2017-10-11 00:37:49 UTC (rev 223160)
@@ -16,6 +16,7 @@
supportedMethods: 'https://apple.com/apple-pay',
data: {
version: 2,
+ merchantIdentifier: '',
countryCode: 'US',
currencyCode: 'USD',
supportedNetworks: ['visa', 'masterCard'],
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (223159 => 223160)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-10-11 00:37:49 UTC (rev 223160)
@@ -1,3 +1,12 @@
+2017-10-10 Andy Estes <aes...@apple.com>
+
+ [Payment Request] Implement PaymentRequest.canMakePayment()
+ https://bugs.webkit.org/show_bug.cgi?id=178048
+
+ Reviewed by Youenn Fablet.
+
+ * web-platform-tests/payment-request/payment-request-canmakepayment-method.https-expected.txt: Removed.
+
2017-10-09 Chris Dumez <cdu...@apple.com>
It should not be possible to submit a form that is disconnected
Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-canmakepayment-method.https-expected.txt (223159 => 223160)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-canmakepayment-method.https-expected.txt 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-canmakepayment-method.https-expected.txt 2017-10-11 00:37:49 UTC (rev 223160)
@@ -1,8 +0,0 @@
-
-FAIL If request.[[state]] is "created", then return a promise that resolves to true for known method. assert_equals: if it throws, then it must be a NotAllowedError. expected "NotAllowedError" but got "Error"
-FAIL If request.[[state]] is "interactive", then return a promise rejected with an "InvalidStateError" DOMException. assert_throws: function "function () { throw e }" threw object "NotSupportedError: The operation is not supported." that is not a DOMException AbortError: property "code" is equal to 9, expected 20
-PASS If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.
-FAIL If payment method identifier and serialized parts are supported, resolve promise with true. assert_true: basic-card should be supported expected true got false
-PASS If payment method identifier is unknown, resolve promise with false.
-PASS Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.
-
Modified: trunk/LayoutTests/platform/ios-wk2/TestExpectations (223159 => 223160)
--- trunk/LayoutTests/platform/ios-wk2/TestExpectations 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/platform/ios-wk2/TestExpectations 2017-10-11 00:37:49 UTC (rev 223160)
@@ -40,6 +40,7 @@
# skip in favor of tests in http/tests/paymentrequest
imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ]
imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ]
+imported/w3c/web-platform-tests/payment-request/payment-request-canmakepayment-method.https.html [ WontFix ]
# skip manual payment-request tests
imported/w3c/web-platform-tests/payment-request/algorithms-manual.https.html [ Skip ]
Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (223159 => 223160)
--- trunk/LayoutTests/platform/mac-wk2/TestExpectations 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations 2017-10-11 00:37:49 UTC (rev 223160)
@@ -38,6 +38,7 @@
# skip in favor of tests in http/tests/paymentrequest
imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ]
imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ]
+imported/w3c/web-platform-tests/payment-request/payment-request-canmakepayment-method.https.html [ WontFix ]
# skip manual payment-request tests
imported/w3c/web-platform-tests/payment-request/algorithms-manual.https.html [ Skip ]
Modified: trunk/Source/WebCore/ChangeLog (223159 => 223160)
--- trunk/Source/WebCore/ChangeLog 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/ChangeLog 2017-10-11 00:37:49 UTC (rev 223160)
@@ -1,3 +1,37 @@
+2017-10-10 Andy Estes <aes...@apple.com>
+
+ [Payment Request] Implement PaymentRequest.canMakePayment()
+ https://bugs.webkit.org/show_bug.cgi?id=178048
+
+ Reviewed by Youenn Fablet.
+
+ Test: http/tests/paymentrequest/payment-request-canmakepayment-method.https.html
+
+ * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+ (WebCore::ApplePayPaymentHandler::convertData): Moved
+ ApplePayRequest-to-ApplePaySessionPaymentRequest conversion from here to show().
+ (WebCore::ApplePayPaymentHandler::show): Returned an exception if
+ ApplePaySessionPaymentRequest conversion fails.
+ (WebCore::shouldDiscloseApplePayCapability): Checked if we are in an ephimeral session or if
+ Settings::applePayCapabilityDisclosureAllowed() is false.
+ (WebCore::ApplePayPaymentHandler::canMakePayment): Called
+ PaymentCoordinator::canMakePayments() or PaymentCoordinator::canMakePaymentsWithActiveCard()
+ depending on shouldDiscloseApplePayCapability().
+ * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
+ * Modules/applepay/paymentrequest/ApplePayRequest.h:
+ * Modules/applepay/paymentrequest/ApplePayRequest.idl: Defined merchantIdentifier.
+ * Modules/paymentrequest/PaymentHandler.h:
+ * Modules/paymentrequest/PaymentRequest.cpp:
+ (WebCore::parse): Moved JSON-parsing to here from show().
+ (WebCore::PaymentRequest::show): Returned the exception from PaymentHandler::show().
+ (WebCore::PaymentRequest::canMakePayment): For each payment method, try to create a
+ PaymentHandler.
+ For the first valid PaymentHandler, call canMakePayment() and pass a lambda that resolves
+ the promise.
+ * Modules/paymentrequest/PaymentRequest.h:
+ * Modules/paymentrequest/PaymentRequest.idl: Added CallWith=Document annotations to show()
+ and canMakePayment().
+
2017-10-10 Chris Dumez <cdu...@apple.com>
Unreviewed, really fix the build with certain SDKs.
Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp (223159 => 223160)
--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp 2017-10-11 00:37:49 UTC (rev 223160)
@@ -32,13 +32,14 @@
#include "ApplePayMerchantCapability.h"
#include "ApplePaySessionPaymentRequest.h"
#include "Document.h"
-#include "Frame.h"
#include "JSApplePayRequest.h"
#include "LinkIconCollector.h"
#include "MainFrame.h"
+#include "Page.h"
#include "PaymentContact.h"
#include "PaymentCoordinator.h"
#include "PaymentRequestValidator.h"
+#include "Settings.h"
namespace WebCore {
@@ -108,7 +109,7 @@
ASSERT_NOT_REACHED();
return ApplePaySessionPaymentRequest::ShippingType::Shipping;
}
-
+
static ApplePaySessionPaymentRequest::ShippingMethod convert(const PaymentShippingOption& shippingOption)
{
ApplePaySessionPaymentRequest::ShippingMethod result;
@@ -125,7 +126,13 @@
if (throwScope.exception())
return Exception { ExistingExceptionError };
- auto validatedRequest = convertAndValidate(applePayRequest.version, applePayRequest);
+ m_applePayRequest = WTFMove(applePayRequest);
+ return { };
+}
+
+ExceptionOr<void> ApplePayPaymentHandler::show(Document& document)
+{
+ auto validatedRequest = convertAndValidate(m_applePayRequest->version, *m_applePayRequest);
if (validatedRequest.hasException())
return validatedRequest.releaseException();
@@ -154,17 +161,12 @@
if (exception.hasException())
return exception.releaseException();
- m_applePayRequest = WTFMove(request);
- return { };
-}
-
-void ApplePayPaymentHandler::show(Document& document)
-{
Vector<URL> linkIconURLs;
for (auto& icon : LinkIconCollector { document }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon }))
linkIconURLs.append(icon.url);
- paymentCoordinator(document).beginPaymentSession(*this, document.url(), linkIconURLs, *m_applePayRequest);
+ paymentCoordinator(document).beginPaymentSession(*this, document.url(), linkIconURLs, request);
+ return { };
}
void ApplePayPaymentHandler::hide(Document& document)
@@ -172,6 +174,25 @@
paymentCoordinator(document).abortPaymentSession();
}
+static bool shouldDiscloseApplePayCapability(Document& document)
+{
+ auto* page = document.page();
+ if (!page || page->usesEphemeralSession())
+ return false;
+
+ return document.settings().applePayCapabilityDisclosureAllowed();
+}
+
+void ApplePayPaymentHandler::canMakePayment(Document& document, WTF::Function<void(bool)>&& completionHandler)
+{
+ if (!shouldDiscloseApplePayCapability(document)) {
+ completionHandler(paymentCoordinator(document).canMakePayments());
+ return;
+ }
+
+ paymentCoordinator(document).canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document.domain(), WTFMove(completionHandler));
+}
+
} // namespace WebCore
#endif // ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h (223159 => 223160)
--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h 2017-10-11 00:37:49 UTC (rev 223160)
@@ -27,7 +27,7 @@
#if ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
-#include "ApplePaySessionPaymentRequest.h"
+#include "ApplePayRequest.h"
#include "PaymentHandler.h"
#include "PaymentSession.h"
#include <wtf/Noncopyable.h>
@@ -48,8 +48,9 @@
// PaymentHandler
ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) final;
- void show(Document&) final;
+ ExceptionOr<void> show(Document&) final;
void hide(Document&) final;
+ void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) final;
// PaymentSession
void validateMerchant(const URL&) final { }
@@ -60,7 +61,7 @@
void didCancelPaymentSession() final { }
Ref<PaymentRequest> m_paymentRequest;
- std::optional<ApplePaySessionPaymentRequest> m_applePayRequest;
+ std::optional<ApplePayRequest> m_applePayRequest;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.h (223159 => 223160)
--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.h 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.h 2017-10-11 00:37:49 UTC (rev 223160)
@@ -33,6 +33,7 @@
struct ApplePayRequest : public ApplePayRequestBase {
unsigned long version;
+ String merchantIdentifier;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.idl (223159 => 223160)
--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.idl 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.idl 2017-10-11 00:37:49 UTC (rev 223160)
@@ -27,4 +27,5 @@
Conditional=APPLE_PAY&PAYMENT_REQUEST,
] dictionary ApplePayRequest : ApplePayRequestBase {
required unsigned long version;
+ required DOMString merchantIdentifier;
};
Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h (223159 => 223160)
--- trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h 2017-10-11 00:37:49 UTC (rev 223160)
@@ -29,6 +29,7 @@
#include "PaymentRequest.h"
#include "PaymentSessionBase.h"
+#include <wtf/Function.h>
namespace JSC {
class ExecState;
@@ -45,8 +46,9 @@
static bool hasActiveSession(Document&);
virtual ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) = 0;
- virtual void show(Document&) = 0;
+ virtual ExceptionOr<void> show(Document&) = 0;
virtual void hide(Document&) = 0;
+ virtual void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) = 0;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp (223159 => 223160)
--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp 2017-10-11 00:37:49 UTC (rev 223160)
@@ -340,8 +340,17 @@
ASSERT(!m_activePaymentHandler);
}
+static ExceptionOr<JSC::JSValue> parse(ScriptExecutionContext& context, const String& string)
+{
+ auto scope = DECLARE_THROW_SCOPE(context.vm());
+ JSC::JSValue data = "" string);
+ if (scope.exception())
+ return Exception { ExistingExceptionError };
+ return WTFMove(data);
+}
+
// https://www.w3.org/TR/payment-request/#show()-method
-void PaymentRequest::show(ShowPromise&& promise)
+void PaymentRequest::show(Document& document, ShowPromise&& promise)
{
// FIXME: Reject promise with SecurityError if show() was not triggered by a user gesture.
// Find a way to do this without breaking the payment-request web platform tests.
@@ -351,7 +360,6 @@
return;
}
- auto& document = downcast<Document>(*scriptExecutionContext());
if (PaymentHandler::hasActiveSession(document)) {
promise.reject(Exception { AbortError });
return;
@@ -363,10 +371,9 @@
RefPtr<PaymentHandler> selectedPaymentHandler;
for (auto& paymentMethod : m_serializedMethodData) {
- auto scope = DECLARE_THROW_SCOPE(document.vm());
- JSC::JSValue data = "" paymentMethod.serializedData);
- if (scope.exception()) {
- m_showPromise->reject(Exception { ExistingExceptionError });
+ auto data = "" paymentMethod.serializedData);
+ if (data.hasException()) {
+ m_showPromise->reject(data.releaseException());
return;
}
@@ -374,7 +381,7 @@
if (!handler)
continue;
- auto result = handler->convertData(*document.execState(), WTFMove(data));
+ auto result = handler->convertData(*document.execState(), data.releaseReturnValue());
if (result.hasException()) {
m_showPromise->reject(result.releaseException());
return;
@@ -389,11 +396,30 @@
return;
}
+ auto exception = selectedPaymentHandler->show(document);
+ if (exception.hasException()) {
+ m_showPromise->reject(exception.releaseException());
+ return;
+ }
+
ASSERT(!m_activePaymentHandler);
m_activePaymentHandler = WTFMove(selectedPaymentHandler);
+ setPendingActivity(this); // unsetPendingActivity() is called below in stop()
+}
- m_activePaymentHandler->show(document);
- setPendingActivity(this);
+void PaymentRequest::stop()
+{
+ if (m_state != State::Interactive)
+ return;
+
+ if (auto paymentHandler = std::exchange(m_activePaymentHandler, nullptr)) {
+ unsetPendingActivity(this);
+ paymentHandler->hide(downcast<Document>(*scriptExecutionContext()));
+ }
+
+ ASSERT(m_state == State::Interactive);
+ m_state = State::Closed;
+ m_showPromise->reject(Exception { AbortError });
}
// https://www.w3.org/TR/payment-request/#abort()-method
@@ -408,7 +434,7 @@
}
// https://www.w3.org/TR/payment-request/#canmakepayment()-method
-void PaymentRequest::canMakePayment(CanMakePaymentPromise&& promise)
+void PaymentRequest::canMakePayment(Document& document, CanMakePaymentPromise&& promise)
{
if (m_state != State::Created) {
promise.reject(Exception { InvalidStateError });
@@ -415,7 +441,25 @@
return;
}
- // FIXME: Resolve the promise with true if we can support any of the payment methods in m_serializedMethodData.
+ for (auto& paymentMethod : m_serializedMethodData) {
+ auto data = "" paymentMethod.serializedData);
+ if (data.hasException())
+ continue;
+
+ auto handler = PaymentHandler::create(*this, paymentMethod.identifier);
+ if (!handler)
+ continue;
+
+ auto exception = handler->convertData(*document.execState(), data.releaseReturnValue());
+ if (exception.hasException())
+ continue;
+
+ handler->canMakePayment(document, [promise = WTFMove(promise)](bool canMakePayment) mutable {
+ promise.resolve(canMakePayment);
+ });
+ return;
+ }
+
promise.resolve(false);
}
@@ -443,21 +487,6 @@
}
}
-void PaymentRequest::stop()
-{
- if (m_state != State::Interactive)
- return;
-
- if (auto paymentHandler = std::exchange(m_activePaymentHandler, nullptr)) {
- unsetPendingActivity(this);
- paymentHandler->hide(downcast<Document>(*scriptExecutionContext()));
- }
-
- ASSERT(m_state == State::Interactive);
- m_state = State::Closed;
- m_showPromise->reject(Exception { AbortError });
-}
-
} // namespace WebCore
#endif // ENABLE(PAYMENT_REQUEST)
Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h (223159 => 223160)
--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h 2017-10-11 00:37:49 UTC (rev 223160)
@@ -54,9 +54,9 @@
static ExceptionOr<Ref<PaymentRequest>> create(Document&, Vector<PaymentMethodData>&&, PaymentDetailsInit&&, PaymentOptions&&);
~PaymentRequest();
- void show(ShowPromise&&);
+ void show(Document&, ShowPromise&&);
ExceptionOr<void> abort(AbortPromise&&);
- void canMakePayment(CanMakePaymentPromise&&);
+ void canMakePayment(Document&, CanMakePaymentPromise&&);
const String& id() const;
PaymentAddress* shippingAddress() const { return m_shippingAddress.get(); }
@@ -103,7 +103,6 @@
RefPtr<PaymentAddress> m_shippingAddress;
State m_state { State::Created };
std::optional<ShowPromise> m_showPromise;
- std::optional<CanMakePaymentPromise> m_canMakePaymentPromise;
RefPtr<PaymentHandler> m_activePaymentHandler;
};
Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl (223159 => 223160)
--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl 2017-10-11 00:09:20 UTC (rev 223159)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl 2017-10-11 00:37:49 UTC (rev 223160)
@@ -32,9 +32,9 @@
EnabledBySetting=PaymentRequest,
SecureContext
] interface PaymentRequest : EventTarget {
- Promise<PaymentResponse> show();
+ [CallWith=Document] Promise<PaymentResponse> show();
[MayThrowException] Promise<void> abort();
- Promise<boolean> canMakePayment();
+ [CallWith=Document] Promise<boolean> canMakePayment();
readonly attribute DOMString id;
readonly attribute PaymentAddress? shippingAddress;