[Apple Pay] Disable Apple Pay on platforms that don't have PassKit.framework
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jan 2018 21:28:05 +0000 (21:28 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jan 2018 21:28:05 +0000 (21:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181335
<rdar://problem/36311296>

Reviewed by Brady Eidson.

When Safari is running in the macOS Base System, PassKit.framework is not available.
If we fail to dlopen PassKit, we should disable Apple Pay.

* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetApplePayEnabled):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/ApplePay/WebPaymentCoordinatorProxy.h:
* UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::WebPaymentCoordinatorProxy::availablePaymentNetworks):
(WebKit::WebPaymentCoordinatorProxy::platformSupportsPayments):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226458 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h
Source/WebKit/UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm

index 2e250ea..24116d0 100644 (file)
@@ -1,3 +1,23 @@
+2018-01-05  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Disable Apple Pay on platforms that don't have PassKit.framework
+        https://bugs.webkit.org/show_bug.cgi?id=181335
+        <rdar://problem/36311296>
+
+        Reviewed by Brady Eidson.
+
+        When Safari is running in the macOS Base System, PassKit.framework is not available.
+        If we fail to dlopen PassKit, we should disable Apple Pay.
+
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetApplePayEnabled):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h:
+        * UIProcess/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
+        (WebKit::WebPaymentCoordinatorProxy::availablePaymentNetworks):
+        (WebKit::WebPaymentCoordinatorProxy::platformSupportsPayments):
+
 2018-01-05  Dan Bernstein  <mitz@apple.com>
 
         Fixed the build following AppKit API deprecations in a recent SDKs
index a6d2510..5ecbcbb 100644 (file)
 #include <WebCore/Settings.h>
 #include <wtf/RefPtr.h>
 
+#if ENABLE(APPLE_PAY)
+#include "WebPaymentCoordinatorProxy.h"
+#endif
+
 using namespace WebKit;
 
 WKTypeID WKPreferencesGetTypeID()
@@ -1777,6 +1781,10 @@ WK_EXPORT bool WKPreferencesGetApplePayEnabled(WKPreferencesRef preferencesRef)
 
 void WKPreferencesSetApplePayEnabled(WKPreferencesRef preferencesRef, bool enabled)
 {
+#if ENABLE(APPLE_PAY)
+    if (!WebPaymentCoordinatorProxy::platformSupportsPayments())
+        enabled = false;
+#endif
     WebKit::toImpl(preferencesRef)->setApplePayEnabled(enabled);
 }
 
index 323b968..7124412 100644 (file)
@@ -74,6 +74,7 @@
 #import "WebFullScreenManagerProxy.h"
 #import "WebPageGroup.h"
 #import "WebPageProxy.h"
+#import "WebPaymentCoordinatorProxy.h"
 #import "WebPreferencesKeys.h"
 #import "WebProcessPool.h"
 #import "WebProcessProxy.h"
@@ -588,7 +589,8 @@ static void validate(WKWebViewConfiguration *configuration)
 #endif
 
 #if ENABLE(APPLE_PAY)
-    pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::applePayEnabledKey(), WebKit::WebPreferencesStore::Value(!![_configuration _applePayEnabled]));
+    bool applePayEnabled = [_configuration _applePayEnabled] && WebKit::WebPaymentCoordinatorProxy::platformSupportsPayments();
+    pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::applePayEnabledKey(), WebKit::WebPreferencesStore::Value(applePayEnabled));
 #endif
 
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::needsStorageAccessFromFileURLsQuirkKey(), WebKit::WebPreferencesStore::Value(!![_configuration _needsStorageAccessFromFileURLsQuirk]));
index 520fb20..c9741b0 100644 (file)
@@ -69,6 +69,7 @@ public:
 
     void hidePaymentUI();
 
+    static bool platformSupportsPayments();
     static Vector<String> availablePaymentNetworks();
 
 private:
index 94111fe..876c546 100644 (file)
@@ -39,7 +39,7 @@
 #import <wtf/SoftLinking.h>
 
 #if PLATFORM(MAC)
-SOFT_LINK_PRIVATE_FRAMEWORK(PassKit)
+SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(PassKit)
 #else
 SOFT_LINK_FRAMEWORK(PassKit)
 #endif
@@ -849,6 +849,9 @@ void WebPaymentCoordinatorProxy::platformCompletePaymentMethodSelection(const st
 
 Vector<String> WebPaymentCoordinatorProxy::availablePaymentNetworks()
 {
+    if (!platformSupportsPayments())
+        return { };
+
     NSArray<PKPaymentNetwork> *availableNetworks = [getPKPaymentRequestClass() availableNetworks];
     Vector<String> result;
     result.reserveInitialCapacity(availableNetworks.count);
@@ -857,6 +860,15 @@ Vector<String> WebPaymentCoordinatorProxy::availablePaymentNetworks()
     return result;
 }
 
+bool WebPaymentCoordinatorProxy::platformSupportsPayments()
+{
+#if PLATFORM(MAC)
+    return PassKitLibrary();
+#else
+    return true;
+#endif
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(APPLE_PAY)