Most visited

Recently visited

Added in API level 1

WebChromeClient

public class WebChromeClient
extends Object

java.lang.Object
   ↳ android.webkit.WebChromeClient


Summary

Nested classes

interface WebChromeClient.CustomViewCallback

A callback interface used by the host application to notify the current page that its custom view has been dismissed. 

class WebChromeClient.FileChooserParams

Parameters used in the onShowFileChooser(WebView, ValueCallback, WebChromeClient.FileChooserParams) method. 

Public constructors

WebChromeClient()

Public methods

Bitmap getDefaultVideoPoster()

When not playing, video elements are represented by a 'poster' image.

View getVideoLoadingProgressView()

Obtains a View to be displayed while buffering of full screen video is taking place.

void getVisitedHistory(ValueCallback<String[]> callback)

Obtains a list of all visited history items, used for link coloring

void onCloseWindow(WebView window)

Notify the host application to close the given WebView and remove it from the view system if necessary.

boolean onConsoleMessage(ConsoleMessage consoleMessage)

Report a JavaScript console message to the host application.

void onConsoleMessage(String message, int lineNumber, String sourceID)

This method was deprecated in API level 8. Use onConsoleMessage(ConsoleMessage) instead.

boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg)

Request the host application to create a new window.

void onExceededDatabaseQuota(String url, String databaseIdentifier, long quota, long estimatedDatabaseSize, long totalQuota, WebStorage.QuotaUpdater quotaUpdater)

This method was deprecated in API level 19. This method is no longer called; WebView now uses the HTML5 / JavaScript Quota Management API.

void onGeolocationPermissionsHidePrompt()

Notify the host application that a request for Geolocation permissions, made with a previous call to onGeolocationPermissionsShowPrompt() has been canceled.

void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback)

Notify the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin.

void onHideCustomView()

Notify the host application that the current page has exited full screen mode.

boolean onJsAlert(WebView view, String url, String message, JsResult result)

Tell the client to display a javascript alert dialog.

boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result)

Tell the client to display a dialog to confirm navigation away from the current page.

boolean onJsConfirm(WebView view, String url, String message, JsResult result)

Tell the client to display a confirm dialog to the user.

boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result)

Tell the client to display a prompt dialog to the user.

boolean onJsTimeout()

This method was deprecated in API level 17. This method is no longer supported and will not be invoked.

void onPermissionRequest(PermissionRequest request)

Notify the host application that web content is requesting permission to access the specified resources and the permission currently isn't granted or denied.

void onPermissionRequestCanceled(PermissionRequest request)

Notify the host application that the given permission request has been canceled.

void onProgressChanged(WebView view, int newProgress)

Tell the host application the current progress of loading a page.

void onReachedMaxAppCacheSize(long requiredStorage, long quota, WebStorage.QuotaUpdater quotaUpdater)

This method was deprecated in API level 19. This method is no longer called; WebView now uses the HTML5 / JavaScript Quota Management API.

void onReceivedIcon(WebView view, Bitmap icon)

Notify the host application of a new favicon for the current page.

void onReceivedTitle(WebView view, String title)

Notify the host application of a change in the document title.

void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed)

Notify the host application of the url for an apple-touch-icon.

void onRequestFocus(WebView view)

Request display and focus for this WebView.

void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback)

This method was deprecated in API level 18. This method supports the obsolete plugin mechanism, and will not be invoked in future

void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)

Notify the host application that the current page has entered full screen mode.

boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)

Tell the client to show a file chooser.

Inherited methods

From class java.lang.Object

Public constructors

WebChromeClient

Added in API level 1
WebChromeClient ()

Public methods

getDefaultVideoPoster

Added in API level 7
Bitmap getDefaultVideoPoster ()

When not playing, video elements are represented by a 'poster' image. The image to use can be specified by the poster attribute of the video tag in HTML. If the attribute is absent, then a default poster will be used. This method allows the ChromeClient to provide that default image.

Returns
Bitmap Bitmap The image to use as a default poster, or null if no such image is available.

getVideoLoadingProgressView

Added in API level 7
View getVideoLoadingProgressView ()

Obtains a View to be displayed while buffering of full screen video is taking place. The host application can override this method to provide a View containing a spinner or similar.

Returns
View View The View to be displayed whilst the video is loading.

getVisitedHistory

Added in API level 7
void getVisitedHistory (ValueCallback<String[]> callback)

Obtains a list of all visited history items, used for link coloring

Parameters
callback ValueCallback

onCloseWindow

Added in API level 1
void onCloseWindow (WebView window)

Notify the host application to close the given WebView and remove it from the view system if necessary. At this point, WebCore has stopped any loading in this window and has removed any cross-scripting ability in javascript.

Parameters
window WebView: The WebView that needs to be closed.

onConsoleMessage

Added in API level 8
boolean onConsoleMessage (ConsoleMessage consoleMessage)

Report a JavaScript console message to the host application. The ChromeClient should override this to process the log message as they see fit.

Parameters
consoleMessage ConsoleMessage: Object containing details of the console message.
Returns
boolean true if the message is handled by the client.

onConsoleMessage

Added in API level 7
void onConsoleMessage (String message, 
                int lineNumber, 
                String sourceID)

This method was deprecated in API level 8.
Use onConsoleMessage(ConsoleMessage) instead.

Report a JavaScript error message to the host application. The ChromeClient should override this to process the log message as they see fit.

Parameters
message String: The error message to report.
lineNumber int: The line number of the error.
sourceID String: The name of the source file that caused the error.

onCreateWindow

Added in API level 1
boolean onCreateWindow (WebView view, 
                boolean isDialog, 
                boolean isUserGesture, 
                Message resultMsg)

Request the host application to create a new window. If the host application chooses to honor this request, it should return true from this method, create a new WebView to host the window, insert it into the View system and send the supplied resultMsg message to its target with the new WebView as an argument. If the host application chooses not to honor the request, it should return false from this method. The default implementation of this method does nothing and hence returns false.

Parameters
view WebView: The WebView from which the request for a new window originated.
isDialog boolean: True if the new window should be a dialog, rather than a full-size window.
isUserGesture boolean: True if the request was initiated by a user gesture, such as the user clicking a link.
resultMsg Message: The message to send when once a new WebView has been created. resultMsg.obj is a WebView.WebViewTransport object. This should be used to transport the new WebView, by calling WebView.WebViewTransport.setWebView(WebView).
Returns
boolean This method should return true if the host application will create a new window, in which case resultMsg should be sent to its target. Otherwise, this method should return false. Returning false from this method but also sending resultMsg will result in undefined behavior.

onExceededDatabaseQuota

Added in API level 5
void onExceededDatabaseQuota (String url, 
                String databaseIdentifier, 
                long quota, 
                long estimatedDatabaseSize, 
                long totalQuota, 
                WebStorage.QuotaUpdater quotaUpdater)

This method was deprecated in API level 19.
This method is no longer called; WebView now uses the HTML5 / JavaScript Quota Management API.

Tell the client that the quota has been exceeded for the Web SQL Database API for a particular origin and request a new quota. The client must respond by invoking the updateQuota(long) method of the supplied WebStorage.QuotaUpdater instance. The minimum value that can be set for the new quota is the current quota. The default implementation responds with the current quota, so the quota will not be increased.

Parameters
url String: The URL of the page that triggered the notification
databaseIdentifier String: The identifier of the database where the quota was exceeded.
quota long: The quota for the origin, in bytes
estimatedDatabaseSize long: The estimated size of the offending database, in bytes
totalQuota long: The total quota for all origins, in bytes
quotaUpdater WebStorage.QuotaUpdater: An instance of WebStorage.QuotaUpdater which must be used to inform the WebView of the new quota.

onGeolocationPermissionsHidePrompt

Added in API level 5
void onGeolocationPermissionsHidePrompt ()

Notify the host application that a request for Geolocation permissions, made with a previous call to onGeolocationPermissionsShowPrompt() has been canceled. Any related UI should therefore be hidden.

onGeolocationPermissionsShowPrompt

Added in API level 5
void onGeolocationPermissionsShowPrompt (String origin, 
                GeolocationPermissions.Callback callback)

Notify the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin. The host application should invoke the specified callback with the desired permission state. See GeolocationPermissions for details.

Note that for applications targeting Android N and later SDKs (API level > M) this method is only called for requests originating from secure origins such as https. On non-secure origins geolocation requests are automatically denied.

Parameters
origin String: The origin of the web content attempting to use the Geolocation API.
callback GeolocationPermissions.Callback: The callback to use to set the permission state for the origin.

onHideCustomView

Added in API level 7
void onHideCustomView ()

Notify the host application that the current page has exited full screen mode. The host application must hide the custom View, ie. the View passed to onShowCustomView(View, WebChromeClient.CustomViewCallback) when the content entered fullscreen. Also see "Full screen support" documentation on WebView.

onJsAlert

Added in API level 1
boolean onJsAlert (WebView view, 
                String url, 
                String message, 
                JsResult result)

Tell the client to display a javascript alert dialog. If the client returns true, WebView will assume that the client will handle the dialog. If the client returns false, it will continue execution.

Parameters
view WebView: The WebView that initiated the callback.
url String: The url of the page requesting the dialog.
message String: Message to be displayed in the window.
result JsResult: A JsResult to confirm that the user hit enter.
Returns
boolean boolean Whether the client will handle the alert dialog.

onJsBeforeUnload

Added in API level 1
boolean onJsBeforeUnload (WebView view, 
                String url, 
                String message, 
                JsResult result)

Tell the client to display a dialog to confirm navigation away from the current page. This is the result of the onbeforeunload javascript event. If the client returns true, WebView will assume that the client will handle the confirm dialog and call the appropriate JsResult method. If the client returns false, a default value of true will be returned to javascript to accept navigation away from the current page. The default behavior is to return false. Setting the JsResult to true will navigate away from the current page, false will cancel the navigation.

Parameters
view WebView: The WebView that initiated the callback.
url String: The url of the page requesting the dialog.
message String: Message to be displayed in the window.
result JsResult: A JsResult used to send the user's response to javascript.
Returns
boolean boolean Whether the client will handle the confirm dialog.

onJsConfirm

Added in API level 1
boolean onJsConfirm (WebView view, 
                String url, 
                String message, 
                JsResult result)

Tell the client to display a confirm dialog to the user. If the client returns true, WebView will assume that the client will handle the confirm dialog and call the appropriate JsResult method. If the client returns false, a default value of false will be returned to javascript. The default behavior is to return false.

Parameters
view WebView: The WebView that initiated the callback.
url String: The url of the page requesting the dialog.
message String: Message to be displayed in the window.
result JsResult: A JsResult used to send the user's response to javascript.
Returns
boolean boolean Whether the client will handle the confirm dialog.

onJsPrompt

Added in API level 1
boolean onJsPrompt (WebView view, 
                String url, 
                String message, 
                String defaultValue, 
                JsPromptResult result)

Tell the client to display a prompt dialog to the user. If the client returns true, WebView will assume that the client will handle the prompt dialog and call the appropriate JsPromptResult method. If the client returns false, a default value of false will be returned to to javascript. The default behavior is to return false.

Parameters
view WebView: The WebView that initiated the callback.
url String: The url of the page requesting the dialog.
message String: Message to be displayed in the window.
defaultValue String: The default value displayed in the prompt dialog.
result JsPromptResult: A JsPromptResult used to send the user's reponse to javascript.
Returns
boolean boolean Whether the client will handle the prompt dialog.

onJsTimeout

Added in API level 7
boolean onJsTimeout ()

This method was deprecated in API level 17.
This method is no longer supported and will not be invoked.

Tell the client that a JavaScript execution timeout has occured. And the client may decide whether or not to interrupt the execution. If the client returns true, the JavaScript will be interrupted. If the client returns false, the execution will continue. Note that in the case of continuing execution, the timeout counter will be reset, and the callback will continue to occur if the script does not finish at the next check point.

Returns
boolean boolean Whether the JavaScript execution should be interrupted.

onPermissionRequest

Added in API level 21
void onPermissionRequest (PermissionRequest request)

Notify the host application that web content is requesting permission to access the specified resources and the permission currently isn't granted or denied. The host application must invoke grant(String[]) or deny(). If this method isn't overridden, the permission is denied.

Parameters
request PermissionRequest: the PermissionRequest from current web content.

onPermissionRequestCanceled

Added in API level 21
void onPermissionRequestCanceled (PermissionRequest request)

Notify the host application that the given permission request has been canceled. Any related UI should therefore be hidden.

Parameters
request PermissionRequest: the PermissionRequest that needs be canceled.

onProgressChanged

Added in API level 1
void onProgressChanged (WebView view, 
                int newProgress)

Tell the host application the current progress of loading a page.

Parameters
view WebView: The WebView that initiated the callback.
newProgress int: Current page loading progress, represented by an integer between 0 and 100.

onReachedMaxAppCacheSize

Added in API level 7
void onReachedMaxAppCacheSize (long requiredStorage, 
                long quota, 
                WebStorage.QuotaUpdater quotaUpdater)

This method was deprecated in API level 19.
This method is no longer called; WebView now uses the HTML5 / JavaScript Quota Management API.

Notify the host application that the Application Cache has reached the maximum size. The client must respond by invoking the updateQuota(long) method of the supplied WebStorage.QuotaUpdater instance. The minimum value that can be set for the new quota is the current quota. The default implementation responds with the current quota, so the quota will not be increased.

Parameters
requiredStorage long: The amount of storage required by the Application Cache operation that triggered this notification, in bytes.
quota long: the current maximum Application Cache size, in bytes
quotaUpdater WebStorage.QuotaUpdater: An instance of WebStorage.QuotaUpdater which must be used to inform the WebView of the new quota.

onReceivedIcon

Added in API level 1
void onReceivedIcon (WebView view, 
                Bitmap icon)

Notify the host application of a new favicon for the current page.

Parameters
view WebView: The WebView that initiated the callback.
icon Bitmap: A Bitmap containing the favicon for the current page.

onReceivedTitle

Added in API level 1
void onReceivedTitle (WebView view, 
                String title)

Notify the host application of a change in the document title.

Parameters
view WebView: The WebView that initiated the callback.
title String: A String containing the new title of the document.

onReceivedTouchIconUrl

Added in API level 7
void onReceivedTouchIconUrl (WebView view, 
                String url, 
                boolean precomposed)

Notify the host application of the url for an apple-touch-icon.

Parameters
view WebView: The WebView that initiated the callback.
url String: The icon url.
precomposed boolean: True if the url is for a precomposed touch icon.

onRequestFocus

Added in API level 1
void onRequestFocus (WebView view)

Request display and focus for this WebView. This may happen due to another WebView opening a link in this WebView and requesting that this WebView be displayed.

Parameters
view WebView: The WebView that needs to be focused.

onShowCustomView

Added in API level 14
void onShowCustomView (View view, 
                int requestedOrientation, 
                WebChromeClient.CustomViewCallback callback)

This method was deprecated in API level 18.
This method supports the obsolete plugin mechanism, and will not be invoked in future

Notify the host application that the current page would like to show a custom View in a particular orientation.

Parameters
view View: is the View object to be shown.
requestedOrientation int: An orientation constant as used in ActivityInfo.screenOrientation.
callback WebChromeClient.CustomViewCallback: is the callback to be invoked if and when the view is dismissed.

onShowCustomView

Added in API level 7
void onShowCustomView (View view, 
                WebChromeClient.CustomViewCallback callback)

Notify the host application that the current page has entered full screen mode. The host application must show the custom View which contains the web contents — video or other HTML content — in full screen mode. Also see "Full screen support" documentation on WebView.

Parameters
view View: is the View object to be shown.
callback WebChromeClient.CustomViewCallback: invoke this callback to request the page to exit full screen mode.

onShowFileChooser

Added in API level 21
boolean onShowFileChooser (WebView webView, 
                ValueCallback<Uri[]> filePathCallback, 
                WebChromeClient.FileChooserParams fileChooserParams)

Tell the client to show a file chooser. This is called to handle HTML forms with 'file' input type, in response to the user pressing the "Select File" button. To cancel the request, call filePathCallback.onReceiveValue(null) and return true.

Parameters
webView WebView: The WebView instance that is initiating the request.
filePathCallback ValueCallback: Invoke this callback to supply the list of paths to files to upload, or NULL to cancel. Must only be called if the showFileChooser implementations returns true.
fileChooserParams WebChromeClient.FileChooserParams: Describes the mode of file chooser to be opened, and options to be used with it.
Returns
boolean true if filePathCallback will be invoked, false to use default handling.

See also:

Hooray!