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.WebView; 20 21 import org.jspecify.annotations.NonNull; 22 import org.jspecify.annotations.Nullable; 23 24 /** 25 * Used to receive callbacks on {@link WebView} renderer events. 26 * <p> 27 * WebViewRenderProcessClient instances may be set or retrieved via {@link 28 * WebViewCompat#setWebViewRenderProcessClient(WebView, java.util.concurrent.Executor, 29 * WebViewRenderProcessClient)} 30 * and {@link WebViewCompat#getWebViewRenderProcessClient(WebView)}. 31 * <p> 32 * Instances may be attached to multiple WebViews, and thus a single renderer event may cause 33 * a callback to be called multiple times with different WebView parameters. 34 */ 35 public abstract class WebViewRenderProcessClient { 36 /** 37 * Called when the renderer currently associated with {@code view} becomes unresponsive as a 38 * result of a long running blocking task such as the execution of JavaScript. 39 * 40 * <p>If a WebView fails to process an input event, or successfully navigate to a new URL within 41 * a reasonable time frame, the renderer is considered to be unresponsive, and this callback 42 * will be called. 43 * 44 * <p>This callback will continue to be called at regular intervals as long as the renderer 45 * remains unresponsive. If the renderer becomes responsive again, {@link 46 * WebViewRenderProcessClient#onRenderProcessResponsive} will be called once, and this method 47 * will not subsequently be called unless another period of unresponsiveness is detected. 48 * 49 * <p>The minimum interval between successive calls to {@code onRenderProcessUnresponsive} is 5 50 * seconds. 51 * 52 * <p>No action is taken by WebView as a result of this method call. Applications may 53 * choose to terminate the associated renderer via the object that is passed to this callback, 54 * if in multi-process mode, however this must be accompanied by correctly handling 55 * {@link android.webkit.WebViewClient#onRenderProcessGone} for this WebView, and all other 56 * WebViews associated with the same renderer. Failure to do so will result in application 57 * termination. 58 * 59 * @param view The {@link android.webkit.WebView} for which unresponsiveness was detected. 60 * @param renderer The {@link WebViewRenderProcess} that has become unresponsive, or 61 * {@code null} if WebView is running in single process mode. 62 */ onRenderProcessUnresponsive( @onNull WebView view, @Nullable WebViewRenderProcess renderer)63 public abstract void onRenderProcessUnresponsive( 64 @NonNull WebView view, @Nullable WebViewRenderProcess renderer); 65 66 /** 67 * Called once when an unresponsive renderer currently associated with {@code view} becomes 68 * responsive. 69 * 70 * <p>After a WebView renderer becomes unresponsive, which is notified to the application by 71 * {@link WebViewRenderProcessClient#onRenderProcessUnresponsive}, it is possible for the 72 * blocking renderer task to complete, returning the renderer to a responsive state. In that 73 * case, this method is called once to indicate responsiveness. 74 * 75 * <p>No action is taken by WebView as a result of this method call. 76 * 77 * @param view The {@link android.webkit.WebView} for which responsiveness was detected. 78 * 79 * @param renderer The {@link WebViewRenderProcess} that has become responsive, or {@code null} 80 * if WebView is running in single process mode. 81 */ onRenderProcessResponsive( @onNull WebView view, @Nullable WebViewRenderProcess renderer)82 public abstract void onRenderProcessResponsive( 83 @NonNull WebView view, @Nullable WebViewRenderProcess renderer); 84 } 85