Profile


interface Profile


A Profile represents one browsing session for WebView.

You can have multiple profiles and each profile holds its own set of data. The creation and deletion of the Profile is being managed by ProfileStore.

Summary

Nested types

@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.METHOD, ElementType.TYPE, ElementType.FIELD])
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
annotation Profile.ExperimentalUrlPrefetch

Denotes that the UrlPrefetch API surface is experimental.

Constants

const String!

Represents the name of the default profile which can't be deleted.

Public functions

Unit
@RequiresFeature(name = WebViewFeature.PROFILE_URL_PREFETCH, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@AnyThread
@Profile.ExperimentalUrlPrefetch
clearPrefetchAsync(
    url: String,
    operationCallback: PrefetchOperationCallback<Void!>
)

Removes a cached prefetch response for the provided url if it exists, otherwise does nothing.

CookieManager
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getCookieManager()

Returns the profile's cookie manager.

GeolocationPermissions
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getGeolocationPermissions()

Returns the geolocation permissions of the profile.

String
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getName()
ServiceWorkerController
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getServiceWorkerController()

Returns the service worker controller of the profile.

WebStorage
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
getWebStorage()

Returns the profile's web storage.

Unit
@RequiresFeature(name = WebViewFeature.PROFILE_URL_PREFETCH, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@AnyThread
@Profile.ExperimentalUrlPrefetch
prefetchUrlAsync(
    url: String,
    cancellationSignal: CancellationSignal?,
    operationCallback: PrefetchOperationCallback<Void!>
)

Starts a URL prefetch request.

Unit
@RequiresFeature(name = WebViewFeature.PROFILE_URL_PREFETCH, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@AnyThread
@Profile.ExperimentalUrlPrefetch
prefetchUrlAsync(
    url: String,
    cancellationSignal: CancellationSignal?,
    operationCallback: PrefetchOperationCallback<Void!>,
    prefetchParameters: PrefetchParameters
)

Starts a URL prefetch request.

Constants

DEFAULT_PROFILE_NAME

Added in 1.9.0
const val DEFAULT_PROFILE_NAME = "Default": String!

Represents the name of the default profile which can't be deleted.

Public functions

clearPrefetchAsync

@RequiresFeature(name = WebViewFeature.PROFILE_URL_PREFETCH, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@AnyThread
@Profile.ExperimentalUrlPrefetch
fun clearPrefetchAsync(
    url: String,
    operationCallback: PrefetchOperationCallback<Void!>
): Unit

Removes a cached prefetch response for the provided url if it exists, otherwise does nothing.

Calling this does not guarantee that the prefetched response will not be served to a WebView before it is cleared.

Parameters
url: String

the url associated with the prefetch request.

operationCallback: PrefetchOperationCallback<Void!>

runs when the clear operation is complete Or and error occurred during it.

getCookieManager

Added in 1.9.0
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun getCookieManager(): CookieManager

Returns the profile's cookie manager.

Can be called from any thread.

Throws
java.lang.IllegalStateException

if the profile has been deleted by deleteProfile}.

getGeolocationPermissions

Added in 1.9.0
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun getGeolocationPermissions(): GeolocationPermissions

Returns the geolocation permissions of the profile.

Can be called from any thread.

Throws
java.lang.IllegalStateException

if the profile has been deleted by deleteProfile}.

getName

Added in 1.9.0
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun getName(): String
Returns
String

the name of this Profile which was used to create the Profile from ProfileStore create methods.

getServiceWorkerController

Added in 1.9.0
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun getServiceWorkerController(): ServiceWorkerController

Returns the service worker controller of the profile.

Can be called from any thread.

Throws
java.lang.IllegalStateException

if the profile has been deleted by deleteProfile}.

getWebStorage

Added in 1.9.0
@AnyThread
@RequiresFeature(name = WebViewFeature.MULTI_PROFILE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun getWebStorage(): WebStorage

Returns the profile's web storage.

Can be called from any thread.

Throws
java.lang.IllegalStateException

if the profile has been deleted by deleteProfile}.

prefetchUrlAsync

@RequiresFeature(name = WebViewFeature.PROFILE_URL_PREFETCH, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@AnyThread
@Profile.ExperimentalUrlPrefetch
fun prefetchUrlAsync(
    url: String,
    cancellationSignal: CancellationSignal?,
    operationCallback: PrefetchOperationCallback<Void!>
): Unit

Starts a URL prefetch request. Can be called from any thread.

All WebViews associated with this Profile will use a URL request matching algorithm during execution of all variants of loadUrl for determining if there was already a prefetch request executed for the provided URL. This includes prefetches that are "in progress". If a prefetch is matched, WebView will leverage that for handling the URL, otherwise the URL will be handled normally (i.e. through a network request).

Applications will still be responsible for calling loadUrl to display web contents in a WebView.

For max latency saving benefits, it is recommended to call this method as early as possible (i.e. before any WebView associated with this profile is created).

Only supports HTTPS scheme.

All result callbacks will be resolved on the calling thread.

Parameters
url: String

the url associated with the prefetch request.

cancellationSignal: CancellationSignal?

will make the best effort to cancel an in-flight prefetch request, However cancellation is not guaranteed.

operationCallback: PrefetchOperationCallback<Void!>

callbacks for reporting result back to application.

prefetchUrlAsync

@RequiresFeature(name = WebViewFeature.PROFILE_URL_PREFETCH, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@AnyThread
@Profile.ExperimentalUrlPrefetch
fun prefetchUrlAsync(
    url: String,
    cancellationSignal: CancellationSignal?,
    operationCallback: PrefetchOperationCallback<Void!>,
    prefetchParameters: PrefetchParameters
): Unit

Starts a URL prefetch request. Can be called from any thread.

All WebViews associated with this Profile will use a URL request matching algorithm during execution of all variants of loadUrl for determining if there was already a prefetch request executed for the provided URL. This includes prefetches that are "in progress". If a prefetch is matched, WebView will leverage that for handling the URL, otherwise the URL will be handled normally (i.e. through a network request).

Applications will still be responsible for calling loadUrl to display web contents in a WebView.

For max latency saving benefits, it is recommended to call this method as early as possible (i.e. before any WebView associated with this profile is created).

Only supports HTTPS scheme.

All result callbacks will be resolved on the calling thread.

Parameters
url: String

the url associated with the prefetch request.

cancellationSignal: CancellationSignal?

will make the best effort to cancel an in-flight prefetch request, However cancellation is not guaranteed.

operationCallback: PrefetchOperationCallback<Void!>

callbacks for reporting result back to application.

prefetchParameters: PrefetchParameters

custom prefetch parameters.