WebStorageCompat


public final class WebStorageCompat


Compatibility class for android.webkit.WebStorage that introduces new methods to completely clear data.

WebStorage is tied to WebView Profile instances. If your app uses multiple profiles, then you should ensure that you clear data for all relevant profiles.

A android.webkit.WebStorage instance can be obtained from getInstance, or from getWebStorage if your app is using multiple WebView profiles.

Summary

Public methods

static void
@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
deleteBrowsingData(
    @NonNull WebStorage instance,
    @NonNull Runnable doneCallback
)

Delete all data stored by websites in the given WebStorage instance.

static void
@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
deleteBrowsingData(
    @NonNull WebStorage instance,
    @NonNull Executor executor,
    @NonNull Runnable doneCallback
)

Delete all data stored by websites in the given WebStorage instance.

static @NonNull String
@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
deleteBrowsingDataForSite(
    @NonNull WebStorage instance,
    @NonNull String site,
    @NonNull Runnable doneCallback
)

Delete data stored by web storage APIs for the specified domain in the given WebStorage instance.

static @NonNull String
@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
deleteBrowsingDataForSite(
    @NonNull WebStorage instance,
    @NonNull String site,
    @NonNull Executor executor,
    @NonNull Runnable doneCallback
)

Delete data stored by web storage APIs for the specified domain in the given WebStorage instance.

Public methods

deleteBrowsingData

@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
public static void deleteBrowsingData(
    @NonNull WebStorage instance,
    @NonNull Runnable doneCallback
)

Delete all data stored by websites in the given WebStorage instance.

This method functions as deleteBrowsingData, but invokes the doneCallback on the UI thread.

deleteBrowsingData

@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
public static void deleteBrowsingData(
    @NonNull WebStorage instance,
    @NonNull Executor executor,
    @NonNull Runnable doneCallback
)

Delete all data stored by websites in the given WebStorage instance. This includes network cache, cookies, and any JavaScript-readable storage.

This method will delete all data that was stored before being invoked. Deletion is not an atomic operation, so it may also delete data that is stored during deletion, but this is not guaranteed.

Parameters
@NonNull WebStorage instance

WebStorage instance to delete all data in.

@NonNull Executor executor

Executor to run the doneCallback.

@NonNull Runnable doneCallback

callback that will be invoked when deletion is complete.

deleteBrowsingDataForSite

@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
public static @NonNull String deleteBrowsingDataForSite(
    @NonNull WebStorage instance,
    @NonNull String site,
    @NonNull Runnable doneCallback
)

Delete data stored by web storage APIs for the specified domain in the given WebStorage instance.

This method functions as deleteBrowsingDataForSite, but invokes the doneCallback on the UI thread.

deleteBrowsingDataForSite

@RequiresFeature(name = WebViewFeature.DELETE_BROWSING_DATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
public static @NonNull String deleteBrowsingDataForSite(
    @NonNull WebStorage instance,
    @NonNull String site,
    @NonNull Executor executor,
    @NonNull Runnable doneCallback
)

Delete data stored by web storage APIs for the specified domain in the given WebStorage instance. This includes network cache, cookies, and any JavaScript-readable storage.

For partitioned storage, this method will remove all data owned by the site, as well as all storage for content embedded in the specified site, e.g. iframed content.

This method deletes storage for the site part of the input argument. This means that if the input argument contains a subdomain (for example www.example.com), then this method will delete everything belonging to example.com.

This method will delete all data that was stored before being invoked. Deletion is not an atomic operation, so it may also delete data that is stored during deletion, but this is not guaranteed.

Parameters
@NonNull WebStorage instance

WebStorage instance to delete all data in.

@NonNull String site

The site to delete for. This can be a domain name, or a full URL.

@NonNull Executor executor

Executor to run the doneCallback.

@NonNull Runnable doneCallback

callback that will be invoked when deletion is complete.

Returns
@NonNull String

The domain that was used for deletion. This will be the top-level domain part of the domain parameter.

Throws
java.lang.IllegalArgumentException

if unable to parse the domain as a domain name.