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