Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c304362 authored by Nate Fischer's avatar Nate Fischer
Browse files

Add WebViewClient#onSafeBrowsingHit() API

This adds the WebViewClient#onSafeBrowsingHit() API and its default
implementation.

This also adds the relevant constants. This includes
SAFE_BROWSING_THREAT_UNKNOWN, in case we expose new threat types in the
future.

Bug: 62723291
Test: N/A
Change-Id: I0b424a952466b23db4cf296573680a0a6c61b981
parent 09c2b234
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -48923,6 +48923,7 @@ package android.webkit {
    method public void onReceivedLoginRequest(android.webkit.WebView, java.lang.String, java.lang.String, java.lang.String);
    method public void onReceivedSslError(android.webkit.WebView, android.webkit.SslErrorHandler, android.net.http.SslError);
    method public boolean onRenderProcessGone(android.webkit.WebView, android.webkit.RenderProcessGoneDetail);
    method public void onSafeBrowsingHit(android.webkit.WebView, android.webkit.WebResourceRequest, int, android.webkit.ValueCallback<java.lang.Integer>);
    method public void onScaleChanged(android.webkit.WebView, float, float);
    method public deprecated void onTooManyRedirects(android.webkit.WebView, android.os.Message, android.os.Message);
    method public void onUnhandledKeyEvent(android.webkit.WebView, android.view.KeyEvent);
@@ -48947,6 +48948,13 @@ package android.webkit {
    field public static final int ERROR_UNSAFE_RESOURCE = -16; // 0xfffffff0
    field public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; // 0xfffffffd
    field public static final int ERROR_UNSUPPORTED_SCHEME = -10; // 0xfffffff6
    field public static final int SAFE_BROWSING_ACTION_BACK_TO_SAFETY = 2; // 0x2
    field public static final int SAFE_BROWSING_ACTION_PROCEED = 1; // 0x1
    field public static final int SAFE_BROWSING_ACTION_SHOW_INTERSTITIAL = 0; // 0x0
    field public static final int SAFE_BROWSING_THREAT_MALWARE = 1; // 0x1
    field public static final int SAFE_BROWSING_THREAT_PHISHING = 2; // 0x2
    field public static final int SAFE_BROWSING_THREAT_UNKNOWN = 0; // 0x0
    field public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE = 3; // 0x3
  }
  public abstract class WebViewDatabase {
+8 −0
Original line number Diff line number Diff line
@@ -52599,6 +52599,7 @@ package android.webkit {
    method public void onReceivedLoginRequest(android.webkit.WebView, java.lang.String, java.lang.String, java.lang.String);
    method public void onReceivedSslError(android.webkit.WebView, android.webkit.SslErrorHandler, android.net.http.SslError);
    method public boolean onRenderProcessGone(android.webkit.WebView, android.webkit.RenderProcessGoneDetail);
    method public void onSafeBrowsingHit(android.webkit.WebView, android.webkit.WebResourceRequest, int, android.webkit.ValueCallback<java.lang.Integer>);
    method public void onScaleChanged(android.webkit.WebView, float, float);
    method public deprecated void onTooManyRedirects(android.webkit.WebView, android.os.Message, android.os.Message);
    method public void onUnhandledKeyEvent(android.webkit.WebView, android.view.KeyEvent);
@@ -52623,6 +52624,13 @@ package android.webkit {
    field public static final int ERROR_UNSAFE_RESOURCE = -16; // 0xfffffff0
    field public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; // 0xfffffffd
    field public static final int ERROR_UNSUPPORTED_SCHEME = -10; // 0xfffffff6
    field public static final int SAFE_BROWSING_ACTION_BACK_TO_SAFETY = 2; // 0x2
    field public static final int SAFE_BROWSING_ACTION_PROCEED = 1; // 0x1
    field public static final int SAFE_BROWSING_ACTION_SHOW_INTERSTITIAL = 0; // 0x0
    field public static final int SAFE_BROWSING_THREAT_MALWARE = 1; // 0x1
    field public static final int SAFE_BROWSING_THREAT_PHISHING = 2; // 0x2
    field public static final int SAFE_BROWSING_THREAT_UNKNOWN = 0; // 0x0
    field public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE = 3; // 0x3
  }
  public abstract class WebViewDatabase {
+8 −0
Original line number Diff line number Diff line
@@ -49339,6 +49339,7 @@ package android.webkit {
    method public void onReceivedLoginRequest(android.webkit.WebView, java.lang.String, java.lang.String, java.lang.String);
    method public void onReceivedSslError(android.webkit.WebView, android.webkit.SslErrorHandler, android.net.http.SslError);
    method public boolean onRenderProcessGone(android.webkit.WebView, android.webkit.RenderProcessGoneDetail);
    method public void onSafeBrowsingHit(android.webkit.WebView, android.webkit.WebResourceRequest, int, android.webkit.ValueCallback<java.lang.Integer>);
    method public void onScaleChanged(android.webkit.WebView, float, float);
    method public deprecated void onTooManyRedirects(android.webkit.WebView, android.os.Message, android.os.Message);
    method public void onUnhandledKeyEvent(android.webkit.WebView, android.view.KeyEvent);
@@ -49363,6 +49364,13 @@ package android.webkit {
    field public static final int ERROR_UNSAFE_RESOURCE = -16; // 0xfffffff0
    field public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; // 0xfffffffd
    field public static final int ERROR_UNSUPPORTED_SCHEME = -10; // 0xfffffff6
    field public static final int SAFE_BROWSING_ACTION_BACK_TO_SAFETY = 2; // 0x2
    field public static final int SAFE_BROWSING_ACTION_PROCEED = 1; // 0x1
    field public static final int SAFE_BROWSING_ACTION_SHOW_INTERSTITIAL = 0; // 0x0
    field public static final int SAFE_BROWSING_THREAT_MALWARE = 1; // 0x1
    field public static final int SAFE_BROWSING_THREAT_PHISHING = 2; // 0x2
    field public static final int SAFE_BROWSING_THREAT_UNKNOWN = 0; // 0x0
    field public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE = 3; // 0x3
  }
  public abstract class WebViewDatabase {
+37 −0
Original line number Diff line number Diff line
@@ -237,6 +237,22 @@ public class WebViewClient {
    /** Resource load was cancelled by Safe Browsing */
    public static final int ERROR_UNSAFE_RESOURCE = -16;

    /** The resource was blocked for an unknown reason */
    public static final int SAFE_BROWSING_THREAT_UNKNOWN = 0;
    /** The resource was blocked because it contains malware */
    public static final int SAFE_BROWSING_THREAT_MALWARE = 1;
    /** The resource was blocked because it contains deceptive content */
    public static final int SAFE_BROWSING_THREAT_PHISHING = 2;
    /** The resource was blocked because it contains unwanted software */
    public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE = 3;

    /** Display the default interstitial */
    public static final int SAFE_BROWSING_ACTION_SHOW_INTERSTITIAL = 0;
    /** Act as if the user clicked "visit this unsafe site" */
    public static final int SAFE_BROWSING_ACTION_PROCEED = 1;
    /** Act as if the user clicked "Back to safety" */
    public static final int SAFE_BROWSING_ACTION_BACK_TO_SAFETY = 2;

    /**
     * Report an error to the host application. These errors are unrecoverable
     * (i.e. the main resource is unavailable). The errorCode parameter
@@ -496,4 +512,25 @@ public class WebViewClient {
    public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
        return false;
    }

    /**
     * Notify the host application that a loading URL has been flagged by Safe Browsing.
     *
     * The application must invoke the callback to indicate the preferred response. The default
     * behavior is to show an interstitial to the user (SAFE_BROWSING_ACTION_SHOW_INTERSTITIAL).
     *
     * If the application needs to show its own custom interstitial UI, the callback can be invoked
     * asynchronously with SAFE_BROWSING_ACTION_BACK_TO_SAFETY or SAFE_BROWSING_ACTION_PROCEED,
     * depending on user response.
     *
     * @param view The WebView that hit the malicious resource.
     * @param request Object containing the details of the request.
     * @param threatType The reason the resource was caught by Safe Browsing, corresponding to a
     *                   SAFE_BROWSING_THREAT_* value.
     * @param callback Applications must invoke this callback with one of SAFE_BROWSING_ACTION_*.
     */
    public void onSafeBrowsingHit(WebView view, WebResourceRequest request, int threatType,
            ValueCallback<Integer> callback) {
        callback.onReceiveValue(SAFE_BROWSING_ACTION_SHOW_INTERSTITIAL);
    }
}