diff options
| author | Xin Li <delphij@google.com> | 2017-12-06 11:51:59 -0800 |
|---|---|---|
| committer | Xin Li <delphij@google.com> | 2017-12-06 14:24:49 -0800 |
| commit | 5364be50cd0431c3b323fd8a3725df5146d01e99 (patch) | |
| tree | 379823ce960e903a2ba0313591c947ee2d595cf7 /core/java/android/webkit/WebViewClient.java | |
| parent | 8ab47567b2140da30257bc4e3b70495c8f17281e (diff) | |
| parent | 592f539419226f5d8652c434b34885b93fda0f8d (diff) | |
DO NOT MERGE: Merge Oreo MR1 into master
Exempt-From-Owner-Approval: Changes already landed internally
Change-Id: I727a014df2fb05a4b13cb67b1fcb760a8b387523
Diffstat (limited to 'core/java/android/webkit/WebViewClient.java')
| -rw-r--r-- | core/java/android/webkit/WebViewClient.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/java/android/webkit/WebViewClient.java b/core/java/android/webkit/WebViewClient.java index 788908ad9468..cbe75c405fe4 100644 --- a/core/java/android/webkit/WebViewClient.java +++ b/core/java/android/webkit/WebViewClient.java @@ -16,6 +16,7 @@ package android.webkit; +import android.annotation.IntDef; import android.graphics.Bitmap; import android.net.http.SslError; import android.os.Message; @@ -23,6 +24,9 @@ import android.view.InputEvent; import android.view.KeyEvent; import android.view.ViewRootImpl; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + public class WebViewClient { /** @@ -150,6 +154,10 @@ public class WebViewClient { * other than the UI thread so clients should exercise caution * when accessing private data or the view system. * + * <p>Note: when Safe Browsing is enabled, these URLs still undergo Safe Browsing checks. If + * this is undesired, whitelist the URL with {@link WebView#setSafeBrowsingWhitelist} or ignore + * the warning with {@link #onSafeBrowsingHit}. + * * @param view The {@link android.webkit.WebView} that is requesting the * resource. * @param url The raw url of the resource. @@ -173,6 +181,10 @@ public class WebViewClient { * other than the UI thread so clients should exercise caution * when accessing private data or the view system. * + * <p>Note: when Safe Browsing is enabled, these URLs still undergo Safe Browsing checks. If + * this is undesired, whitelist the URL with {@link WebView#setSafeBrowsingWhitelist} or ignore + * the warning with {@link #onSafeBrowsingHit}. + * * @param view The {@link android.webkit.WebView} that is requesting the * resource. * @param request Object containing the details of the request. @@ -237,6 +249,25 @@ public class WebViewClient { /** Resource load was cancelled by Safe Browsing */ public static final int ERROR_UNSAFE_RESOURCE = -16; + /** @hide */ + @IntDef({ + SAFE_BROWSING_THREAT_UNKNOWN, + SAFE_BROWSING_THREAT_MALWARE, + SAFE_BROWSING_THREAT_PHISHING, + SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE + }) + @Retention(RetentionPolicy.SOURCE) + public @interface SafeBrowsingThreat {} + + /** 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; + /** * Report an error to the host application. These errors are unrecoverable * (i.e. the main resource is unavailable). The errorCode parameter @@ -496,4 +527,24 @@ 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, with the reporting checkbox visible. + * + * If the application needs to show its own custom interstitial UI, the callback can be invoked + * asynchronously with backToSafety() or 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 one of the callback methods. + */ + public void onSafeBrowsingHit(WebView view, WebResourceRequest request, + @SafeBrowsingThreat int threatType, SafeBrowsingResponse callback) { + callback.showInterstitial(/* allowReporting */ true); + } } |
