blob: 3517c74b680e9c7c5af56802fbcad7ef8c6235d7 [file] [log] [blame]
Tim Volodine28c83562016-01-20 19:23:03 +00001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21
22/**
23 * Manages Service Workers used by WebView.
Tim Volodineb90f5382016-04-29 12:44:41 +010024 *
25 * <p>Example usage:
26 * <pre class="prettyprint">
27 * ServiceWorkerController swController = ServiceWorkerController.getInstance();
28 * swController.setServiceWorkerClient(new ServiceWorkerClient() {
29 * {@literal @}Override
30 * public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
31 * // Capture request here and generate response or allow pass-through
32 * // by returning null.
33 * return null;
34 * }
35 * });
Nate Fischerf02f8462017-09-11 15:16:33 -070036 * </pre>
Tim Volodine28c83562016-01-20 19:23:03 +000037 */
38public abstract class ServiceWorkerController {
39
40 /**
41 * Returns the default ServiceWorkerController instance. At present there is
42 * only one ServiceWorkerController instance for all WebView instances,
43 * however this restriction may be relaxed in the future.
44 *
Tim Volodineb90f5382016-04-29 12:44:41 +010045 * @return the default ServiceWorkerController instance
Tim Volodine28c83562016-01-20 19:23:03 +000046 */
47 @NonNull
48 public static ServiceWorkerController getInstance() {
49 return WebViewFactory.getProvider().getServiceWorkerController();
50 }
51
52 /**
53 * Gets the settings for all service workers.
54 *
Tim Volodineb90f5382016-04-29 12:44:41 +010055 * @return the current ServiceWorkerWebSettings
Tim Volodine28c83562016-01-20 19:23:03 +000056 */
57 @NonNull
58 public abstract ServiceWorkerWebSettings getServiceWorkerWebSettings();
59
60 /**
61 * Sets the client to capture service worker related callbacks.
Tim Volodineb90f5382016-04-29 12:44:41 +010062 *
63 * A {@link ServiceWorkerClient} should be set before any service workers are
64 * active, e.g. a safe place is before any WebView instances are created or
65 * pages loaded.
Tim Volodine28c83562016-01-20 19:23:03 +000066 */
67 public abstract void setServiceWorkerClient(@Nullable ServiceWorkerClient client);
68}
69