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. 
Public Constructors
WebChromeClient()
Public Methods
Bitmap getDefaultVideoPoster()
When not playing, video elements are represented by a 'poster' image.
View getVideoLoadingProgressView()
When the user starts to playback a video element, it may take time for enough data to be buffered before the first frames can be rendered.
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.
void onConsoleMessage(String message, int lineNumber, String sourceID)
This method is deprecated. Use onConsoleMessage(ConsoleMessage) instead.
boolean onConsoleMessage(ConsoleMessage consoleMessage)
Report a JavaScript console message to the host application.
boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg)
Request the host application to create a new Webview.
void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
Tell the client that the database quota for the origin has been exceeded.
void onGeolocationPermissionsHidePrompt()
Instructs the client to hide the Geolocation permissions prompt.
void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback)
Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
void onHideCustomView()
Notify the host application that the current page would like to hide its custom view.
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()
Tell the client that a JavaScript execution timeout has occured.
void onProgressChanged(WebView view, int newProgress)
Tell the host application the current progress of loading a page.
void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
Tell the client that the Application Cache has exceeded its max size.
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, WebChromeClient.CustomViewCallback callback)
Notify the host application that the current page would like to show a custom View.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public WebChromeClient ()

Since: API Level 1

Public Methods

public Bitmap getDefaultVideoPoster ()

Since: API Level 7

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 The image to use as a default poster, or null if no such image is available.

public View getVideoLoadingProgressView ()

Since: API Level 7

When the user starts to playback a video element, it may take time for enough data to be buffered before the first frames can be rendered. While this buffering is taking place, the ChromeClient can use this function to provide a View to be displayed. For example, the ChromeClient could show a spinner animation.

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

public void getVisitedHistory (ValueCallback<String[]> callback)

Since: API Level 7

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

public void onCloseWindow (WebView window)

Since: API Level 1

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 The WebView that needs to be closed.

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

Since: API Level 7

This method is deprecated.
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 The error message to report.
lineNumber The line number of the error.
sourceID The name of the source file that caused the error.

public boolean onConsoleMessage (ConsoleMessage consoleMessage)

Since: API Level 8

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 Object containing details of the console message.
Returns
  • true if the message is handled by the client.

public boolean onCreateWindow (WebView view, boolean dialog, boolean userGesture, Message resultMsg)

Since: API Level 1

Request the host application to create a new Webview. The host application should handle placement of the new WebView in the view system. The default behavior returns null.

Parameters
view The WebView that initiated the callback.
dialog True if the new window is meant to be a small dialog window.
userGesture True if the request was initiated by a user gesture such as clicking a link.
resultMsg The message to send when done creating a new WebView. Set the new WebView through resultMsg.obj which is WebView.WebViewTransport() and then call resultMsg.sendToTarget();
Returns
  • Similar to javscript dialogs, this method should return true if the client is going to handle creating a new WebView. Note that the WebView will halt processing if this method returns true so make sure to call resultMsg.sendToTarget(). It is undefined behavior to call resultMsg.sendToTarget() after returning false from this method.

public void onExceededDatabaseQuota (String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)

Since: API Level 5

Tell the client that the database quota for the origin has been exceeded.

Parameters
url The URL that triggered the notification
databaseIdentifier The identifier of the database that caused the quota overflow.
currentQuota The current quota for the origin.
estimatedSize The estimated size of the database.
totalUsedQuota is the sum of all origins' quota.
quotaUpdater A callback to inform the WebCore thread that a new quota is available. This callback must always be executed at some point to ensure that the sleeping WebCore thread is woken up.

public void onGeolocationPermissionsHidePrompt ()

Since: API Level 5

Instructs the client to hide the Geolocation permissions prompt.

public void onGeolocationPermissionsShowPrompt (String origin, GeolocationPermissions.Callback callback)

Since: API Level 5

Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.

public void onHideCustomView ()

Since: API Level 7

Notify the host application that the current page would like to hide its custom view.

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

Since: API Level 1

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 The WebView that initiated the callback.
url The url of the page requesting the dialog.
message Message to be displayed in the window.
result A JsResult to confirm that the user hit enter.
Returns
  • boolean Whether the client will handle the alert dialog.

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

Since: API Level 1

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 The WebView that initiated the callback.
url The url of the page requesting the dialog.
message Message to be displayed in the window.
result A JsResult used to send the user's response to javascript.
Returns
  • boolean Whether the client will handle the confirm dialog.

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

Since: API Level 1

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 The WebView that initiated the callback.
url The url of the page requesting the dialog.
message Message to be displayed in the window.
result A JsResult used to send the user's response to javascript.
Returns
  • boolean Whether the client will handle the confirm dialog.

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

Since: API Level 1

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 The WebView that initiated the callback.
url The url of the page requesting the dialog.
message Message to be displayed in the window.
defaultValue The default value displayed in the prompt dialog.
result A JsPromptResult used to send the user's reponse to javascript.
Returns
  • boolean Whether the client will handle the prompt dialog.

public boolean onJsTimeout ()

Since: API Level 7

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 Whether the JavaScript execution should be interrupted.

public void onProgressChanged (WebView view, int newProgress)

Since: API Level 1

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

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

public void onReachedMaxAppCacheSize (long spaceNeeded, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)

Since: API Level 7

Tell the client that the Application Cache has exceeded its max size.

Parameters
spaceNeeded is the amount of disk space that would be needed in order for the last appcache operation to succeed.
totalUsedQuota is the sum of all origins' quota.
quotaUpdater A callback to inform the WebCore thread that a new app cache size is available. This callback must always be executed at some point to ensure that the sleeping WebCore thread is woken up.

public void onReceivedIcon (WebView view, Bitmap icon)

Since: API Level 1

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

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

public void onReceivedTitle (WebView view, String title)

Since: API Level 1

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

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

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

Since: API Level 7

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

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

public void onRequestFocus (WebView view)

Since: API Level 1

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 The WebView that needs to be focused.

public void onShowCustomView (View view, WebChromeClient.CustomViewCallback callback)

Since: API Level 7

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

Parameters
view is the View object to be shown.
callback is the callback to be invoked if and when the view is dismissed.