diff options
| -rw-r--r-- | core/java/android/webkit/ServiceWorkerClient.java | 7 | ||||
| -rw-r--r-- | core/java/android/webkit/ServiceWorkerController.java | 21 | ||||
| -rw-r--r-- | core/java/android/webkit/ServiceWorkerWebSettings.java | 13 | ||||
| -rw-r--r-- | core/java/android/webkit/WebSettings.java | 11 |
4 files changed, 40 insertions, 12 deletions
diff --git a/core/java/android/webkit/ServiceWorkerClient.java b/core/java/android/webkit/ServiceWorkerClient.java index 85de698678d9..23340550def3 100644 --- a/core/java/android/webkit/ServiceWorkerClient.java +++ b/core/java/android/webkit/ServiceWorkerClient.java @@ -16,7 +16,10 @@ package android.webkit; - +/** + * Base class for clients to capture Service Worker related callbacks, + * see {@link ServiceWorkerController} for usage example. + */ public class ServiceWorkerClient { /** @@ -32,7 +35,7 @@ public class ServiceWorkerClient { * @return A {@link android.webkit.WebResourceResponse} containing the * response information or null if the WebView should load the * resource itself. - * @see {@link WebViewClient#shouldInterceptRequest()} + * @see WebViewClient#shouldInterceptRequest(WebView, WebResourceRequest) */ public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) { return null; diff --git a/core/java/android/webkit/ServiceWorkerController.java b/core/java/android/webkit/ServiceWorkerController.java index 91155584a19d..571d45e22d3b 100644 --- a/core/java/android/webkit/ServiceWorkerController.java +++ b/core/java/android/webkit/ServiceWorkerController.java @@ -21,6 +21,19 @@ import android.annotation.Nullable; /** * Manages Service Workers used by WebView. + * + * <p>Example usage: + * <pre class="prettyprint"> + * ServiceWorkerController swController = ServiceWorkerController.getInstance(); + * swController.setServiceWorkerClient(new ServiceWorkerClient() { + * {@literal @}Override + * public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) { + * // Capture request here and generate response or allow pass-through + * // by returning null. + * return null; + * } + * }); + * </pre></p> */ public abstract class ServiceWorkerController { @@ -29,7 +42,7 @@ public abstract class ServiceWorkerController { * only one ServiceWorkerController instance for all WebView instances, * however this restriction may be relaxed in the future. * - * @return The default ServiceWorkerController instance. + * @return the default ServiceWorkerController instance */ @NonNull public static ServiceWorkerController getInstance() { @@ -39,13 +52,17 @@ public abstract class ServiceWorkerController { /** * Gets the settings for all service workers. * - * @return The current ServiceWorkerWebSettings + * @return the current ServiceWorkerWebSettings */ @NonNull public abstract ServiceWorkerWebSettings getServiceWorkerWebSettings(); /** * Sets the client to capture service worker related callbacks. + * + * A {@link ServiceWorkerClient} should be set before any service workers are + * active, e.g. a safe place is before any WebView instances are created or + * pages loaded. */ public abstract void setServiceWorkerClient(@Nullable ServiceWorkerClient client); } diff --git a/core/java/android/webkit/ServiceWorkerWebSettings.java b/core/java/android/webkit/ServiceWorkerWebSettings.java index 8b104d1c7e3b..92e9fbe29b55 100644 --- a/core/java/android/webkit/ServiceWorkerWebSettings.java +++ b/core/java/android/webkit/ServiceWorkerWebSettings.java @@ -30,9 +30,12 @@ public abstract class ServiceWorkerWebSettings { /** * Overrides the way the cache is used, see {@link WebSettings#setCacheMode}. * - * @param mode the mode to use + * @param mode the mode to use. One of {@link WebSettings#LOAD_DEFAULT}, + * {@link WebSettings#LOAD_CACHE_ELSE_NETWORK}, {@link WebSettings#LOAD_NO_CACHE} + * or {@link WebSettings#LOAD_CACHE_ONLY}. The default value is + * {@link WebSettings#LOAD_DEFAULT}. */ - public abstract void setCacheMode(int mode); + public abstract void setCacheMode(@WebSettings.CacheMode int mode); /** * Gets the current setting for overriding the cache mode. @@ -40,6 +43,7 @@ public abstract class ServiceWorkerWebSettings { * @return the current setting for overriding the cache mode * @see #setCacheMode */ + @WebSettings.CacheMode public abstract int getCacheMode(); /** @@ -69,11 +73,10 @@ public abstract class ServiceWorkerWebSettings { public abstract boolean getAllowFileAccess(); /** - * Sets whether the Service Workers should not load resources from the network, + * Sets whether Service Workers should not load resources from the network, * see {@link WebSettings#setBlockNetworkLoads}. * - * @param flag whether the Service Workers should not load any resources from the - * network + * @param flag true means block network loads by the Service Workers */ public abstract void setBlockNetworkLoads(boolean flag); diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java index 49effe47aa55..5c473970a4de 100644 --- a/core/java/android/webkit/WebSettings.java +++ b/core/java/android/webkit/WebSettings.java @@ -119,6 +119,11 @@ public abstract class WebSettings { int value; } + /** @hide */ + @IntDef({LOAD_DEFAULT, LOAD_NORMAL, LOAD_CACHE_ELSE_NETWORK, LOAD_NO_CACHE, LOAD_CACHE_ONLY}) + @Retention(RetentionPolicy.SOURCE) + public @interface CacheMode {} + /** * Default cache usage mode. If the navigation type doesn't impose any * specific behavior, use cached resources when they are available @@ -876,8 +881,7 @@ public abstract class WebSettings { * {@link android.Manifest.permission#INTERNET} permission, otherwise it is * true. * - * @param flag whether the WebView should not load any resources from the - * network + * @param flag true means block network loads by the WebView * @see android.webkit.WebView#reload */ public abstract void setBlockNetworkLoads(boolean flag); @@ -1275,7 +1279,7 @@ public abstract class WebSettings { * * @param mode the mode to use */ - public abstract void setCacheMode(int mode); + public abstract void setCacheMode(@CacheMode int mode); /** * Gets the current setting for overriding the cache mode. @@ -1283,6 +1287,7 @@ public abstract class WebSettings { * @return the current setting for overriding the cache mode * @see #setCacheMode */ + @CacheMode public abstract int getCacheMode(); /** |