The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.webkit; |
| 18 | |
Nate Fischer | 5ab00b3 | 2017-07-13 15:28:21 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
| 22 | import android.net.http.SslError; |
| 23 | import android.os.Message; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 24 | import android.view.InputEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.view.KeyEvent; |
John Reck | d6b1098 | 2012-04-19 18:01:35 -0700 | [diff] [blame] | 26 | import android.view.ViewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
Nate Fischer | 5ab00b3 | 2017-07-13 15:28:21 -0700 | [diff] [blame] | 28 | import java.lang.annotation.Retention; |
| 29 | import java.lang.annotation.RetentionPolicy; |
| 30 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | public class WebViewClient { |
| 32 | |
| 33 | /** |
Paul Miller | f2043b4 | 2018-07-25 18:11:26 -0700 | [diff] [blame] | 34 | * Give the host application a chance to take control when a URL is about to be loaded in the |
| 35 | * current WebView. If a WebViewClient is not provided, by default WebView will ask Activity |
| 36 | * Manager to choose the proper handler for the URL. If a WebViewClient is provided, returning |
| 37 | * {@code true} causes the current WebView to abort loading the URL, while returning |
| 38 | * {@code false} causes the WebView to continue loading the URL as usual. |
| 39 | * |
| 40 | * <p class="note"><b>Note:</b> Do not call {@link WebView#loadUrl(String)} with the same |
| 41 | * URL and then return {@code true}. This unnecessarily cancels the current load and starts a |
| 42 | * new load with the same URL. The correct way to continue loading a given URL is to simply |
| 43 | * return {@code false}, without calling {@link WebView#loadUrl(String)}. |
| 44 | * |
| 45 | * <p class="note"><b>Note:</b> This method is not called for POST requests. |
| 46 | * |
| 47 | * <p class="note"><b>Note:</b> This method may be called for subframes and with non-HTTP(S) |
| 48 | * schemes; calling {@link WebView#loadUrl(String)} with such a URL will fail. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 49 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | * @param view The WebView that is initiating the callback. |
Paul Miller | f2043b4 | 2018-07-25 18:11:26 -0700 | [diff] [blame] | 51 | * @param url The URL to be loaded. |
| 52 | * @return {@code true} to cancel the current load, otherwise return {@code false}. |
Mikhail Naganov | b851929 | 2015-10-26 13:27:33 -0700 | [diff] [blame] | 53 | * @deprecated Use {@link #shouldOverrideUrlLoading(WebView, WebResourceRequest) |
| 54 | * shouldOverrideUrlLoading(WebView, WebResourceRequest)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | */ |
Mikhail Naganov | b851929 | 2015-10-26 13:27:33 -0700 | [diff] [blame] | 56 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | /** |
Paul Miller | f2043b4 | 2018-07-25 18:11:26 -0700 | [diff] [blame] | 62 | * Give the host application a chance to take control when a URL is about to be loaded in the |
| 63 | * current WebView. If a WebViewClient is not provided, by default WebView will ask Activity |
| 64 | * Manager to choose the proper handler for the URL. If a WebViewClient is provided, returning |
| 65 | * {@code true} causes the current WebView to abort loading the URL, while returning |
| 66 | * {@code false} causes the WebView to continue loading the URL as usual. |
Mikhail Naganov | b851929 | 2015-10-26 13:27:33 -0700 | [diff] [blame] | 67 | * |
Paul Miller | f2043b4 | 2018-07-25 18:11:26 -0700 | [diff] [blame] | 68 | * <p class="note"><b>Note:</b> Do not call {@link WebView#loadUrl(String)} with the request's |
| 69 | * URL and then return {@code true}. This unnecessarily cancels the current load and starts a |
| 70 | * new load with the same URL. The correct way to continue loading a given URL is to simply |
| 71 | * return {@code false}, without calling {@link WebView#loadUrl(String)}. |
| 72 | * |
| 73 | * <p class="note"><b>Note:</b> This method is not called for POST requests. |
| 74 | * |
| 75 | * <p class="note"><b>Note:</b> This method may be called for subframes and with non-HTTP(S) |
| 76 | * schemes; calling {@link WebView#loadUrl(String)} with such a URL will fail. |
Mikhail Naganov | b851929 | 2015-10-26 13:27:33 -0700 | [diff] [blame] | 77 | * |
| 78 | * @param view The WebView that is initiating the callback. |
| 79 | * @param request Object containing the details of the request. |
Paul Miller | f2043b4 | 2018-07-25 18:11:26 -0700 | [diff] [blame] | 80 | * @return {@code true} to cancel the current load, otherwise return {@code false}. |
Mikhail Naganov | b851929 | 2015-10-26 13:27:33 -0700 | [diff] [blame] | 81 | */ |
| 82 | public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { |
| 83 | return shouldOverrideUrlLoading(view, request.getUrl().toString()); |
| 84 | } |
| 85 | |
| 86 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | * Notify the host application that a page has started loading. This method |
| 88 | * is called once for each main frame load so a page with iframes or |
| 89 | * framesets will call onPageStarted one time for the main frame. This also |
| 90 | * means that onPageStarted will not be called when the contents of an |
Marcin Kosiba | 16687cc | 2015-01-27 17:35:49 +0000 | [diff] [blame] | 91 | * embedded frame changes, i.e. clicking a link whose target is an iframe, |
| 92 | * it will also not be called for fragment navigations (navigations to |
| 93 | * #fragment_id). |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 94 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | * @param view The WebView that is initiating the callback. |
| 96 | * @param url The url to be loaded. |
| 97 | * @param favicon The favicon for this page if it already exists in the |
| 98 | * database. |
| 99 | */ |
| 100 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Notify the host application that a page has finished loading. This method |
| 105 | * is called only for main frame. When onPageFinished() is called, the |
| 106 | * rendering picture may not be updated yet. To get the notification for the |
| 107 | * new Picture, use {@link WebView.PictureListener#onNewPicture}. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 108 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | * @param view The WebView that is initiating the callback. |
| 110 | * @param url The url of the page. |
| 111 | */ |
| 112 | public void onPageFinished(WebView view, String url) { |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Notify the host application that the WebView will load the resource |
| 117 | * specified by the given url. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 118 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | * @param view The WebView that is initiating the callback. |
| 120 | * @param url The url of the resource the WebView will load. |
| 121 | */ |
| 122 | public void onLoadResource(WebView view, String url) { |
| 123 | } |
| 124 | |
| 125 | /** |
Tobias Sargeant | b365604 | 2015-05-13 11:23:57 +0100 | [diff] [blame] | 126 | * Notify the host application that {@link android.webkit.WebView} content left over from |
| 127 | * previous page navigations will no longer be drawn. |
Tobias Sargeant | a8352f4 | 2015-03-03 18:07:40 +0000 | [diff] [blame] | 128 | * |
Tobias Sargeant | b365604 | 2015-05-13 11:23:57 +0100 | [diff] [blame] | 129 | * <p>This callback can be used to determine the point at which it is safe to make a recycled |
| 130 | * {@link android.webkit.WebView} visible, ensuring that no stale content is shown. It is called |
| 131 | * at the earliest point at which it can be guaranteed that {@link WebView#onDraw} will no |
| 132 | * longer draw any content from previous navigations. The next draw will display either the |
| 133 | * {@link WebView#setBackgroundColor background color} of the {@link WebView}, or some of the |
| 134 | * contents of the newly loaded page. |
Tobias Sargeant | a8352f4 | 2015-03-03 18:07:40 +0000 | [diff] [blame] | 135 | * |
Tobias Sargeant | b365604 | 2015-05-13 11:23:57 +0100 | [diff] [blame] | 136 | * <p>This method is called when the body of the HTTP response has started loading, is reflected |
| 137 | * in the DOM, and will be visible in subsequent draws. This callback occurs early in the |
| 138 | * document loading process, and as such you should expect that linked resources (for example, |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 139 | * CSS and images) may not be available. |
Tobias Sargeant | a8352f4 | 2015-03-03 18:07:40 +0000 | [diff] [blame] | 140 | * |
Tobias Sargeant | b365604 | 2015-05-13 11:23:57 +0100 | [diff] [blame] | 141 | * <p>For more fine-grained notification of visual state updates, see {@link |
Nate Fischer | f02f846 | 2017-09-11 15:16:33 -0700 | [diff] [blame] | 142 | * WebView#postVisualStateCallback}. |
Tobias Sargeant | a8352f4 | 2015-03-03 18:07:40 +0000 | [diff] [blame] | 143 | * |
Tobias Sargeant | b365604 | 2015-05-13 11:23:57 +0100 | [diff] [blame] | 144 | * <p>Please note that all the conditions and recommendations applicable to |
Nate Fischer | f02f846 | 2017-09-11 15:16:33 -0700 | [diff] [blame] | 145 | * {@link WebView#postVisualStateCallback} also apply to this API. |
Tobias Sargeant | b365604 | 2015-05-13 11:23:57 +0100 | [diff] [blame] | 146 | * |
Nate Fischer | f02f846 | 2017-09-11 15:16:33 -0700 | [diff] [blame] | 147 | * <p>This callback is only called for main frame navigations. |
Tobias Sargeant | b365604 | 2015-05-13 11:23:57 +0100 | [diff] [blame] | 148 | * |
| 149 | * @param view The {@link android.webkit.WebView} for which the navigation occurred. |
| 150 | * @param url The URL corresponding to the page navigation that triggered this callback. |
Tobias Sargeant | a8352f4 | 2015-03-03 18:07:40 +0000 | [diff] [blame] | 151 | */ |
| 152 | public void onPageCommitVisible(WebView view, String url) { |
| 153 | } |
| 154 | |
| 155 | /** |
Patrick Scott | c12544a | 2010-11-11 13:16:44 -0500 | [diff] [blame] | 156 | * Notify the host application of a resource request and allow the |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 157 | * application to return the data. If the return value is {@code null}, the WebView |
Patrick Scott | c12544a | 2010-11-11 13:16:44 -0500 | [diff] [blame] | 158 | * will continue to load the resource as usual. Otherwise, the return |
Nate Fischer | 7051dd1 | 2017-10-26 14:51:25 -0700 | [diff] [blame] | 159 | * response and data will be used. |
| 160 | * |
Nate Fischer | db01023 | 2018-03-26 18:46:31 -0700 | [diff] [blame] | 161 | * <p>This callback is invoked for a variety of URL schemes (e.g., {@code http(s):}, {@code |
| 162 | * data:}, {@code file:}, etc.), not only those schemes which send requests over the network. |
| 163 | * This is not called for {@code javascript:} URLs, {@code blob:} URLs, or for assets accessed |
| 164 | * via {@code file:///android_asset/} or {@code file:///android_res/} URLs. |
| 165 | * |
| 166 | * <p>In the case of redirects, this is only called for the initial resource URL, not any |
| 167 | * subsequent redirect URLs. |
| 168 | * |
Nate Fischer | 7051dd1 | 2017-10-26 14:51:25 -0700 | [diff] [blame] | 169 | * <p class="note"><b>Note:</b> This method is called on a thread |
Martin Kosiba | 15cb825 | 2012-11-13 14:40:41 +0000 | [diff] [blame] | 170 | * other than the UI thread so clients should exercise caution |
| 171 | * when accessing private data or the view system. |
Patrick Scott | c12544a | 2010-11-11 13:16:44 -0500 | [diff] [blame] | 172 | * |
Nate Fischer | 7051dd1 | 2017-10-26 14:51:25 -0700 | [diff] [blame] | 173 | * <p class="note"><b>Note:</b> When Safe Browsing is enabled, these URLs still undergo Safe |
| 174 | * Browsing checks. If this is undesired, whitelist the URL with {@link |
| 175 | * WebView#setSafeBrowsingWhitelist} or ignore the warning with {@link #onSafeBrowsingHit}. |
Nate Fischer | b5a9bf4 | 2017-09-11 15:42:28 -0700 | [diff] [blame] | 176 | * |
Patrick Scott | c12544a | 2010-11-11 13:16:44 -0500 | [diff] [blame] | 177 | * @param view The {@link android.webkit.WebView} that is requesting the |
| 178 | * resource. |
| 179 | * @param url The raw url of the resource. |
| 180 | * @return A {@link android.webkit.WebResourceResponse} containing the |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 181 | * response information or {@code null} if the WebView should load the |
Patrick Scott | c12544a | 2010-11-11 13:16:44 -0500 | [diff] [blame] | 182 | * resource itself. |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 183 | * @deprecated Use {@link #shouldInterceptRequest(WebView, WebResourceRequest) |
| 184 | * shouldInterceptRequest(WebView, WebResourceRequest)} instead. |
Patrick Scott | c12544a | 2010-11-11 13:16:44 -0500 | [diff] [blame] | 185 | */ |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 186 | @Deprecated |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame] | 187 | @Nullable |
Patrick Scott | c12544a | 2010-11-11 13:16:44 -0500 | [diff] [blame] | 188 | public WebResourceResponse shouldInterceptRequest(WebView view, |
| 189 | String url) { |
| 190 | return null; |
| 191 | } |
| 192 | |
| 193 | /** |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 194 | * Notify the host application of a resource request and allow the |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 195 | * application to return the data. If the return value is {@code null}, the WebView |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 196 | * will continue to load the resource as usual. Otherwise, the return |
Nate Fischer | 7051dd1 | 2017-10-26 14:51:25 -0700 | [diff] [blame] | 197 | * response and data will be used. |
| 198 | * |
Nate Fischer | db01023 | 2018-03-26 18:46:31 -0700 | [diff] [blame] | 199 | * <p>This callback is invoked for a variety of URL schemes (e.g., {@code http(s):}, {@code |
| 200 | * data:}, {@code file:}, etc.), not only those schemes which send requests over the network. |
| 201 | * This is not called for {@code javascript:} URLs, {@code blob:} URLs, or for assets accessed |
| 202 | * via {@code file:///android_asset/} or {@code file:///android_res/} URLs. |
| 203 | * |
| 204 | * <p>In the case of redirects, this is only called for the initial resource URL, not any |
| 205 | * subsequent redirect URLs. |
| 206 | * |
Nate Fischer | 7051dd1 | 2017-10-26 14:51:25 -0700 | [diff] [blame] | 207 | * <p class="note"><b>Note:</b> This method is called on a thread |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 208 | * other than the UI thread so clients should exercise caution |
| 209 | * when accessing private data or the view system. |
| 210 | * |
Nate Fischer | 7051dd1 | 2017-10-26 14:51:25 -0700 | [diff] [blame] | 211 | * <p class="note"><b>Note:</b> When Safe Browsing is enabled, these URLs still undergo Safe |
| 212 | * Browsing checks. If this is undesired, whitelist the URL with {@link |
| 213 | * WebView#setSafeBrowsingWhitelist} or ignore the warning with {@link #onSafeBrowsingHit}. |
Nate Fischer | b5a9bf4 | 2017-09-11 15:42:28 -0700 | [diff] [blame] | 214 | * |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 215 | * @param view The {@link android.webkit.WebView} that is requesting the |
| 216 | * resource. |
| 217 | * @param request Object containing the details of the request. |
| 218 | * @return A {@link android.webkit.WebResourceResponse} containing the |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 219 | * response information or {@code null} if the WebView should load the |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 220 | * resource itself. |
| 221 | */ |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame] | 222 | @Nullable |
Marcin Kosiba | d72e7ba | 2014-07-15 17:33:47 +0100 | [diff] [blame] | 223 | public WebResourceResponse shouldInterceptRequest(WebView view, |
| 224 | WebResourceRequest request) { |
| 225 | return shouldInterceptRequest(view, request.getUrl().toString()); |
| 226 | } |
| 227 | |
| 228 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | * Notify the host application that there have been an excessive number of |
| 230 | * HTTP redirects. As the host application if it would like to continue |
| 231 | * trying to load the resource. The default behavior is to send the cancel |
| 232 | * message. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 233 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | * @param view The WebView that is initiating the callback. |
| 235 | * @param cancelMsg The message to send if the host wants to cancel |
| 236 | * @param continueMsg The message to send if the host wants to continue |
Patrick Scott | 6a5b0ec | 2010-01-08 09:55:33 -0500 | [diff] [blame] | 237 | * @deprecated This method is no longer called. When the WebView encounters |
| 238 | * a redirect loop, it will cancel the load. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | */ |
Kristian Monsen | b5503c1 | 2010-08-31 14:02:38 +0100 | [diff] [blame] | 240 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | public void onTooManyRedirects(WebView view, Message cancelMsg, |
| 242 | Message continueMsg) { |
| 243 | cancelMsg.sendToTarget(); |
| 244 | } |
| 245 | |
Patrick Scott | 05c9ed9 | 2009-08-25 13:51:08 -0400 | [diff] [blame] | 246 | // These ints must match up to the hidden values in EventHandler. |
| 247 | /** Generic error */ |
| 248 | public static final int ERROR_UNKNOWN = -1; |
| 249 | /** Server or proxy hostname lookup failed */ |
| 250 | public static final int ERROR_HOST_LOOKUP = -2; |
| 251 | /** Unsupported authentication scheme (not basic or digest) */ |
| 252 | public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; |
| 253 | /** User authentication failed on server */ |
| 254 | public static final int ERROR_AUTHENTICATION = -4; |
| 255 | /** User authentication failed on proxy */ |
| 256 | public static final int ERROR_PROXY_AUTHENTICATION = -5; |
| 257 | /** Failed to connect to the server */ |
| 258 | public static final int ERROR_CONNECT = -6; |
| 259 | /** Failed to read or write to the server */ |
| 260 | public static final int ERROR_IO = -7; |
| 261 | /** Connection timed out */ |
| 262 | public static final int ERROR_TIMEOUT = -8; |
| 263 | /** Too many redirects */ |
| 264 | public static final int ERROR_REDIRECT_LOOP = -9; |
| 265 | /** Unsupported URI scheme */ |
| 266 | public static final int ERROR_UNSUPPORTED_SCHEME = -10; |
| 267 | /** Failed to perform SSL handshake */ |
| 268 | public static final int ERROR_FAILED_SSL_HANDSHAKE = -11; |
| 269 | /** Malformed URL */ |
| 270 | public static final int ERROR_BAD_URL = -12; |
| 271 | /** Generic file error */ |
| 272 | public static final int ERROR_FILE = -13; |
| 273 | /** File not found */ |
| 274 | public static final int ERROR_FILE_NOT_FOUND = -14; |
| 275 | /** Too many requests during this load */ |
| 276 | public static final int ERROR_TOO_MANY_REQUESTS = -15; |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 277 | /** Resource load was canceled by Safe Browsing */ |
Nate Fischer | 3c7c937 | 2017-03-06 17:11:40 -0800 | [diff] [blame] | 278 | public static final int ERROR_UNSAFE_RESOURCE = -16; |
Patrick Scott | 05c9ed9 | 2009-08-25 13:51:08 -0400 | [diff] [blame] | 279 | |
Nate Fischer | 5ab00b3 | 2017-07-13 15:28:21 -0700 | [diff] [blame] | 280 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 281 | @IntDef(prefix = { "SAFE_BROWSING_THREAT_" }, value = { |
| 282 | SAFE_BROWSING_THREAT_UNKNOWN, |
| 283 | SAFE_BROWSING_THREAT_MALWARE, |
| 284 | SAFE_BROWSING_THREAT_PHISHING, |
| 285 | SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE |
Nate Fischer | 5ab00b3 | 2017-07-13 15:28:21 -0700 | [diff] [blame] | 286 | }) |
| 287 | @Retention(RetentionPolicy.SOURCE) |
| 288 | public @interface SafeBrowsingThreat {} |
| 289 | |
Nate Fischer | 0c30436 | 2017-06-16 15:32:50 -0700 | [diff] [blame] | 290 | /** The resource was blocked for an unknown reason */ |
| 291 | public static final int SAFE_BROWSING_THREAT_UNKNOWN = 0; |
| 292 | /** The resource was blocked because it contains malware */ |
| 293 | public static final int SAFE_BROWSING_THREAT_MALWARE = 1; |
| 294 | /** The resource was blocked because it contains deceptive content */ |
| 295 | public static final int SAFE_BROWSING_THREAT_PHISHING = 2; |
| 296 | /** The resource was blocked because it contains unwanted software */ |
| 297 | public static final int SAFE_BROWSING_THREAT_UNWANTED_SOFTWARE = 3; |
| 298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | /** |
Patrick Scott | 05c9ed9 | 2009-08-25 13:51:08 -0400 | [diff] [blame] | 300 | * Report an error to the host application. These errors are unrecoverable |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 301 | * (i.e. the main resource is unavailable). The {@code errorCode} parameter |
| 302 | * corresponds to one of the {@code ERROR_*} constants. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | * @param view The WebView that is initiating the callback. |
Patrick Scott | 447811c | 2009-09-01 09:57:20 -0400 | [diff] [blame] | 304 | * @param errorCode The error code corresponding to an ERROR_* value. |
Patrick Scott | 05c9ed9 | 2009-08-25 13:51:08 -0400 | [diff] [blame] | 305 | * @param description A String describing the error. |
| 306 | * @param failingUrl The url that failed to load. |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 307 | * @deprecated Use {@link #onReceivedError(WebView, WebResourceRequest, WebResourceError) |
| 308 | * onReceivedError(WebView, WebResourceRequest, WebResourceError)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | */ |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 310 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | public void onReceivedError(WebView view, int errorCode, |
| 312 | String description, String failingUrl) { |
| 313 | } |
| 314 | |
| 315 | /** |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 316 | * Report web resource loading error to the host application. These errors usually indicate |
| 317 | * inability to connect to the server. Note that unlike the deprecated version of the callback, |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 318 | * the new version will be called for any resource (iframe, image, etc.), not just for the main |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 319 | * page. Thus, it is recommended to perform minimum required work in this callback. |
| 320 | * @param view The WebView that is initiating the callback. |
| 321 | * @param request The originating request. |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 322 | * @param error Information about the error occurred. |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 323 | */ |
| 324 | public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { |
| 325 | if (request.isForMainFrame()) { |
| 326 | onReceivedError(view, |
Mikhail Naganov | 8d4f07f | 2015-05-12 17:44:15 -0700 | [diff] [blame] | 327 | error.getErrorCode(), error.getDescription().toString(), |
| 328 | request.getUrl().toString()); |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Notify the host application that an HTTP error has been received from the server while |
| 334 | * loading a resource. HTTP errors have status codes >= 400. This callback will be called |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 335 | * for any resource (iframe, image, etc.), not just for the main page. Thus, it is recommended |
| 336 | * to perform minimum required work in this callback. Note that the content of the server |
| 337 | * response may not be provided within the {@code errorResponse} parameter. |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 338 | * @param view The WebView that is initiating the callback. |
| 339 | * @param request The originating request. |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 340 | * @param errorResponse Information about the error occurred. |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 341 | */ |
| 342 | public void onReceivedHttpError( |
Mikhail Naganov | 8d4f07f | 2015-05-12 17:44:15 -0700 | [diff] [blame] | 343 | WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { |
Mikhail Naganov | 25e8954 | 2015-02-09 17:01:40 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | * As the host application if the browser should resend data as the |
| 348 | * requested page was a result of a POST. The default is to not resend the |
| 349 | * data. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 350 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | * @param view The WebView that is initiating the callback. |
| 352 | * @param dontResend The message to send if the browser should not resend |
| 353 | * @param resend The message to send if the browser should resend data |
| 354 | */ |
| 355 | public void onFormResubmission(WebView view, Message dontResend, |
| 356 | Message resend) { |
| 357 | dontResend.sendToTarget(); |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Notify the host application to update its visited links database. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 362 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | * @param view The WebView that is initiating the callback. |
| 364 | * @param url The url being visited. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 365 | * @param isReload {@code true} if this url is being reloaded. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | */ |
| 367 | public void doUpdateVisitedHistory(WebView view, String url, |
| 368 | boolean isReload) { |
| 369 | } |
| 370 | |
| 371 | /** |
Steve Block | fe33a75 | 2011-10-04 19:09:13 +0100 | [diff] [blame] | 372 | * Notify the host application that an SSL error occurred while loading a |
Nate Fischer | 9f726cd | 2019-01-17 21:27:45 -0800 | [diff] [blame] | 373 | * resource. The host application must call either {@link SslErrorHandler#cancel} or |
| 374 | * {@link SslErrorHandler#proceed}. Note that the decision may be retained for use in |
Steve Block | fe33a75 | 2011-10-04 19:09:13 +0100 | [diff] [blame] | 375 | * response to future SSL errors. The default behavior is to cancel the |
| 376 | * load. |
Torne (Richard Coles) | 97bf0be | 2018-05-16 10:51:56 -0400 | [diff] [blame] | 377 | * <p> |
Nate Fischer | 9f726cd | 2019-01-17 21:27:45 -0800 | [diff] [blame] | 378 | * This API is only called for recoverable SSL certificate errors. In the case of |
| 379 | * non-recoverable errors (such as when the server fails the client), WebView will call {@link |
| 380 | * #onReceivedError(WebView, WebResourceRequest, WebResourceError)} with {@link |
| 381 | * #ERROR_FAILED_SSL_HANDSHAKE}. |
| 382 | * <p> |
Torne (Richard Coles) | 97bf0be | 2018-05-16 10:51:56 -0400 | [diff] [blame] | 383 | * Applications are advised not to prompt the user about SSL errors, as |
| 384 | * the user is unlikely to be able to make an informed security decision |
| 385 | * and WebView does not provide any UI for showing the details of the |
| 386 | * error in a meaningful way. |
| 387 | * <p> |
| 388 | * Application overrides of this method may display custom error pages or |
| 389 | * silently log issues, but it is strongly recommended to always call |
Nate Fischer | 9f726cd | 2019-01-17 21:27:45 -0800 | [diff] [blame] | 390 | * {@link SslErrorHandler#cancel} and never allow proceeding past errors. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 391 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | * @param view The WebView that is initiating the callback. |
Nate Fischer | 9f726cd | 2019-01-17 21:27:45 -0800 | [diff] [blame] | 393 | * @param handler An {@link SslErrorHandler} that will handle the user's |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | * response. |
| 395 | * @param error The SSL error object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | */ |
| 397 | public void onReceivedSslError(WebView view, SslErrorHandler handler, |
| 398 | SslError error) { |
| 399 | handler.cancel(); |
| 400 | } |
| 401 | |
| 402 | /** |
Nate Fischer | da0f1b4 | 2017-11-29 12:18:54 -0800 | [diff] [blame] | 403 | * Notify the host application to handle a SSL client certificate request. The host application |
| 404 | * is responsible for showing the UI if desired and providing the keys. There are three ways to |
| 405 | * respond: {@link ClientCertRequest#proceed}, {@link ClientCertRequest#cancel}, or {@link |
| 406 | * ClientCertRequest#ignore}. Webview stores the response in memory (for the life of the |
| 407 | * application) if {@link ClientCertRequest#proceed} or {@link ClientCertRequest#cancel} is |
| 408 | * called and does not call {@code onReceivedClientCertRequest()} again for the same host and |
| 409 | * port pair. Webview does not store the response if {@link ClientCertRequest#ignore} |
Selim Gurun | 977d943 | 2016-02-16 12:30:08 -0800 | [diff] [blame] | 410 | * is called. Note that, multiple layers in chromium network stack might be |
| 411 | * caching the responses, so the behavior for ignore is only a best case |
| 412 | * effort. |
Selim Gurun | b6aa97e | 2014-03-26 14:10:28 -0700 | [diff] [blame] | 413 | * |
| 414 | * This method is called on the UI thread. During the callback, the |
| 415 | * connection is suspended. |
| 416 | * |
Selim Gurun | a679ac5 | 2015-06-19 11:27:38 -0700 | [diff] [blame] | 417 | * For most use cases, the application program should implement the |
| 418 | * {@link android.security.KeyChainAliasCallback} interface and pass it to |
| 419 | * {@link android.security.KeyChain#choosePrivateKeyAlias} to start an |
| 420 | * activity for the user to choose the proper alias. The keychain activity will |
| 421 | * provide the alias through the callback method in the implemented interface. Next |
| 422 | * the application should create an async task to call |
| 423 | * {@link android.security.KeyChain#getPrivateKey} to receive the key. |
| 424 | * |
| 425 | * An example implementation of client certificates can be seen at |
| 426 | * <A href="https://android.googlesource.com/platform/packages/apps/Browser/+/android-5.1.1_r1/src/com/android/browser/Tab.java"> |
| 427 | * AOSP Browser</a> |
| 428 | * |
Selim Gurun | b6aa97e | 2014-03-26 14:10:28 -0700 | [diff] [blame] | 429 | * The default behavior is to cancel, returning no client certificate. |
| 430 | * |
| 431 | * @param view The WebView that is initiating the callback |
| 432 | * @param request An instance of a {@link ClientCertRequest} |
| 433 | * |
Selim Gurun | b6aa97e | 2014-03-26 14:10:28 -0700 | [diff] [blame] | 434 | */ |
| 435 | public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { |
| 436 | request.cancel(); |
| 437 | } |
| 438 | |
| 439 | /** |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 440 | * Notifies the host application that the WebView received an HTTP |
| 441 | * authentication request. The host application can use the supplied |
| 442 | * {@link HttpAuthHandler} to set the WebView's response to the request. |
| 443 | * The default behavior is to cancel the request. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 444 | * |
Steve Block | 46ce1db | 2012-07-17 16:43:00 +0100 | [diff] [blame] | 445 | * @param view the WebView that is initiating the callback |
| 446 | * @param handler the HttpAuthHandler used to set the WebView's response |
| 447 | * @param host the host requiring authentication |
| 448 | * @param realm the realm for which authentication is required |
Jonathan Dixon | 47aaba3 | 2012-11-30 16:32:17 -0800 | [diff] [blame] | 449 | * @see WebView#getHttpAuthUsernamePassword |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | */ |
| 451 | public void onReceivedHttpAuthRequest(WebView view, |
| 452 | HttpAuthHandler handler, String host, String realm) { |
| 453 | handler.cancel(); |
| 454 | } |
| 455 | |
| 456 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | * Give the host application a chance to handle the key event synchronously. |
| 458 | * e.g. menu shortcut key events need to be filtered this way. If return |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 459 | * true, WebView will not handle the key event. If return {@code false}, WebView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | * will always handle the key event, so none of the super in the view chain |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 461 | * will see the key event. The default behavior returns {@code false}. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 462 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | * @param view The WebView that is initiating the callback. |
| 464 | * @param event The key event. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 465 | * @return {@code true} if the host application wants to handle the key event |
| 466 | * itself, otherwise return {@code false} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | */ |
| 468 | public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) { |
| 469 | return false; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Notify the host application that a key was not handled by the WebView. |
| 474 | * Except system keys, WebView always consumes the keys in the normal flow |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 475 | * or if {@link #shouldOverrideKeyEvent} returns {@code true}. This is called asynchronously |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 476 | * from where the key is dispatched. It gives the host application a chance |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | * to handle the unhandled key events. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 478 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | * @param view The WebView that is initiating the callback. |
| 480 | * @param event The key event. |
| 481 | */ |
| 482 | public void onUnhandledKeyEvent(WebView view, KeyEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 483 | onUnhandledInputEventInternal(view, event); |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Notify the host application that a input event was not handled by the WebView. |
| 488 | * Except system keys, WebView always consumes input events in the normal flow |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 489 | * or if {@link #shouldOverrideKeyEvent} returns {@code true}. This is called asynchronously |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 490 | * from where the event is dispatched. It gives the host application a chance |
| 491 | * to handle the unhandled input events. |
| 492 | * |
Michael Wright | 1feb11f | 2014-05-01 15:41:33 -0700 | [diff] [blame] | 493 | * Note that if the event is a {@link android.view.MotionEvent}, then it's lifetime is only |
| 494 | * that of the function call. If the WebViewClient wishes to use the event beyond that, then it |
| 495 | * <i>must</i> create a copy of the event. |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 496 | * |
Michael Wright | 1feb11f | 2014-05-01 15:41:33 -0700 | [diff] [blame] | 497 | * It is the responsibility of overriders of this method to call |
| 498 | * {@link #onUnhandledKeyEvent(WebView, KeyEvent)} |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 499 | * when appropriate if they wish to continue receiving events through it. |
| 500 | * |
| 501 | * @param view The WebView that is initiating the callback. |
| 502 | * @param event The input event. |
Michael Wright | 1ad3955 | 2016-04-27 13:07:18 -0400 | [diff] [blame] | 503 | * @removed |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 504 | */ |
| 505 | public void onUnhandledInputEvent(WebView view, InputEvent event) { |
| 506 | if (event instanceof KeyEvent) { |
| 507 | onUnhandledKeyEvent(view, (KeyEvent) event); |
| 508 | return; |
| 509 | } |
| 510 | onUnhandledInputEventInternal(view, event); |
| 511 | } |
| 512 | |
| 513 | private void onUnhandledInputEventInternal(WebView view, InputEvent event) { |
John Reck | d6b1098 | 2012-04-19 18:01:35 -0700 | [diff] [blame] | 514 | ViewRootImpl root = view.getViewRootImpl(); |
| 515 | if (root != null) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 516 | root.dispatchUnhandledInputEvent(event); |
John Reck | d6b1098 | 2012-04-19 18:01:35 -0700 | [diff] [blame] | 517 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Notify the host application that the scale applied to the WebView has |
| 522 | * changed. |
Brian Carlstrom | a147759 | 2011-02-11 13:39:56 -0800 | [diff] [blame] | 523 | * |
Philipp Hasper | 802aa0f | 2015-05-12 09:09:25 +0200 | [diff] [blame] | 524 | * @param view The WebView that is initiating the callback. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | * @param oldScale The old scale factor |
| 526 | * @param newScale The new scale factor |
| 527 | */ |
| 528 | public void onScaleChanged(WebView view, float oldScale, float newScale) { |
| 529 | } |
Patrick Scott | 85a50ff | 2011-01-25 14:42:12 -0500 | [diff] [blame] | 530 | |
| 531 | /** |
| 532 | * Notify the host application that a request to automatically log in the |
| 533 | * user has been processed. |
| 534 | * @param view The WebView requesting the login. |
| 535 | * @param realm The account realm used to look up accounts. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 536 | * @param account An optional account. If not {@code null}, the account should be |
Patrick Scott | 85a50ff | 2011-01-25 14:42:12 -0500 | [diff] [blame] | 537 | * checked against accounts on the device. If it is a valid |
| 538 | * account, it should be used to log in the user. |
| 539 | * @param args Authenticator specific arguments used to log in the user. |
| 540 | */ |
| 541 | public void onReceivedLoginRequest(WebView view, String realm, |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame] | 542 | @Nullable String account, String args) { |
Patrick Scott | 85a50ff | 2011-01-25 14:42:12 -0500 | [diff] [blame] | 543 | } |
Tao Bai | c53fae1 | 2016-11-16 15:21:40 -0800 | [diff] [blame] | 544 | |
| 545 | /** |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 546 | * Notify host application that the given WebView's render process has exited. |
Tao Bai | c53fae1 | 2016-11-16 15:21:40 -0800 | [diff] [blame] | 547 | * |
| 548 | * Multiple WebView instances may be associated with a single render process; |
| 549 | * onRenderProcessGone will be called for each WebView that was affected. |
| 550 | * The application's implementation of this callback should only attempt to |
| 551 | * clean up the specific WebView given as a parameter, and should not assume |
| 552 | * that other WebView instances are affected. |
| 553 | * |
| 554 | * The given WebView can't be used, and should be removed from the view hierarchy, |
| 555 | * all references to it should be cleaned up, e.g any references in the Activity |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 556 | * or other classes saved using {@link android.view.View#findViewById} and similar calls, etc. |
Tao Bai | c53fae1 | 2016-11-16 15:21:40 -0800 | [diff] [blame] | 557 | * |
| 558 | * To cause an render process crash for test purpose, the application can |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 559 | * call {@code loadUrl("chrome://crash")} on the WebView. Note that multiple WebView |
Tao Bai | c53fae1 | 2016-11-16 15:21:40 -0800 | [diff] [blame] | 560 | * instances may be affected if they share a render process, not just the |
| 561 | * specific WebView which loaded chrome://crash. |
| 562 | * |
| 563 | * @param view The WebView which needs to be cleaned up. |
| 564 | * @param detail the reason why it exited. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 565 | * @return {@code true} if the host application handled the situation that process has |
Tao Bai | dd264f6 | 2017-01-30 16:54:28 -0800 | [diff] [blame] | 566 | * exited, otherwise, application will crash if render process crashed, |
| 567 | * or be killed if render process was killed by the system. |
Tao Bai | c53fae1 | 2016-11-16 15:21:40 -0800 | [diff] [blame] | 568 | */ |
| 569 | public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) { |
| 570 | return false; |
| 571 | } |
Nate Fischer | 0c30436 | 2017-06-16 15:32:50 -0700 | [diff] [blame] | 572 | |
| 573 | /** |
| 574 | * Notify the host application that a loading URL has been flagged by Safe Browsing. |
| 575 | * |
| 576 | * The application must invoke the callback to indicate the preferred response. The default |
Nate Fischer | 2f7af06 | 2017-07-06 11:32:31 -0700 | [diff] [blame] | 577 | * behavior is to show an interstitial to the user, with the reporting checkbox visible. |
Nate Fischer | 0c30436 | 2017-06-16 15:32:50 -0700 | [diff] [blame] | 578 | * |
| 579 | * If the application needs to show its own custom interstitial UI, the callback can be invoked |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 580 | * asynchronously with {@link SafeBrowsingResponse#backToSafety} or {@link |
| 581 | * SafeBrowsingResponse#proceed}, depending on user response. |
Nate Fischer | 0c30436 | 2017-06-16 15:32:50 -0700 | [diff] [blame] | 582 | * |
| 583 | * @param view The WebView that hit the malicious resource. |
| 584 | * @param request Object containing the details of the request. |
| 585 | * @param threatType The reason the resource was caught by Safe Browsing, corresponding to a |
Nate Fischer | 73fd92a | 2017-10-31 13:49:09 -0700 | [diff] [blame] | 586 | * {@code SAFE_BROWSING_THREAT_*} value. |
Nate Fischer | 2f7af06 | 2017-07-06 11:32:31 -0700 | [diff] [blame] | 587 | * @param callback Applications must invoke one of the callback methods. |
Nate Fischer | 0c30436 | 2017-06-16 15:32:50 -0700 | [diff] [blame] | 588 | */ |
Nate Fischer | 5ab00b3 | 2017-07-13 15:28:21 -0700 | [diff] [blame] | 589 | public void onSafeBrowsingHit(WebView view, WebResourceRequest request, |
| 590 | @SafeBrowsingThreat int threatType, SafeBrowsingResponse callback) { |
Nate Fischer | 2f7af06 | 2017-07-06 11:32:31 -0700 | [diff] [blame] | 591 | callback.showInterstitial(/* allowReporting */ true); |
Nate Fischer | 0c30436 | 2017-06-16 15:32:50 -0700 | [diff] [blame] | 592 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | } |