public class WebViewClient extends Object
Modifier and Type | Field and Description |
---|---|
static int |
ERROR_AUTHENTICATION
User authentication failed on server
|
static int |
ERROR_BAD_URL
Malformed URL
|
static int |
ERROR_CONNECT
Failed to connect to the server
|
static int |
ERROR_FAILED_SSL_HANDSHAKE
Failed to perform SSL handshake
|
static int |
ERROR_FILE
Generic file error
|
static int |
ERROR_FILE_NOT_FOUND
File not found
|
static int |
ERROR_HOST_LOOKUP
Server or proxy hostname lookup failed
|
static int |
ERROR_IO
Failed to read or write to the server
|
static int |
ERROR_PROXY_AUTHENTICATION
User authentication failed on proxy
|
static int |
ERROR_REDIRECT_LOOP
Too many redirects
|
static int |
ERROR_TIMEOUT
Connection timed out
|
static int |
ERROR_TOO_MANY_REQUESTS
Too many requests during this load
|
static int |
ERROR_UNKNOWN
Generic error
|
static int |
ERROR_UNSUPPORTED_AUTH_SCHEME
Unsupported authentication scheme (not basic or digest)
|
static int |
ERROR_UNSUPPORTED_SCHEME
Unsupported URI scheme
|
Constructor and Description |
---|
WebViewClient() |
Modifier and Type | Method and Description |
---|---|
void |
doUpdateVisitedHistory(WebView view,
String url,
boolean isReload)
Notify the host application to update its visited links database.
|
void |
onFormResubmission(WebView view,
Message dontResend,
Message resend)
As the host application if the browser should resend data as the
requested page was a result of a POST.
|
void |
onLoadResource(WebView view,
String url)
Notify the host application that the WebView will load the resource
specified by the given url.
|
void |
onPageCommitVisible(WebView view,
String url)
Notify the host application that
WebView content left over from
previous page navigations will no longer be drawn. |
void |
onPageFinished(WebView view,
String url)
Notify the host application that a page has finished loading.
|
void |
onPageStarted(WebView view,
String url,
Bitmap favicon)
Notify the host application that a page has started loading.
|
void |
onReceivedClientCertRequest(WebView view,
ClientCertRequest request)
Notify the host application to handle a SSL client certificate
request.
|
void |
onReceivedError(WebView view,
int errorCode,
String description,
String failingUrl)
Deprecated.
|
void |
onReceivedError(WebView view,
WebResourceRequest request,
WebResourceError error)
Report web resource loading error to the host application.
|
void |
onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler,
String host,
String realm)
Notifies the host application that the WebView received an HTTP
authentication request.
|
void |
onReceivedHttpError(WebView view,
WebResourceRequest request,
WebResourceResponse errorResponse)
Notify the host application that an HTTP error has been received from the server while
loading a resource.
|
void |
onReceivedLoginRequest(WebView view,
String realm,
String account,
String args)
Notify the host application that a request to automatically log in the
user has been processed.
|
void |
onReceivedSslError(WebView view,
SslErrorHandler handler,
SslError error)
Notify the host application that an SSL error occurred while loading a
resource.
|
void |
onScaleChanged(WebView view,
float oldScale,
float newScale)
Notify the host application that the scale applied to the WebView has
changed.
|
void |
onTooManyRedirects(WebView view,
Message cancelMsg,
Message continueMsg)
Deprecated.
This method is no longer called. When the WebView encounters
a redirect loop, it will cancel the load.
|
void |
onUnhandledInputEvent(WebView view,
InputEvent event)
Notify the host application that a input event was not handled by the WebView.
|
void |
onUnhandledKeyEvent(WebView view,
KeyEvent event)
Notify the host application that a key was not handled by the WebView.
|
WebResourceResponse |
shouldInterceptRequest(WebView view,
String url)
Deprecated.
Use
shouldInterceptRequest(WebView, WebResourceRequest) instead. |
WebResourceResponse |
shouldInterceptRequest(WebView view,
WebResourceRequest request)
Notify the host application of a resource request and allow the
application to return the data.
|
boolean |
shouldOverrideKeyEvent(WebView view,
KeyEvent event)
Give the host application a chance to handle the key event synchronously.
|
boolean |
shouldOverrideUrlLoading(WebView view,
String url)
Deprecated.
|
boolean |
shouldOverrideUrlLoading(WebView view,
WebResourceRequest request)
Give the host application a chance to take over the control when a new
url is about to be loaded in the current WebView.
|
public static final int ERROR_UNKNOWN
public static final int ERROR_HOST_LOOKUP
public static final int ERROR_UNSUPPORTED_AUTH_SCHEME
public static final int ERROR_AUTHENTICATION
public static final int ERROR_PROXY_AUTHENTICATION
public static final int ERROR_CONNECT
public static final int ERROR_IO
public static final int ERROR_TIMEOUT
public static final int ERROR_REDIRECT_LOOP
public static final int ERROR_UNSUPPORTED_SCHEME
public static final int ERROR_FAILED_SSL_HANDSHAKE
public static final int ERROR_BAD_URL
public static final int ERROR_FILE
public static final int ERROR_FILE_NOT_FOUND
public static final int ERROR_TOO_MANY_REQUESTS
@Deprecated public boolean shouldOverrideUrlLoading(WebView view, String url)
shouldOverrideUrlLoading(WebView, WebResourceRequest)
instead.view
- The WebView that is initiating the callback.url
- The url to be loaded.public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
Notes:
WebView.loadUrl(String)
with the request's url from inside the method and then return true,
as this will make WebView to attempt loading a non-http url, and thus fail.view
- The WebView that is initiating the callback.request
- Object containing the details of the request.public void onPageStarted(WebView view, String url, Bitmap favicon)
view
- The WebView that is initiating the callback.url
- The url to be loaded.favicon
- The favicon for this page if it already exists in the
database.public void onPageFinished(WebView view, String url)
WebView.PictureListener.onNewPicture(android.webkit.WebView, android.graphics.Picture)
.view
- The WebView that is initiating the callback.url
- The url of the page.public void onLoadResource(WebView view, String url)
view
- The WebView that is initiating the callback.url
- The url of the resource the WebView will load.public void onPageCommitVisible(WebView view, String url)
WebView
content left over from
previous page navigations will no longer be drawn.
This callback can be used to determine the point at which it is safe to make a recycled
WebView
visible, ensuring that no stale content is shown. It is called
at the earliest point at which it can be guaranteed that WebView.onDraw(android.graphics.Canvas)
will no
longer draw any content from previous navigations. The next draw will display either the
background color
of the WebView
, or some of the
contents of the newly loaded page.
This method is called when the body of the HTTP response has started loading, is reflected in the DOM, and will be visible in subsequent draws. This callback occurs early in the document loading process, and as such you should expect that linked resources (for example, css and images) may not be available.
For more fine-grained notification of visual state updates, see WebView.postVisualStateCallback(long, android.webkit.WebView.VisualStateCallback)
.
Please note that all the conditions and recommendations applicable to
WebView.postVisualStateCallback(long, android.webkit.WebView.VisualStateCallback)
also apply to this API.
This callback is only called for main frame navigations.
view
- The WebView
for which the navigation occurred.url
- The URL corresponding to the page navigation that triggered this callback.@Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url)
shouldInterceptRequest(WebView, WebResourceRequest)
instead.view
- The WebView
that is requesting the
resource.url
- The raw url of the resource.WebResourceResponse
containing the
response information or null if the WebView should load the
resource itself.public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request)
view
- The WebView
that is requesting the
resource.request
- Object containing the details of the request.WebResourceResponse
containing the
response information or null if the WebView should load the
resource itself.@Deprecated public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg)
view
- The WebView that is initiating the callback.cancelMsg
- The message to send if the host wants to cancelcontinueMsg
- The message to send if the host wants to continue@Deprecated public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
onReceivedError(WebView, WebResourceRequest, WebResourceError)
instead.view
- The WebView that is initiating the callback.errorCode
- The error code corresponding to an ERROR_* value.description
- A String describing the error.failingUrl
- The url that failed to load.public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error)
view
- The WebView that is initiating the callback.request
- The originating request.error
- Information about the error occured.public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse)
view
- The WebView that is initiating the callback.request
- The originating request.errorResponse
- Information about the error occured.public void onFormResubmission(WebView view, Message dontResend, Message resend)
view
- The WebView that is initiating the callback.dontResend
- The message to send if the browser should not resendresend
- The message to send if the browser should resend datapublic void doUpdateVisitedHistory(WebView view, String url, boolean isReload)
view
- The WebView that is initiating the callback.url
- The url being visited.isReload
- True if this url is being reloaded.public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
view
- The WebView that is initiating the callback.handler
- An SslErrorHandler object that will handle the user's
response.error
- The SSL error object.public void onReceivedClientCertRequest(WebView view, ClientCertRequest request)
KeyChainAliasCallback
interface and pass it to
KeyChain.choosePrivateKeyAlias(android.app.Activity, android.security.KeyChainAliasCallback, java.lang.String[], java.security.Principal[], java.lang.String, int, java.lang.String)
to start an
activity for the user to choose the proper alias. The keychain activity will
provide the alias through the callback method in the implemented interface. Next
the application should create an async task to call
KeyChain.getPrivateKey(android.content.Context, java.lang.String)
to receive the key.
An example implementation of client certificates can be seen at
AOSP Browser
The default behavior is to cancel, returning no client certificate.view
- The WebView that is initiating the callbackrequest
- An instance of a ClientCertRequest
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm)
HttpAuthHandler
to set the WebView's response to the request.
The default behavior is to cancel the request.view
- the WebView that is initiating the callbackhandler
- the HttpAuthHandler used to set the WebView's responsehost
- the host requiring authenticationrealm
- the realm for which authentication is requiredWebView.getHttpAuthUsernamePassword(java.lang.String, java.lang.String)
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event)
view
- The WebView that is initiating the callback.event
- The key event.public void onUnhandledKeyEvent(WebView view, KeyEvent event)
view
- The WebView that is initiating the callback.event
- The key event.public void onUnhandledInputEvent(WebView view, InputEvent event)
MotionEvent
, then it's lifetime is only
that of the function call. If the WebViewClient wishes to use the event beyond that, then it
must create a copy of the event.
It is the responsibility of overriders of this method to call
onUnhandledKeyEvent(WebView, KeyEvent)
when appropriate if they wish to continue receiving events through it.view
- The WebView that is initiating the callback.event
- The input event.public void onScaleChanged(WebView view, float oldScale, float newScale)
view
- The WebView that is initiating the callback.oldScale
- The old scale factornewScale
- The new scale factorpublic void onReceivedLoginRequest(WebView view, String realm, String account, String args)
view
- The WebView requesting the login.realm
- The account realm used to look up accounts.account
- An optional account. If not null, the account should be
checked against accounts on the device. If it is a valid
account, it should be used to log in the user.args
- Authenticator specific arguments used to log in the user.