Merge "[wv] Add WebView unresponsive renderer APIs."

This commit is contained in:
Toby Sargeant
2019-01-17 10:31:42 +00:00
committed by Android (Google) Code Review
6 changed files with 228 additions and 0 deletions

View File

@@ -54253,6 +54253,8 @@ package android.webkit {
method public static java.lang.ClassLoader getWebViewClassLoader();
method public android.webkit.WebViewClient getWebViewClient();
method public android.os.Looper getWebViewLooper();
method public android.webkit.WebViewRenderer getWebViewRenderer();
method public android.webkit.WebViewRendererClient getWebViewRendererClient();
method public void goBack();
method public void goBackOrForward(int);
method public void goForward();
@@ -54302,6 +54304,8 @@ package android.webkit {
method public void setWebChromeClient(android.webkit.WebChromeClient);
method public static void setWebContentsDebuggingEnabled(boolean);
method public void setWebViewClient(android.webkit.WebViewClient);
method public void setWebViewRendererClient(java.util.concurrent.Executor, android.webkit.WebViewRendererClient);
method public void setWebViewRendererClient(android.webkit.WebViewRendererClient);
method public deprecated boolean shouldDelayChildPressedState();
method public deprecated boolean showFindDialog(java.lang.String, boolean);
method public static void startSafeBrowsing(android.content.Context, android.webkit.ValueCallback<java.lang.Boolean>);
@@ -54417,6 +54421,16 @@ package android.webkit {
method public android.webkit.WebView getWebView();
}
public abstract class WebViewRenderer {
method public abstract boolean terminate();
}
public abstract class WebViewRendererClient {
ctor public WebViewRendererClient();
method public abstract void onRendererResponsive(android.webkit.WebView, android.webkit.WebViewRenderer);
method public abstract void onRendererUnresponsive(android.webkit.WebView, android.webkit.WebViewRenderer);
}
}
package android.widget {

View File

@@ -8503,6 +8503,8 @@ package android.webkit {
method public abstract int getVisibleTitleHeight();
method public abstract android.webkit.WebChromeClient getWebChromeClient();
method public abstract android.webkit.WebViewClient getWebViewClient();
method public abstract android.webkit.WebViewRenderer getWebViewRenderer();
method public abstract android.webkit.WebViewRendererClient getWebViewRendererClient();
method public abstract android.view.View getZoomControls();
method public abstract void goBack();
method public abstract void goBackOrForward(int);
@@ -8552,6 +8554,7 @@ package android.webkit {
method public abstract void setVerticalScrollbarOverlay(boolean);
method public abstract void setWebChromeClient(android.webkit.WebChromeClient);
method public abstract void setWebViewClient(android.webkit.WebViewClient);
method public abstract void setWebViewRendererClient(java.util.concurrent.Executor, android.webkit.WebViewRendererClient);
method public abstract boolean showFindDialog(java.lang.String, boolean);
method public abstract void stopLoading();
method public abstract boolean zoomBy(float);

View File

@@ -16,6 +16,7 @@
package android.webkit;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -69,6 +70,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
/**
* A View that displays web pages.
@@ -1688,6 +1690,84 @@ public class WebView extends AbsoluteLayout
return mProvider.getWebViewClient();
}
/**
* Gets the WebView renderer associated with this WebView.
*
* <p>In {@link android.os.Build.VERSION_CODES#O} and above, WebView may
* run in "multiprocess" mode. In multiprocess mode, rendering of web
* content is performed by a sandboxed renderer process separate to the
* application process. This renderer process may be shared with other
* WebViews in the application, but is not shared with other application
* processes.
*
* <p>If WebView is running in multiprocess mode, this method returns a
* handle to the renderer process associated with the WebView, which can
* be used to control the renderer process.
*
* @return the {@link WebViewRenderer} renderer handle associated
* with this {@link WebView}, or {@code null} if
* WebView is not runing in multiprocess mode.
*/
@Nullable
public WebViewRenderer getWebViewRenderer() {
checkThread();
return mProvider.getWebViewRenderer();
}
/**
* Sets the renderer client object associated with this WebView.
*
* <p>The renderer client encapsulates callbacks relevant to WebView renderer
* state. See {@link WebViewRendererClient} for details.
*
* <p>Although many WebView instances may share a single underlying
* renderer, and renderers may live either in the application
* process, or in a sandboxed process that is isolated from the
* application process, instances of {@link WebViewRendererClient}
* are set per-WebView. Callbacks represent renderer events from
* the perspective of this WebView, and may or may not be correlated
* with renderer events affecting other WebViews.
*
* @param executor the Executor on which {@link WebViewRendererClient} callbacks will execute.
* @param webViewRendererClient the {@link WebViewRendererClient} object.
*/
public void setWebViewRendererClient(
@NonNull @CallbackExecutor Executor executor,
@NonNull WebViewRendererClient webViewRendererClient) {
checkThread();
mProvider.setWebViewRendererClient(executor, webViewRendererClient);
}
/**
* Sets the renderer client object associated with this WebView.
*
* See {@link #setWebViewRendererClient(Executor,WebViewRendererClient)} for details.
*
* <p> {@link WebViewRendererClient} callbacks will run on the thread that this WebView was
* initialized on.
*
* @param webViewRendererClient the {@link WebViewRendererClient} object.
*/
public void setWebViewRendererClient(
@Nullable WebViewRendererClient webViewRendererClient) {
checkThread();
mProvider.setWebViewRendererClient(null, webViewRendererClient);
}
/**
* Gets the renderer client object associated with this WebView.
*
* @return the {@link WebViewRendererClient} object associated with this WebView, if one has
* been set via {@link #setWebViewRendererClient(WebViewRendererClient)} or {@code null}
* otherwise.
*/
@Nullable
public WebViewRendererClient getWebViewRendererClient() {
checkThread();
return mProvider.getWebViewRendererClient();
}
/**
* Registers the interface to be used when content can not be handled by
* the rendering engine, and should be downloaded instead. This will replace

View File

@@ -54,6 +54,7 @@ import android.webkit.WebView.VisualStateCallback;
import java.io.BufferedWriter;
import java.io.File;
import java.util.Map;
import java.util.concurrent.Executor;
/**
* WebView backend provider interface: this interface is the abstract backend to a WebView
@@ -237,6 +238,14 @@ public interface WebViewProvider {
public WebViewClient getWebViewClient();
public WebViewRenderer getWebViewRenderer();
public void setWebViewRendererClient(
@Nullable Executor executor,
@Nullable WebViewRendererClient client);
public WebViewRendererClient getWebViewRendererClient();
public void setDownloadListener(DownloadListener listener);
public void setWebChromeClient(WebChromeClient client);

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.webkit;
/**
* WebViewRenderer provides an opaque handle to a {@link WebView} renderer.
*/
public abstract class WebViewRenderer {
/**
* Cause this renderer to terminate.
*
* <p>Calling this on a not yet started, or an already terminated renderer will have no effect.
*
* <p>Terminating a renderer process may have an effect on multiple {@link WebView} instances.
*
* <p>Renderer termination must be handled by properly overriding
* {@link WebViewClient#onRenderProcessGone} for every WebView that shares this
* renderer. If termination is not handled by all associated WebViews, then the application
* process will also be terminated.
*
* @return {@code true} if it was possible to terminate this renderer, {@code false} otherwise.
*/
public abstract boolean terminate();
/**
* This class cannot be created by applications.
* @hide
*/
public WebViewRenderer() {
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.webkit;
import android.annotation.NonNull;
import android.annotation.Nullable;
/**
* Used to receive callbacks on {@link WebView} renderer events.
*
* WebViewRendererClient instances may be set or retrieved via {@link
* WebView#setWebViewRendererClient(WebViewRendererClient)} and {@link
* WebView#getWebViewRendererClient()}.
*
* Instances may be attached to multiple WebViews, and thus a single renderer event may cause
* a callback to be called multiple times with different WebView parameters.
*/
public abstract class WebViewRendererClient {
/**
* Called when the renderer currently associated with {@code view} becomes unresponsive as a
* result of a long running blocking task such as the execution of JavaScript.
*
* <p>If a WebView fails to process an input event, or successfully navigate to a new URL within
* a reasonable time frame, the renderer is considered to be unresponsive, and this callback
* will be called.
*
* <p>This callback will continue to be called at regular intervals as long as the renderer
* remains unresponsive. If the renderer becomes responsive again, {@link
* WebViewRendererClient#onRendererResponsive} will be called once, and this method will not
* subsequently be called unless another period of unresponsiveness is detected.
*
* <p>No action is taken by WebView as a result of this method call. Applications may
* choose to terminate the associated renderer via the object that is passed to this callback,
* if in multiprocess mode, however this must be accompanied by correctly handling
* {@link WebViewClient#onRenderProcessGone} for this WebView, and all other WebViews associated
* with the same renderer. Failure to do so will result in application termination.
*
* @param view The {@link WebView} for which unresponsiveness was detected.
* @param renderer The {@link WebViewRenderer} that has become unresponsive,
* or {@code null} if WebView is running in single process mode.
*/
public abstract void onRendererUnresponsive(
@NonNull WebView view, @Nullable WebViewRenderer renderer);
/**
* Called once when an unresponsive renderer currently associated with {@code view} becomes
* responsive.
*
* <p>After a WebView renderer becomes unresponsive, which is notified to the application by
* {@link WebViewRendererClient#onRendererUnresponsive}, it is possible for the blocking
* renderer task to complete, returning the renderer to a responsive state. In that case,
* this method is called once to indicate responsiveness.
*
* <p>No action is taken by WebView as a result of this method call.
*
* @param view The {@link WebView} for which responsiveness was detected.
*
* @param renderer The {@link WebViewRenderer} that has become responsive, or {@code null} if
* WebView is running in single process mode.
*/
public abstract void onRendererResponsive(
@NonNull WebView view, @Nullable WebViewRenderer renderer);
}