Android WebView has supported core Safe Browsing features since 2017.
See the relevant Chromium classes in //components/safe_browsing/.
For info on the feature, see https://safebrowsing.google.com/.
If Google Play Services (AKA GMSCore) is uninstalled, disabled, or out-of-date, WebView cannot perform Safe Browsing checks (with the exception of hard-coded URLs). Before trying Safe Browsing locally, make sure this is up-to-date:
$ adb shell am start -a "android.intent.action.VIEW" -d "market://details?id=com.google.android.gms" # Then, manually update GMS in the UI.
If Google Play Services is installed, the user must opt into Google Play Protect's “Verify Apps” setting: Settings > Google > Security > Google Play Protect > Scan device for security threats
.
Safe Browsing is enabled by default, but applications can explicitly disable it with a manifest tag:
<manifest> <application> <meta-data android:name="android.webkit.WebView.EnableSafeBrowsing" android:value="false" /> ... </application> </manifest>
WebView supports Safe Browsing checks (for testing purposes) on hard-coded WebUI URLs defined in //components/safe_browsing/web_ui/constants.cc
(ex. chrome://safe-browsing/match?type=malware
).
These URLs don't show meaningful content, but will trigger an interstitial when trying to navigate to them. WebView relies on these URLs in our CTS tests, so they must never change (but more URLs may be added).
See this page.
Automated tests live here.
You can manually test Safe Browsing with the WebView Shell. Navigate to one of the hard-coded URLs mentioned above.
To test more complex scenarios and WebView's Safe Browsing APIs, please try out the open source WebView demo app.
As Chrome supports more threat types, so can WebView. The steps are:
WebViewClient.java
, please consult a WebView team member before this step). The new threat type constant should only be used when the application targets the new Android SDK: use SAFE_BROWSING_THREAT_UNKNOWN for apps with older targetSdkVersions (see http://crbug.com/887186#c15 and http://b/117470538).