Changeset 242616 in webkit


Ignore:
Timestamp:
Mar 7, 2019 3:30:42 PM (5 years ago)
Author:
aestes@apple.com
Message:

[Apple Pay] Untangle PKPaymentAuthorizationViewController from WebPaymentCoordinatorProxy
https://bugs.webkit.org/show_bug.cgi?id=195349
<rdar://problem/48625510>

Reviewed by Alex Christensen.

Source/WebCore/PAL:

Moved soft-linking of PKPaymentErrorDomain from WebPaymentCoordinatorProxy to here and used
a more descriptive platform macro.

  • pal/cocoa/PassKitSoftLink.h:
  • pal/cocoa/PassKitSoftLink.mm:

Source/WebKit:

Introduced PaymentAuthorizationPresenter and WKPaymentAuthorizationDelegate to encapsulate
PKPaymentAuthorizationViewController and its delegate. Taught WebPaymentCoordinatorProxy to
interact with PaymentAuthorizationPresenter rather than PKPAVC directly.

These changes will allow us to swap out PKPaymentAuthorizationViewController with PKPaymentAuthorizationController in a follow-on patch.

  • Platform/cocoa/PaymentAuthorizationPresenter.h: Added. Defined the abstract interface for

payment authorization presenters that use PKPA(V)C.

  • Platform/cocoa/PaymentAuthorizationPresenter.mm: Added.

(WebKit::toPKPaymentAuthorizationStatus): Moved from WebPaymentCoordinatorProxyCocoa.mm.
(WebKit::toPKPaymentErrorCode): Ditto.
(WebKit::toNSError): Ditto.
(WebKit::toNSErrors): Ditto.
(WebKit::toPKShippingMethods): Ditto.
(WebKit::PaymentAuthorizationPresenter::completeMerchantValidation): Added. Implements the
logic previously in WebPaymentCoordinatorProxy::platformCompleteMerchantValidation.
(WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection): Ditto for
WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection.
(WebKit::PaymentAuthorizationPresenter::completePaymentSession): Ditto for
(WebKit::PaymentAuthorizationPresenter::completeShippingContactSelection): Ditto for
WebPaymentCoordinatorProxy::platformCompletePaymentSession.
(WebKit::PaymentAuthorizationPresenter::completeShippingMethodSelection): Ditto for
WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection.

  • Platform/cocoa/PaymentAuthorizationViewController.h: Added. Defined a subclass of PaymentAuthorizationPresenter for PKPaymentAuthorizationViewController.
  • Platform/cocoa/PaymentAuthorizationViewController.mm: Added.

(-[WKPaymentAuthorizationViewControllerDelegate initWithPresenter:]): Added a PKPAVC
delegate that's a subclass of WKPaymentAuthorizationDelegate.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewControllerDidFinish:]):
Called -[WKPaymentAuthorizationDelegate _didFinish].
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didAuthorizePayment:handler:]): Called
-[WKPaymentAuthorizationDelegate _didAuthorizePayment:completion:].
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingMethod:handler:]): Called
-[WKPaymentAuthorizationDelegate _didSelectShippingMethod:completion:].
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingContact:handler:]): Called
-[WKPaymentAuthorizationDelegate _didSelectShippingContact:completion:].
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectPaymentMethod:handler:]): Called
-[WKPaymentAuthorizationDelegate _didSelectPaymentMethod:completion:].
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:willFinishWithError:]):
Called -[WKPaymentAuthorizationDelegate _willFinishWithError:].
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didRequestMerchantSession:]): Called
-[WKPaymentAuthorizationDelegate _didRequestMerchantSession:].

  • Platform/cocoa/WKPaymentAuthorizationDelegate.h: Added.
  • Platform/cocoa/WKPaymentAuthorizationDelegate.mm: Added.

(-[WKPaymentAuthorizationDelegate summaryItems]): Added a summaryItems getter.
(-[WKPaymentAuthorizationDelegate shippingMethods]): Ditto for shippingMethods.
(-[WKPaymentAuthorizationDelegate completeMerchantValidation:error:]): Called
_didRequestMerchantSessionCompletion then set it to nil.
(-[WKPaymentAuthorizationDelegate completePaymentMethodSelection:]): Ditto for
_didSelectPaymentMethodCompletion.
(-[WKPaymentAuthorizationDelegate completePaymentSession:errors:didReachFinalState:]): Ditto
for _didAuthorizePaymentCompletion.
(-[WKPaymentAuthorizationDelegate completeShippingContactSelection:summaryItems:shippingMethods:errors:]):
Ditto for _didSelectShippingContactCompletion.
(-[WKPaymentAuthorizationDelegate completeShippingMethodSelection:]): Ditto for
_didSelectShippingMethodCompletion.
(-[WKPaymentAuthorizationDelegate invalidate]): If there's an outstanding authorization
callback, called -completePaymentSession:errors:didReachFinalState: with a state of
PKPaymentAuthorizationStatusFailure.
(-[WKPaymentAuthorizationDelegate _initWithPresenter:]):
(-[WKPaymentAuthorizationDelegate _didAuthorizePayment:completion:]): Added. Implements the
logic previously in WKPaymentAuthorizationViewControllerDelegate.
(-[WKPaymentAuthorizationDelegate _didFinish]): Ditto.
(-[WKPaymentAuthorizationDelegate _didRequestMerchantSession:]): Ditto.
(-[WKPaymentAuthorizationDelegate _didSelectPaymentMethod:completion:]): Ditto.
(-[WKPaymentAuthorizationDelegate _didSelectShippingContact:completion:]): Ditto.
(toShippingMethod): Moved from WebPaymentCoordinatorProxyCocoa.mm.
(-[WKPaymentAuthorizationDelegate _didSelectShippingMethod:completion:]): Added. Implements
the logic previously in WKPaymentAuthorizationViewControllerDelegate.
(-[WKPaymentAuthorizationDelegate _willFinishWithError:]): Ditto.

  • Shared/ApplePay/WebPaymentCoordinatorProxy.cpp:

(WebKit::WebPaymentCoordinatorProxy::presenterWillValidateMerchant): To conform to
PaymentAuthorizationPresenter::Client, renamed from validateMerchant.
(WebKit::WebPaymentCoordinatorProxy::presenterDidAuthorizePayment): Renamed from
didAuthorizePayment.
(WebKit::WebPaymentCoordinatorProxy::presenterDidFinish): Moved logic here that previously
existed in WKPaymentAuthorizationViewControllerDelegate.
(WebKit::WebPaymentCoordinatorProxy::presenterDidSelectShippingMethod): Renamed from
didSelectShippingMethod.
(WebKit::WebPaymentCoordinatorProxy::presenterDidSelectShippingContact): Renamed from
didSelectShippingContact.
(WebKit::WebPaymentCoordinatorProxy::presenterDidSelectPaymentMethod): Renamed from
didSelectPaymentMethod.
(WebKit::WebPaymentCoordinatorProxy::validateMerchant): Renamed to
presenterWillValidateMerchant.
(WebKit::WebPaymentCoordinatorProxy::didAuthorizePayment): Renamed to
presenterDidAuthorizePayment.
(WebKit::WebPaymentCoordinatorProxy::didSelectShippingMethod): Renamed to
presenterDidSelectShippingMethod.
(WebKit::WebPaymentCoordinatorProxy::didSelectShippingContact): Renamed to
presenterDidSelectShippingContact.
(WebKit::WebPaymentCoordinatorProxy::didSelectPaymentMethod): Renamed to
didSelectPaymentMethod.

  • Shared/ApplePay/WebPaymentCoordinatorProxy.h: Changed WebPaymentCoordinatorProxy to

subclass PaymentAuthorizationPresenter::Client.

  • Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h: Removed WKPaymentAuthorizationViewControllerDelegate interface and declared some helper functions

needed by PaymentAuthorizationPresenter.

  • Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:

(WebKit::toPKPaymentSummaryItemType): Removed static keyword.
(WebKit::toDecimalNumber): Ditto.
(WebKit::toPKPaymentSummaryItem): Ditto.
(WebKit::toPKPaymentSummaryItems): Ditto.
(WebKit::toPKShippingMethod): Ditto.
(WebKit::WebPaymentCoordinatorProxy::platformPaymentRequest): Changed to call
m_authorizationPresenter.
(WebKit::WebPaymentCoordinatorProxy::platformCompletePaymentSession): Ditto.
(WebKit::WebPaymentCoordinatorProxy::platformCompleteMerchantValidation): Ditto.
(WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection): Ditto.
(WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection): Ditto.
(WebKit::WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection): Ditto.
(-[WKPaymentAuthorizationViewControllerDelegate initWithPaymentCoordinatorProxy:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate invalidate]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:willFinishWithError:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didRequestMerchantSession:]): Deleted.
(toShippingMethod): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didAuthorizePayment:handler:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectPaymentMethod:handler:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingMethod:handler:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingContact:handler:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didAuthorizePayment:completion:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingMethod:completion:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectPaymentMethod:completion:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingContact:completion:]): Deleted.
(-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewControllerDidFinish:]): Deleted.
(WebKit::toPKPaymentAuthorizationStatus): Moved to PaymentAuthorizationPresenter.mm.
(WebKit::toPKPaymentErrorCode): Ditto.
(WebKit::toNSError): Ditto.
(WebKit::toNSErrors): Ditto.

  • Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm:

(WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): Changed to present a
PaymentAuthorizationPresenter rather than a PKPAVC.
(WebKit::WebPaymentCoordinatorProxy::hidePaymentUI): Changed to dismiss a
PaymentAuthorizationPresenter rather than a PKPAVC.

  • Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm:

(WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): Ditto.
(WebKit::WebPaymentCoordinatorProxy::hidePaymentUI): Ditto.

  • SourcesCocoa.txt:
  • UIProcess/WebPageProxy.h:
  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::paymentCoordinatorAuthorizationPresenter): Added. Returns a new
PaymentAuthorizationViewController.

  • WebKit.xcodeproj/project.pbxproj:
Location:
trunk/Source
Files:
6 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/PAL/ChangeLog

    r242368 r242616  
     12019-03-07  Andy Estes  <aestes@apple.com>
     2
     3        [Apple Pay] Untangle PKPaymentAuthorizationViewController from WebPaymentCoordinatorProxy
     4        https://bugs.webkit.org/show_bug.cgi?id=195349
     5        <rdar://problem/48625510>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Moved soft-linking of PKPaymentErrorDomain from WebPaymentCoordinatorProxy to here and used
     10        a more descriptive platform macro.
     11
     12        * pal/cocoa/PassKitSoftLink.h:
     13        * pal/cocoa/PassKitSoftLink.mm:
     14
    1152019-03-01  Conrad Shultz  <conrad_shultz@apple.com>
    216
  • trunk/Source/WebCore/PAL/pal/cocoa/PassKitSoftLink.h

    r238470 r242616  
    4646SOFT_LINK_FUNCTION_FOR_HEADER(PAL, PassKit, PKDrawApplePayButton, void, (CGContextRef context, CGRect drawRect, CGFloat scale, PKPaymentButtonType type, PKPaymentButtonStyle style, NSString *languageCode), (context, drawRect, scale, type, style, languageCode))
    4747
    48 #if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
     48#if HAVE(PASSKIT_GRANULAR_ERRORS)
    4949SOFT_LINK_CLASS_FOR_HEADER(PAL, PKPaymentAuthorizationResult)
    5050SOFT_LINK_CLASS_FOR_HEADER(PAL, PKPaymentRequestPaymentMethodUpdate)
     
    5858SOFT_LINK_CONSTANT_FOR_HEADER(PAL, PassKit, PKContactFieldPostalAddress, PKContactField)
    5959SOFT_LINK_CONSTANT_FOR_HEADER(PAL, PassKit, PKPaymentErrorContactFieldUserInfoKey, PKPaymentErrorKey)
     60SOFT_LINK_CONSTANT_FOR_HEADER(PAL, PassKit, PKPaymentErrorDomain, NSString *)
    6061SOFT_LINK_CONSTANT_FOR_HEADER(PAL, PassKit, PKPaymentErrorPostalAddressUserInfoKey, PKPaymentErrorKey)
    6162
  • trunk/Source/WebCore/PAL/pal/cocoa/PassKitSoftLink.mm

    r238434 r242616  
    5050SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, PassKit, PKDrawApplePayButton, void, (CGContextRef context, CGRect drawRect, CGFloat scale, PKPaymentButtonType type, PKPaymentButtonStyle style, NSString *languageCode), (context, drawRect, scale, type, style, languageCode))
    5151
    52 #if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
     52#if HAVE(PASSKIT_GRANULAR_ERRORS)
    5353SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKPaymentAuthorizationResult, PAL_EXPORT)
    5454SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKPaymentRequestPaymentMethodUpdate, PAL_EXPORT)
     
    6262SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKContactFieldPostalAddress, PKContactField, PAL_EXPORT)
    6363SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKPaymentErrorContactFieldUserInfoKey, PKPaymentErrorKey, PAL_EXPORT)
     64SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKPaymentErrorDomain, NSString *, PAL_EXPORT)
    6465SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, PassKit, PKPaymentErrorPostalAddressUserInfoKey, PKPaymentErrorKey, PAL_EXPORT)
    6566
  • trunk/Source/WebKit/ChangeLog

    r242611 r242616  
     12019-03-07  Andy Estes  <aestes@apple.com>
     2
     3        [Apple Pay] Untangle PKPaymentAuthorizationViewController from WebPaymentCoordinatorProxy
     4        https://bugs.webkit.org/show_bug.cgi?id=195349
     5        <rdar://problem/48625510>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Introduced PaymentAuthorizationPresenter and WKPaymentAuthorizationDelegate to encapsulate
     10        PKPaymentAuthorizationViewController and its delegate. Taught WebPaymentCoordinatorProxy to
     11        interact with PaymentAuthorizationPresenter rather than PKPAVC directly.
     12
     13        These changes will allow us to swap out PKPaymentAuthorizationViewController with PKPaymentAuthorizationController in a follow-on patch.
     14
     15        * Platform/cocoa/PaymentAuthorizationPresenter.h: Added. Defined the abstract interface for
     16        payment authorization presenters that use PKPA(V)C.
     17        * Platform/cocoa/PaymentAuthorizationPresenter.mm: Added.
     18        (WebKit::toPKPaymentAuthorizationStatus): Moved from WebPaymentCoordinatorProxyCocoa.mm.
     19        (WebKit::toPKPaymentErrorCode): Ditto.
     20        (WebKit::toNSError): Ditto.
     21        (WebKit::toNSErrors): Ditto.
     22        (WebKit::toPKShippingMethods): Ditto.
     23        (WebKit::PaymentAuthorizationPresenter::completeMerchantValidation): Added. Implements the
     24        logic previously in WebPaymentCoordinatorProxy::platformCompleteMerchantValidation.
     25        (WebKit::PaymentAuthorizationPresenter::completePaymentMethodSelection): Ditto for
     26        WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection.
     27        (WebKit::PaymentAuthorizationPresenter::completePaymentSession): Ditto for
     28        (WebKit::PaymentAuthorizationPresenter::completeShippingContactSelection): Ditto for
     29        WebPaymentCoordinatorProxy::platformCompletePaymentSession.
     30        (WebKit::PaymentAuthorizationPresenter::completeShippingMethodSelection): Ditto for
     31        WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection.
     32        * Platform/cocoa/PaymentAuthorizationViewController.h: Added. Defined a subclass of PaymentAuthorizationPresenter for PKPaymentAuthorizationViewController.
     33        * Platform/cocoa/PaymentAuthorizationViewController.mm: Added.
     34        (-[WKPaymentAuthorizationViewControllerDelegate initWithPresenter:]): Added a PKPAVC
     35        delegate that's a subclass of WKPaymentAuthorizationDelegate.
     36        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewControllerDidFinish:]):
     37        Called -[WKPaymentAuthorizationDelegate _didFinish].
     38        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didAuthorizePayment:handler:]): Called
     39        -[WKPaymentAuthorizationDelegate _didAuthorizePayment:completion:].
     40        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingMethod:handler:]): Called
     41        -[WKPaymentAuthorizationDelegate _didSelectShippingMethod:completion:].
     42        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingContact:handler:]): Called
     43        -[WKPaymentAuthorizationDelegate _didSelectShippingContact:completion:].
     44        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectPaymentMethod:handler:]): Called
     45        -[WKPaymentAuthorizationDelegate _didSelectPaymentMethod:completion:].
     46        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:willFinishWithError:]):
     47        Called -[WKPaymentAuthorizationDelegate _willFinishWithError:].
     48        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didRequestMerchantSession:]): Called
     49        -[WKPaymentAuthorizationDelegate _didRequestMerchantSession:].
     50        * Platform/cocoa/WKPaymentAuthorizationDelegate.h: Added.
     51        * Platform/cocoa/WKPaymentAuthorizationDelegate.mm: Added.
     52        (-[WKPaymentAuthorizationDelegate summaryItems]): Added a summaryItems getter.
     53        (-[WKPaymentAuthorizationDelegate shippingMethods]): Ditto for shippingMethods.
     54        (-[WKPaymentAuthorizationDelegate completeMerchantValidation:error:]): Called
     55        _didRequestMerchantSessionCompletion then set it to nil.
     56        (-[WKPaymentAuthorizationDelegate completePaymentMethodSelection:]): Ditto for
     57        _didSelectPaymentMethodCompletion.
     58        (-[WKPaymentAuthorizationDelegate completePaymentSession:errors:didReachFinalState:]): Ditto
     59        for _didAuthorizePaymentCompletion.
     60        (-[WKPaymentAuthorizationDelegate completeShippingContactSelection:summaryItems:shippingMethods:errors:]):
     61        Ditto for _didSelectShippingContactCompletion.
     62        (-[WKPaymentAuthorizationDelegate completeShippingMethodSelection:]): Ditto for
     63        _didSelectShippingMethodCompletion.
     64        (-[WKPaymentAuthorizationDelegate invalidate]): If there's an outstanding authorization
     65        callback, called -completePaymentSession:errors:didReachFinalState: with a state of
     66        PKPaymentAuthorizationStatusFailure.
     67        (-[WKPaymentAuthorizationDelegate _initWithPresenter:]):
     68        (-[WKPaymentAuthorizationDelegate _didAuthorizePayment:completion:]): Added. Implements the
     69        logic previously in WKPaymentAuthorizationViewControllerDelegate.
     70        (-[WKPaymentAuthorizationDelegate _didFinish]): Ditto.
     71        (-[WKPaymentAuthorizationDelegate _didRequestMerchantSession:]): Ditto.
     72        (-[WKPaymentAuthorizationDelegate _didSelectPaymentMethod:completion:]): Ditto.
     73        (-[WKPaymentAuthorizationDelegate _didSelectShippingContact:completion:]): Ditto.
     74        (toShippingMethod): Moved from WebPaymentCoordinatorProxyCocoa.mm.
     75        (-[WKPaymentAuthorizationDelegate _didSelectShippingMethod:completion:]): Added. Implements
     76        the logic previously in WKPaymentAuthorizationViewControllerDelegate.
     77        (-[WKPaymentAuthorizationDelegate _willFinishWithError:]): Ditto.
     78        * Shared/ApplePay/WebPaymentCoordinatorProxy.cpp:
     79        (WebKit::WebPaymentCoordinatorProxy::presenterWillValidateMerchant): To conform to
     80        PaymentAuthorizationPresenter::Client, renamed from validateMerchant.
     81        (WebKit::WebPaymentCoordinatorProxy::presenterDidAuthorizePayment): Renamed from
     82        didAuthorizePayment.
     83        (WebKit::WebPaymentCoordinatorProxy::presenterDidFinish): Moved logic here that previously
     84        existed in WKPaymentAuthorizationViewControllerDelegate.
     85        (WebKit::WebPaymentCoordinatorProxy::presenterDidSelectShippingMethod): Renamed from
     86        didSelectShippingMethod.
     87        (WebKit::WebPaymentCoordinatorProxy::presenterDidSelectShippingContact): Renamed from
     88        didSelectShippingContact.
     89        (WebKit::WebPaymentCoordinatorProxy::presenterDidSelectPaymentMethod): Renamed from
     90        didSelectPaymentMethod.
     91        (WebKit::WebPaymentCoordinatorProxy::validateMerchant): Renamed to
     92        presenterWillValidateMerchant.
     93        (WebKit::WebPaymentCoordinatorProxy::didAuthorizePayment): Renamed to
     94        presenterDidAuthorizePayment.
     95        (WebKit::WebPaymentCoordinatorProxy::didSelectShippingMethod): Renamed to
     96        presenterDidSelectShippingMethod.
     97        (WebKit::WebPaymentCoordinatorProxy::didSelectShippingContact): Renamed to
     98        presenterDidSelectShippingContact.
     99        (WebKit::WebPaymentCoordinatorProxy::didSelectPaymentMethod): Renamed to
     100        didSelectPaymentMethod.
     101        * Shared/ApplePay/WebPaymentCoordinatorProxy.h: Changed WebPaymentCoordinatorProxy to
     102        subclass PaymentAuthorizationPresenter::Client.
     103        * Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h: Removed WKPaymentAuthorizationViewControllerDelegate interface and declared some helper functions
     104        needed by PaymentAuthorizationPresenter.
     105        * Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
     106        (WebKit::toPKPaymentSummaryItemType): Removed static keyword.
     107        (WebKit::toDecimalNumber): Ditto.
     108        (WebKit::toPKPaymentSummaryItem): Ditto.
     109        (WebKit::toPKPaymentSummaryItems): Ditto.
     110        (WebKit::toPKShippingMethod): Ditto.
     111        (WebKit::WebPaymentCoordinatorProxy::platformPaymentRequest): Changed to call
     112        m_authorizationPresenter.
     113        (WebKit::WebPaymentCoordinatorProxy::platformCompletePaymentSession): Ditto.
     114        (WebKit::WebPaymentCoordinatorProxy::platformCompleteMerchantValidation): Ditto.
     115        (WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection): Ditto.
     116        (WebKit::WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection): Ditto.
     117        (WebKit::WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection): Ditto.
     118        (-[WKPaymentAuthorizationViewControllerDelegate initWithPaymentCoordinatorProxy:]): Deleted.
     119        (-[WKPaymentAuthorizationViewControllerDelegate invalidate]): Deleted.
     120        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:willFinishWithError:]): Deleted.
     121        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didRequestMerchantSession:]): Deleted.
     122        (toShippingMethod): Deleted.
     123        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didAuthorizePayment:handler:]): Deleted.
     124        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectPaymentMethod:handler:]): Deleted.
     125        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingMethod:handler:]): Deleted.
     126        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingContact:handler:]): Deleted.
     127        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didAuthorizePayment:completion:]): Deleted.
     128        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingMethod:completion:]): Deleted.
     129        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectPaymentMethod:completion:]): Deleted.
     130        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewController:didSelectShippingContact:completion:]): Deleted.
     131        (-[WKPaymentAuthorizationViewControllerDelegate paymentAuthorizationViewControllerDidFinish:]): Deleted.
     132        (WebKit::toPKPaymentAuthorizationStatus): Moved to PaymentAuthorizationPresenter.mm.
     133        (WebKit::toPKPaymentErrorCode): Ditto.
     134        (WebKit::toNSError): Ditto.
     135        (WebKit::toNSErrors): Ditto.
     136        * Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm:
     137        (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): Changed to present a
     138        PaymentAuthorizationPresenter rather than a PKPAVC.
     139        (WebKit::WebPaymentCoordinatorProxy::hidePaymentUI): Changed to dismiss a
     140        PaymentAuthorizationPresenter rather than a PKPAVC.
     141        * Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm:
     142        (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): Ditto.
     143        (WebKit::WebPaymentCoordinatorProxy::hidePaymentUI): Ditto.
     144        * SourcesCocoa.txt:
     145        * UIProcess/WebPageProxy.h:
     146        * UIProcess/ios/WebPageProxyIOS.mm:
     147        (WebKit::WebPageProxy::paymentCoordinatorAuthorizationPresenter): Added. Returns a new
     148        PaymentAuthorizationViewController.
     149        * WebKit.xcodeproj/project.pbxproj:
     150
    11512019-03-07  Chris Dumez  <cdumez@apple.com>
    2152
  • trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.cpp

    r242356 r242616  
    231231}
    232232
    233 void WebPaymentCoordinatorProxy::validateMerchant(const URL& url)
     233void WebPaymentCoordinatorProxy::presenterWillValidateMerchant(PaymentAuthorizationPresenter&, const URL& url)
    234234{
    235235    ASSERT(m_merchantValidationState == MerchantValidationState::Idle);
     
    239239}
    240240
    241 void WebPaymentCoordinatorProxy::didAuthorizePayment(const WebCore::Payment& payment)
     241void WebPaymentCoordinatorProxy::presenterDidAuthorizePayment(PaymentAuthorizationPresenter&, const WebCore::Payment& payment)
    242242{
    243243    m_state = State::Authorized;
     
    245245}
    246246
    247 void WebPaymentCoordinatorProxy::didSelectShippingMethod(const WebCore::ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod)
     247void WebPaymentCoordinatorProxy::presenterDidFinish(PaymentAuthorizationPresenter&, bool didReachFinalState)
     248{
     249    if (!didReachFinalState)
     250        didCancelPaymentSession();
     251    hidePaymentUI();
     252}
     253
     254void WebPaymentCoordinatorProxy::presenterDidSelectShippingMethod(PaymentAuthorizationPresenter&, const WebCore::ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod)
    248255{
    249256    ASSERT(m_state == State::Active);
     
    253260}
    254261
    255 void WebPaymentCoordinatorProxy::didSelectShippingContact(const WebCore::PaymentContact& shippingContact)
     262void WebPaymentCoordinatorProxy::presenterDidSelectShippingContact(PaymentAuthorizationPresenter&, const WebCore::PaymentContact& shippingContact)
    256263{
    257264    ASSERT(m_state == State::Active);
     
    261268}
    262269
    263 void WebPaymentCoordinatorProxy::didSelectPaymentMethod(const WebCore::PaymentMethod& paymentMethod)
     270void WebPaymentCoordinatorProxy::presenterDidSelectPaymentMethod(PaymentAuthorizationPresenter&, const WebCore::PaymentMethod& paymentMethod)
    264271{
    265272    ASSERT(m_state == State::Active);
  • trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h

    r242356 r242616  
    3030#include "MessageReceiver.h"
    3131#include "MessageSender.h"
     32#include "PaymentAuthorizationPresenter.h"
    3233#include <WebCore/PaymentHeaders.h>
    3334#include <wtf/Forward.h>
     
    5758OBJC_CLASS PKPaymentRequest;
    5859OBJC_CLASS UIViewController;
    59 OBJC_CLASS WKPaymentAuthorizationViewControllerDelegate;
    6060
    6161namespace WebKit {
     
    6363class WebPageProxy;
    6464
    65 class WebPaymentCoordinatorProxy : private IPC::MessageReceiver, private IPC::MessageSender, public CanMakeWeakPtr<WebPaymentCoordinatorProxy> {
     65class WebPaymentCoordinatorProxy
     66    : private IPC::MessageReceiver
     67    , private IPC::MessageSender
     68    , public CanMakeWeakPtr<WebPaymentCoordinatorProxy>
     69    , public PaymentAuthorizationPresenter::Client {
    6670public:
    6771    struct Client {
     
    7680        virtual UIViewController *paymentCoordinatorPresentingViewController(const WebPaymentCoordinatorProxy&) = 0;
    7781        virtual const String& paymentCoordinatorCTDataConnectionServiceType(const WebPaymentCoordinatorProxy&) = 0;
     82        virtual std::unique_ptr<PaymentAuthorizationPresenter> paymentCoordinatorAuthorizationPresenter(WebPaymentCoordinatorProxy&, PKPaymentRequest *) = 0;
    7883#endif
    7984#if PLATFORM(MAC)
     
    8691
    8792    void didCancelPaymentSession();
    88     void validateMerchant(const URL&);
    89     void didAuthorizePayment(const WebCore::Payment&);
    90     void didSelectShippingMethod(const WebCore::ApplePaySessionPaymentRequest::ShippingMethod&);
    91     void didSelectShippingContact(const WebCore::PaymentContact&);
    92     void didSelectPaymentMethod(const WebCore::PaymentMethod&);
    93 
    9493    void hidePaymentUI();
    9594
     
    102101    IPC::Connection* messageSenderConnection() const final;
    103102    uint64_t messageSenderDestinationID() const final;
     103   
     104    // PaymentAuthorizationPresenter::Client
     105    void presenterDidAuthorizePayment(PaymentAuthorizationPresenter&, const WebCore::Payment&) final;
     106    void presenterDidFinish(PaymentAuthorizationPresenter&, bool didReachFinalState) final;
     107    void presenterDidSelectPaymentMethod(PaymentAuthorizationPresenter&, const WebCore::PaymentMethod&) final;
     108    void presenterDidSelectShippingContact(PaymentAuthorizationPresenter&, const WebCore::PaymentContact&) final;
     109    void presenterDidSelectShippingMethod(PaymentAuthorizationPresenter&, const WebCore::ApplePaySessionPaymentRequest::ShippingMethod&) final;
     110    void presenterWillValidateMerchant(PaymentAuthorizationPresenter&, const URL&) final;
    104111
    105112    // Message handlers
     
    174181    } m_merchantValidationState { MerchantValidationState::Idle };
    175182
    176     RetainPtr<PKPaymentAuthorizationViewController> m_paymentAuthorizationViewController;
    177     RetainPtr<WKPaymentAuthorizationViewControllerDelegate> m_paymentAuthorizationViewControllerDelegate;
     183    std::unique_ptr<PaymentAuthorizationPresenter> m_authorizationPresenter;
    178184
    179185#if PLATFORM(MAC)
  • trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.h

    r242356 r242616  
    2828#if ENABLE(APPLE_PAY)
    2929
    30 #import "WebPaymentCoordinatorProxy.h"
    31 #import <WebCore/PaymentHeaders.h>
    3230#import <pal/spi/cocoa/PassKitSPI.h>
    33 #import <wtf/BlockPtr.h>
    3431
    35 @interface WKPaymentAuthorizationViewControllerDelegate : NSObject <PKPaymentAuthorizationViewControllerDelegate, PKPaymentAuthorizationViewControllerPrivateDelegate> {
    36 @package
    37     WebKit::WebPaymentCoordinatorProxy* _webPaymentCoordinatorProxy;
    38     RetainPtr<NSArray> _paymentSummaryItems;
    39     RetainPtr<NSArray> _shippingMethods;
     32namespace WebKit {
    4033
    41     BlockPtr<void(PKPaymentMerchantSession *, NSError *)> _sessionBlock;
     34// FIXME: Rather than having these free functions scattered about, Apple Pay data types should know
     35// how to convert themselves to and from their platform representations.
     36NSArray *toPKPaymentSummaryItems(const WebCore::ApplePaySessionPaymentRequest::TotalAndLineItems&);
     37NSDecimalNumber *toDecimalNumber(const String& amount);
     38PKPaymentSummaryItem *toPKPaymentSummaryItem(const WebCore::ApplePaySessionPaymentRequest::LineItem&);
     39PKPaymentSummaryItemType toPKPaymentSummaryItemType(WebCore::ApplePaySessionPaymentRequest::LineItem::Type);
     40PKShippingMethod *toPKShippingMethod(const WebCore::ApplePaySessionPaymentRequest::ShippingMethod&);
    4241
    43     BOOL _didReachFinalState;
    44 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    45     BlockPtr<void(PKPaymentAuthorizationResult *)> _paymentAuthorizedCompletion;
    46     BlockPtr<void(PKPaymentRequestPaymentMethodUpdate *)> _didSelectPaymentMethodCompletion;
    47     BlockPtr<void(PKPaymentRequestShippingMethodUpdate *)> _didSelectShippingMethodCompletion;
    48     BlockPtr<void(PKPaymentRequestShippingContactUpdate *)> _didSelectShippingContactCompletion;
    49 #else
    50     BlockPtr<void(PKPaymentAuthorizationStatus)> _paymentAuthorizedCompletion;
    51     BlockPtr<void(NSArray *)> _didSelectPaymentMethodCompletion;
    52     BlockPtr<void(PKPaymentAuthorizationStatus, NSArray *)> _didSelectShippingMethodCompletion;
    53     BlockPtr<void(PKPaymentAuthorizationStatus, NSArray *, NSArray *)> _didSelectShippingContactCompletion;
    54 #endif
    55 }
     42} // namespace WebKit
    5643
    57 - (instancetype)initWithPaymentCoordinatorProxy:(WebKit::WebPaymentCoordinatorProxy&)webPaymentCoordinatorProxy;
    58 
    59 - (void)invalidate;
    60 
    61 @end
    62 
    63 #endif
     44#endif // ENABLE(APPLE_PAY)
  • trunk/Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm

    r242356 r242616  
    2929#if ENABLE(APPLE_PAY)
    3030
     31#import "WKPaymentAuthorizationDelegate.h"
    3132#import "WebPaymentCoordinatorProxy.h"
    32 #import "WebProcessPool.h"
    3333#import <WebCore/PaymentAuthorizationStatus.h>
    3434#import <WebCore/PaymentHeaders.h>
     
    3737#import <wtf/RunLoop.h>
    3838#import <wtf/URL.h>
    39 
    40 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    41 SOFT_LINK_FRAMEWORK(Contacts)
    42 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressStreetKey, NSString *);
    43 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressSubLocalityKey, NSString *);
    44 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressCityKey, NSString *);
    45 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressSubAdministrativeAreaKey, NSString *);
    46 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressStateKey, NSString *);
    47 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressPostalCodeKey, NSString *);
    48 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressCountryKey, NSString *);
    49 SOFT_LINK_CONSTANT(Contacts, CNPostalAddressISOCountryCodeKey, NSString *);
    50 SOFT_LINK_CONSTANT(PAL::PassKit, PKPaymentErrorDomain, NSString *);
    51 #endif
    52 
    53 @implementation WKPaymentAuthorizationViewControllerDelegate
    54 
    55 - (instancetype)initWithPaymentCoordinatorProxy:(WebKit::WebPaymentCoordinatorProxy&)webPaymentCoordinatorProxy
    56 {
    57     if (!(self = [super init]))
    58         return nullptr;
    59 
    60     _webPaymentCoordinatorProxy = &webPaymentCoordinatorProxy;
    61 
    62     return self;
    63 }
    64 
    65 - (void)invalidate
    66 {
    67     _webPaymentCoordinatorProxy = nullptr;
    68     if (_paymentAuthorizedCompletion) {
    69 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    70         _paymentAuthorizedCompletion(adoptNS([PAL::allocPKPaymentAuthorizationResultInstance() initWithStatus:PKPaymentAuthorizationStatusFailure errors:@[ ]]).get());
    71 #else
    72         _paymentAuthorizedCompletion(PKPaymentAuthorizationStatusFailure);
    73 #endif
    74         _paymentAuthorizedCompletion = nullptr;
    75     }
    76 }
    77 
    78 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller willFinishWithError:(NSError *)error
    79 {
    80 }
    81 
    82 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didRequestMerchantSession:(void(^)(PKPaymentMerchantSession *, NSError *))sessionBlock
    83 {
    84     ASSERT(!_sessionBlock);
    85     _sessionBlock = sessionBlock;
    86 
    87     [PAL::getPKPaymentAuthorizationViewControllerClass() paymentServicesMerchantURL:^(NSURL *merchantURL, NSError *error) {
    88         if (error)
    89             LOG_ERROR("PKCanMakePaymentsWithMerchantIdentifierAndDomain error %@", error);
    90 
    91         dispatch_async(dispatch_get_main_queue(), ^{
    92             ASSERT(_sessionBlock);
    93 
    94             if (!_webPaymentCoordinatorProxy) {
    95                 _sessionBlock(nullptr, nullptr);
    96                 return;
    97             }
    98 
    99             _webPaymentCoordinatorProxy->validateMerchant(merchantURL);
    100         });
    101     }];
    102 }
    103 
    104 static WebCore::ApplePaySessionPaymentRequest::ShippingMethod toShippingMethod(PKShippingMethod *shippingMethod)
    105 {
    106     ASSERT(shippingMethod);
    107 
    108     WebCore::ApplePaySessionPaymentRequest::ShippingMethod result;
    109     result.label = shippingMethod.label;
    110     result.detail = shippingMethod.detail;
    111     result.amount = shippingMethod.amount.stringValue;
    112     result.identifier = shippingMethod.identifier;
    113 
    114     return result;
    115 }
    116 
    117 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    118 
    119 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment handler:(void (^)(PKPaymentAuthorizationResult *result))completion
    120 {
    121     if (!_webPaymentCoordinatorProxy) {
    122         completion(adoptNS([PAL::allocPKPaymentAuthorizationResultInstance() initWithStatus:PKPaymentAuthorizationStatusFailure errors:@[ ]]).get());
    123         return;
    124     }
    125 
    126     ASSERT(!_paymentAuthorizedCompletion);
    127     _paymentAuthorizedCompletion = completion;
    128 
    129     _webPaymentCoordinatorProxy->didAuthorizePayment(WebCore::Payment(payment));
    130 }
    131 
    132 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectPaymentMethod:(PKPaymentMethod *)paymentMethod handler:(void (^)(PKPaymentRequestPaymentMethodUpdate *update))completion
    133 {
    134     if (!_webPaymentCoordinatorProxy) {
    135         completion(adoptNS([PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:@[ ]]).get());
    136         return;
    137     }
    138 
    139     ASSERT(!_didSelectPaymentMethodCompletion);
    140     _didSelectPaymentMethodCompletion = completion;
    141     _webPaymentCoordinatorProxy->didSelectPaymentMethod(WebCore::PaymentMethod(paymentMethod));
    142 }
    143 
    144 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(PKShippingMethod *)shippingMethod handler:(void (^)(PKPaymentRequestShippingMethodUpdate *update))completion {
    145     if (!_webPaymentCoordinatorProxy) {
    146         completion(adoptNS([PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:@[ ]]).get());
    147         return;
    148     }
    149 
    150     ASSERT(!_didSelectShippingMethodCompletion);
    151     _didSelectShippingMethodCompletion = completion;
    152     _webPaymentCoordinatorProxy->didSelectShippingMethod(toShippingMethod(shippingMethod));
    153 }
    154 
    155 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact handler:(void (^)(PKPaymentRequestShippingContactUpdate *update))completion
    156 {
    157     if (!_webPaymentCoordinatorProxy) {
    158         completion(adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:@[ ] paymentSummaryItems:@[ ] shippingMethods:@[ ]]).get());
    159         return;
    160     }
    161 
    162     ASSERT(!_didSelectShippingContactCompletion);
    163     _didSelectShippingContactCompletion = completion;
    164     _webPaymentCoordinatorProxy->didSelectShippingContact(WebCore::PaymentContact(contact));
    165 }
    166 
    167 #endif
    168 
    169 #if !HAVE(PASSKIT_GRANULAR_ERRORS)
    170 
    171 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion
    172 {
    173     if (!_webPaymentCoordinatorProxy) {
    174         completion(PKPaymentAuthorizationStatusFailure);
    175         return;
    176     }
    177 
    178     ASSERT(!_paymentAuthorizedCompletion);
    179     _paymentAuthorizedCompletion = completion;
    180 
    181     _webPaymentCoordinatorProxy->didAuthorizePayment(WebCore::Payment(payment));
    182 }
    183 
    184 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKPaymentSummaryItem *> *summaryItems))completion
    185 {
    186     if (!_webPaymentCoordinatorProxy) {
    187         completion(PKPaymentAuthorizationStatusFailure, @[ ]);
    188         return;
    189     }
    190 
    191     ASSERT(!_didSelectShippingMethodCompletion);
    192     _didSelectShippingMethodCompletion = completion;
    193     _webPaymentCoordinatorProxy->didSelectShippingMethod(toShippingMethod(shippingMethod));
    194 }
    195 
    196 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectPaymentMethod:(PKPaymentMethod *)paymentMethod completion:(void (^)(NSArray<PKPaymentSummaryItem *> *summaryItems))completion
    197 {
    198     if (!_webPaymentCoordinatorProxy) {
    199         completion(@[ ]);
    200         return;
    201     }
    202 
    203     ASSERT(!_didSelectPaymentMethodCompletion);
    204     _didSelectPaymentMethodCompletion = completion;
    205 
    206     _webPaymentCoordinatorProxy->didSelectPaymentMethod(WebCore::PaymentMethod(paymentMethod));
    207 }
    208 
    209 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> *shippingMethods, NSArray<PKPaymentSummaryItem *> *summaryItems))completion
    210 {
    211     if (!_webPaymentCoordinatorProxy) {
    212         completion(PKPaymentAuthorizationStatusFailure, @[ ], @[ ]);
    213         return;
    214     }
    215 
    216     ASSERT(!_didSelectShippingContactCompletion);
    217     _didSelectShippingContactCompletion = completion;
    218     _webPaymentCoordinatorProxy->didSelectShippingContact(WebCore::PaymentContact(contact));
    219 }
    220 
    221 #endif
    222 
    223 - (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
    224 {
    225     if (!_webPaymentCoordinatorProxy)
    226         return;
    227 
    228     if (!_didReachFinalState)
    229         _webPaymentCoordinatorProxy->didCancelPaymentSession();
    230 
    231     _webPaymentCoordinatorProxy->hidePaymentUI();
    232 }
    233 
    234 @end
    23539
    23640// FIXME: Once rdar://problem/24420024 has been fixed, import PKPaymentRequest_Private.h instead.
     
    323127#endif
    324128
    325 static PKPaymentSummaryItemType toPKPaymentSummaryItemType(WebCore::ApplePaySessionPaymentRequest::LineItem::Type type)
     129PKPaymentSummaryItemType toPKPaymentSummaryItemType(WebCore::ApplePaySessionPaymentRequest::LineItem::Type type)
    326130{
    327131    switch (type) {
     
    334138}
    335139
    336 static NSDecimalNumber *toDecimalNumber(const String& amount)
     140NSDecimalNumber *toDecimalNumber(const String& amount)
    337141{
    338142    if (!amount)
     
    341145}
    342146
    343 static RetainPtr<PKPaymentSummaryItem> toPKPaymentSummaryItem(const WebCore::ApplePaySessionPaymentRequest::LineItem& lineItem)
     147PKPaymentSummaryItem *toPKPaymentSummaryItem(const WebCore::ApplePaySessionPaymentRequest::LineItem& lineItem)
    344148{
    345149    return [PAL::getPKPaymentSummaryItemClass() summaryItemWithLabel:lineItem.label amount:toDecimalNumber(lineItem.amount) type:toPKPaymentSummaryItemType(lineItem.type)];
    346150}
    347151
    348 static RetainPtr<NSArray> toPKPaymentSummaryItems(const WebCore::ApplePaySessionPaymentRequest::TotalAndLineItems& totalAndLineItems)
    349 {
    350     auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
     152NSArray *toPKPaymentSummaryItems(const WebCore::ApplePaySessionPaymentRequest::TotalAndLineItems& totalAndLineItems)
     153{
     154    NSMutableArray *paymentSummaryItems = [NSMutableArray arrayWithCapacity:totalAndLineItems.lineItems.size() + 1];
    351155    for (auto& lineItem : totalAndLineItems.lineItems) {
    352         if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
    353             [paymentSummaryItems addObject:summaryItem.get()];
    354     }
    355 
    356     if (auto totalItem = toPKPaymentSummaryItem(totalAndLineItems.total))
    357         [paymentSummaryItems addObject:totalItem.get()];
     156        if (PKPaymentSummaryItem *summaryItem = toPKPaymentSummaryItem(lineItem))
     157            [paymentSummaryItems addObject:summaryItem];
     158    }
     159
     160    if (PKPaymentSummaryItem *totalItem = toPKPaymentSummaryItem(totalAndLineItems.total))
     161        [paymentSummaryItems addObject:totalItem];
    358162
    359163    return paymentSummaryItems;
     
    400204}
    401205
    402 static RetainPtr<PKShippingMethod> toPKShippingMethod(const WebCore::ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod)
    403 {
    404     RetainPtr<PKShippingMethod> result = [PAL::getPKShippingMethodClass() summaryItemWithLabel:shippingMethod.label amount:toDecimalNumber(shippingMethod.amount)];
     206PKShippingMethod *toPKShippingMethod(const WebCore::ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod)
     207{
     208    PKShippingMethod *result = [PAL::getPKShippingMethodClass() summaryItemWithLabel:shippingMethod.label amount:toDecimalNumber(shippingMethod.amount)];
    405209    [result setIdentifier:shippingMethod.identifier];
    406210    [result setDetail:shippingMethod.detail];
     
    471275    auto shippingMethods = adoptNS([[NSMutableArray alloc] init]);
    472276    for (auto& shippingMethod : paymentRequest.shippingMethods())
    473         [shippingMethods addObject:toPKShippingMethod(shippingMethod).get()];
     277        [shippingMethods addObject:toPKShippingMethod(shippingMethod)];
    474278    [result setShippingMethods:shippingMethods.get()];
    475279
    476280    auto paymentSummaryItems = adoptNS([[NSMutableArray alloc] init]);
    477281    for (auto& lineItem : paymentRequest.lineItems()) {
    478         if (auto summaryItem = toPKPaymentSummaryItem(lineItem))
    479             [paymentSummaryItems addObject:summaryItem.get()];
    480     }
    481 
    482     if (auto totalItem = toPKPaymentSummaryItem(paymentRequest.total()))
    483         [paymentSummaryItems addObject:totalItem.get()];
     282        if (PKPaymentSummaryItem *summaryItem = toPKPaymentSummaryItem(lineItem))
     283            [paymentSummaryItems addObject:summaryItem];
     284    }
     285
     286    if (PKPaymentSummaryItem *totalItem = toPKPaymentSummaryItem(paymentRequest.total()))
     287        [paymentSummaryItems addObject:totalItem];
    484288
    485289    [result setPaymentSummaryItems:paymentSummaryItems.get()];
     
    514318}
    515319
    516 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    517 static PKPaymentAuthorizationStatus toPKPaymentAuthorizationStatus(WebCore::PaymentAuthorizationStatus status)
    518 {
    519     switch (status) {
    520     case WebCore::PaymentAuthorizationStatus::Success:
    521         return PKPaymentAuthorizationStatusSuccess;
    522     case WebCore::PaymentAuthorizationStatus::Failure:
    523         return PKPaymentAuthorizationStatusFailure;
    524     case WebCore::PaymentAuthorizationStatus::PINRequired:
    525         return PKPaymentAuthorizationStatusPINRequired;
    526     case WebCore::PaymentAuthorizationStatus::PINIncorrect:
    527         return PKPaymentAuthorizationStatusPINIncorrect;
    528     case WebCore::PaymentAuthorizationStatus::PINLockout:
    529         return PKPaymentAuthorizationStatusPINLockout;
    530     }
    531 }
    532 
    533 static PKPaymentErrorCode toPKPaymentErrorCode(WebCore::PaymentError::Code code)
    534 {
    535     switch (code) {
    536     case WebCore::PaymentError::Code::Unknown:
    537         return PKPaymentUnknownError;
    538     case WebCore::PaymentError::Code::ShippingContactInvalid:
    539         return PKPaymentShippingContactInvalidError;
    540     case WebCore::PaymentError::Code::BillingContactInvalid:
    541         return PKPaymentBillingContactInvalidError;
    542     case WebCore::PaymentError::Code::AddressUnserviceable:
    543         return PKPaymentShippingAddressUnserviceableError;
    544     }
    545 }
    546 
    547 static RetainPtr<NSError> toNSError(const WebCore::PaymentError& error)
    548 {
    549     auto userInfo = adoptNS([[NSMutableDictionary alloc] init]);
    550     [userInfo setObject:error.message forKey:NSLocalizedDescriptionKey];
    551 
    552     if (error.contactField) {
    553         NSString *pkContactField = nil;
    554         NSString *postalAddressKey = nil;
    555 
    556         switch (*error.contactField) {
    557         case WebCore::PaymentError::ContactField::PhoneNumber:
    558             pkContactField = PAL::get_PassKit_PKContactFieldPhoneNumber();
    559             break;
    560 
    561         case WebCore::PaymentError::ContactField::EmailAddress:
    562             pkContactField = PAL::get_PassKit_PKContactFieldEmailAddress();
    563             break;
    564 
    565         case WebCore::PaymentError::ContactField::Name:
    566             pkContactField = PAL::get_PassKit_PKContactFieldName();
    567             break;
    568 
    569         case WebCore::PaymentError::ContactField::PhoneticName:
    570             pkContactField = PAL::get_PassKit_PKContactFieldPhoneticName();
    571             break;
    572 
    573         case WebCore::PaymentError::ContactField::PostalAddress:
    574             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    575             break;
    576 
    577         case WebCore::PaymentError::ContactField::AddressLines:
    578             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    579             postalAddressKey = getCNPostalAddressStreetKey();
    580             break;
    581 
    582         case WebCore::PaymentError::ContactField::SubLocality:
    583             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    584             postalAddressKey = getCNPostalAddressSubLocalityKey();
    585             break;
    586 
    587         case WebCore::PaymentError::ContactField::Locality:
    588             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    589             postalAddressKey = getCNPostalAddressCityKey();
    590             break;
    591 
    592         case WebCore::PaymentError::ContactField::PostalCode:
    593             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    594             postalAddressKey = getCNPostalAddressPostalCodeKey();
    595             break;
    596 
    597         case WebCore::PaymentError::ContactField::SubAdministrativeArea:
    598             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    599             postalAddressKey = getCNPostalAddressSubAdministrativeAreaKey();
    600             break;
    601 
    602         case WebCore::PaymentError::ContactField::AdministrativeArea:
    603             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    604             postalAddressKey = getCNPostalAddressStateKey();
    605             break;
    606 
    607         case WebCore::PaymentError::ContactField::Country:
    608             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    609             postalAddressKey = getCNPostalAddressCountryKey();
    610             break;
    611 
    612         case WebCore::PaymentError::ContactField::CountryCode:
    613             pkContactField = PAL::get_PassKit_PKContactFieldPostalAddress();
    614             postalAddressKey = getCNPostalAddressISOCountryCodeKey();
    615             break;
    616         }
    617 
    618         [userInfo setObject:pkContactField forKey:PAL::get_PassKit_PKPaymentErrorContactFieldUserInfoKey()];
    619         if (postalAddressKey)
    620             [userInfo setObject:postalAddressKey forKey:PAL::get_PassKit_PKPaymentErrorPostalAddressUserInfoKey()];
    621     }
    622 
    623     return adoptNS([[NSError alloc] initWithDomain:getPKPaymentErrorDomain() code:toPKPaymentErrorCode(error.code) userInfo:userInfo.get()]);
    624 }
    625 
    626 static RetainPtr<NSArray> toNSErrors(const Vector<WebCore::PaymentError>& errors)
    627 {
    628     auto result = adoptNS([[NSMutableArray alloc] init]);
    629 
    630     for (const auto& error : errors) {
    631         if (auto nsError = toNSError(error))
    632             [result addObject:nsError.get()];
    633     }
    634 
    635     return result;
    636 }
    637 #else
    638 static PKPaymentAuthorizationStatus toPKPaymentAuthorizationStatus(const Optional<WebCore::PaymentAuthorizationResult>& result)
    639 {
    640     if (!result)
    641         return PKPaymentAuthorizationStatusSuccess;
    642 
    643     if (result->errors.size() == 1) {
    644         auto& error = result->errors[0];
    645         switch (error.code) {
    646         case WebCore::PaymentError::Code::Unknown:
    647         case WebCore::PaymentError::Code::AddressUnserviceable:
    648             return PKPaymentAuthorizationStatusFailure;
    649 
    650         case WebCore::PaymentError::Code::BillingContactInvalid:
    651             return PKPaymentAuthorizationStatusInvalidBillingPostalAddress;
    652 
    653         case WebCore::PaymentError::Code::ShippingContactInvalid:
    654             if (error.contactField && error.contactField == WebCore::PaymentError::ContactField::PostalAddress)
    655                 return PKPaymentAuthorizationStatusInvalidShippingPostalAddress;
    656 
    657             return PKPaymentAuthorizationStatusInvalidShippingContact;
    658         }
    659     }
    660 
    661     switch (result->status) {
    662     case WebCore::PaymentAuthorizationStatus::Success:
    663         return PKPaymentAuthorizationStatusSuccess;
    664     case WebCore::PaymentAuthorizationStatus::Failure:
    665         return PKPaymentAuthorizationStatusFailure;
    666     case WebCore::PaymentAuthorizationStatus::PINRequired:
    667         return PKPaymentAuthorizationStatusPINRequired;
    668     case WebCore::PaymentAuthorizationStatus::PINIncorrect:
    669         return PKPaymentAuthorizationStatusPINIncorrect;
    670     case WebCore::PaymentAuthorizationStatus::PINLockout:
    671         return PKPaymentAuthorizationStatusPINLockout;
    672     }
    673 
    674     return PKPaymentAuthorizationStatusFailure;
    675 }
    676 #endif
    677 
    678320void WebPaymentCoordinatorProxy::platformCompletePaymentSession(const Optional<WebCore::PaymentAuthorizationResult>& result)
    679321{
    680     ASSERT(m_paymentAuthorizationViewController);
    681     ASSERT(m_paymentAuthorizationViewControllerDelegate);
    682 
    683     m_paymentAuthorizationViewControllerDelegate->_didReachFinalState = WebCore::isFinalStateResult(result);
    684 
    685 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    686     auto status = result ? result->status : WebCore::PaymentAuthorizationStatus::Success;
    687     auto pkPaymentAuthorizationResult = adoptNS([PAL::allocPKPaymentAuthorizationResultInstance() initWithStatus:toPKPaymentAuthorizationStatus(status) errors:result ? toNSErrors(result->errors).get() : @[ ]]);
    688     m_paymentAuthorizationViewControllerDelegate->_paymentAuthorizedCompletion(pkPaymentAuthorizationResult.get());
    689 #else
    690     m_paymentAuthorizationViewControllerDelegate->_paymentAuthorizedCompletion(toPKPaymentAuthorizationStatus(result));
    691 #endif
    692     m_paymentAuthorizationViewControllerDelegate->_paymentAuthorizedCompletion = nullptr;
     322    m_authorizationPresenter->completePaymentSession(result);
    693323}
    694324
    695325void WebPaymentCoordinatorProxy::platformCompleteMerchantValidation(const WebCore::PaymentMerchantSession& paymentMerchantSession)
    696326{
    697     ASSERT(m_paymentAuthorizationViewController);
    698     ASSERT(m_paymentAuthorizationViewControllerDelegate);
    699 
    700     m_paymentAuthorizationViewControllerDelegate->_sessionBlock(paymentMerchantSession.pkPaymentMerchantSession(), nullptr);
    701     m_paymentAuthorizationViewControllerDelegate->_sessionBlock = nullptr;
     327    m_authorizationPresenter->completeMerchantValidation(paymentMerchantSession);
    702328}
    703329
    704330void WebPaymentCoordinatorProxy::platformCompleteShippingMethodSelection(const Optional<WebCore::ShippingMethodUpdate>& update)
    705331{
    706     ASSERT(m_paymentAuthorizationViewController);
    707     ASSERT(m_paymentAuthorizationViewControllerDelegate);
    708 
    709     if (update)
    710         m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = toPKPaymentSummaryItems(update->newTotalAndLineItems);
    711 
    712 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    713     auto pkShippingMethodUpdate = adoptNS([PAL::allocPKPaymentRequestShippingMethodUpdateInstance() initWithPaymentSummaryItems:m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get()]);
    714     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion(pkShippingMethodUpdate.get());
    715 #else
    716     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion(PKPaymentAuthorizationStatusSuccess, m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
    717 #endif
    718     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingMethodCompletion = nullptr;
    719 }
    720 
    721 #if !HAVE(PASSKIT_GRANULAR_ERRORS)
    722 static PKPaymentAuthorizationStatus toPKPaymentAuthorizationStatus(const Optional<WebCore::ShippingContactUpdate>& update)
    723 {
    724     if (!update || update->errors.isEmpty())
    725         return PKPaymentAuthorizationStatusSuccess;
    726 
    727     if (update->errors.size() == 1) {
    728         auto& error = update->errors[0];
    729         switch (error.code) {
    730         case WebCore::PaymentError::Code::Unknown:
    731         case WebCore::PaymentError::Code::AddressUnserviceable:
    732             return PKPaymentAuthorizationStatusFailure;
    733 
    734         case WebCore::PaymentError::Code::BillingContactInvalid:
    735             return PKPaymentAuthorizationStatusInvalidBillingPostalAddress;
    736 
    737         case WebCore::PaymentError::Code::ShippingContactInvalid:
    738             if (error.contactField && error.contactField == WebCore::PaymentError::ContactField::PostalAddress)
    739                 return PKPaymentAuthorizationStatusInvalidShippingPostalAddress;
    740 
    741             return PKPaymentAuthorizationStatusInvalidShippingContact;
    742         }
    743     }
    744 
    745     return PKPaymentAuthorizationStatusFailure;
    746 }
    747 #endif
     332    m_authorizationPresenter->completeShippingMethodSelection(update);
     333}
    748334
    749335void WebPaymentCoordinatorProxy::platformCompleteShippingContactSelection(const Optional<WebCore::ShippingContactUpdate>& update)
    750336{
    751     ASSERT(m_paymentAuthorizationViewController);
    752     ASSERT(m_paymentAuthorizationViewControllerDelegate);
    753 
    754     if (update) {
    755         m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = toPKPaymentSummaryItems(update->newTotalAndLineItems);
    756 
    757         auto shippingMethods = adoptNS([[NSMutableArray alloc] init]);
    758         for (auto& shippingMethod : update->newShippingMethods)
    759             [shippingMethods addObject:toPKShippingMethod(shippingMethod).get()];
    760 
    761         m_paymentAuthorizationViewControllerDelegate->_shippingMethods = WTFMove(shippingMethods);
    762     }
    763 
    764 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    765     auto pkShippingContactUpdate = adoptNS([PAL::allocPKPaymentRequestShippingContactUpdateInstance() initWithErrors:update ? toNSErrors(update->errors).get() : @[ ] paymentSummaryItems:m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get() shippingMethods:m_paymentAuthorizationViewControllerDelegate->_shippingMethods.get()]);
    766     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion(pkShippingContactUpdate.get());
    767 #else
    768     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion(toPKPaymentAuthorizationStatus(update), m_paymentAuthorizationViewControllerDelegate->_shippingMethods.get(), m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
    769 #endif
    770     m_paymentAuthorizationViewControllerDelegate->_didSelectShippingContactCompletion = nullptr;
     337    m_authorizationPresenter->completeShippingContactSelection(update);
    771338}
    772339
    773340void WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection(const Optional<WebCore::PaymentMethodUpdate>& update)
    774341{
    775     ASSERT(m_paymentAuthorizationViewController);
    776     ASSERT(m_paymentAuthorizationViewControllerDelegate);
    777 
    778     if (update)
    779         m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = toPKPaymentSummaryItems(update->newTotalAndLineItems);
    780 
    781 #if HAVE(PASSKIT_GRANULAR_ERRORS)
    782     auto pkPaymentMethodUpdate = adoptNS([PAL::allocPKPaymentRequestPaymentMethodUpdateInstance() initWithPaymentSummaryItems:m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get()]);
    783     m_paymentAuthorizationViewControllerDelegate->_didSelectPaymentMethodCompletion(pkPaymentMethodUpdate.get());
    784 #else
    785     m_paymentAuthorizationViewControllerDelegate->_didSelectPaymentMethodCompletion(m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems.get());
    786 #endif
    787     m_paymentAuthorizationViewControllerDelegate->_didSelectPaymentMethodCompletion = nullptr;
     342    m_authorizationPresenter->completePaymentMethodSelection(update);
    788343}
    789344
  • trunk/Source/WebKit/Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm

    r242356 r242616  
    3030
    3131#import "APIUIClient.h"
     32#import "PaymentAuthorizationPresenter.h"
    3233#import "WebPageProxy.h"
    33 #import "WebPaymentCoordinatorProxyCocoa.h"
    3434#import <PassKit/PassKit.h>
    3535#import <UIKit/UIViewController.h>
     
    4141void WebPaymentCoordinatorProxy::platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler)
    4242{
    43     UIViewController *presentingViewController = m_client.paymentCoordinatorPresentingViewController(*this);
    44 
    45     if (!presentingViewController) {
    46         completionHandler(false);
    47         return;
    48     }
    49 
    50     ASSERT(!m_paymentAuthorizationViewController);
    51 
    5243    auto paymentRequest = platformPaymentRequest(originatingURL, linkIconURLStrings, request);
    5344
    54     m_paymentAuthorizationViewController = adoptNS([PAL::allocPKPaymentAuthorizationViewControllerInstance() initWithPaymentRequest:paymentRequest.get()]);
    55     if (!m_paymentAuthorizationViewController) {
    56         completionHandler(false);
    57         return;
    58     }
     45    ASSERT(!m_authorizationPresenter);
     46    m_authorizationPresenter = m_client.paymentCoordinatorAuthorizationPresenter(*this, paymentRequest.get());
     47    if (!m_authorizationPresenter)
     48        return completionHandler(false);
    5949
    60     m_paymentAuthorizationViewControllerDelegate = adoptNS([[WKPaymentAuthorizationViewControllerDelegate alloc] initWithPaymentCoordinatorProxy:*this]);
    61     m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = [paymentRequest paymentSummaryItems];
    62     m_paymentAuthorizationViewControllerDelegate->_shippingMethods = [paymentRequest shippingMethods];
    63 
    64     [m_paymentAuthorizationViewController setDelegate:m_paymentAuthorizationViewControllerDelegate.get()];
    65     [m_paymentAuthorizationViewController setPrivateDelegate:m_paymentAuthorizationViewControllerDelegate.get()];
    66 
    67     [presentingViewController presentViewController:m_paymentAuthorizationViewController.get() animated:YES completion:nullptr];
    68 
    69     completionHandler(true);
     50    m_authorizationPresenter->present(m_client.paymentCoordinatorPresentingViewController(*this), WTFMove(completionHandler));
    7051}
    7152
    7253void WebPaymentCoordinatorProxy::hidePaymentUI()
    7354{
    74     ASSERT(m_paymentAuthorizationViewController);
    75     ASSERT(m_paymentAuthorizationViewControllerDelegate);
    76 
    77     [[m_paymentAuthorizationViewController presentingViewController] dismissViewControllerAnimated:YES completion:nullptr];
    78     [m_paymentAuthorizationViewController setDelegate:nil];
    79     [m_paymentAuthorizationViewController setPrivateDelegate:nil];
    80     m_paymentAuthorizationViewController = nullptr;
    81 
    82     [m_paymentAuthorizationViewControllerDelegate invalidate];
    83     m_paymentAuthorizationViewControllerDelegate = nullptr;
     55    m_authorizationPresenter->dismiss();
     56    m_authorizationPresenter = nullptr;
    8457}
    8558
  • trunk/Source/WebKit/Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm

    r242356 r242616  
    2929#if PLATFORM(MAC) && ENABLE(APPLE_PAY)
    3030
     31#import "PaymentAuthorizationViewController.h"
    3132#import "WebPageProxy.h"
    32 #import "WebPaymentCoordinatorProxyCocoa.h"
    3333#import <pal/cocoa/PassKitSoftLink.h>
    3434#import <wtf/BlockPtr.h>
     
    6565        ASSERT(viewController);
    6666
    67         paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate = adoptNS([[WKPaymentAuthorizationViewControllerDelegate alloc] initWithPaymentCoordinatorProxy:*paymentCoordinatorProxy]);
    68         paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate->_paymentSummaryItems = [paymentRequest paymentSummaryItems];
    69         paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate->_shippingMethods = [paymentRequest shippingMethods];
    70         paymentCoordinatorProxy->m_paymentAuthorizationViewController = viewController;
    71         [paymentCoordinatorProxy->m_paymentAuthorizationViewController setDelegate:paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate.get()];
    72         [paymentCoordinatorProxy->m_paymentAuthorizationViewController setPrivateDelegate:paymentCoordinatorProxy->m_paymentAuthorizationViewControllerDelegate.get()];
     67        paymentCoordinatorProxy->m_authorizationPresenter = std::make_unique<PaymentAuthorizationViewController>(*paymentCoordinatorProxy, paymentRequest.get(), viewController);
    7368
    7469        ASSERT(!paymentCoordinatorProxy->m_sheetWindow);
     
    9186        ++m_showPaymentUIRequestSeed;
    9287
    93         ASSERT(!m_paymentAuthorizationViewController);
    94         ASSERT(!m_paymentAuthorizationViewControllerDelegate);
     88        ASSERT(!m_authorizationPresenter);
    9589        ASSERT(!m_sheetWindow);
    9690        return;
    9791    }
    9892
    99     ASSERT(m_paymentAuthorizationViewController);
    100     ASSERT(m_paymentAuthorizationViewControllerDelegate);
     93    ASSERT(m_authorizationPresenter);
    10194    ASSERT(m_sheetWindow);
    10295
     
    10598
    10699    [[m_sheetWindow sheetParent] endSheet:m_sheetWindow.get()];
    107     [m_paymentAuthorizationViewController setDelegate:nil];
    108     [m_paymentAuthorizationViewController setPrivateDelegate:nil];
    109     m_paymentAuthorizationViewController = nullptr;
    110 
    111     [m_paymentAuthorizationViewControllerDelegate invalidate];
    112     m_paymentAuthorizationViewControllerDelegate = nullptr;
     100    m_authorizationPresenter->dismiss();
     101    m_authorizationPresenter = nullptr;
    113102
    114103    m_sheetWindow = nullptr;
  • trunk/Source/WebKit/SourcesCocoa.txt

    r242503 r242616  
    1 // Copyright (C) 2018 Apple Inc. All rights reserved.
     1// Copyright (C) 2018-2019 Apple Inc. All rights reserved.
    22//
    33// Redistribution and use in source and binary forms, with or without
     
    6666Platform/classifier/ResourceLoadStatisticsClassifier.cpp
    6767
     68Platform/cocoa/PaymentAuthorizationPresenter.mm
     69Platform/cocoa/PaymentAuthorizationViewController.mm
    6870Platform/cocoa/SharedMemoryCocoa.cpp
    6971Platform/cocoa/WKCrashReporter.mm
     72Platform/cocoa/WKPaymentAuthorizationDelegate.mm
    7073Platform/cocoa/WebKitAdditions.mm @no-unify
    7174
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r242551 r242616  
    19871987    UIViewController *paymentCoordinatorPresentingViewController(const WebPaymentCoordinatorProxy&) final;
    19881988    const String& paymentCoordinatorCTDataConnectionServiceType(const WebPaymentCoordinatorProxy&) final;
     1989    std::unique_ptr<PaymentAuthorizationPresenter> paymentCoordinatorAuthorizationPresenter(WebPaymentCoordinatorProxy&, PKPaymentRequest *) final;
    19891990#endif
    19901991#if ENABLE(APPLE_PAY) && PLATFORM(MAC)
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r242551 r242616  
    3939#import "NavigationState.h"
    4040#import "PageClient.h"
     41#import "PaymentAuthorizationViewController.h"
    4142#import "PrintInfo.h"
    4243#import "RemoteLayerTreeDrawingAreaProxy.h"
     
    11801181#if ENABLE(APPLE_PAY)
    11811182
     1183std::unique_ptr<PaymentAuthorizationPresenter> WebPageProxy::paymentCoordinatorAuthorizationPresenter(WebPaymentCoordinatorProxy& paymentCoordinatorProxy, PKPaymentRequest *paymentRequest)
     1184{
     1185    return std::make_unique<PaymentAuthorizationViewController>(paymentCoordinatorProxy, paymentRequest);
     1186}
     1187
    11821188UIViewController *WebPageProxy::paymentCoordinatorPresentingViewController(const WebPaymentCoordinatorProxy&)
    11831189{
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r242503 r242616  
    294294                1AB16AE21648656D00290D62 /* RemoteLayerTreeDrawingAreaProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB16AE01648656D00290D62 /* RemoteLayerTreeDrawingAreaProxy.h */; };
    295295                1AB16AEA164B3A8800290D62 /* RemoteLayerTreeContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB16AE8164B3A8800290D62 /* RemoteLayerTreeContext.h */; };
    296                 1AB1F77E1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB1F7781D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h */; };
    297296                1AB1F78C1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB1F7891D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h */; };
    298297                1AB1F7961D1B3613007C9BD1 /* WebPaymentCoordinatorMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB1F7921D1B3613007C9BD1 /* WebPaymentCoordinatorMessageReceiver.cpp */; };
     
    12851284                A15EEDE61E301CEE000069B0 /* WKPasswordView.h in Headers */ = {isa = PBXBuildFile; fileRef = A15EEDE41E301CEE000069B0 /* WKPasswordView.h */; };
    12861285                A175C44A21AA3171000037D0 /* ArgumentCodersCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = A175C44921AA3170000037D0 /* ArgumentCodersCocoa.h */; };
     1286                A1798B3E222D97A2000764BD /* PaymentAuthorizationPresenter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1798B3D222D97A2000764BD /* PaymentAuthorizationPresenter.h */; };
     1287                A1798B43222D98DF000764BD /* PaymentAuthorizationViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = A1798B3F222D98B6000764BD /* PaymentAuthorizationViewController.h */; };
     1288                A1798B49222E531D000764BD /* WKPaymentAuthorizationDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = A1798B47222E530A000764BD /* WKPaymentAuthorizationDelegate.h */; };
     1289                A1798B4C222F1BD4000764BD /* WebPaymentCoordinatorProxyCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = A1798B4B222F1BD4000764BD /* WebPaymentCoordinatorProxyCocoa.h */; };
    12871290                A181A79821ACC74B0059A316 /* WebKitAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = A181A79721ACAC610059A316 /* WebKitAdditions.mm */; };
    12881291                A182D5B51BE6BD250087A7CC /* AccessibilityIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = A182D5B31BE6BD250087A7CC /* AccessibilityIOS.h */; };
     
    22292232                1AB1F7721D1B2F7E007C9BD1 /* WebPaymentCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPaymentCoordinator.h; sourceTree = "<group>"; };
    22302233                1AB1F7731D1B2F7E007C9BD1 /* WebPaymentCoordinator.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebPaymentCoordinator.messages.in; sourceTree = "<group>"; };
    2231                 1AB1F7781D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPaymentCoordinatorProxyCocoa.h; sourceTree = "<group>"; };
    22322234                1AB1F7791D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPaymentCoordinatorProxyCocoa.mm; sourceTree = "<group>"; };
    22332235                1AB1F77B1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPaymentCoordinatorProxyIOS.mm; sourceTree = "<group>"; };
     
    38543856                A175C44921AA3170000037D0 /* ArgumentCodersCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArgumentCodersCocoa.h; sourceTree = "<group>"; };
    38553857                A175C44B21AA331B000037D0 /* ArgumentCodersCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ArgumentCodersCocoa.mm; sourceTree = "<group>"; };
     3858                A1798B3D222D97A2000764BD /* PaymentAuthorizationPresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentAuthorizationPresenter.h; sourceTree = "<group>"; };
     3859                A1798B3F222D98B6000764BD /* PaymentAuthorizationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentAuthorizationViewController.h; sourceTree = "<group>"; };
     3860                A1798B40222D98B6000764BD /* PaymentAuthorizationViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PaymentAuthorizationViewController.mm; sourceTree = "<group>"; };
     3861                A1798B47222E530A000764BD /* WKPaymentAuthorizationDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKPaymentAuthorizationDelegate.h; sourceTree = "<group>"; };
     3862                A1798B48222E530A000764BD /* WKPaymentAuthorizationDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPaymentAuthorizationDelegate.mm; sourceTree = "<group>"; };
     3863                A1798B4A222F133A000764BD /* PaymentAuthorizationPresenter.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PaymentAuthorizationPresenter.mm; sourceTree = "<group>"; };
     3864                A1798B4B222F1BD4000764BD /* WebPaymentCoordinatorProxyCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebPaymentCoordinatorProxyCocoa.h; sourceTree = "<group>"; };
    38563865                A181A79721ACAC610059A316 /* WebKitAdditions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebKitAdditions.mm; sourceTree = "<group>"; };
    38573866                A182D5B21BE6BD250087A7CC /* AccessibilityIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AccessibilityIOS.mm; sourceTree = "<group>"; };
     
    52735282                        isa = PBXGroup;
    52745283                        children = (
    5275                                 1AB1F7781D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h */,
     5284                                A1798B4B222F1BD4000764BD /* WebPaymentCoordinatorProxyCocoa.h */,
    52765285                                1AB1F7791D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.mm */,
    52775286                        );
     
    63906399                        isa = PBXGroup;
    63916400                        children = (
     6401                                A1798B3D222D97A2000764BD /* PaymentAuthorizationPresenter.h */,
     6402                                A1798B4A222F133A000764BD /* PaymentAuthorizationPresenter.mm */,
     6403                                A1798B3F222D98B6000764BD /* PaymentAuthorizationViewController.h */,
     6404                                A1798B40222D98B6000764BD /* PaymentAuthorizationViewController.mm */,
    63926405                                4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */,
    63936406                                A181A79721ACAC610059A316 /* WebKitAdditions.mm */,
    63946407                                A1FB68221F6E518200C43F9F /* WKCrashReporter.h */,
    63956408                                A1FB68231F6E518200C43F9F /* WKCrashReporter.mm */,
     6409                                A1798B47222E530A000764BD /* WKPaymentAuthorizationDelegate.h */,
     6410                                A1798B48222E530A000764BD /* WKPaymentAuthorizationDelegate.mm */,
    63966411                        );
    63976412                        path = cocoa;
     
    92579272                                1A8B66B01BC43C860082DF77 /* PageLoadStateObserver.h in Headers */,
    92589273                                C574A58112E66681002DFE98 /* PasteboardTypes.h in Headers */,
     9274                                A1798B3E222D97A2000764BD /* PaymentAuthorizationPresenter.h in Headers */,
     9275                                A1798B43222D98DF000764BD /* PaymentAuthorizationViewController.h in Headers */,
    92599276                                C1E123BA20A11573002646F4 /* PDFContextMenu.h in Headers */,
    92609277                                E19582D3153CBFD700B60875 /* PDFKitImports.h in Headers */,
     
    95619578                                1AB1F7971D1B3613007C9BD1 /* WebPaymentCoordinatorMessages.h in Headers */,
    95629579                                1AB1F78C1D1B3355007C9BD1 /* WebPaymentCoordinatorProxy.h in Headers */,
    9563                                 1AB1F77E1D1B30A9007C9BD1 /* WebPaymentCoordinatorProxyCocoa.h in Headers */,
     9580                                A1798B4C222F1BD4000764BD /* WebPaymentCoordinatorProxyCocoa.h in Headers */,
    95649581                                1AB1F7991D1B3613007C9BD1 /* WebPaymentCoordinatorProxyMessages.h in Headers */,
    95659582                                0F850FE71ED7C39F00FB77A7 /* WebPerformanceLoggingClient.h in Headers */,
     
    98759892                                A5EFD38C16B0E88C00B2F0E8 /* WKPageVisibilityTypes.h in Headers */,
    98769893                                A15EEDE61E301CEE000069B0 /* WKPasswordView.h in Headers */,
     9894                                A1798B49222E531D000764BD /* WKPaymentAuthorizationDelegate.h in Headers */,
    98779895                                2D6AB541192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.h in Headers */,
    98789896                                A1046EA12079263100F0C5D8 /* WKPDFView.h in Headers */,
     
    1086910887                                E18E6917169B667B009B6670 /* SecItemShimProxyMessageReceiver.cpp in Sources */,
    1087010888                                617A52D81F43A9DA00DCDC0A /* ServiceWorkerClientFetchMessageReceiver.cpp in Sources */,
     10889                                41DE7C6C22278F1E00532B65 /* ServiceWorkerFetchTask.cpp in Sources */,
    1087110890                                2D92A787212B6AB100F493FD /* ShareableBitmap.cpp in Sources */,
    1087210891                                2DE6943D18BD2A68005C15E5 /* SmartMagnificationControllerMessageReceiver.cpp in Sources */,
     
    1105311072                                2D8508D8212E33ED000EF46C /* UnifiedSource98.cpp in Sources */,
    1105411073                                2D8508C5212E33ED000EF46C /* UnifiedSource99.cpp in Sources */,
    11055                                 41DE7C6C22278F1E00532B65 /* ServiceWorkerFetchTask.cpp in Sources */,
    1105611074                                2D8508D2212E33ED000EF46C /* UnifiedSource100.cpp in Sources */,
    1105711075                                CD491B0D1E732E4D00009066 /* UserMediaCaptureManagerMessageReceiver.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.