[WebAuthn] Enable WebAuthn by default for MobileSafari and SafariViewService
https://bugs.webkit.org/show_bug.cgi?id=201369
<rdar://problem/54903724>

Reviewed by Brent Fulgham.

Source/WebCore:

* platform/RuntimeApplicationChecks.h:
* platform/cocoa/RuntimeApplicationChecksCocoa.mm:
(WebCore::IOSApplication::isSafariViewService):
Adds a way to detect SafariViewService.

Source/WebKit:

Communications to security keys require entitlements, which are not guaranteed to be present in third party
WKWebView clients. Therefore, only enable WebAuthn by default for MobileSafari and SafariViewService.

* Shared/WebPreferences.yaml:
* Shared/WebPreferencesDefaultValues.cpp:
(WebKit::defaultWebAuthenticationEnabled):
* Shared/WebPreferencesDefaultValues.h:

LayoutTests:

* http/wpt/webauthn/public-key-credential-get-success-nfc.https.html:
Imporves the test a bit.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@249436 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index d16a95b..166971a 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2019-09-03  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [WebAuthn] Enable WebAuthn by default for MobileSafari and SafariViewService
+        https://bugs.webkit.org/show_bug.cgi?id=201369
+        <rdar://problem/54903724>
+
+        Reviewed by Brent Fulgham.
+
+        * http/wpt/webauthn/public-key-credential-get-success-nfc.https.html:
+        Imporves the test a bit.
+
 2019-09-03  Antoine Quint  <graouts@apple.com>
 
         [iOS] Treat a two-finger single tap as if the user tapped with the Cmd key pressed
diff --git a/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-nfc.https.html b/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-nfc.https.html
index 9321c90..fc7c6aa 100644
--- a/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-nfc.https.html
+++ b/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-nfc.https.html
@@ -25,7 +25,7 @@
         const options = {
             publicKey: {
                 challenge: Base64URL.parse("MTIzNDU2"),
-                allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
+                allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64), transports: ["nfc"] }],
                 timeout: 100
             }
         };
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index f2ff828..a5617cb 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,16 @@
+2019-09-03  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [WebAuthn] Enable WebAuthn by default for MobileSafari and SafariViewService
+        https://bugs.webkit.org/show_bug.cgi?id=201369
+        <rdar://problem/54903724>
+
+        Reviewed by Brent Fulgham.
+
+        * platform/RuntimeApplicationChecks.h:
+        * platform/cocoa/RuntimeApplicationChecksCocoa.mm:
+        (WebCore::IOSApplication::isSafariViewService):
+        Adds a way to detect SafariViewService.
+
 2019-09-03  Simon Fraser  <simon.fraser@apple.com>
 
         Make "clips compositing descendants" an indirect compositing reason
diff --git a/Source/WebCore/platform/RuntimeApplicationChecks.h b/Source/WebCore/platform/RuntimeApplicationChecks.h
index e28468d..dde7405 100644
--- a/Source/WebCore/platform/RuntimeApplicationChecks.h
+++ b/Source/WebCore/platform/RuntimeApplicationChecks.h
@@ -79,6 +79,7 @@
 WEBCORE_EXPORT bool isMobileMail();
 WEBCORE_EXPORT bool isMailCompositionService();
 WEBCORE_EXPORT bool isMobileSafari();
+WEBCORE_EXPORT bool isSafariViewService();
 WEBCORE_EXPORT bool isIMDb();
 WEBCORE_EXPORT bool isWebBookmarksD();
 WEBCORE_EXPORT bool isDumpRenderTree();
diff --git a/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm b/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm
index a9cac9a..8a11e67 100644
--- a/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm
+++ b/Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm
@@ -214,6 +214,12 @@
     return isMobileSafari;
 }
 
+bool IOSApplication::isSafariViewService()
+{
+    static bool isSafariViewService = applicationBundleIsEqualTo("com.apple.SafariViewService"_s);
+    return isSafariViewService;
+}
+
 bool IOSApplication::isIMDb()
 {
     static bool isIMDb = applicationBundleIsEqualTo("com.imdb.imdb"_s);
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index a50e898..5745945 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,19 @@
+2019-09-03  Jiewen Tan  <jiewen_tan@apple.com>
+
+        [WebAuthn] Enable WebAuthn by default for MobileSafari and SafariViewService
+        https://bugs.webkit.org/show_bug.cgi?id=201369
+        <rdar://problem/54903724>
+
+        Reviewed by Brent Fulgham.
+
+        Communications to security keys require entitlements, which are not guaranteed to be present in third party
+        WKWebView clients. Therefore, only enable WebAuthn by default for MobileSafari and SafariViewService.
+
+        * Shared/WebPreferences.yaml:
+        * Shared/WebPreferencesDefaultValues.cpp:
+        (WebKit::defaultWebAuthenticationEnabled):
+        * Shared/WebPreferencesDefaultValues.h:
+
 2019-09-03  Chris Dumez  <cdumez@apple.com>
 
         Rename WebPage::pageID() to WebPage::identifier()
diff --git a/Source/WebKit/Shared/WebPreferences.yaml b/Source/WebKit/Shared/WebPreferences.yaml
index c6ea609..70b0e48 100644
--- a/Source/WebKit/Shared/WebPreferences.yaml
+++ b/Source/WebKit/Shared/WebPreferences.yaml
@@ -767,7 +767,7 @@
 
 WebAuthenticationEnabled:
   type: bool
-  defaultValue: DEFAULT_WEB_AUTHENTICATION_ENABLED
+  defaultValue: defaultWebAuthenticationEnabled()
   humanReadableName: "Web Authentication"
   humanReadableDescription: "Enable Web Authentication support"
   webcoreBinding: RuntimeEnabledFeatures
diff --git a/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp b/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp
index ae650a6..fe14e3f 100644
--- a/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp
+++ b/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp
@@ -77,4 +77,15 @@
 
 #endif // ENABLE(TEXT_AUTOSIZING) && !PLATFORM(IOS_FAMILY)
 
+bool defaultWebAuthenticationEnabled()
+{
+#if PLATFORM(IOS_FAMILY)
+    return WebCore::IOSApplication::isMobileSafari() || WebCore::IOSApplication::isSafariViewService();
+#elif PLATFORM(MAC)
+    return true;
+#else
+    return false;
+#endif
+}
+
 } // namespace WebKit
diff --git a/Source/WebKit/Shared/WebPreferencesDefaultValues.h b/Source/WebKit/Shared/WebPreferencesDefaultValues.h
index 1ca4408..011dc44 100644
--- a/Source/WebKit/Shared/WebPreferencesDefaultValues.h
+++ b/Source/WebKit/Shared/WebPreferencesDefaultValues.h
@@ -270,12 +270,6 @@
 #define DEFAULT_APPLE_PAY_ENABLED false
 #endif
 
-#if PLATFORM(MAC)
-#define DEFAULT_WEB_AUTHENTICATION_ENABLED true
-#else
-#define DEFAULT_WEB_AUTHENTICATION_ENABLED false
-#endif
-
 namespace WebKit {
 
 bool defaultPassiveTouchListenersAsDefaultOnDocument();
@@ -286,4 +280,6 @@
 bool defaultTextAutosizingUsesIdempotentMode();
 #endif
 
+bool defaultWebAuthenticationEnabled();
+
 } // namespace WebKit