[Apple Pay] Stop eagerly loading PassKit.framework
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 21 Jan 2018 04:29:46 +0000 (04:29 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 21 Jan 2018 04:29:46 +0000 (04:29 +0000)
commit74e43757de95e9c69a221aa8bfd061919b2b066f
tree8b09faca29d02f1bf08895e0c13640fcbf4a4db1
parentf671550fcdd56105b21c5c92c17f993b675e6dec
[Apple Pay] Stop eagerly loading PassKit.framework
https://bugs.webkit.org/show_bug.cgi?id=181911
<rdar://problem/36555369>

Reviewed by Tim Horton.

Source/WebCore:

r226458 and r226123 added code that caused PassKit.framework to be eagerly loaded when
initializing a WKWebView. This is costly and should only be done when Apple Pay is first used.

To avoid eagerly loading PassKit, this patch does two things:

1. Instead of sending the available payment networks as part of WebPageCreationParameters,
PaymentCoordinator asks for them using a syncrhonous message the first time they are needed.
2. Instead of setting the Apple Pay preference to false when PassKit can't be loaded,
the following API entry points check for a missing PassKit and return false, or throw
exceptions, or reject promises:
    - ApplePaySession.canMakePayments()
    - ApplePaySession.canMakePaymentsWithActiveCard()
    - ApplePaySession.openPaymentSetup()
    - ApplePaySession.begin()

No new tests for (1), which causes no change in behavior. (2) was manually verified by
locally moving aside PassKit.framework, but that's not possible to do in an automated test.

* Modules/applepay/PaymentCoordinator.cpp:
(WebCore::PaymentCoordinator::PaymentCoordinator):
(WebCore::PaymentCoordinator::validatedPaymentNetwork const):
(WebCore::toHashSet): Deleted.
* Modules/applepay/PaymentCoordinator.h:
* Modules/applepay/PaymentCoordinatorClient.h:
* loader/EmptyClients.cpp:
* page/MainFrame.cpp:
(WebCore::MainFrame::MainFrame):

Removed PaymentCoordinator::m_availablePaymentNetworks and made
PaymentCoordinator::validatedPaymentNetwork() call
PaymentCoordinatorClient::validatedPaymentNetwork() instead.

* page/PageConfiguration.h:

Removed availablePaymentNetworks from PageConfiguration.

* testing/Internals.cpp:
(WebCore::Internals::Internals):
* testing/MockPaymentCoordinator.cpp:
(WebCore::MockPaymentCoordinator::validatedPaymentNetwork):
* testing/MockPaymentCoordinator.h:

Implemented PaymentCoordinatorClient::validatedPaymentNetwork().

Source/WebKit:

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:

Removed availablePaymentNetworks from WebPageCreationParameters.

* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetApplePayEnabled):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):

Stopped calling WebPaymentCoordinatorProxy::platformSupportsPayments().

* UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp:
(WebKit::WebPaymentCoordinatorProxy::availablePaymentNetworks):
* UIProcess/ApplePay/WebPaymentCoordinatorProxy.h:
* UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in:

Added message AvailablePaymentNetworks, which synchronously returns a Vector of payment
networks.

* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::WebPaymentCoordinatorProxy::platformCanMakePayments):

Returned false if PassKitLibrary() fails.

(WebKit::WebPaymentCoordinatorProxy::platformCanMakePaymentsWithActiveCard):
(WebKit::WebPaymentCoordinatorProxy::platformOpenPaymentSetup):

Called completionHandler with false if PassKitLibrary() fails.

(WebKit::WebPaymentCoordinatorProxy::platformAvailablePaymentNetworks):
(WebKit::WebPaymentCoordinatorProxy::availablePaymentNetworks):

Renamed availablePaymentNetworks to platformAvailablePaymentNetworks

(WebKit::WebPaymentCoordinatorProxy::platformSupportsPayments): Deleted.

* UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm:
(WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI):

Called completionHandler with false if PassKitLibrary() fails.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):

Stopped calling WebPaymentCoordinatorProxy::availablePaymentNetworks().

* WebProcess/ApplePay/WebPaymentCoordinator.cpp:
(WebKit::WebPaymentCoordinator::availablePaymentNetworks):
(WebKit::WebPaymentCoordinator::validatedPaymentNetwork):
* WebProcess/ApplePay/WebPaymentCoordinator.h:

Implemented PaymentCoordinatorClient::validatedPaymentNetwork(). m_availablePaymentNetworks
starts off as std::nullopt, but is initialized by sending the AvailablePaymentNetworks sync
message the first time it's accessed.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):

Stopped setting PageConfiguration::availablePaymentNetworks.

Source/WebKitLegacy/mac:

* WebCoreSupport/WebPaymentCoordinatorClient.h:
* WebCoreSupport/WebPaymentCoordinatorClient.mm:
(WebPaymentCoordinatorClient::validatedPaymentNetwork):

Implemented PaymentCoordinatorClient::validatedPaymentNetwork().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227274 268f45cc-cd09-0410-ab3c-d52691b4dbfc
27 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/PaymentCoordinator.cpp
Source/WebCore/Modules/applepay/PaymentCoordinator.h
Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/page/MainFrame.cpp
Source/WebCore/page/PageConfiguration.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/MockPaymentCoordinator.cpp
Source/WebCore/testing/MockPaymentCoordinator.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp
Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h
Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in
Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm
Source/WebKit/UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/WebProcess/ApplePay/WebPaymentCoordinator.cpp
Source/WebKit/WebProcess/ApplePay/WebPaymentCoordinator.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebPaymentCoordinatorClient.h
Source/WebKitLegacy/mac/WebCoreSupport/WebPaymentCoordinatorClient.mm