Changeset 223193 in webkit


Ignore:
Timestamp:
Oct 11, 2017 10:48:26 AM (7 years ago)
Author:
aestes@apple.com
Message:

[Payment Request] Implement Apple Pay merchant validation
https://bugs.webkit.org/show_bug.cgi?id=178159

Reviewed by Brady Eidson.

Source/WebCore:

When ApplePayPaymentHandler::validateMerchant() is called, dispatch the
applepayvalidatemerchant event to the PaymentRequest object.

The event object is an ApplePayMerchantValidationEvent, on which the client calls complete()
with a merchant session.

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

  • DerivedSources.make:
  • Modules/applepay/ApplePayValidateMerchantEvent.h:
  • Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.cpp: Added.

(WebCore::ApplePayMerchantValidationEvent::create):
(WebCore::ApplePayMerchantValidationEvent::ApplePayMerchantValidationEvent):
(WebCore::ApplePayMerchantValidationEvent::complete):
(WebCore::ApplePayMerchantValidationEvent::eventInterface const):

  • Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.h: Added.
  • Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.idl: Added.
  • Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:

(WebCore::ApplePayPaymentHandler::validateMerchant):

  • Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
  • Modules/paymentrequest/PaymentRequest.idl:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/EventNames.h:
  • dom/EventNames.in:
  • testing/Internals.cpp:

(WebCore::Internals::Internals):

  • testing/MockPaymentCoordinator.cpp:

(WebCore::MockPaymentCoordinator::MockPaymentCoordinator):
(WebCore::MockPaymentCoordinator::showPaymentUI):

  • testing/MockPaymentCoordinator.h:

LayoutTests:

  • http/tests/ssl/applepay/ApplePayMerchantValidationEvent.https-expected.txt: Added.
  • http/tests/ssl/applepay/ApplePayMerchantValidationEvent.https.html: Added.
Location:
trunk
Files:
3 added
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223191 r223193  
     12017-10-11  Andy Estes  <aestes@apple.com>
     2
     3        [Payment Request] Implement Apple Pay merchant validation
     4        https://bugs.webkit.org/show_bug.cgi?id=178159
     5
     6        Reviewed by Brady Eidson.
     7
     8        * http/tests/ssl/applepay/ApplePayMerchantValidationEvent.https-expected.txt: Added.
     9        * http/tests/ssl/applepay/ApplePayMerchantValidationEvent.https.html: Added.
     10
    1112017-10-11  Brady Eidson  <beidson@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r223192 r223193  
     12017-10-11  Andy Estes  <aestes@apple.com>
     2
     3        [Payment Request] Implement Apple Pay merchant validation
     4        https://bugs.webkit.org/show_bug.cgi?id=178159
     5
     6        Reviewed by Brady Eidson.
     7
     8        When ApplePayPaymentHandler::validateMerchant() is called, dispatch the
     9        applepayvalidatemerchant event to the PaymentRequest object.
     10
     11        The event object is an ApplePayMerchantValidationEvent, on which the client calls complete()
     12        with a merchant session.
     13
     14        Test: http/tests/ssl/applepay/ApplePayMerchantValidationEvent.https.html
     15
     16        * DerivedSources.make:
     17        * Modules/applepay/ApplePayValidateMerchantEvent.h:
     18        * Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.cpp: Added.
     19        (WebCore::ApplePayMerchantValidationEvent::create):
     20        (WebCore::ApplePayMerchantValidationEvent::ApplePayMerchantValidationEvent):
     21        (WebCore::ApplePayMerchantValidationEvent::complete):
     22        (WebCore::ApplePayMerchantValidationEvent::eventInterface const):
     23        * Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.h: Added.
     24        * Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.idl: Added.
     25        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
     26        (WebCore::ApplePayPaymentHandler::validateMerchant):
     27        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
     28        * Modules/paymentrequest/PaymentRequest.idl:
     29        * WebCore.xcodeproj/project.pbxproj:
     30        * dom/EventNames.h:
     31        * dom/EventNames.in:
     32        * testing/Internals.cpp:
     33        (WebCore::Internals::Internals):
     34        * testing/MockPaymentCoordinator.cpp:
     35        (WebCore::MockPaymentCoordinator::MockPaymentCoordinator):
     36        (WebCore::MockPaymentCoordinator::showPaymentUI):
     37        * testing/MockPaymentCoordinator.h:
     38
    1392017-10-11  Chris Dumez  <cdumez@apple.com>
    240
  • trunk/Source/WebCore/DerivedSources.make

    r222997 r223193  
    108108        $(WebCore)/Modules/applepay/ApplePayShippingMethodUpdate.idl \
    109109    $(WebCore)/Modules/applepay/ApplePayValidateMerchantEvent.idl \
     110    $(WebCore)/Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.idl \
    110111    $(WebCore)/Modules/applepay/paymentrequest/ApplePayRequest.idl \
    111112    $(WebCore)/Modules/beacon/NavigatorBeacon.idl \
  • trunk/Source/WebCore/Modules/applepay/ApplePayValidateMerchantEvent.h

    r202309 r223193  
    3333namespace WebCore {
    3434
    35 class ApplePayValidateMerchantEvent final : public Event {
     35class ApplePayValidateMerchantEvent : public Event {
    3636public:
    3737    static Ref<ApplePayValidateMerchantEvent> create(const AtomicString& type, const URL& validationURL)
     
    4444    const String& validationURL() const { return m_validationURL.string(); }
    4545
    46 private:
     46protected:
    4747    ApplePayValidateMerchantEvent(const AtomicString& type, const URL& validationURL);
    4848
     
    5050    EventInterface eventInterface() const override;
    5151
     52private:
    5253    const URL m_validationURL;
    5354};
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.h

    r223192 r223193  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
    28 #if ENABLE(APPLE_PAY)
     28#if ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
    2929
    30 #include "Event.h"
    31 #include "URL.h"
     30#include "ApplePayValidateMerchantEvent.h"
     31
     32namespace JSC {
     33class JSValue;
     34}
    3235
    3336namespace WebCore {
    3437
    35 class ApplePayValidateMerchantEvent final : public Event {
     38class Document;
     39
     40class ApplePayMerchantValidationEvent final : public ApplePayValidateMerchantEvent {
    3641public:
    37     static Ref<ApplePayValidateMerchantEvent> create(const AtomicString& type, const URL& validationURL)
    38     {
    39         return adoptRef(*new ApplePayValidateMerchantEvent(type, validationURL));
    40     }
    41 
    42     virtual ~ApplePayValidateMerchantEvent();
    43 
    44     const String& validationURL() const { return m_validationURL.string(); }
     42    static Ref<ApplePayMerchantValidationEvent> create(const AtomicString&, const URL&);
     43    ExceptionOr<void> complete(Document&, JSC::JSValue);
    4544
    4645private:
    47     ApplePayValidateMerchantEvent(const AtomicString& type, const URL& validationURL);
     46    ApplePayMerchantValidationEvent(const AtomicString&, const URL&);
    4847
    49     // Event.
    50     EventInterface eventInterface() const override;
     48    // Event
     49    EventInterface eventInterface() const final;
    5150
    52     const URL m_validationURL;
     51    bool m_isCompleted { false };
    5352};
    5453
    55 }
     54} // namespace WebCore
    5655
    57 #endif
     56#endif // ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayMerchantValidationEvent.idl

    r223192 r223193  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #pragma once
    27 
    28 #if ENABLE(APPLE_PAY)
    29 
    30 #include "Event.h"
    31 #include "URL.h"
    32 
    33 namespace WebCore {
    34 
    35 class ApplePayValidateMerchantEvent final : public Event {
    36 public:
    37     static Ref<ApplePayValidateMerchantEvent> create(const AtomicString& type, const URL& validationURL)
    38     {
    39         return adoptRef(*new ApplePayValidateMerchantEvent(type, validationURL));
    40     }
    41 
    42     virtual ~ApplePayValidateMerchantEvent();
    43 
    44     const String& validationURL() const { return m_validationURL.string(); }
    45 
    46 private:
    47     ApplePayValidateMerchantEvent(const AtomicString& type, const URL& validationURL);
    48 
    49     // Event.
    50     EventInterface eventInterface() const override;
    51 
    52     const URL m_validationURL;
     26[
     27    Conditional=APPLE_PAY&PAYMENT_REQUEST,
     28    NoInterfaceObject,
     29] interface ApplePayMerchantValidationEvent : ApplePayValidateMerchantEvent {
     30    [MayThrowException, CallWith=Document] void complete(any merchantSession);
    5331};
    54 
    55 }
    56 
    57 #endif
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp

    r223188 r223193  
    3131#include "ApplePayContactField.h"
    3232#include "ApplePayMerchantCapability.h"
     33#include "ApplePayMerchantValidationEvent.h"
    3334#include "ApplePaySessionPaymentRequest.h"
    3435#include "Document.h"
     36#include "EventNames.h"
    3537#include "JSApplePayRequest.h"
    3638#include "LinkIconCollector.h"
     
    233235}
    234236
     237void ApplePayPaymentHandler::validateMerchant(const URL& validationURL)
     238{
     239    if (validationURL.isValid())
     240        m_paymentRequest->dispatchEvent(ApplePayMerchantValidationEvent::create(eventNames().applepayvalidatemerchantEvent, validationURL).get());
     241}
     242
    235243} // namespace WebCore
    236244
  • trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h

    r223160 r223193  
    5454
    5555    // PaymentSession
    56     void validateMerchant(const URL&) final { }
     56    void validateMerchant(const URL&) final;
    5757    void didAuthorizePayment(const Payment&) final { }
    5858    void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final { }
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl

    r223160 r223193  
    4343
    4444    attribute EventHandler onshippingaddresschange;
     45    attribute EventHandler onshippingoptionchange;
    4546
    46     attribute EventHandler onshippingoptionchange;
     47    [Conditional=APPLE_PAY] attribute EventHandler onapplepayvalidatemerchant;
    4748};
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r223192 r223193  
    45414541                A1F76B5B1F44D3B20014C318 /* PaymentComplete.h in Headers */ = {isa = PBXBuildFile; fileRef = A1F76B581F44D3B20014C318 /* PaymentComplete.h */; };
    45424542                A1F78D0C1C25424C00245446 /* ResourceResponseCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1F78D0B1C25422C00245446 /* ResourceResponseCocoa.mm */; };
     4543                A1F929691F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A1F929661F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.h */; };
     4544                A1F9296A1F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1F929671F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.cpp */; };
     4545                A1F9296F1F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1F9296D1F8D9F5A00523AF3 /* JSApplePayMerchantValidationEvent.cpp */; };
     4546                A1F929701F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = A1F9296E1F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.h */; };
    45434547                A2B9217316C5CC420041DCD9 /* IntRectExtent.h in Headers */ = {isa = PBXBuildFile; fileRef = A2B9217216C5CC420041DCD9 /* IntRectExtent.h */; settings = {ATTRIBUTES = (Private, ); }; };
    45444548                A31C4E4D16E02AA6002F7957 /* OESTextureHalfFloat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A31C4E4C16E02AA6002F7957 /* OESTextureHalfFloat.cpp */; };
     
    1305113055                A1F76B5A1F44D3B20014C318 /* PaymentComplete.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PaymentComplete.idl; sourceTree = "<group>"; };
    1305213056                A1F78D0B1C25422C00245446 /* ResourceResponseCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceResponseCocoa.mm; sourceTree = "<group>"; };
     13057                A1F929661F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplePayMerchantValidationEvent.h; sourceTree = "<group>"; };
     13058                A1F929671F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ApplePayMerchantValidationEvent.cpp; sourceTree = "<group>"; };
     13059                A1F929681F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = ApplePayMerchantValidationEvent.idl; sourceTree = "<group>"; };
     13060                A1F9296D1F8D9F5A00523AF3 /* JSApplePayMerchantValidationEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSApplePayMerchantValidationEvent.cpp; sourceTree = "<group>"; };
     13061                A1F9296E1F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSApplePayMerchantValidationEvent.h; sourceTree = "<group>"; };
    1305313062                A208E222A56A0C7575F2A72E /* RenderMathMLMenclose.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMathMLMenclose.h; sourceTree = "<group>"; };
    1305413063                A2B9217216C5CC420041DCD9 /* IntRectExtent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntRectExtent.h; sourceTree = "<group>"; };
     
    1744817457                                A1DF5A891F7EC0000058A477 /* JSApplePayMerchantCapability.cpp */,
    1744917458                                A1DF5A8A1F7EC0000058A477 /* JSApplePayMerchantCapability.h */,
     17459                                A1F9296D1F8D9F5A00523AF3 /* JSApplePayMerchantValidationEvent.cpp */,
     17460                                A1F9296E1F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.h */,
    1745017461                                7C65231D1E018B5A00677F22 /* JSApplePayPayment.cpp */,
    1745117462                                7C65230A1E00DBB400677F22 /* JSApplePayPayment.h */,
     
    2174321754                        isa = PBXGroup;
    2174421755                        children = (
     21756                                A1F929671F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.cpp */,
     21757                                A1F929661F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.h */,
     21758                                A1F929681F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.idl */,
    2174521759                                A1DF5AA11F7EE1130058A477 /* ApplePayPaymentHandler.cpp */,
    2174621760                                A1DF5AA01F7EE1130058A477 /* ApplePayPaymentHandler.h */,
     
    2723527249                                7C6579E31E00827000E3A27A /* ApplePayLineItem.h in Headers */,
    2723627250                                A1DF5A861F7EBDF20058A477 /* ApplePayMerchantCapability.h in Headers */,
     27251                                A1F929691F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.h in Headers */,
    2723727252                                7C6523011E00D03400677F22 /* ApplePayPayment.h in Headers */,
    2723827253                                1A8A64521D19FCFB00D0E00F /* ApplePayPaymentAuthorizedEvent.h in Headers */,
     
    2850028515                                7C6579F01E00856600E3A27A /* JSApplePayLineItem.h in Headers */,
    2850128516                                A1DF5A8E1F7EC0020058A477 /* JSApplePayMerchantCapability.h in Headers */,
     28517                                A1F929701F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.h in Headers */,
    2850228518                                7C6523141E00DBB400677F22 /* JSApplePayPayment.h in Headers */,
    2850328519                                1AE96A8B1D1A0DDD00B86768 /* JSApplePayPaymentAuthorizedEvent.h in Headers */,
     
    3143631452                                1ADFDFE01E71D8EE008F5D34 /* ApplePayError.cpp in Sources */,
    3143731453                                A1DF5AA91F8070D40058A477 /* ApplePayMerchantCapability.cpp in Sources */,
     31454                                A1F9296A1F8D9CDB00523AF3 /* ApplePayMerchantValidationEvent.cpp in Sources */,
    3143831455                                1A8A64511D19FCFB00D0E00F /* ApplePayPaymentAuthorizedEvent.cpp in Sources */,
    3143931456                                A1DF5AA31F7EE1130058A477 /* ApplePayPaymentHandler.cpp in Sources */,
     
    3253732554                                7C6579EF1E00856600E3A27A /* JSApplePayLineItem.cpp in Sources */,
    3253832555                                A1DF5A8D1F7EC0020058A477 /* JSApplePayMerchantCapability.cpp in Sources */,
     32556                                A1F9296F1F8D9F5B00523AF3 /* JSApplePayMerchantValidationEvent.cpp in Sources */,
    3253932557                                7C65231E1E018B5A00677F22 /* JSApplePayPayment.cpp in Sources */,
    3254032558                                1ADFDFF01E71E4AC008F5D34 /* JSApplePayPaymentAuthorizationResult.cpp in Sources */,
  • trunk/Source/WebCore/dom/EventNames.h

    r221966 r223193  
    5454    macro(animationiteration) \
    5555    macro(animationstart) \
     56    macro(applepayvalidatemerchant) \
    5657    macro(audioend) \
    5758    macro(audioprocess) \
  • trunk/Source/WebCore/dom/EventNames.in

    r221966 r223193  
    3636WheelEvent
    3737XMLHttpRequestProgressEvent
     38ApplePayMerchantValidationEvent conditional=APPLE_PAY
    3839ApplePayPaymentAuthorizedEvent conditional=APPLE_PAY
    3940ApplePayPaymentMethodSelectedEvent conditional=APPLE_PAY
  • trunk/Source/WebCore/testing/Internals.cpp

    r223109 r223193  
    509509#if ENABLE(APPLE_PAY)
    510510    if (auto frame = document.frame())
    511         frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*new MockPaymentCoordinator()));
     511        frame->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*new MockPaymentCoordinator(frame->mainFrame())));
    512512#endif
    513513}
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp

    r223076 r223193  
    2929#if ENABLE(APPLE_PAY)
    3030
     31#include "MainFrame.h"
     32#include "PaymentCoordinator.h"
     33#include "URL.h"
    3134#include <wtf/RunLoop.h>
    3235
    3336namespace WebCore {
     37
     38MockPaymentCoordinator::MockPaymentCoordinator(MainFrame& mainFrame)
     39    : m_mainFrame { mainFrame }
     40{
     41}
    3442
    3543bool MockPaymentCoordinator::supportsVersion(unsigned version)
     
    6775bool MockPaymentCoordinator::showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest&)
    6876{
     77    RunLoop::main().dispatch([mainFrame = makeRef(m_mainFrame)]() {
     78        mainFrame->paymentCoordinator().validateMerchant({ URL(), ASCIILiteral("https://webkit.org/") });
     79    });
    6980    return true;
    7081}
  • trunk/Source/WebCore/testing/MockPaymentCoordinator.h

    r223076 r223193  
    3131
    3232namespace WebCore {
     33   
     34class MainFrame;
    3335
    3436class MockPaymentCoordinator final : public PaymentCoordinatorClient {
     37public:
     38    explicit MockPaymentCoordinator(MainFrame&);
     39
    3540private:
    3641    bool supportsVersion(unsigned) final;
     
    4752    void cancelPaymentSession() final { }
    4853    void paymentCoordinatorDestroyed() final;
     54
     55    MainFrame& m_mainFrame;
    4956};
    5057
Note: See TracChangeset for help on using the changeset viewer.