⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243447 in webkit


Ignore:
Timestamp:
Mar 25, 2019, 1:23:43 PM (7 years ago)
Author:
aestes@apple.com
Message:

[Apple Pay] Call +canMakePayments on a work queue
https://bugs.webkit.org/show_bug.cgi?id=196179
<rdar://problem/45388749>

Reviewed by Brady Eidson.

Calling +canMakePayments on either PKPaymentAuthorizationController or
PKPaymentAuthorizationViewController results in synchronous IPC and is therefore very
expensive to call on the main thread. On iOS, these calls are made in the network process,
and on Mac in the UI process.

Call these methods on a work queue to avoid main thread spins.

  • Shared/ApplePay/WebPaymentCoordinatorProxy.cpp:

(WebKit::WebPaymentCoordinatorProxy::canMakePayments):

  • Shared/ApplePay/WebPaymentCoordinatorProxy.h:
  • Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm:

(WebKit::WebPaymentCoordinatorProxy::platformCanMakePayments):

  • Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm:

(WebKit::WebPaymentCoordinatorProxy::platformCanMakePayments):

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243443 r243447  
     12019-03-25  Andy Estes  <aestes@apple.com>
     2
     3        [Apple Pay] Call +canMakePayments on a work queue
     4        https://bugs.webkit.org/show_bug.cgi?id=196179
     5        <rdar://problem/45388749>
     6
     7        Reviewed by Brady Eidson.
     8
     9        Calling +canMakePayments on either PKPaymentAuthorizationController or
     10        PKPaymentAuthorizationViewController results in synchronous IPC and is therefore very
     11        expensive to call on the main thread. On iOS, these calls are made in the network process,
     12        and on Mac in the UI process.
     13
     14        Call these methods on a work queue to avoid main thread spins.
     15
     16        * Shared/ApplePay/WebPaymentCoordinatorProxy.cpp:
     17        (WebKit::WebPaymentCoordinatorProxy::canMakePayments):
     18        * Shared/ApplePay/WebPaymentCoordinatorProxy.h:
     19        * Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm:
     20        (WebKit::WebPaymentCoordinatorProxy::platformCanMakePayments):
     21        * Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm:
     22        (WebKit::WebPaymentCoordinatorProxy::platformCanMakePayments):
     23
    1242019-03-25  Andy Estes  <aestes@apple.com>
    225
  • trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.cpp

    r243443 r243447  
    4646WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy(WebPaymentCoordinatorProxy::Client& client)
    4747    : m_client { client }
     48    , m_canMakePaymentsQueue { WorkQueue::create("com.apple.WebKit.CanMakePayments") }
    4849{
    4950    m_client.paymentCoordinatorAddMessageReceiver(*this, Messages::WebPaymentCoordinatorProxy::messageReceiverName(), *this);
     
    7172void WebPaymentCoordinatorProxy::canMakePayments(CompletionHandler<void(bool)>&& reply)
    7273{
    73     reply(platformCanMakePayments());
     74    platformCanMakePayments(WTFMove(reply));
    7475}
    7576
  • trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h

    r243443 r243447  
    3535#include <wtf/RetainPtr.h>
    3636#include <wtf/WeakPtr.h>
     37#include <wtf/WorkQueue.h>
    3738
    3839#if USE(APPLE_INTERNAL_SDK)
     
    133134    void hidePaymentUI();
    134135
    135     bool platformCanMakePayments();
     136    void platformCanMakePayments(CompletionHandler<void(bool)>&&);
    136137    void platformCanMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, PAL::SessionID, WTF::Function<void(bool)>&& completionHandler);
    137138    void platformOpenPaymentSetup(const String& merchantIdentifier, const String& domainName, WTF::Function<void(bool)>&& completionHandler);
     
    184185
    185186    std::unique_ptr<PaymentAuthorizationPresenter> m_authorizationPresenter;
     187    Ref<WorkQueue> m_canMakePaymentsQueue;
    186188
    187189#if PLATFORM(MAC)
  • trunk/Source/WebKit/Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm

    r243412 r243447  
    3939namespace WebKit {
    4040
    41 bool WebPaymentCoordinatorProxy::platformCanMakePayments()
     41void WebPaymentCoordinatorProxy::platformCanMakePayments(CompletionHandler<void(bool)>&& completionHandler)
    4242{
    43     return [PAL::getPKPaymentAuthorizationControllerClass() canMakePayments];
     43    m_canMakePaymentsQueue->dispatch([theClass = retainPtr(PAL::getPKPaymentAuthorizationControllerClass()), completionHandler = WTFMove(completionHandler)]() mutable {
     44        RunLoop::main().dispatch([canMakePayments = [theClass canMakePayments], completionHandler = WTFMove(completionHandler)]() mutable {
     45            completionHandler(canMakePayments);
     46        });
     47    });
    4448}
    4549
  • trunk/Source/WebKit/Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm

    r243412 r243447  
    3636namespace WebKit {
    3737
    38 bool WebPaymentCoordinatorProxy::platformCanMakePayments()
     38void WebPaymentCoordinatorProxy::platformCanMakePayments(CompletionHandler<void(bool)>&& completionHandler)
    3939{
    4040    if (!PAL::isPassKitFrameworkAvailable())
    41         return false;
     41        return completionHandler(false);
    4242
    43     return [PAL::getPKPaymentAuthorizationViewControllerClass() canMakePayments];
     43    m_canMakePaymentsQueue->dispatch([theClass = retainPtr(PAL::getPKPaymentAuthorizationViewControllerClass()), completionHandler = WTFMove(completionHandler)]() mutable {
     44        RunLoop::main().dispatch([canMakePayments = [theClass canMakePayments], completionHandler = WTFMove(completionHandler)]() mutable {
     45            completionHandler(canMakePayments);
     46        });
     47    });
    4448}
    4549
Note: See TracChangeset for help on using the changeset viewer.