Changeset 206238 in webkit


Ignore:
Timestamp:
Sep 21, 2016 3:51:52 PM (8 years ago)
Author:
andersca@apple.com
Message:

Source/WebCore:
support openPaymentSetup API on ApplePaySession object
https://bugs.webkit.org/show_bug.cgi?id=162357
rdar://problem/26776939

Reviewed by Tim Horton.

  • Modules/applepay/ApplePaySession.cpp:

(WebCore::ApplePaySession::openPaymentSetup):
Perform security checks and then call into the PaymentCoordiantor. In its completion handler, we resolve the promise.

  • Modules/applepay/ApplePaySession.h:

Add new members.

  • Modules/applepay/ApplePaySession.idl:

Add openPaymentSetup declaration.

  • Modules/applepay/PaymentCoordinator.cpp:

(WebCore::PaymentCoordinator::openPaymentSetup):
Call through to the clients.

  • Modules/applepay/PaymentCoordinator.h:
  • Modules/applepay/PaymentCoordinatorClient.h:

Add new members.

  • loader/EmptyClients.cpp:

Add new stub.

  • platform/spi/cocoa/PassKitSPI.h:

Add SPI declaration.

Source/WebKit/mac:
Support openPaymentSetup API on ApplePaySession object
https://bugs.webkit.org/show_bug.cgi?id=162357
rdar://problem/26776939

Reviewed by Tim Horton.

Add openPaymentSetup stub.

  • WebCoreSupport/WebPaymentCoordinatorClient.h:
  • WebCoreSupport/WebPaymentCoordinatorClient.mm:

(WebPaymentCoordinatorClient::openPaymentSetup):

Source/WebKit2:
support openPaymentSetup API on ApplePaySession object
https://bugs.webkit.org/show_bug.cgi?id=162357
rdar://problem/26776939

Reviewed by Tim Horton.

  • UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp:

(WebKit::WebPaymentCoordinatorProxy::openPaymentSetup):
Call through to platformOpenPaymentSetup, and in the completion handler, send back a OpenPaymentSetupReply message.

  • UIProcess/ApplePay/WebPaymentCoordinatorProxy.h:

Add new members.

  • UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in:

Add OpenPaymentSetup message.

  • UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:

(WebKit::WebPaymentCoordinatorProxy::platformOpenPaymentSetup):
Allocate a PKPassLibrary and call openPaymentSetupForMerchantIdentifier:domain:completion: on it.

  • WebProcess/ApplePay/WebPaymentCoordinator.cpp:

(WebKit::generateOpenPaymentSetupReplyID):
New helper function to generate a reply ID.

(WebKit::WebPaymentCoordinator::openPaymentSetup):
Add the completion handler to m_pendingOpenPaymentSetupCallbacks and send a OpenPaymentSetup message to the UI process.

(WebKit::WebPaymentCoordinator::openPaymentSetupReply):
Grab the callback given its ID and invoke it.

  • WebProcess/ApplePay/WebPaymentCoordinator.h:

Add new members.

  • WebProcess/ApplePay/WebPaymentCoordinator.messages.in:

Add OpenPaymentSetupReply message.

Location:
trunk/Source
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206236 r206238  
     12016-09-21  Anders Carlsson  <andersca@apple.com>
     2
     3        support openPaymentSetup API on ApplePaySession object
     4        https://bugs.webkit.org/show_bug.cgi?id=162357
     5        rdar://problem/26776939
     6
     7        Reviewed by Tim Horton.
     8
     9        * Modules/applepay/ApplePaySession.cpp:
     10        (WebCore::ApplePaySession::openPaymentSetup):
     11        Perform security checks and then call into the PaymentCoordiantor. In its completion handler, we resolve the promise.
     12
     13        * Modules/applepay/ApplePaySession.h:
     14        Add new members.
     15
     16        * Modules/applepay/ApplePaySession.idl:
     17        Add openPaymentSetup declaration.
     18
     19        * Modules/applepay/PaymentCoordinator.cpp:
     20        (WebCore::PaymentCoordinator::openPaymentSetup):
     21        Call through to the clients.
     22
     23        * Modules/applepay/PaymentCoordinator.h:
     24        * Modules/applepay/PaymentCoordinatorClient.h:
     25        Add new members.
     26
     27        * loader/EmptyClients.cpp:
     28        Add new stub.
     29
     30        * platform/spi/cocoa/PassKitSPI.h:
     31        Add SPI declaration.
     32
    1332016-09-21  Commit Queue  <commit-queue@webkit.org>
    234
  • trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp

    r205257 r206238  
    764764}
    765765
     766void ApplePaySession::openPaymentSetup(ScriptExecutionContext& scriptExecutionContext, const String& merchantIdentifier, Ref<DeferredWrapper>&& passedPromise, ExceptionCode& ec)
     767{
     768    auto& document = downcast<Document>(scriptExecutionContext);
     769    DOMWindow& window = *document.domWindow();
     770
     771    String errorMessage;
     772    if (!canCallApplePaySessionAPIs(document, errorMessage)) {
     773        window.printErrorMessage(errorMessage);
     774        ec = INVALID_ACCESS_ERR;
     775        return;
     776    }
     777
     778    if (!ScriptController::processingUserGesture()) {
     779        window.printErrorMessage("Must call ApplePaySession.openPaymemntSetup from a user gesture handler.");
     780        ec = INVALID_ACCESS_ERR;
     781        return;
     782    }
     783
     784    RefPtr<DeferredWrapper> promise(WTFMove(passedPromise));
     785    auto& paymentCoordinator = document.frame()->mainFrame().paymentCoordinator();
     786
     787    paymentCoordinator.openPaymentSetup(merchantIdentifier, document.domain(), [promise](bool result) mutable {
     788        promise->resolve(result);
     789    });
     790}
     791
    766792void ApplePaySession::begin(ExceptionCode& ec)
    767793{
  • trunk/Source/WebCore/Modules/applepay/ApplePaySession.h

    r205257 r206238  
    6565    static bool canMakePayments(ScriptExecutionContext&, ExceptionCode&);
    6666    static void canMakePaymentsWithActiveCard(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredWrapper>&&, ExceptionCode&);
     67    static void openPaymentSetup(ScriptExecutionContext&, const String& merchantIdentifier, Ref<DeferredWrapper>&&, ExceptionCode&);
    6768
    6869    void begin(ExceptionCode&);
  • trunk/Source/WebCore/Modules/applepay/ApplePaySession.idl

    r202309 r206238  
    4444    [CallWith=ScriptExecutionContext, RaisesException] static boolean canMakePayments();
    4545    [CallWith=ScriptExecutionContext, RaisesException] static Promise canMakePaymentsWithActiveCard(DOMString merchantIdentifier);
     46    [CallWith=ScriptExecutionContext, RaisesException] static Promise openPaymentSetup(DOMString merchantIdentifier);
    4647
    4748    [RaisesException] void begin();
  • trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp

    r203746 r206238  
    5959{
    6060    m_client.canMakePaymentsWithActiveCard(merchantIdentifier, domainName, WTFMove(completionHandler));
     61}
     62
     63void PaymentCoordinator::openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler)
     64{
     65    m_client.openPaymentSetup(merchantIdentifier, domainName, WTFMove(completionHandler));
    6166}
    6267
  • trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h

    r203084 r206238  
    5050    bool canMakePayments();
    5151    void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler);
     52    void openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler);
    5253
    5354    bool hasActiveSession() const { return m_activeSession; }
  • trunk/Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h

    r203084 r206238  
    4343    virtual bool canMakePayments() = 0;
    4444    virtual void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) = 0;
     45    virtual void openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) = 0;
    4546
    4647    virtual bool showPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLs, const PaymentRequest&) = 0;
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r205462 r206238  
    5959    bool canMakePayments() override { return false; }
    6060    void canMakePaymentsWithActiveCard(const String&, const String&, std::function<void (bool)> completionHandler) override { callOnMainThread([completionHandler] { completionHandler(false); }); }
     61    void openPaymentSetup(const String&, const String&, std::function<void (bool)> completionHandler) override { callOnMainThread([completionHandler] { completionHandler(false); }); }
     62
    6163    bool showPaymentUI(const URL&, const Vector<URL>&, const PaymentRequest&) override { return false; }
    6264    void completeMerchantValidation(const PaymentMerchantSession&) override { }
  • trunk/Source/WebCore/platform/spi/cocoa/PassKitSPI.h

    r205992 r206238  
    233233extern "C"
    234234void PKDrawApplePayButton(_Nonnull CGContextRef, CGRect drawRect, CGFloat scale, PKPaymentButtonType, PKPaymentButtonStyle, NSString * _Nullable languageCode);
     235
     236NS_ASSUME_NONNULL_BEGIN
     237
     238@interface PKPassLibrary ()
     239- (void)openPaymentSetupForMerchantIdentifier:(NSString *)identifier domain:(NSString *)domain completion:(void(^)(BOOL success))completion;
     240@end
     241
     242NS_ASSUME_NONNULL_END
  • trunk/Source/WebKit/mac/ChangeLog

    r206119 r206238  
     12016-09-21  Anders Carlsson  <andersca@apple.com>
     2
     3        Support openPaymentSetup API on ApplePaySession object
     4        https://bugs.webkit.org/show_bug.cgi?id=162357
     5        rdar://problem/26776939
     6
     7        Reviewed by Tim Horton.
     8
     9        Add openPaymentSetup stub.
     10
     11        * WebCoreSupport/WebPaymentCoordinatorClient.h:
     12        * WebCoreSupport/WebPaymentCoordinatorClient.mm:
     13        (WebPaymentCoordinatorClient::openPaymentSetup):
     14
    1152016-09-19  Daniel Bates  <dabates@apple.com>
    216
  • trunk/Source/WebKit/mac/WebCoreSupport/WebPaymentCoordinatorClient.h

    r203084 r206238  
    4040    bool canMakePayments() override;
    4141    void canMakePaymentsWithActiveCard(const String&, const String&, std::function<void (bool)> completionHandler) override;
     42    void openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) override;
    4243    bool showPaymentUI(const WebCore::URL&, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest&) override;
    4344    void completeMerchantValidation(const WebCore::PaymentMerchantSession&) override;
  • trunk/Source/WebKit/mac/WebCoreSupport/WebPaymentCoordinatorClient.mm

    r203084 r206238  
    5656}
    5757
     58void WebPaymentCoordinatorClient::openPaymentSetup(const String&, const String&, std::function<void (bool)> completionHandler)
     59{
     60    callOnMainThread([completionHandler] {
     61        completionHandler(false);
     62    });
     63}
     64
    5865bool WebPaymentCoordinatorClient::showPaymentUI(const WebCore::URL&, const Vector<WebCore::URL>&, const WebCore::PaymentRequest&)
    5966{
  • trunk/Source/WebKit2/ChangeLog

    r206216 r206238  
     12016-09-21  Anders Carlsson  <andersca@apple.com>
     2
     3        support openPaymentSetup API on ApplePaySession object
     4        https://bugs.webkit.org/show_bug.cgi?id=162357
     5        rdar://problem/26776939
     6
     7        Reviewed by Tim Horton.
     8
     9        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp:
     10        (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup):
     11        Call through to platformOpenPaymentSetup, and in the completion handler, send back a OpenPaymentSetupReply message.
     12
     13        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h:
     14        Add new members.
     15
     16        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in:
     17        Add OpenPaymentSetup message.
     18
     19        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
     20        (WebKit::WebPaymentCoordinatorProxy::platformOpenPaymentSetup):
     21        Allocate a PKPassLibrary and call openPaymentSetupForMerchantIdentifier:domain:completion: on it.
     22
     23        * WebProcess/ApplePay/WebPaymentCoordinator.cpp:
     24        (WebKit::generateOpenPaymentSetupReplyID):
     25        New helper function to generate a reply ID.
     26
     27        (WebKit::WebPaymentCoordinator::openPaymentSetup):
     28        Add the completion handler to m_pendingOpenPaymentSetupCallbacks and send a OpenPaymentSetup message to the UI process.
     29
     30        (WebKit::WebPaymentCoordinator::openPaymentSetupReply):
     31        Grab the callback given its ID and invoke it.
     32
     33        * WebProcess/ApplePay/WebPaymentCoordinator.h:
     34        Add new members.
     35
     36        * WebProcess/ApplePay/WebPaymentCoordinator.messages.in:
     37        Add OpenPaymentSetupReply message.
     38
    1392016-09-21  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
    240
  • trunk/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp

    r206176 r206238  
    7676}
    7777
     78void WebPaymentCoordinatorProxy::openPaymentSetup(const String& merchantIdentifier, const String& domainName, uint64_t requestID)
     79{
     80    auto weakThis = m_weakPtrFactory.createWeakPtr();
     81    platformOpenPaymentSetup(merchantIdentifier, domainName, [weakThis, requestID](bool result) {
     82        auto paymentCoordinatorProxy = weakThis.get();
     83        if (!paymentCoordinatorProxy)
     84            return;
     85
     86        paymentCoordinatorProxy->m_webPageProxy.send(Messages::WebPaymentCoordinator::OpenPaymentSetupReply(requestID, result));
     87    });
     88}
     89
    7890void WebPaymentCoordinatorProxy::showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::PaymentRequest& paymentRequest, bool& result)
    7991{
  • trunk/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h

    r204668 r206238  
    7878    void canMakePayments(bool& reply);
    7979    void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, uint64_t requestID);
     80    void openPaymentSetup(const String& merchantIdentifier, const String& domainName, uint64_t requestID);
    8081    void showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::PaymentRequest&, bool& result);
    8182    void completeMerchantValidation(const WebCore::PaymentMerchantSession&);
     
    9596    bool platformCanMakePayments();
    9697    void platformCanMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler);
     98    void platformOpenPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler);
    9799    void platformShowPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest&, std::function<void (bool)> completionHandler);
    98100    void platformCompleteMerchantValidation(const WebCore::PaymentMerchantSession&);
  • trunk/Source/WebKit2/UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in

    r203084 r206238  
    2929    CanMakePayments() -> (bool result)
    3030    CanMakePaymentsWithActiveCard(String merchantIdentifier, String domainName, uint64_t requestID)
     31    OpenPaymentSetup(String merchantIdentifier, String domainName, uint64_t requestID)
    3132
    3233    ShowPaymentUI(String originatingURLString, Vector<String> linkIconURLStrings, WebCore::PaymentRequest paymentRequest) -> (bool result)
  • trunk/Source/WebKit2/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm

    r204587 r206238  
    4343#endif
    4444
     45SOFT_LINK_CLASS(PassKit, PKPassLibrary);
    4546SOFT_LINK_CLASS(PassKit, PKPaymentAuthorizationViewController);
    4647SOFT_LINK_CLASS(PassKit, PKPaymentMerchantSession);
     
    221222        });
    222223    });
     224}
     225
     226void WebPaymentCoordinatorProxy::platformOpenPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler)
     227{
     228    auto passLibrary = adoptNS([allocPKPassLibraryInstance() init]);
     229    if (![passLibrary respondsToSelector:@selector(openPaymentSetupForMerchantIdentifier:domain:completion:)]) {
     230        RunLoop::main().dispatch([completionHandler] {
     231            completionHandler(false);
     232        });
     233        return;
     234    }
     235
     236    [passLibrary openPaymentSetupForMerchantIdentifier:merchantIdentifier domain:domainName completion:[completionHandler](BOOL result) {
     237        RunLoop::main().dispatch([completionHandler, result] {
     238            completionHandler(result);
     239        });
     240    }];
    223241}
    224242
  • trunk/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.cpp

    r204587 r206238  
    8585}
    8686
     87static uint64_t generateOpenPaymentSetupReplyID()
     88{
     89    static uint64_t openPaymentSetupReplyID;
     90
     91    return ++openPaymentSetupReplyID;
     92}
     93
     94void WebPaymentCoordinator::openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler)
     95{
     96    auto replyID = generateOpenPaymentSetupReplyID();
     97
     98    m_pendingOpenPaymentSetupCallbacks.add(replyID, WTFMove(completionHandler));
     99    m_webPage.send(Messages::WebPaymentCoordinatorProxy::OpenPaymentSetup(merchantIdentifier, domainName, replyID));
     100}
     101
    87102bool WebPaymentCoordinator::showPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest& paymentRequest)
    88103{
     
    169184}
    170185
     186void WebPaymentCoordinator::openPaymentSetupReply(uint64_t requestID, bool result)
     187{
     188    auto callback = m_pendingOpenPaymentSetupCallbacks.take(requestID);
     189    callback(result);
     190}
     191
    171192WebCore::PaymentCoordinator& WebPaymentCoordinator::paymentCoordinator()
    172193{
  • trunk/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.h

    r204668 r206238  
    5757    bool canMakePayments() override;
    5858    void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) override;
     59    void openPaymentSetup(const String& merchantIdentifier, const String& domainName, std::function<void (bool)> completionHandler) override;
    5960    bool showPaymentUI(const WebCore::URL& originatingURL, const Vector<WebCore::URL>& linkIconURLs, const WebCore::PaymentRequest&) override;
    6061    void completeMerchantValidation(const WebCore::PaymentMerchantSession&) override;
     
    7879    void didCancelPayment();
    7980    void canMakePaymentsWithActiveCardReply(uint64_t requestID, bool canMakePayments);
     81    void openPaymentSetupReply(uint64_t requestID, bool result);
    8082
    8183    WebCore::PaymentCoordinator& paymentCoordinator();
     
    8486
    8587    HashMap<uint64_t, std::function<void (bool)>> m_pendingCanMakePaymentsWithActiveCardCallbacks;
     88    HashMap<uint64_t, std::function<void (bool)>> m_pendingOpenPaymentSetupCallbacks;
    8689};
    8790
  • trunk/Source/WebKit2/WebProcess/ApplePay/WebPaymentCoordinator.messages.in

    r202432 r206238  
    3434    DidCancelPayment()
    3535    CanMakePaymentsWithActiveCardReply(uint64_t requestID, bool canMakePayments)
     36    OpenPaymentSetupReply(uint64_t requestID, bool result)
    3637}
    3738
Note: See TracChangeset for help on using the changeset viewer.