- Revision
- 243447
- Author
- [email protected]
- Date
- 2019-03-25 13:23:43 -0700 (Mon, 25 Mar 2019)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (243446 => 243447)
--- trunk/Source/WebKit/ChangeLog 2019-03-25 19:11:31 UTC (rev 243446)
+++ trunk/Source/WebKit/ChangeLog 2019-03-25 20:23:43 UTC (rev 243447)
@@ -1,5 +1,28 @@
2019-03-25 Andy Estes <[email protected]>
+ [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):
+
+2019-03-25 Andy Estes <[email protected]>
+
[Apple Pay] Remove the AvailablePaymentNetworks synchronous message
https://bugs.webkit.org/show_bug.cgi?id=196180
Modified: trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.cpp (243446 => 243447)
--- trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.cpp 2019-03-25 19:11:31 UTC (rev 243446)
+++ trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.cpp 2019-03-25 20:23:43 UTC (rev 243447)
@@ -45,6 +45,7 @@
WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy(WebPaymentCoordinatorProxy::Client& client)
: m_client { client }
+ , m_canMakePaymentsQueue { WorkQueue::create("com.apple.WebKit.CanMakePayments") }
{
m_client.paymentCoordinatorAddMessageReceiver(*this, Messages::WebPaymentCoordinatorProxy::messageReceiverName(), *this);
finishConstruction(*this);
@@ -70,7 +71,7 @@
void WebPaymentCoordinatorProxy::canMakePayments(CompletionHandler<void(bool)>&& reply)
{
- reply(platformCanMakePayments());
+ platformCanMakePayments(WTFMove(reply));
}
void WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, PAL::SessionID sessionID, CompletionHandler<void(bool)>&& completionHandler)
Modified: trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h (243446 => 243447)
--- trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h 2019-03-25 19:11:31 UTC (rev 243446)
+++ trunk/Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h 2019-03-25 20:23:43 UTC (rev 243447)
@@ -34,6 +34,7 @@
#include <wtf/Forward.h>
#include <wtf/RetainPtr.h>
#include <wtf/WeakPtr.h>
+#include <wtf/WorkQueue.h>
#if USE(APPLE_INTERNAL_SDK)
#include <WebKitAdditions/WebPaymentCoordinatorProxyAdditions.h>
@@ -132,7 +133,7 @@
void didReachFinalState();
void hidePaymentUI();
- bool platformCanMakePayments();
+ void platformCanMakePayments(CompletionHandler<void(bool)>&&);
void platformCanMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, PAL::SessionID, WTF::Function<void(bool)>&& completionHandler);
void platformOpenPaymentSetup(const String& merchantIdentifier, const String& domainName, WTF::Function<void(bool)>&& completionHandler);
void platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLs, PAL::SessionID, const WebCore::ApplePaySessionPaymentRequest&, CompletionHandler<void(bool)>&&);
@@ -183,6 +184,7 @@
} m_merchantValidationState { MerchantValidationState::Idle };
std::unique_ptr<PaymentAuthorizationPresenter> m_authorizationPresenter;
+ Ref<WorkQueue> m_canMakePaymentsQueue;
#if PLATFORM(MAC)
uint64_t m_showPaymentUIRequestSeed { 0 };
Modified: trunk/Source/WebKit/Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm (243446 => 243447)
--- trunk/Source/WebKit/Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm 2019-03-25 19:11:31 UTC (rev 243446)
+++ trunk/Source/WebKit/Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm 2019-03-25 20:23:43 UTC (rev 243447)
@@ -38,9 +38,13 @@
namespace WebKit {
-bool WebPaymentCoordinatorProxy::platformCanMakePayments()
+void WebPaymentCoordinatorProxy::platformCanMakePayments(CompletionHandler<void(bool)>&& completionHandler)
{
- return [PAL::getPKPaymentAuthorizationControllerClass() canMakePayments];
+ m_canMakePaymentsQueue->dispatch([theClass = retainPtr(PAL::getPKPaymentAuthorizationControllerClass()), completionHandler = WTFMove(completionHandler)]() mutable {
+ RunLoop::main().dispatch([canMakePayments = [theClass canMakePayments], completionHandler = WTFMove(completionHandler)]() mutable {
+ completionHandler(canMakePayments);
+ });
+ });
}
void WebPaymentCoordinatorProxy::platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLStrings, PAL::SessionID sessionID, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler)
Modified: trunk/Source/WebKit/Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm (243446 => 243447)
--- trunk/Source/WebKit/Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm 2019-03-25 19:11:31 UTC (rev 243446)
+++ trunk/Source/WebKit/Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm 2019-03-25 20:23:43 UTC (rev 243447)
@@ -35,12 +35,16 @@
namespace WebKit {
-bool WebPaymentCoordinatorProxy::platformCanMakePayments()
+void WebPaymentCoordinatorProxy::platformCanMakePayments(CompletionHandler<void(bool)>&& completionHandler)
{
if (!PAL::isPassKitFrameworkAvailable())
- return false;
+ return completionHandler(false);
- return [PAL::getPKPaymentAuthorizationViewControllerClass() canMakePayments];
+ m_canMakePaymentsQueue->dispatch([theClass = retainPtr(PAL::getPKPaymentAuthorizationViewControllerClass()), completionHandler = WTFMove(completionHandler)]() mutable {
+ RunLoop::main().dispatch([canMakePayments = [theClass canMakePayments], completionHandler = WTFMove(completionHandler)]() mutable {
+ completionHandler(canMakePayments);
+ });
+ });
}
void WebPaymentCoordinatorProxy::platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLStrings, PAL::SessionID sessionID, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler)