1 /*
2  * Copyright 2018 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 
17 package androidx.webkit;
18 
19 import android.webkit.WebResourceRequest;
20 import android.webkit.WebResourceResponse;
21 
22 import androidx.annotation.WorkerThread;
23 
24 import org.jspecify.annotations.NonNull;
25 import org.jspecify.annotations.Nullable;
26 
27 /**
28  * Base class for clients to capture Service Worker related callbacks,
29  * see {@link ServiceWorkerControllerCompat} for usage example.
30  */
31 public abstract class ServiceWorkerClientCompat {
32     /**
33      *
34      * Notify the host application of a resource request and allow the
35      * application to return the data. If the return value is {@code null}, the
36      * Service Worker will continue to load the resource as usual.
37      * Otherwise, the return response and data will be used.
38      *
39      * <p class="note"><b>Note:</b> This method is called on a thread other than the UI thread so
40      * clients should exercise caution when accessing private data or the view system.
41      *
42      * <p>This method is called only if {@link
43      * WebViewFeature#SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST} is supported. You can check whether
44      * that flag is supported using {@link WebViewFeature#isFeatureSupported(String)}.
45      *
46      * @param request Object containing the details of the request.
47      * @return A {@link android.webkit.WebResourceResponse} containing the
48      * response information or {@code null} if the WebView should load the
49      * resource itself.
50      * @see android.webkit.WebViewClient#shouldInterceptRequest(android.webkit.WebView,
51      * WebResourceRequest)
52      */
53     @WorkerThread
shouldInterceptRequest( @onNull WebResourceRequest request)54     public abstract @Nullable WebResourceResponse shouldInterceptRequest(
55             @NonNull WebResourceRequest request);
56 }
57