• BlackBerry Dynamics
  • Runtime library for Android applications
  • 10.2.0.79
BBWebChromeClient Class Reference

Provides additional functionality for BBWebView. More...

Inherits BBWebChromeClientImpl.

Description

Class provides additional functionality for BBWebView. These include:

  • Outputting a JavaScript console message
  • Showing a JavaScript prompt dialog
  • Notifying on page loading progress
  • etc

Public Member Functions

 BBWebChromeClient ()
 Creates BBWebChromeClient object.
 
 BBWebChromeClient (WebClientObserver clientObserver)
 Creates BBWebChromeClient object. More...
 
boolean onConsoleMessage (android.webkit.ConsoleMessage consoleMessage)
 Redirects logs from JavaScript console inside Dynamics runtime. More...
 
boolean onJsPrompt (WebView view, String url, String message, String defaultValue, JsPromptResult result)
 Shows JavaScript prompt dialog with passed massage. More...
 
void onProgressChanged (WebView view, int newProgress)
 Notifies about progress change attached listeners. More...
 
void onReceivedTitle (WebView view, String title)
 Notify the host application of a change in the document title. More...
 
void onReceivedIcon (WebView view, Bitmap icon)
 Notify the host application of a new favicon for the current page. More...
 
void onReceivedTouchIconUrl (WebView view, String url, boolean precomposed)
 Notify the host application of the url for an apple-touch-icon. More...
 
void onShowCustomView (View view, CustomViewCallback callback)
 Notify the host application that the current page has entered full screen mode. More...
 
void onShowCustomView (View view, int requestedOrientation, CustomViewCallback callback)
 Notify the host application that the current page would like to show a custom View in a particular orientation. More...
 
void onHideCustomView ()
 Notify the host application that the current page has exited full screen mode. More...
 
boolean onCreateWindow (WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg)
 Request the host application to create a new window. More...
 
void onRequestFocus (WebView view)
 Request display and focus for this WebView. More...
 
void onCloseWindow (WebView window)
 Notify the host application to close the given WebView and remove it from the view system if necessary. More...
 
boolean onJsAlert (WebView view, String url, String message, JsResult result)
 Notify the host application that the web page wants to display a JavaScript. More...
 
boolean onJsConfirm (WebView view, String url, String message, JsResult result)
 Notify the host application that the web page wants to display a JavaScript. More...
 
boolean onJsBeforeUnload (WebView view, String url, String message, JsResult result)
 Notify the host application that the web page wants to confirm navigation from JavaScript. More...
 
void onExceededDatabaseQuota (String url, String databaseIdentifier, long quota, long estimatedDatabaseSize, long totalQuota, WebStorage.QuotaUpdater quotaUpdater)
 Tell the client that the quota has been exceeded for the Web SQL Database API for a particular origin and request a new quota. More...
 
void onReachedMaxAppCacheSize (long requiredStorage, long quota, WebStorage.QuotaUpdater quotaUpdater)
 Notify the host application that the Application Cache has reached the maximum size. More...
 
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. More...
 
void onGeolocationPermissionsHidePrompt ()
 Notify the host application that a request for Geolocation permissions, made with a previous call to onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) onGeolocationPermissionsShowPrompt() has been canceled. More...
 
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. More...
 
void onPermissionRequestCanceled (PermissionRequest request)
 Notify the host application that the given permission request has been canceled. More...
 
boolean onJsTimeout ()
 Tell the client that a JavaScript execution timeout has occured. More...
 
void onConsoleMessage (String message, int lineNumber, String sourceID)
 Report a JavaScript error message to the host application. More...
 
Bitmap getDefaultVideoPoster ()
 When not playing, video elements are represented by a 'poster' image. More...
 
View getVideoLoadingProgressView ()
 Obtains a View to be displayed while buffering of full screen video is taking place. More...
 
void getVisitedHistory (ValueCallback< String[]> callback)
 Obtains a list of all visited history items, used for link coloring.
 
boolean onShowFileChooser (WebView webView, ValueCallback< Uri[]> filePathCallback, FileChooserParams fileChooserParams)
 Tell the client to show a file chooser. More...
 

Constructor & Destructor Documentation

◆ BBWebChromeClient()

BBWebChromeClient ( WebClientObserver  clientObserver)
Parameters
clientObserver- observer for progress changes of web page loading

Member Function Documentation

◆ onConsoleMessage() [1/2]

boolean onConsoleMessage ( android.webkit.ConsoleMessage  consoleMessage)
Parameters
consoleMessageObject containing details of the console message.
Returns
true if the message is handled by the client.

◆ onJsPrompt()

boolean onJsPrompt ( WebView  view,
String  url,
String  message,
String  defaultValue,
JsPromptResult  result 
)
Parameters
viewThe WebView that initiated the callback.
urlNot currently used.
messageMessage to be displayed in the window.
defaultValueThe default value displayed in the prompt dialog.
resultA JsPromptResult used to send the user's response to javascript.
Returns
boolean
  • true if the request is handled or ignored.
  • false if the WebView needs to show the default dialog.

◆ onProgressChanged()

void onProgressChanged ( WebView  view,
int  newProgress 
)

Please, see WebClientObserver.

Parameters
viewThe WebView that initiated the callback.
newProgressCurrent page loading progress, represented by an integer between 0 and 100.

◆ onReceivedTitle()

void onReceivedTitle ( WebView  view,
String  title 
)
Parameters
viewThe WebView that initiated the callback.
titleA String containing the new title of the document.

◆ onReceivedIcon()

void onReceivedIcon ( WebView  view,
Bitmap  icon 
)
Parameters
viewThe WebView that initiated the callback.
iconA Bitmap containing the favicon for the current page.

◆ onReceivedTouchIconUrl()

void onReceivedTouchIconUrl ( WebView  view,
String  url,
boolean  precomposed 
)
Parameters
viewThe WebView that initiated the callback.
urlThe icon url.
precomposedtrue if the url is for a precomposed touch icon.

◆ onShowCustomView() [1/2]

void onShowCustomView ( View  view,
CustomViewCallback  callback 
)

After this call, web content will no longer be rendered in the WebView, but will instead be rendered in

view

. The host application should add this View to a Window which is configured with android.view.WindowManager.LayoutParams::FLAG_FULLSCREEN flag in order to actually display this web content full screen.

The application may explicitly exit fullscreen mode by invoking

callback

(ex. when the user presses the back button). However, this is generally not necessary as the web page will often show its own UI to close out of fullscreen. Regardless of how the WebView exits fullscreen mode, WebView will invoke onHideCustomView(), signaling for the application to remove the custom View.

If this method is not overridden, WebView will report to the web page it does not support fullscreen mode and will not honor the web page's request to run in fullscreen mode.

Note: if overriding this method, the application must also override onHideCustomView().

Parameters
viewis the View object to be shown.
callbackinvoke this callback to request the page to exit full screen mode.

◆ onShowCustomView() [2/2]

void onShowCustomView ( View  view,
int  requestedOrientation,
CustomViewCallback  callback 
)
Parameters
viewis the View object to be shown.
requestedOrientationAn orientation constant as used in ActivityInfo::screenOrientation ActivityInfo.screenOrientation.
callbackis the callback to be invoked if and when the view is dismissed.
Deprecated:
This method supports the obsolete plugin mechanism, and will not be invoked in future

◆ onHideCustomView()

void onHideCustomView ( )

The host application must hide the custom View (the View which was previously passed to onShowCustomView(View, CustomViewCallback) onShowCustomView()). After this call, web content will render in the original WebView again.

Note: if overriding this method, the application must also override onShowCustomView(View, CustomViewCallback) onShowCustomView().

◆ onCreateWindow()

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

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

.

Applications should typically not allow windows to be created when the

isUserGesture

flag is false, as this may be an unwanted popup.

Applications should be careful how they display the new window: don't simply overlay it over the existing WebView as this may mislead the user about which site they are viewing. If your application displays the URL of the main page, make sure to also display the URL of the new window in a similar fashion. If your application does not display URLs, consider disallowing the creation of new windows entirely.

Note: There is no trustworthy way to tell which page requested the new window: the request might originate from a third-party iframe inside the WebView.

Parameters
viewThe WebView from which the request for a new window originated.
isDialogtrue if the new window should be a dialog, rather than a full-size window.
isUserGesturetrue if the request was initiated by a user gesture, such as the user clicking a link.
resultMsgThe 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) WebView.WebViewTransport.setWebView(WebView).
Returns
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.

◆ onRequestFocus()

void onRequestFocus ( WebView  view)

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

Parameters
viewThe WebView that needs to be focused.

◆ onCloseWindow()

void onCloseWindow ( WebView  window)

At this point, WebCore has stopped any loading in this window and has removed any cross-scripting ability in javascript.

As with onCreateWindow, the application should ensure that any URL or security indicator displayed is updated so that the user can tell that the page they were interacting with has been closed.

Parameters
windowThe WebView that needs to be closed.

◆ onJsAlert()

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

dialog.

The default behavior if this method returns

false

or is not overridden is to show a dialog containing the alert message and suspend JavaScript execution until the dialog is dismissed.

To show a custom dialog, the app should return

true

from this method, in which case the default dialog will not be shown and JavaScript execution will be suspended. The app should call

JsResult.confirm()

when the custom dialog is dismissed such that JavaScript execution can be resumed.

To suppress the dialog and allow JavaScript execution to continue, call

JsResult.confirm()

immediately and then return

true

.

Note that if the WebChromeClient is set to be

null

, or if WebChromeClient is not set at all, the default dialog will be suppressed and Javascript execution will continue immediately.

Note that the default dialog does not inherit the android.view.Display::FLAG_SECURE flag from the parent window.

Parameters
viewThe WebView that initiated the callback.
urlThe url of the page requesting the dialog.
messageMessage to be displayed in the window.
resultA JsResult to confirm that the user closed the window.
Returns
boolean
true
if the request is handled or ignored.
false
if WebView needs to show the default dialog.

◆ onJsConfirm()

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

dialog.

The default behavior if this method returns

false

or is not overridden is to show a dialog containing the message and suspend JavaScript execution until the dialog is dismissed. The default dialog will return

true

to the JavaScript

confirm()

code when the user presses the 'confirm' button, and will return

false

to the JavaScript code when the user presses the 'cancel' button or dismisses the dialog.

To show a custom dialog, the app should return

true

from this method, in which case the default dialog will not be shown and JavaScript execution will be suspended. The app should call

JsResult.confirm()

or

JsResult.cancel()

when the custom dialog is dismissed.

To suppress the dialog and allow JavaScript execution to continue, call

JsResult.confirm()

or

JsResult.cancel()

immediately and then return

true

.

Note that if the WebChromeClient is set to be

null

, or if WebChromeClient is not set at all, the default dialog will be suppressed and the default value of

false

will be returned to the JavaScript code immediately.

Note that the default dialog does not inherit the android.view.Display::FLAG_SECURE flag from the parent window.

Parameters
viewThe WebView that initiated the callback.
urlThe url of the page requesting the dialog.
messageMessage to be displayed in the window.
resultA JsResult used to send the user's response to javascript.
Returns
boolean
true
if the request is handled or ignored.
false
if WebView needs to show the default dialog.

◆ onJsBeforeUnload()

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

.

The default behavior if this method returns

false

or is not overridden is to show a dialog containing the message and suspend JavaScript execution until the dialog is dismissed. The default dialog will continue the navigation if the user confirms the navigation, and will stop the navigation if the user wants to stay on the current page.

To show a custom dialog, the app should return

true

from this method, in which case the default dialog will not be shown and JavaScript execution will be suspended. When the custom dialog is dismissed, the app should call

JsResult.confirm()

to continue the navigation or,

JsResult.cancel()

to stay on the current page.

To suppress the dialog and allow JavaScript execution to continue, call

JsResult.confirm()

or

JsResult.cancel()

immediately and then return

true

.

Note that if the WebChromeClient is set to be

null

, or if WebChromeClient is not set at all, the default dialog will be suppressed and the navigation will be resumed immediately.

Note that the default dialog does not inherit the android.view.Display::FLAG_SECURE flag from the parent window.

Parameters
viewThe WebView that initiated the callback.
urlThe url of the page requesting the dialog.
messageMessage to be displayed in the window.
resultA JsResult used to send the user's response to javascript.
Returns
boolean
true
if the request is handled or ignored.
false
if WebView needs to show the default dialog.

◆ onExceededDatabaseQuota()

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

The client must respond by invoking the WebStorage.QuotaUpdater::updateQuota(long) 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
urlThe URL of the page that triggered the notification
databaseIdentifierThe identifier of the database where the quota was exceeded.
quotaThe quota for the origin, in bytes
estimatedDatabaseSizeThe estimated size of the offending database, in bytes
totalQuotaThe total quota for all origins, in bytes
quotaUpdaterAn instance of WebStorage.QuotaUpdater which must be used to inform the WebView of the new quota.
Deprecated:
This method is no longer called; WebView now uses the HTML5 / JavaScript Quota Management API.

◆ onReachedMaxAppCacheSize()

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

The client must respond by invoking the WebStorage.QuotaUpdater::updateQuota(long) 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
requiredStorageThe amount of storage required by the Application Cache operation that triggered this notification, in bytes.
quotathe current maximum Application Cache size, in bytes
quotaUpdaterAn instance of WebStorage.QuotaUpdater which must be used to inform the WebView of the new quota.
Deprecated:
This method is no longer called; WebView now uses the HTML5 / JavaScript Quota Management API.

◆ onGeolocationPermissionsShowPrompt()

void onGeolocationPermissionsShowPrompt ( String  origin,
GeolocationPermissions.Callback  callback 
)

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 > android.os.Build.VERSION_CODES::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
originThe origin of the web content attempting to use the Geolocation API.
callbackThe callback to use to set the permission state for the origin.

◆ onGeolocationPermissionsHidePrompt()

void onGeolocationPermissionsHidePrompt ( )

Any related UI should therefore be hidden.

◆ onPermissionRequest()

void onPermissionRequest ( PermissionRequest  request)

The host application must invoke PermissionRequest::grant(String[]) or PermissionRequest::deny().

If this method isn't overridden, the permission is denied.

Parameters
requestthe PermissionRequest from current web content.

◆ onPermissionRequestCanceled()

void onPermissionRequestCanceled ( PermissionRequest  request)

Any related UI should therefore be hidden.

Parameters
requestthe PermissionRequest that needs be canceled.

◆ onJsTimeout()

boolean onJsTimeout ( )

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.
Deprecated:
This method is no longer supported and will not be invoked.

◆ onConsoleMessage() [2/2]

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

The ChromeClient should override this to process the log message as they see fit.

Parameters
messageThe error message to report.
lineNumberThe line number of the error.
sourceIDThe name of the source file that caused the error.
Deprecated:
Use onConsoleMessage(ConsoleMessage) instead.

◆ getDefaultVideoPoster()

Bitmap getDefaultVideoPoster ( )

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.

◆ getVideoLoadingProgressView()

View getVideoLoadingProgressView ( )

The host application can override this method to provide a View containing a spinner or similar.

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

◆ onShowFileChooser()

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

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
webViewThe WebView instance that is initiating the request.
filePathCallbackInvoke this callback to supply the list of paths to files to upload, or
null
to cancel. Must only be called if the onShowFileChooser implementation returns
true
.
fileChooserParamsDescribes the mode of file chooser to be opened, and options to be used with it.
Returns
true
if filePathCallback will be invoked,
false
to use default handling.
See also
FileChooserParams