diff options
author | Mikhail Naganov <mnaganov@google.com> | 2015-02-09 17:01:40 +0000 |
---|---|---|
committer | Mikhail Naganov <mnaganov@google.com> | 2015-03-06 10:12:14 +0000 |
commit | 25e89545736d62c59d19dd9b9587f7b0cbbee068 (patch) | |
tree | 646317a9a2d10571bcd5c36ab4fa2e46498361e8 /core/java/android/webkit/WebViewClient.java | |
parent | a92d6e28ad26184d4b2b90b6a7ae5f69edcbeca1 (diff) | |
download | frameworks_base-25e89545736d62c59d19dd9b9587f7b0cbbee068.zip frameworks_base-25e89545736d62c59d19dd9b9587f7b0cbbee068.tar.gz frameworks_base-25e89545736d62c59d19dd9b9587f7b0cbbee068.tar.bz2 |
Provide better error reporting for WebView
Add new callbacks into WebViewClient that will provide notifications
about subresource loading errors and HTTP errors received from servers.
Bug: 19313118
Change-Id: Idb47f53ef7e72cb95f3e9b89d1e238d69e896b8b
Diffstat (limited to 'core/java/android/webkit/WebViewClient.java')
-rw-r--r-- | core/java/android/webkit/WebViewClient.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/core/java/android/webkit/WebViewClient.java b/core/java/android/webkit/WebViewClient.java index 01f9b37..34b8cf6 100644 --- a/core/java/android/webkit/WebViewClient.java +++ b/core/java/android/webkit/WebViewClient.java @@ -174,6 +174,8 @@ public class WebViewClient { public static final int ERROR_FILE_NOT_FOUND = -14; /** Too many requests during this load */ public static final int ERROR_TOO_MANY_REQUESTS = -15; + /** Request blocked by the browser */ + public static final int ERROR_BLOCKED = -16; /** * Report an error to the host application. These errors are unrecoverable @@ -183,12 +185,45 @@ public class WebViewClient { * @param errorCode The error code corresponding to an ERROR_* value. * @param description A String describing the error. * @param failingUrl The url that failed to load. + * @deprecated Use {@link #onReceivedError(WebView, WebResourceRequest, WebResourceError) + * onReceivedError(WebView, WebResourceRequest, WebResourceError)} instead. */ + @Deprecated public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { } /** + * Report web resource loading error to the host application. These errors usually indicate + * inability to connect to the server. Note that unlike the deprecated version of the callback, + * the new version will be called for any resource (iframe, image, etc), not just for the main + * page. Thus, it is recommended to perform minimum required work in this callback. + * @param view The WebView that is initiating the callback. + * @param request The originating request. + * @param error Information about the error occured. + */ + public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { + if (request.isForMainFrame()) { + onReceivedError(view, + error.getErrorCode(), error.getDescription(), request.getUrl().toString()); + } + } + + /** + * Notify the host application that an HTTP error has been received from the server while + * loading a resource. HTTP errors have status codes >= 400. This callback will be called + * for any resource (iframe, image, etc), not just for the main page. Thus, it is recommended to + * perform minimum required work in this callback. Note that the content of the server + * response may not be provided within the <b>errorResponse</b> parameter. + * @param view The WebView that is initiating the callback. + * @param request The originating request. + * @param errorResponse Information about the error occured. + */ + public void onReceivedHttpError( + WebView view, WebResourceRequest request, WebResourceResponseBase errorResponse) { + } + + /** * As the host application if the browser should resend data as the * requested page was a result of a POST. The default is to not resend the * data. |