Changeset 223855 in webkit


Ignore:
Timestamp:
Oct 23, 2017 2:00:45 PM (7 years ago)
Author:
aestes@apple.com
Message:

[Payment Request] Resolve PaymentRequest.show()'s accept promise when a payment is authorized
https://bugs.webkit.org/show_bug.cgi?id=178609
<rdar://problem/33542813>

Reviewed by Alex Christensen.

Source/WebCore:

This patch implements the logic for resolving PaymentRequest.show()'s accept promise when
the user authorizes a payment, and implements PaymentResponse.complete().

Tests: http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html

http/tests/paymentrequest/payment-response-complete-method.https.html
http/tests/paymentrequest/payment-response-methodName-attribute.https.html
http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html
http/tests/paymentrequest/payment-response-payerName-attribute.https.html
http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html

  • DerivedSources.make:
  • Modules/applepay/ApplePayPaymentContact.h:
  • Modules/applepay/Payment.h:

(WebCore::Payment::Payment): Deleted.
(WebCore::Payment::pkPayment const): Deleted.

  • Modules/applepay/PaymentContact.h:

(WebCore::PaymentContact::PaymentContact): Deleted.
(WebCore::PaymentContact::pkContact const): Deleted.

  • Modules/applepay/cocoa/PaymentContactCocoa.mm:

(WebCore::convert):

  • Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:

(WebCore::ApplePayPaymentHandler::hasActiveSession):
(WebCore::ApplePayPaymentHandler::ApplePayPaymentHandler):
(WebCore::ApplePayPaymentHandler::document):
(WebCore::ApplePayPaymentHandler::paymentCoordinator):
(WebCore::ApplePayPaymentHandler::convertData):
(WebCore::ApplePayPaymentHandler::show):
(WebCore::ApplePayPaymentHandler::hide):
(WebCore::ApplePayPaymentHandler::canMakePayment):
(WebCore::ApplePayPaymentHandler::complete):
(WebCore::convert):
(WebCore::ApplePayPaymentHandler::didAuthorizePayment):
(WebCore::ApplePayPaymentHandler::didSelectShippingMethod):
(WebCore::ApplePayPaymentHandler::didSelectShippingContact):

  • Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
  • Modules/paymentrequest/PaymentAddress.h:
  • Modules/paymentrequest/PaymentAddress.idl:
  • Modules/paymentrequest/PaymentHandler.cpp:

(WebCore::PaymentHandler::create):

  • Modules/paymentrequest/PaymentHandler.h:
  • Modules/paymentrequest/PaymentRequest.cpp:

(WebCore::PaymentRequest::show):
(WebCore::PaymentRequest::stop):
(WebCore::PaymentRequest::canMakePayment):
(WebCore::PaymentRequest::canSuspendForDocumentSuspension const):
(WebCore::PaymentRequest::shippingAddressChanged):
(WebCore::PaymentRequest::shippingOptionChanged):
(WebCore::PaymentRequest::accept):
(WebCore::PaymentRequest::complete):

  • Modules/paymentrequest/PaymentRequest.h:
  • Modules/paymentrequest/PaymentResponse.cpp:

(WebCore::PaymentResponse::PaymentResponse):
(WebCore::PaymentResponse::complete):

  • Modules/paymentrequest/PaymentResponse.h:
  • WebCore.xcodeproj/project.pbxproj:
  • testing/Internals.cpp:

(WebCore::Internals::Internals):
(WebCore::Internals::mockPaymentCoordinator const):

  • testing/Internals.h:
  • testing/Internals.idl:
  • testing/MockPayment.h: Added.
  • testing/MockPaymentAddress.h: Added.
  • testing/MockPaymentAddress.idl: Added.
  • testing/MockPaymentContact.h: Added.
  • testing/MockPaymentCoordinator.cpp:

(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
(WebCore::MockPaymentCoordinator::openPaymentSetup):
(WebCore::dispatchIfShowing):
(WebCore::MockPaymentCoordinator::showPaymentUI):
(WebCore::MockPaymentCoordinator::completeMerchantValidation):
(WebCore::MockPaymentCoordinator::completePaymentSession):
(WebCore::MockPaymentCoordinator::abortPaymentSession):
(WebCore::MockPaymentCoordinator::cancelPaymentSession):
(WebCore::MockPaymentCoordinator::paymentCoordinatorDestroyed):

  • testing/MockPaymentCoordinator.h:
  • testing/MockPaymentCoordinator.idl: Added.

LayoutTests:

  • http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https-expected.txt: Added.
  • http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html: Copied from imported/w3c/web-platform-tests/payment-request/PaymentAddress/attributes-and-toJSON-method-manual.https.html.
  • http/tests/paymentrequest/payment-response-complete-method.https-expected.txt: Added.
  • http/tests/paymentrequest/payment-response-complete-method.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/complete-method-manual.https.html.
  • http/tests/paymentrequest/payment-response-methodName-attribute.https-expected.txt: Added.
  • http/tests/paymentrequest/payment-response-methodName-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/methodName-attribute-manual.https.html.
  • http/tests/paymentrequest/payment-response-payerEmail-attribute.https-expected.txt: Added.
  • http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerEmail-attribute-manual.https.html.
  • http/tests/paymentrequest/payment-response-payerName-attribute.https-expected.txt: Added.
  • http/tests/paymentrequest/payment-response-payerName-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerName-attribute-manual.https.html.
  • http/tests/paymentrequest/payment-response-payerPhone-attribute.https-expected.txt: Added.
  • http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerPhone-attribute-manual.https.html.
  • http/tests/paymentrequest/resources/helpers.js: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/helpers.js.

(test):
(async.getPaymentResponse):
(async.getPaymentRequestResponse):
(async.runTest):

Location:
trunk
Files:
14 added
23 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223849 r223855  
     12017-10-23  Andy Estes  <aestes@apple.com>
     2
     3        [Payment Request] Resolve PaymentRequest.show()'s accept promise when a payment is authorized
     4        https://bugs.webkit.org/show_bug.cgi?id=178609
     5        <rdar://problem/33542813>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https-expected.txt: Added.
     10        * http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html: Copied from imported/w3c/web-platform-tests/payment-request/PaymentAddress/attributes-and-toJSON-method-manual.https.html.
     11        * http/tests/paymentrequest/payment-response-complete-method.https-expected.txt: Added.
     12        * http/tests/paymentrequest/payment-response-complete-method.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/complete-method-manual.https.html.
     13        * http/tests/paymentrequest/payment-response-methodName-attribute.https-expected.txt: Added.
     14        * http/tests/paymentrequest/payment-response-methodName-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/methodName-attribute-manual.https.html.
     15        * http/tests/paymentrequest/payment-response-payerEmail-attribute.https-expected.txt: Added.
     16        * http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerEmail-attribute-manual.https.html.
     17        * http/tests/paymentrequest/payment-response-payerName-attribute.https-expected.txt: Added.
     18        * http/tests/paymentrequest/payment-response-payerName-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerName-attribute-manual.https.html.
     19        * http/tests/paymentrequest/payment-response-payerPhone-attribute.https-expected.txt: Added.
     20        * http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/payerPhone-attribute-manual.https.html.
     21        * http/tests/paymentrequest/resources/helpers.js: Copied from imported/w3c/web-platform-tests/payment-request/payment-response/helpers.js.
     22        (test):
     23        (async.getPaymentResponse):
     24        (async.getPaymentRequestResponse):
     25        (async.runTest):
     26
    1272017-10-23  Chris Dumez  <cdumez@apple.com>
    228
  • trunk/Source/WebCore/ChangeLog

    r223854 r223855  
     12017-10-23  Andy Estes  <aestes@apple.com>
     2
     3        [Payment Request] Resolve PaymentRequest.show()'s accept promise when a payment is authorized
     4        https://bugs.webkit.org/show_bug.cgi?id=178609
     5        <rdar://problem/33542813>
     6
     7        Reviewed by Alex Christensen.
     8
     9        This patch implements the logic for resolving PaymentRequest.show()'s accept promise when
     10        the user authorizes a payment, and implements PaymentResponse.complete().
     11
     12        Tests: http/tests/paymentrequest/payment-address-attributes-and-toJSON-method.https.html
     13               http/tests/paymentrequest/payment-response-complete-method.https.html
     14               http/tests/paymentrequest/payment-response-methodName-attribute.https.html
     15               http/tests/paymentrequest/payment-response-payerEmail-attribute.https.html
     16               http/tests/paymentrequest/payment-response-payerName-attribute.https.html
     17               http/tests/paymentrequest/payment-response-payerPhone-attribute.https.html
     18
     19        * DerivedSources.make:
     20        * Modules/applepay/ApplePayPaymentContact.h:
     21        * Modules/applepay/Payment.h:
     22        (WebCore::Payment::Payment): Deleted.
     23        (WebCore::Payment::pkPayment const): Deleted.
     24        * Modules/applepay/PaymentContact.h:
     25        (WebCore::PaymentContact::PaymentContact): Deleted.
     26        (WebCore::PaymentContact::pkContact const): Deleted.
     27        * Modules/applepay/cocoa/PaymentContactCocoa.mm:
     28        (WebCore::convert):
     29        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
     30        (WebCore::ApplePayPaymentHandler::hasActiveSession):
     31        (WebCore::ApplePayPaymentHandler::ApplePayPaymentHandler):
     32        (WebCore::ApplePayPaymentHandler::document):
     33        (WebCore::ApplePayPaymentHandler::paymentCoordinator):
     34        (WebCore::ApplePayPaymentHandler::convertData):
     35        (WebCore::ApplePayPaymentHandler::show):
     36        (WebCore::ApplePayPaymentHandler::hide):
     37        (WebCore::ApplePayPaymentHandler::canMakePayment):
     38        (WebCore::ApplePayPaymentHandler::complete):
     39        (WebCore::convert):
     40        (WebCore::ApplePayPaymentHandler::didAuthorizePayment):
     41        (WebCore::ApplePayPaymentHandler::didSelectShippingMethod):
     42        (WebCore::ApplePayPaymentHandler::didSelectShippingContact):
     43        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
     44        * Modules/paymentrequest/PaymentAddress.h:
     45        * Modules/paymentrequest/PaymentAddress.idl:
     46        * Modules/paymentrequest/PaymentHandler.cpp:
     47        (WebCore::PaymentHandler::create):
     48        * Modules/paymentrequest/PaymentHandler.h:
     49        * Modules/paymentrequest/PaymentRequest.cpp:
     50        (WebCore::PaymentRequest::show):
     51        (WebCore::PaymentRequest::stop):
     52        (WebCore::PaymentRequest::canMakePayment):
     53        (WebCore::PaymentRequest::canSuspendForDocumentSuspension const):
     54        (WebCore::PaymentRequest::shippingAddressChanged):
     55        (WebCore::PaymentRequest::shippingOptionChanged):
     56        (WebCore::PaymentRequest::accept):
     57        (WebCore::PaymentRequest::complete):
     58        * Modules/paymentrequest/PaymentRequest.h:
     59        * Modules/paymentrequest/PaymentResponse.cpp:
     60        (WebCore::PaymentResponse::PaymentResponse):
     61        (WebCore::PaymentResponse::complete):
     62        * Modules/paymentrequest/PaymentResponse.h:
     63        * WebCore.xcodeproj/project.pbxproj:
     64        * testing/Internals.cpp:
     65        (WebCore::Internals::Internals):
     66        (WebCore::Internals::mockPaymentCoordinator const):
     67        * testing/Internals.h:
     68        * testing/Internals.idl:
     69        * testing/MockPayment.h: Added.
     70        * testing/MockPaymentAddress.h: Added.
     71        * testing/MockPaymentAddress.idl: Added.
     72        * testing/MockPaymentContact.h: Added.
     73        * testing/MockPaymentCoordinator.cpp:
     74        (WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
     75        (WebCore::MockPaymentCoordinator::openPaymentSetup):
     76        (WebCore::dispatchIfShowing):
     77        (WebCore::MockPaymentCoordinator::showPaymentUI):
     78        (WebCore::MockPaymentCoordinator::completeMerchantValidation):
     79        (WebCore::MockPaymentCoordinator::completePaymentSession):
     80        (WebCore::MockPaymentCoordinator::abortPaymentSession):
     81        (WebCore::MockPaymentCoordinator::cancelPaymentSession):
     82        (WebCore::MockPaymentCoordinator::paymentCoordinatorDestroyed):
     83        * testing/MockPaymentCoordinator.h:
     84        * testing/MockPaymentCoordinator.idl: Added.
     85
    1862017-10-23  Dean Jackson  <dino@apple.com>
    287
  • trunk/Source/WebCore/DerivedSources.make

    r223828 r223855  
    909909    $(WebCore)/testing/MockContentFilterSettings.idl \
    910910    $(WebCore)/testing/MockPageOverlay.idl \
     911    $(WebCore)/testing/MockPaymentAddress.idl \
     912    $(WebCore)/testing/MockPaymentCoordinator.idl \
    911913    $(WebCore)/testing/TypeConversions.idl \
    912914    $(WebCore)/workers/AbstractWorker.idl \
  • trunk/Source/WebCore/Modules/applepay/ApplePayPaymentContact.h

    r223580 r223855  
    3939    String givenName;
    4040    String familyName;
     41    String localizedName;
    4142    String phoneticGivenName;
    4243    String phoneticFamilyName;
     44    String localizedPhoneticName;
    4345    std::optional<Vector<String>> addressLines;
    4446    String subLocality;
  • trunk/Source/WebCore/Modules/applepay/Payment.h

    r223728 r223855  
    3636struct ApplePayPayment;
    3737
    38 class Payment {
     38class WEBCORE_EXPORT Payment {
    3939public:
    4040    Payment() = default;
     
    4545    }
    4646
    47     ApplePayPayment toApplePayPayment() const;
     47    virtual ~Payment() = default;
     48
     49    virtual ApplePayPayment toApplePayPayment() const;
    4850
    4951    PKPayment *pkPayment() const { return m_pkPayment.get(); }
  • trunk/Source/WebCore/Modules/applepay/PaymentContact.h

    r220718 r223855  
    3737struct ApplePayPaymentContact;
    3838
    39 class PaymentContact {
     39class WEBCORE_EXPORT PaymentContact {
    4040public:
    4141    PaymentContact() = default;
     
    4444    {
    4545    }
     46    virtual ~PaymentContact() = default;
    4647
    4748    static PaymentContact fromApplePayPaymentContact(unsigned version, const ApplePayPaymentContact&);
    48     ApplePayPaymentContact toApplePayPaymentContact() const;
     49    virtual ApplePayPaymentContact toApplePayPaymentContact() const;
    4950
    5051    PKContact *pkContact() const { return m_pkContact.get(); }
  • trunk/Source/WebCore/Modules/applepay/cocoa/PaymentContactCocoa.mm

    r223583 r223855  
    190190    result.givenName = name.givenName;
    191191    result.familyName = name.familyName;
     192    result.localizedName = [NSPersonNameComponentsFormatter localizedStringFromPersonNameComponents:name style:NSPersonNameComponentsFormatterStyleDefault options:0];
    192193
    193194    NSPersonNameComponents *phoneticName = name.phoneticRepresentation;
    194195    result.phoneticGivenName = phoneticName.givenName;
    195196    result.phoneticFamilyName = phoneticName.familyName;
     197    result.localizedPhoneticName = [NSPersonNameComponentsFormatter localizedStringFromPersonNameComponents:name style:NSPersonNameComponentsFormatterStyleDefault options:NSPersonNameComponentsFormatterPhonetic];
    196198
    197199    CNPostalAddress *postalAddress = contact.postalAddress;
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp

    r223193 r223855  
    3232#include "ApplePayMerchantCapability.h"
    3333#include "ApplePayMerchantValidationEvent.h"
     34#include "ApplePayPayment.h"
    3435#include "ApplePaySessionPaymentRequest.h"
    3536#include "Document.h"
    3637#include "EventNames.h"
     38#include "JSApplePayPayment.h"
    3739#include "JSApplePayRequest.h"
    3840#include "LinkIconCollector.h"
    3941#include "MainFrame.h"
    4042#include "Page.h"
     43#include "Payment.h"
     44#include "PaymentAuthorizationStatus.h"
    4145#include "PaymentContact.h"
    4246#include "PaymentCoordinator.h"
    4347#include "PaymentRequestValidator.h"
     48#include "PaymentResponse.h"
    4449#include "Settings.h"
    4550
     
    6267bool ApplePayPaymentHandler::hasActiveSession(Document& document)
    6368{
    64     return paymentCoordinator(document).hasActiveSession();
    65 }
    66 
    67 ApplePayPaymentHandler::ApplePayPaymentHandler(PaymentRequest& paymentRequest)
    68     : m_paymentRequest { paymentRequest }
    69 {
     69    return WebCore::paymentCoordinator(document).hasActiveSession();
     70}
     71
     72ApplePayPaymentHandler::ApplePayPaymentHandler(Document& document, const PaymentRequest::MethodIdentifier& identifier, PaymentRequest& paymentRequest)
     73    : ContextDestructionObserver { &document }
     74    , m_identifier { identifier }
     75    , m_paymentRequest { paymentRequest }
     76{
     77    ASSERT(handlesIdentifier(m_identifier));
     78}
     79
     80Document& ApplePayPaymentHandler::document()
     81{
     82    return downcast<Document>(*scriptExecutionContext());
     83}
     84
     85PaymentCoordinator& ApplePayPaymentHandler::paymentCoordinator()
     86{
     87    return WebCore::paymentCoordinator(document());
    7088}
    7189
     
    141159}
    142160
    143 ExceptionOr<void> ApplePayPaymentHandler::convertData(JSC::ExecState& execState, JSC::JSValue&& data)
    144 {
    145     auto throwScope = DECLARE_THROW_SCOPE(execState.vm());
    146     auto applePayRequest = convertDictionary<ApplePayRequest>(execState, WTFMove(data));
     161ExceptionOr<void> ApplePayPaymentHandler::convertData(JSC::JSValue&& data)
     162{
     163    auto& context = *scriptExecutionContext();
     164    auto throwScope = DECLARE_THROW_SCOPE(context.vm());
     165    auto applePayRequest = convertDictionary<ApplePayRequest>(*context.execState(), WTFMove(data));
    147166    if (throwScope.exception())
    148167        return Exception { ExistingExceptionError };
     
    152171}
    153172
    154 ExceptionOr<void> ApplePayPaymentHandler::show(Document& document)
     173ExceptionOr<void> ApplePayPaymentHandler::show()
    155174{
    156175    auto validatedRequest = convertAndValidate(m_applePayRequest->version, *m_applePayRequest);
     
    204223
    205224    Vector<URL> linkIconURLs;
    206     for (auto& icon : LinkIconCollector { document }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon }))
     225    for (auto& icon : LinkIconCollector { document() }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon }))
    207226        linkIconURLs.append(icon.url);
    208227
    209     paymentCoordinator(document).beginPaymentSession(*this, document.url(), linkIconURLs, request);
     228    paymentCoordinator().beginPaymentSession(*this, document().url(), linkIconURLs, request);
    210229    return { };
    211230}
    212231
    213 void ApplePayPaymentHandler::hide(Document& document)
    214 {
    215     paymentCoordinator(document).abortPaymentSession();
     232void ApplePayPaymentHandler::hide()
     233{
     234    paymentCoordinator().abortPaymentSession();
    216235}
    217236
     
    225244}
    226245
    227 void ApplePayPaymentHandler::canMakePayment(Document& document, WTF::Function<void(bool)>&& completionHandler)
    228 {
    229     if (!shouldDiscloseApplePayCapability(document)) {
    230         completionHandler(paymentCoordinator(document).canMakePayments());
     246void ApplePayPaymentHandler::canMakePayment(Function<void(bool)>&& completionHandler)
     247{
     248    if (!shouldDiscloseApplePayCapability(document())) {
     249        completionHandler(paymentCoordinator().canMakePayments());
    231250        return;
    232251    }
    233252
    234     paymentCoordinator(document).canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document.domain(), WTFMove(completionHandler));
     253    paymentCoordinator().canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document().domain(), WTFMove(completionHandler));
     254}
     255
     256void ApplePayPaymentHandler::complete(std::optional<PaymentComplete>&& result)
     257{
     258    if (!result) {
     259        paymentCoordinator().completePaymentSession(std::nullopt);
     260        return;
     261    }
     262
     263    PaymentAuthorizationResult authorizationResult;
     264    switch (*result) {
     265    case PaymentComplete::Fail:
     266    case PaymentComplete::Unknown:
     267        authorizationResult.status = PaymentAuthorizationStatus::Failure;
     268        authorizationResult.errors.append({ PaymentError::Code::Unknown, { }, std::nullopt });
     269        break;
     270    case PaymentComplete::Success:
     271        authorizationResult.status = PaymentAuthorizationStatus::Success;
     272        break;
     273    }
     274
     275    paymentCoordinator().completePaymentSession(WTFMove(authorizationResult));
    235276}
    236277
     
    241282}
    242283
     284static Ref<PaymentAddress> convert(const ApplePayPaymentContact& contact)
     285{
     286    return PaymentAddress::create(contact.countryCode, contact.addressLines.value_or(Vector<String>()), contact.administrativeArea, contact.locality, contact.subLocality, contact.postalCode, String(), String(), String(), contact.localizedName, contact.phoneNumber);
     287}
     288
     289void ApplePayPaymentHandler::didAuthorizePayment(const Payment& payment)
     290{
     291    auto applePayPayment = payment.toApplePayPayment();
     292    auto& execState = *document().execState();
     293    auto details = JSC::Strong<JSC::JSObject> { execState.vm(), asObject(toJS<IDLDictionary<ApplePayPayment>>(execState, *JSC::jsCast<JSDOMGlobalObject*>(execState.lexicalGlobalObject()), applePayPayment)) };
     294    const auto& shippingContact = applePayPayment.shippingContact.value_or(ApplePayPaymentContact());
     295    m_paymentRequest->accept(WTF::get<URL>(m_identifier).string(), WTFMove(details), convert(shippingContact), shippingContact.localizedName, shippingContact.emailAddress, shippingContact.phoneNumber);
     296}
     297
     298void ApplePayPaymentHandler::didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod)
     299{
     300    m_paymentRequest->shippingOptionChanged(shippingMethod.identifier);
     301}
     302
     303void ApplePayPaymentHandler::didSelectShippingContact(const PaymentContact& shippingContact)
     304{
     305    m_paymentRequest->shippingAddressChanged(convert(shippingContact.toApplePayPaymentContact()));
     306}
     307
    243308} // namespace WebCore
    244309
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h

    r223193 r223855  
    2929
    3030#include "ApplePayRequest.h"
     31#include "ContextDestructionObserver.h"
    3132#include "PaymentHandler.h"
     33#include "PaymentRequest.h"
    3234#include "PaymentSession.h"
    3335#include <wtf/Noncopyable.h>
     
    3638namespace WebCore {
    3739
    38 class PaymentRequest;
     40class PaymentCoordinator;
    3941
    40 class ApplePayPaymentHandler final : public PaymentHandler, public PaymentSession {
     42class ApplePayPaymentHandler final : public PaymentHandler, public PaymentSession, private ContextDestructionObserver {
    4143public:
    4244    static bool handlesIdentifier(const PaymentRequest::MethodIdentifier&);
     
    4547private:
    4648    friend class PaymentHandler;
    47     explicit ApplePayPaymentHandler(PaymentRequest&);
     49    explicit ApplePayPaymentHandler(Document&, const PaymentRequest::MethodIdentifier&, PaymentRequest&);
     50
     51    Document& document();
     52    PaymentCoordinator& paymentCoordinator();
    4853
    4954    // PaymentHandler
    50     ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) final;
    51     ExceptionOr<void> show(Document&) final;
    52     void hide(Document&) final;
    53     void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) final;
     55    ExceptionOr<void> convertData(JSC::JSValue&&) final;
     56    ExceptionOr<void> show() final;
     57    void hide() final;
     58    void canMakePayment(WTF::Function<void(bool)>&& completionHandler) final;
     59    void complete(std::optional<PaymentComplete>&&) final;
    5460
    5561    // PaymentSession
    5662    void validateMerchant(const URL&) final;
    57     void didAuthorizePayment(const Payment&) final { }
    58     void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final { }
    59     void didSelectShippingContact(const PaymentContact&) final { }
     63    void didAuthorizePayment(const Payment&) final;
     64    void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final;
     65    void didSelectShippingContact(const PaymentContact&) final;
    6066    void didSelectPaymentMethod(const PaymentMethod&) final { }
    6167    void didCancelPaymentSession() final { }
    6268
     69    PaymentRequest::MethodIdentifier m_identifier;
    6370    Ref<PaymentRequest> m_paymentRequest;
    6471    std::optional<ApplePayRequest> m_applePayRequest;
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentAddress.cpp

    r223854 r223855  
    2525
    2626#include "config.h"
    27 #include "PaymentHandler.h"
     27#include "PaymentAddress.h"
    2828
    2929#if ENABLE(PAYMENT_REQUEST)
    3030
    31 #if ENABLE(APPLE_PAY)
    32 #include "ApplePayPaymentHandler.h"
    33 #endif
    34 
    3531namespace WebCore {
    3632
    37 RefPtr<PaymentHandler> PaymentHandler::create(PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier)
     33PaymentAddress::PaymentAddress(const String& country, const Vector<String>& addressLine, const String& region, const String& city, const String& dependentLocality, const String& postalCode, const String& sortingCode, const String& languageCode, const String& organization, const String& recipient, const String& phone)
     34    : m_country { country }
     35    , m_addressLine { addressLine }
     36    , m_region { region }
     37    , m_city { city }
     38    , m_dependentLocality { dependentLocality }
     39    , m_postalCode { postalCode }
     40    , m_sortingCode { sortingCode }
     41    , m_languageCode { languageCode }
     42    , m_organization { organization }
     43    , m_recipient { recipient }
     44    , m_phone { phone }
    3845{
    39 #if ENABLE(APPLE_PAY)
    40     if (ApplePayPaymentHandler::handlesIdentifier(identifier))
    41         return adoptRef(new ApplePayPaymentHandler(paymentRequest));
    42 #else
    43     UNUSED_PARAM(paymentRequest);
    44     UNUSED_PARAM(identifier);
    45 #endif
    46 
    47     return nullptr;
    48 }
    49 
    50 bool PaymentHandler::hasActiveSession(Document& document)
    51 {
    52 #if ENABLE(APPLE_PAY)
    53     return ApplePayPaymentHandler::hasActiveSession(document);
    54 #else
    55     UNUSED_PARAM(document);
    56     return false;
    57 #endif
    5846}
    5947
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentAddress.h

    r220955 r223855  
    3636class PaymentAddress final : public RefCounted<PaymentAddress> {
    3737public:
     38    template <typename... Args> static Ref<PaymentAddress> create(Args&&... args)
     39    {
     40        return adoptRef(*new PaymentAddress(std::forward<Args>(args)...));
     41    }
     42
    3843    const String& country() const { return m_country; }
    3944    const Vector<String>& addressLine() const { return m_addressLine; }
     
    4954
    5055private:
     56    PaymentAddress(const String& country, const Vector<String>& addressLine, const String& region, const String& city, const String& dependentLocality, const String& postalCode, const String& sortingCode, const String& languageCode, const String& organization, const String& recipient, const String& phone);
     57
    5158    String m_country;
    5259    Vector<String> m_addressLine;
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentAddress.idl

    r220955 r223855  
    2727    Conditional=PAYMENT_REQUEST,
    2828    EnabledBySetting=PaymentRequest,
     29    Exposed=Window,
    2930    ImplementationLacksVTable,
    3031    SecureContext
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp

    r223076 r223855  
    3535namespace WebCore {
    3636
    37 RefPtr<PaymentHandler> PaymentHandler::create(PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier)
     37RefPtr<PaymentHandler> PaymentHandler::create(Document& document, PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier)
    3838{
    3939#if ENABLE(APPLE_PAY)
    4040    if (ApplePayPaymentHandler::handlesIdentifier(identifier))
    41         return adoptRef(new ApplePayPaymentHandler(paymentRequest));
     41        return adoptRef(new ApplePayPaymentHandler(document, identifier, paymentRequest));
    4242#else
     43    UNUSED_PARAM(document);
    4344    UNUSED_PARAM(paymentRequest);
    4445    UNUSED_PARAM(identifier);
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h

    r223160 r223855  
    3333
    3434namespace JSC {
    35 class ExecState;
    3635class JSValue;
    3736}
     
    4342class PaymentHandler : public virtual PaymentSessionBase {
    4443public:
    45     static RefPtr<PaymentHandler> create(PaymentRequest&, const PaymentRequest::MethodIdentifier&);
     44    static RefPtr<PaymentHandler> create(Document&, PaymentRequest&, const PaymentRequest::MethodIdentifier&);
    4645    static bool hasActiveSession(Document&);
    4746
    48     virtual ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) = 0;
    49     virtual ExceptionOr<void> show(Document&) = 0;
    50     virtual void hide(Document&) = 0;
    51     virtual void canMakePayment(Document&, WTF::Function<void(bool)>&& completionHandler) = 0;
     47    virtual ExceptionOr<void> convertData(JSC::JSValue&&) = 0;
     48    virtual ExceptionOr<void> show() = 0;
     49    virtual void hide() = 0;
     50    virtual void canMakePayment(WTF::Function<void(bool)>&& completionHandler) = 0;
     51    virtual void complete(std::optional<PaymentComplete>&&) = 0;
    5252};
    5353
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp

    r223701 r223855  
    3131#include "ApplePayPaymentHandler.h"
    3232#include "Document.h"
     33#include "JSPaymentResponse.h"
    3334#include "PaymentAddress.h"
    3435#include "PaymentCurrencyAmount.h"
     
    3738#include "PaymentMethodData.h"
    3839#include "PaymentOptions.h"
     40#include "PaymentResponse.h"
    3941#include "ScriptController.h"
    4042#include <JavaScriptCore/JSONObject.h>
     
    377379        }
    378380
    379         auto handler = PaymentHandler::create(*this, paymentMethod.identifier);
     381        auto handler = PaymentHandler::create(document, *this, paymentMethod.identifier);
    380382        if (!handler)
    381383            continue;
    382384
    383         auto result = handler->convertData(*document.execState(), data.releaseReturnValue());
     385        auto result = handler->convertData(data.releaseReturnValue());
    384386        if (result.hasException()) {
    385387            m_showPromise->reject(result.releaseException());
     
    396398    }
    397399
    398     auto exception = selectedPaymentHandler->show(document);
     400    auto exception = selectedPaymentHandler->show();
    399401    if (exception.hasException()) {
    400402        m_showPromise->reject(exception.releaseException());
     
    414416    if (auto paymentHandler = std::exchange(m_activePaymentHandler, nullptr)) {
    415417        unsetPendingActivity(this);
    416         paymentHandler->hide(downcast<Document>(*scriptExecutionContext()));
     418        paymentHandler->hide();
    417419    }
    418420
     
    446448            continue;
    447449
    448         auto handler = PaymentHandler::create(*this, paymentMethod.identifier);
     450        auto handler = PaymentHandler::create(document, *this, paymentMethod.identifier);
    449451        if (!handler)
    450452            continue;
    451453
    452         auto exception = handler->convertData(*document.execState(), data.releaseReturnValue());
     454        auto exception = handler->convertData(data.releaseReturnValue());
    453455        if (exception.hasException())
    454456            continue;
    455457
    456         handler->canMakePayment(document, [promise = WTFMove(promise)](bool canMakePayment) mutable {
     458        handler->canMakePayment([promise = WTFMove(promise)](bool canMakePayment) mutable {
    457459            promise.resolve(canMakePayment);
    458460        });
     
    479481    switch (m_state) {
    480482    case State::Created:
    481     case State::Closed:
    482483        ASSERT(!m_activePaymentHandler);
    483484        return true;
    484485    case State::Interactive:
     486    case State::Closed:
    485487        return !m_activePaymentHandler;
    486488    }
    487489}
    488490
     491void PaymentRequest::shippingAddressChanged(Ref<PaymentAddress>&& shippingAddress)
     492{
     493    ASSERT(m_state == State::Interactive);
     494    m_shippingAddress = WTFMove(shippingAddress);
     495    // FIXME: run the PaymentRequest updated algorithm.
     496}
     497
     498void PaymentRequest::shippingOptionChanged(const String& shippingOption)
     499{
     500    ASSERT(m_state == State::Interactive);
     501    m_shippingOption = shippingOption;
     502    // FIXME: run the PaymentRequest updated algorithm.
     503}
     504
     505void PaymentRequest::accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone)
     506{
     507    ASSERT(m_state == State::Interactive);
     508
     509    auto response = PaymentResponse::create(*this);
     510    response->setRequestId(m_details.id);
     511    response->setMethodName(methodName);
     512    response->setDetails(WTFMove(details));
     513
     514    if (m_options.requestShipping) {
     515        response->setShippingAddress(shippingAddress.ptr());
     516        response->setShippingOption(m_shippingOption);
     517    }
     518
     519    if (m_options.requestPayerName)
     520        response->setPayerName(payerName);
     521
     522    if (m_options.requestPayerEmail)
     523        response->setPayerEmail(payerEmail);
     524
     525    if (m_options.requestPayerPhone)
     526        response->setPayerPhone(payerPhone);
     527
     528    m_showPromise->resolve(response.get());
     529    m_state = State::Closed;
     530}
     531
     532void PaymentRequest::complete(std::optional<PaymentComplete>&& result)
     533{
     534    ASSERT(m_state == State::Closed);
     535    std::exchange(m_activePaymentHandler, nullptr)->complete(WTFMove(result));
     536}
     537
    489538} // namespace WebCore
    490539
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h

    r223160 r223855  
    4343class PaymentHandler;
    4444class PaymentResponse;
     45enum class PaymentComplete;
    4546enum class PaymentShippingType;
    4647struct PaymentMethodData;
     
    6667    const PaymentOptions& paymentOptions() const { return m_options; }
    6768    const PaymentDetailsInit& paymentDetails() const { return m_details; }
     69
     70    void shippingAddressChanged(Ref<PaymentAddress>&&);
     71    void shippingOptionChanged(const String& shippingOption);
     72    void accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone);
     73    void complete(std::optional<PaymentComplete>&&);
    6874
    6975    using MethodIdentifier = Variant<String, URL>;
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentResponse.cpp

    r220955 r223855  
    2929#if ENABLE(PAYMENT_REQUEST)
    3030
     31#include "PaymentRequest.h"
    3132#include <wtf/RunLoop.h>
    3233
    3334namespace WebCore {
    3435
    35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise)
     36PaymentResponse::PaymentResponse(PaymentRequest& request)
     37    : m_request { request }
    3638{
    37     promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
     39}
     40
     41PaymentResponse::~PaymentResponse() = default;
     42
     43void PaymentResponse::complete(std::optional<PaymentComplete>&& result, DOMPromiseDeferred<void>&& promise)
     44{
     45    if (m_completeCalled) {
     46        promise.reject(Exception { InvalidStateError });
     47        return;
     48    }
     49
     50    m_completeCalled = true;
     51    m_request->complete(WTFMove(result));
     52    promise.resolve();
    3853}
    3954
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentResponse.h

    r220955 r223855  
    3333
    3434namespace WebCore {
     35   
     36class Document;
     37class PaymentRequest;
    3538
    3639class PaymentResponse final : public RefCounted<PaymentResponse> {
    3740public:
     41    static Ref<PaymentResponse> create(PaymentRequest& request)
     42    {
     43        return adoptRef(*new PaymentResponse(request));
     44    }
     45
     46    ~PaymentResponse();
     47
    3848    const String& requestId() const { return m_requestId; }
     49    void setRequestId(const String& requestId) { m_requestId = requestId; }
     50
    3951    const String& methodName() const { return m_methodName; }
     52    void setMethodName(const String& methodName) { m_methodName = methodName; }
     53
    4054    const JSC::Strong<JSC::JSObject>& details() const { return m_details; }
     55    void setDetails(JSC::Strong<JSC::JSObject>&& details) { m_details = WTFMove(details); }
     56
    4157    PaymentAddress* shippingAddress() const { return m_shippingAddress.get(); }
     58    void setShippingAddress(PaymentAddress* shippingAddress) { m_shippingAddress = shippingAddress; }
     59
    4260    const String& shippingOption() const { return m_shippingOption; }
     61    void setShippingOption(const String& shippingOption) { m_shippingOption = shippingOption; }
     62
    4363    const String& payerName() const { return m_payerName; }
     64    void setPayerName(const String& payerName) { m_payerName = payerName; }
     65
    4466    const String& payerEmail() const { return m_payerEmail; }
     67    void setPayerEmail(const String& payerEmail) { m_payerEmail = payerEmail; }
     68
    4569    const String& payerPhone() const { return m_payerPhone; }
     70    void setPayerPhone(const String& payerPhone) { m_payerPhone = payerPhone; }
    4671
    4772    void complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&&);
    4873
    4974private:
     75    explicit PaymentResponse(PaymentRequest&);
     76
     77    Ref<PaymentRequest> m_request;
    5078    String m_requestId;
    5179    String m_methodName;
     
    5684    String m_payerEmail;
    5785    String m_payerPhone;
     86    bool m_completeCalled { false };
    5887};
    5988
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r223850 r223855  
    38733873                A14090FB1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A14090FA1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm */; };
    38743874                A14090FD1AA51E480091191A /* ContentFilterUnblockHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = A14090FC1AA51E480091191A /* ContentFilterUnblockHandler.h */; settings = {ATTRIBUTES = (Private, ); }; };
     3875                A146D31A1F99BCF800D29196 /* JSMockPaymentCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A146D3191F99BCBB00D29196 /* JSMockPaymentCoordinator.cpp */; };
     3876                A146D31B1F99BCFB00D29196 /* JSMockPaymentCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D3181F99BCBA00D29196 /* JSMockPaymentCoordinator.h */; };
     3877                A146D3211F99CB1A00D29196 /* MockPaymentAddress.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D31C1F99C9C200D29196 /* MockPaymentAddress.h */; };
     3878                A146D3221F99D0EC00D29196 /* JSMockPaymentAddress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A146D3201F99CA3E00D29196 /* JSMockPaymentAddress.cpp */; };
     3879                A146D3231F99D0EF00D29196 /* JSMockPaymentAddress.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D31F1F99CA3D00D29196 /* JSMockPaymentAddress.h */; };
     3880                A146D3251F99D69800D29196 /* MockPaymentContact.h in Headers */ = {isa = PBXBuildFile; fileRef = A146D3241F99D69800D29196 /* MockPaymentContact.h */; };
    38753881                A14832B0187F618D00DA63A6 /* WAKAppKitStubs.h in Headers */ = {isa = PBXBuildFile; fileRef = A148328C187F508700DA63A6 /* WAKAppKitStubs.h */; settings = {ATTRIBUTES = (Private, ); }; };
    38763882                A14832B1187F61E100DA63A6 /* WAKAppKitStubs.m in Sources */ = {isa = PBXBuildFile; fileRef = A148328D187F508700DA63A6 /* WAKAppKitStubs.m */; };
     
    39073913                A149786F1ABAF33800CEF7E4 /* ContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A149786D1ABAF33800CEF7E4 /* ContentFilter.h */; };
    39083914                A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */; };
     3915                A14BB0A01F9813B800605A35 /* MockPayment.h in Headers */ = {isa = PBXBuildFile; fileRef = A14BB09E1F9813B800605A35 /* MockPayment.h */; };
    39093916                A15D75151E68F7C400A35FBC /* BlobCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A15D75121E68F7B100A35FBC /* BlobCallback.cpp */; };
    39103917                A15D75161E68F7C800A35FBC /* BlobCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = A15D75131E68F7B100A35FBC /* BlobCallback.h */; };
     
    39523959                A1CC567D1F4614B200A4555B /* JSPaymentShippingOption.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC56591F46145C00A4555B /* JSPaymentShippingOption.h */; };
    39533960                A1CC567F1F4614B700A4555B /* JSPaymentShippingType.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC56501F46145300A4555B /* JSPaymentShippingType.h */; };
     3961                A1CFE0321F9E71290065C345 /* PaymentAddress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1CFE0311F9E71290065C345 /* PaymentAddress.cpp */; };
    39543962                A1DE712D18612AC100734192 /* TouchEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1DE712B18612AC100734192 /* TouchEvents.cpp */; };
    39553963                A1DF5A7F1F7EBD0B0058A477 /* ApplePayRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A1DF5A7C1F7EBD0B0058A477 /* ApplePayRequest.h */; };
     
    1213012138                A14090FA1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentFilterUnblockHandlerCocoa.mm; sourceTree = "<group>"; };
    1213112139                A14090FC1AA51E480091191A /* ContentFilterUnblockHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFilterUnblockHandler.h; sourceTree = "<group>"; };
     12140                A146D3161F99B53D00D29196 /* MockPaymentCoordinator.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MockPaymentCoordinator.idl; sourceTree = "<group>"; };
     12141                A146D3181F99BCBA00D29196 /* JSMockPaymentCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMockPaymentCoordinator.h; sourceTree = "<group>"; };
     12142                A146D3191F99BCBB00D29196 /* JSMockPaymentCoordinator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMockPaymentCoordinator.cpp; sourceTree = "<group>"; };
     12143                A146D31C1F99C9C200D29196 /* MockPaymentAddress.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPaymentAddress.h; sourceTree = "<group>"; };
     12144                A146D31E1F99C9C200D29196 /* MockPaymentAddress.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MockPaymentAddress.idl; sourceTree = "<group>"; };
     12145                A146D31F1F99CA3D00D29196 /* JSMockPaymentAddress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMockPaymentAddress.h; sourceTree = "<group>"; };
     12146                A146D3201F99CA3E00D29196 /* JSMockPaymentAddress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMockPaymentAddress.cpp; sourceTree = "<group>"; };
     12147                A146D3241F99D69800D29196 /* MockPaymentContact.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPaymentContact.h; sourceTree = "<group>"; };
    1213212148                A148328C187F508700DA63A6 /* WAKAppKitStubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WAKAppKitStubs.h; sourceTree = "<group>"; };
    1213312149                A148328D187F508700DA63A6 /* WAKAppKitStubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WAKAppKitStubs.m; sourceTree = "<group>"; };
     
    1216412180                A149786D1ABAF33800CEF7E4 /* ContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFilter.h; sourceTree = "<group>"; };
    1216512181                A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformContentFilter.h; sourceTree = "<group>"; };
     12182                A14BB09E1F9813B800605A35 /* MockPayment.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPayment.h; sourceTree = "<group>"; };
    1216612183                A15D75121E68F7B100A35FBC /* BlobCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobCallback.cpp; sourceTree = "<group>"; };
    1216712184                A15D75131E68F7B100A35FBC /* BlobCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlobCallback.h; sourceTree = "<group>"; };
     
    1222712244                A1CC56641F46146700A4555B /* JSPaymentResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPaymentResponse.h; sourceTree = "<group>"; };
    1222812245                A1CC56651F46146800A4555B /* JSPaymentAddress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPaymentAddress.h; sourceTree = "<group>"; };
     12246                A1CFE0311F9E71290065C345 /* PaymentAddress.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PaymentAddress.cpp; sourceTree = "<group>"; };
    1222912247                A1DE712B18612AC100734192 /* TouchEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TouchEvents.cpp; sourceTree = "<group>"; };
    1223012248                A1DF5A7C1F7EBD0B0058A477 /* ApplePayRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplePayRequest.h; sourceTree = "<group>"; };
     
    1750117519                                2DAAE32C19DCAF6000E002D2 /* MockPageOverlayClient.cpp */,
    1750217520                                2DAAE32D19DCAF6000E002D2 /* MockPageOverlayClient.h */,
     17521                                A14BB09E1F9813B800605A35 /* MockPayment.h */,
     17522                                A146D31C1F99C9C200D29196 /* MockPaymentAddress.h */,
     17523                                A146D31E1F99C9C200D29196 /* MockPaymentAddress.idl */,
     17524                                A146D3241F99D69800D29196 /* MockPaymentContact.h */,
    1750317525                                A1AFEDE51F8BFF6D0087013F /* MockPaymentCoordinator.cpp */,
    1750417526                                A1AFEDE41F8BFF6D0087013F /* MockPaymentCoordinator.h */,
     17527                                A146D3161F99B53D00D29196 /* MockPaymentCoordinator.idl */,
    1750517528                                A14061891E2ECA0A0032B34E /* MockPreviewLoaderClient.cpp */,
    1750617529                                A140618A1E2ECA0A0032B34E /* MockPreviewLoaderClient.h */,
     
    1753317556                                2D6F3E921C1F85550061DBD4 /* JSMockPageOverlay.cpp */,
    1753417557                                2D6F3E931C1F85550061DBD4 /* JSMockPageOverlay.h */,
     17558                                A146D3201F99CA3E00D29196 /* JSMockPaymentAddress.cpp */,
     17559                                A146D31F1F99CA3D00D29196 /* JSMockPaymentAddress.h */,
     17560                                A146D3191F99BCBB00D29196 /* JSMockPaymentCoordinator.cpp */,
     17561                                A146D3181F99BCBA00D29196 /* JSMockPaymentCoordinator.h */,
    1753517562                                EBF5121A1696496C0056BD25 /* JSTypeConversions.cpp */,
    1753617563                                EBF5121B1696496C0056BD25 /* JSTypeConversions.h */,
     
    2126221289                        isa = PBXGroup;
    2126321290                        children = (
     21291                                A1CFE0311F9E71290065C345 /* PaymentAddress.cpp */,
    2126421292                                A1F76B401F44CF7F0014C318 /* PaymentAddress.h */,
    2126521293                                A1F76B421F44CF7F0014C318 /* PaymentAddress.idl */,
     
    2667426702                                A19AEA211AAA808600B52B25 /* JSMockContentFilterSettings.h in Headers */,
    2667526703                                538EC9341F99B9F7004D22A8 /* JSMockPageOverlay.h in Headers */,
     26704                                A146D3231F99D0EF00D29196 /* JSMockPaymentAddress.h in Headers */,
     26705                                A146D31B1F99BCFB00D29196 /* JSMockPaymentCoordinator.h in Headers */,
    2667626706                                EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */,
    2667726707                                CDC26B41160A8CCE0026757B /* LegacyMockCDM.h in Headers */,
     
    2668326713                                2D6F3E911C1ECB2F0061DBD4 /* MockPageOverlay.h in Headers */,
    2668426714                                2D97F04819DD4140001EE9C3 /* MockPageOverlayClient.h in Headers */,
     26715                                A14BB0A01F9813B800605A35 /* MockPayment.h in Headers */,
     26716                                A146D3211F99CB1A00D29196 /* MockPaymentAddress.h in Headers */,
     26717                                A146D3251F99D69800D29196 /* MockPaymentContact.h in Headers */,
    2668526718                                A1AFEDE61F8BFF6D0087013F /* MockPaymentCoordinator.h in Headers */,
    2668626719                                A140618C1E2ECA0A0032B34E /* MockPreviewLoaderClient.h in Headers */,
     
    3089930932                                A19AEA221AAA808A00B52B25 /* JSMockContentFilterSettings.cpp in Sources */,
    3090030933                                2D4150DE1C1F868C000A3BA2 /* JSMockPageOverlay.cpp in Sources */,
     30934                                A146D3221F99D0EC00D29196 /* JSMockPaymentAddress.cpp in Sources */,
     30935                                A146D31A1F99BCF800D29196 /* JSMockPaymentCoordinator.cpp in Sources */,
    3090130936                                EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */,
    3090230937                                CDC26B40160A8CC60026757B /* LegacyMockCDM.cpp in Sources */,
     
    3220832243                                A8FA6E5E0E4CFDED00D5CF49 /* Pattern.cpp in Sources */,
    3220932244                                A80A38FE0E50CC8200A25EBC /* PatternCG.cpp in Sources */,
     32245                                A1CFE0321F9E71290065C345 /* PaymentAddress.cpp in Sources */,
    3221032246                                1A8A646C1D19FF8700D0E00F /* PaymentCocoa.mm in Sources */,
    3221132247                                1A8A646D1D19FF8700D0E00F /* PaymentContactCocoa.mm in Sources */,
  • trunk/Source/WebCore/testing/Internals.cpp

    r223839 r223855  
    514514
    515515#if ENABLE(APPLE_PAY)
    516     if (auto frame = document.frame())
    517         frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*new MockPaymentCoordinator(frame->mainFrame())));
     516    auto* frame = document.frame();
     517    if (frame && frame->isMainFrame()) {
     518        m_mockPaymentCoordinator = new MockPaymentCoordinator(frame->mainFrame());
     519        frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*m_mockPaymentCoordinator));
     520    }
    518521#endif
    519522}
     
    42594262}
    42604263
     4264#if ENABLE(APPLE_PAY)
     4265MockPaymentCoordinator& Internals::mockPaymentCoordinator() const
     4266{
     4267    return *m_mockPaymentCoordinator;
     4268}
     4269#endif
     4270
    42614271} // namespace WebCore
  • trunk/Source/WebCore/testing/Internals.h

    r223839 r223855  
    7474class MockContentFilterSettings;
    7575class MockPageOverlay;
     76class MockPaymentCoordinator;
    7677class NodeList;
    7778class Page;
     
    619620
    620621    bool hasServiceWorkerRegisteredForOrigin(const String&);
     622       
     623#if ENABLE(APPLE_PAY)
     624    MockPaymentCoordinator& mockPaymentCoordinator() const;
     625#endif
    621626
    622627    String timelineDescription(AnimationTimeline&);
     
    643648    std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
    644649    RefPtr<CacheStorageConnection> m_cacheStorageConnection;
     650
     651#if ENABLE(APPLE_PAY)
     652    MockPaymentCoordinator* m_mockPaymentCoordinator { nullptr };
     653#endif
    645654};
    646655
  • trunk/Source/WebCore/testing/Internals.idl

    r223839 r223855  
    564564
    565565    [EnabledAtRuntime=WebAnimations] DOMString timelineDescription(AnimationTimeline timeline);
    566 };
     566    [Conditional=APPLE_PAY] readonly attribute MockPaymentCoordinator mockPaymentCoordinator;
     567};
  • trunk/Source/WebCore/testing/MockPayment.h

    r223854 r223855  
    2424 */
    2525
    26 #include "config.h"
    27 #include "PaymentResponse.h"
     26#pragma once
    2827
    29 #if ENABLE(PAYMENT_REQUEST)
     28#if ENABLE(APPLE_PAY)
    3029
    31 #include <wtf/RunLoop.h>
     30#include "ApplePayPayment.h"
     31#include "Payment.h"
    3232
    3333namespace WebCore {
    3434
    35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise)
    36 {
    37     promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
    38 }
     35class MockPayment final : public Payment {
     36public:
     37    explicit MockPayment(ApplePayPayment&& applePayPayment)
     38        : m_applePayPayment { WTFMove(applePayPayment) }
     39    {
     40    }
     41
     42    ApplePayPayment toApplePayPayment() const final { return m_applePayPayment; }
     43
     44private:
     45    ApplePayPayment m_applePayPayment;
     46};
    3947
    4048} // namespace WebCore
    4149
    42 #endif // ENABLE(PAYMENT_REQUEST)
     50#endif // ENABLE(APPLE_PAY)
  • trunk/Source/WebCore/testing/MockPaymentAddress.h

    r223854 r223855  
    2424 */
    2525
    26 #include "config.h"
    27 #include "PaymentResponse.h"
     26#pragma once
    2827
    29 #if ENABLE(PAYMENT_REQUEST)
     28#if ENABLE(APPLE_PAY)
    3029
    31 #include <wtf/RunLoop.h>
     30#include "ApplePayPaymentContact.h"
    3231
    3332namespace WebCore {
    3433
    35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise)
    36 {
    37     promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
    38 }
     34struct MockPaymentAddress : ApplePayPaymentContact {
     35};
    3936
    4037} // namespace WebCore
    4138
    42 #endif // ENABLE(PAYMENT_REQUEST)
     39#endif // ENABLE(APPLE_PAY)
  • trunk/Source/WebCore/testing/MockPaymentAddress.idl

    r223854 r223855  
    2424 */
    2525
    26 #include "config.h"
    27 #include "PaymentResponse.h"
    28 
    29 #if ENABLE(PAYMENT_REQUEST)
    30 
    31 #include <wtf/RunLoop.h>
    32 
    33 namespace WebCore {
    34 
    35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise)
    36 {
    37     promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
    38 }
    39 
    40 } // namespace WebCore
    41 
    42 #endif // ENABLE(PAYMENT_REQUEST)
     26[
     27    Conditional=APPLE_PAY
     28] dictionary MockPaymentAddress {
     29    DOMString countryCode;
     30    FrozenArray<DOMString> addressLines;
     31    DOMString administrativeArea;
     32    DOMString locality;
     33    DOMString subLocality;
     34    DOMString postalCode;
     35    DOMString localizedName;
     36    DOMString phoneNumber;
     37    DOMString emailAddress;
     38};
  • trunk/Source/WebCore/testing/MockPaymentContact.h

    r223854 r223855  
    2424 */
    2525
    26 #include "config.h"
    27 #include "PaymentResponse.h"
     26#pragma once
    2827
    29 #if ENABLE(PAYMENT_REQUEST)
     28#if ENABLE(APPLE_PAY)
    3029
    31 #include <wtf/RunLoop.h>
     30#include "ApplePayPaymentContact.h"
     31#include "PaymentContact.h"
    3232
    3333namespace WebCore {
    3434
    35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise)
    36 {
    37     promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
    38 }
     35class MockPaymentContact final : public PaymentContact {
     36public:
     37    explicit MockPaymentContact(ApplePayPaymentContact&& applePayPaymentContact)
     38        : m_applePayPaymentContact { WTFMove(applePayPaymentContact) }
     39    {
     40    }
     41
     42    ApplePayPaymentContact toApplePayPaymentContact() const final { return m_applePayPaymentContact; }
     43
     44private:
     45    ApplePayPaymentContact m_applePayPaymentContact;
     46};
    3947
    4048} // namespace WebCore
    4149
    42 #endif // ENABLE(PAYMENT_REQUEST)
     50#endif // ENABLE(APPLE_PAY)
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp

    r223193 r223855  
    3030
    3131#include "MainFrame.h"
     32#include "MockPayment.h"
     33#include "MockPaymentContact.h"
    3234#include "PaymentCoordinator.h"
    3335#include "URL.h"
     
    5961}
    6062
    61 void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, WTF::Function<void(bool)>&& completionHandler)
     63void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, Function<void(bool)>&& completionHandler)
    6264{
    6365    RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() {
     
    6668}
    6769
    68 void MockPaymentCoordinator::openPaymentSetup(const String&, const String&, WTF::Function<void(bool)>&& completionHandler)
     70void MockPaymentCoordinator::openPaymentSetup(const String&, const String&, Function<void(bool)>&& completionHandler)
    6971{
    7072    RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() {
     
    7375}
    7476
     77static uint64_t showCount;
     78static uint64_t hideCount;
     79
     80static void dispatchIfShowing(Function<void()>&& function)
     81{
     82    ASSERT(showCount > hideCount);
     83    RunLoop::main().dispatch([currentShowCount = showCount, function = WTFMove(function)]() {
     84        if (showCount > hideCount && showCount == currentShowCount)
     85            function();
     86    });
     87}
     88
    7589bool MockPaymentCoordinator::showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest&)
    7690{
    77     RunLoop::main().dispatch([mainFrame = makeRef(m_mainFrame)]() {
     91    ASSERT(showCount == hideCount);
     92    ++showCount;
     93    dispatchIfShowing([mainFrame = makeRef(m_mainFrame)]() {
    7894        mainFrame->paymentCoordinator().validateMerchant({ URL(), ASCIILiteral("https://webkit.org/") });
    7995    });
     
    8197}
    8298
     99void MockPaymentCoordinator::completeMerchantValidation(const PaymentMerchantSession&)
     100{
     101    dispatchIfShowing([mainFrame = makeRef(m_mainFrame), shippingAddress = m_shippingAddress]() {
     102        ApplePayPaymentContact contact = shippingAddress;
     103        mainFrame->paymentCoordinator().didSelectShippingContact(MockPaymentContact { WTFMove(contact) });
     104
     105        ApplePayPayment payment;
     106        payment.shippingContact = shippingAddress;
     107        mainFrame->paymentCoordinator().didAuthorizePayment(MockPayment { WTFMove(payment) });
     108    });
     109}
     110
     111void MockPaymentCoordinator::completePaymentSession(std::optional<PaymentAuthorizationResult>&&)
     112{
     113    ++hideCount;
     114    ASSERT(showCount == hideCount);
     115}
     116
     117void MockPaymentCoordinator::abortPaymentSession()
     118{
     119    ++hideCount;
     120    ASSERT(showCount == hideCount);
     121}
     122
     123void MockPaymentCoordinator::cancelPaymentSession()
     124{
     125    ++hideCount;
     126    ASSERT(showCount == hideCount);
     127}
     128
    83129void MockPaymentCoordinator::paymentCoordinatorDestroyed()
    84130{
     131    ASSERT(showCount == hideCount);
    85132    delete this;
    86133}
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.h

    r223193 r223855  
    2828#if ENABLE(APPLE_PAY)
    2929
     30#include "MockPaymentAddress.h"
    3031#include "PaymentCoordinatorClient.h"
    3132
     
    3839    explicit MockPaymentCoordinator(MainFrame&);
    3940
     41    void setShippingAddress(MockPaymentAddress&& shippingAddress) { m_shippingAddress = WTFMove(shippingAddress); }
     42
     43    void ref() const { }
     44    void deref() const { }
     45
    4046private:
    4147    bool supportsVersion(unsigned) final;
     
    4450    void openPaymentSetup(const String&, const String&, WTF::Function<void(bool)>&&);
    4551    bool showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest&) final;
    46     void completeMerchantValidation(const PaymentMerchantSession&) final { }
     52    void completeMerchantValidation(const PaymentMerchantSession&) final;
    4753    void completeShippingMethodSelection(std::optional<ShippingMethodUpdate>&&) final { }
    4854    void completeShippingContactSelection(std::optional<ShippingContactUpdate>&&) final { }
    4955    void completePaymentMethodSelection(std::optional<PaymentMethodUpdate>&&) final { }
    50     void completePaymentSession(std::optional<PaymentAuthorizationResult>&&) final { }
    51     void abortPaymentSession() final { }
    52     void cancelPaymentSession() final { }
     56    void completePaymentSession(std::optional<PaymentAuthorizationResult>&&) final;
     57    void abortPaymentSession() final;
     58    void cancelPaymentSession() final;
    5359    void paymentCoordinatorDestroyed() final;
    5460
    5561    MainFrame& m_mainFrame;
     62    MockPaymentAddress m_shippingAddress;
    5663};
    5764
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.idl

    r223854 r223855  
    2424 */
    2525
    26 #include "config.h"
    27 #include "PaymentResponse.h"
    28 
    29 #if ENABLE(PAYMENT_REQUEST)
    30 
    31 #include <wtf/RunLoop.h>
    32 
    33 namespace WebCore {
    34 
    35 void PaymentResponse::complete(std::optional<PaymentComplete>&&, DOMPromiseDeferred<void>&& promise)
    36 {
    37     promise.reject(Exception { NotSupportedError, ASCIILiteral("Not implemented") });
    38 }
    39 
    40 } // namespace WebCore
    41 
    42 #endif // ENABLE(PAYMENT_REQUEST)
     26[
     27    Conditional=APPLE_PAY,
     28    NoInterfaceObject,
     29] interface MockPaymentCoordinator {
     30    void setShippingAddress(MockPaymentAddress shippingAddress);
     31};
Note: See TracChangeset for help on using the changeset viewer.