public class

WebViewRenderProcessClientAdapter

extends java.lang.Object

implements org.chromium.support_lib_boundary.WebViewRendererClientBoundaryInterface

 java.lang.Object

↳androidx.webkit.internal.WebViewRenderProcessClientAdapter

Gradle dependencies

compile group: 'androidx.webkit', name: 'webkit', version: '1.12.0-rc01'

  • groupId: androidx.webkit
  • artifactId: webkit
  • version: 1.12.0-rc01

Artifact androidx.webkit:webkit:1.12.0-rc01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.webkit:webkit com.android.support:webkit

Overview

Adapter class to pass a WebViewRenderProcessClient over to chromium.

Summary

Constructors
publicWebViewRenderProcessClientAdapter(java.util.concurrent.Executor executor, WebViewRenderProcessClient webViewRenderProcessClient)

Methods
public final java.lang.StringgetSupportedFeatures()

Returns the list of features this client supports.

public WebViewRenderProcessClientgetWebViewRenderProcessClient()

public final voidonRendererResponsive(WebView view, java.lang.reflect.InvocationHandler renderer)

Invoked by chromium with arguments that need to be wrapped by support library adapter objects.

public final voidonRendererUnresponsive(WebView view, java.lang.reflect.InvocationHandler renderer)

Invoked by chromium with arguments that need to be wrapped by support library adapter objects.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public WebViewRenderProcessClientAdapter(java.util.concurrent.Executor executor, WebViewRenderProcessClient webViewRenderProcessClient)

Methods

public WebViewRenderProcessClient getWebViewRenderProcessClient()

public final java.lang.String getSupportedFeatures()

Returns the list of features this client supports. This feature list should always be a subset of the Features declared in WebViewFeature.

public final void onRendererUnresponsive(WebView view, java.lang.reflect.InvocationHandler renderer)

Invoked by chromium with arguments that need to be wrapped by support library adapter objects.

public final void onRendererResponsive(WebView view, java.lang.reflect.InvocationHandler renderer)

Invoked by chromium with arguments that need to be wrapped by support library adapter objects.

Source

/*
 * 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 androidx.webkit.internal;

import android.annotation.SuppressLint;
import android.webkit.WebView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.webkit.WebViewRenderProcess;
import androidx.webkit.WebViewRenderProcessClient;

import org.chromium.support_lib_boundary.WebViewRendererClientBoundaryInterface;
import org.chromium.support_lib_boundary.util.Features;

import java.lang.reflect.InvocationHandler;
import java.util.concurrent.Executor;

/**
 * Adapter class to pass a {@link WebViewRenderProcessClient} over to chromium.
 */
public class WebViewRenderProcessClientAdapter implements WebViewRendererClientBoundaryInterface {
    private static final String[] sSupportedFeatures = new String[] {
            Features.WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE,
    };

    private final Executor mExecutor;
    private final WebViewRenderProcessClient mWebViewRenderProcessClient;

    // WebViewRenderProcessClient is a callback class, so it should be last. See
    // https://issuetracker.google.com/issues/139770271.
    @SuppressLint("LambdaLast")
    public WebViewRenderProcessClientAdapter(
            @Nullable Executor executor,
            @Nullable WebViewRenderProcessClient webViewRenderProcessClient) {
        mExecutor = executor;
        mWebViewRenderProcessClient = webViewRenderProcessClient;
    }

    @Nullable
    public WebViewRenderProcessClient getWebViewRenderProcessClient() {
        return mWebViewRenderProcessClient;
    }

    /**
     * Returns the list of features this client supports. This feature list should always be a
     * subset of the Features declared in WebViewFeature.
     */
    @Override
    @NonNull
    public final String[] getSupportedFeatures() {
        return sSupportedFeatures;
    }

    /**
     * Invoked by chromium with arguments that need to be wrapped by support library adapter
     * objects.
     */
    @Override
    public final void onRendererUnresponsive(
            @NonNull final WebView view,
            @NonNull /* WebViewRenderer */ final InvocationHandler renderer) {
        final WebViewRenderProcess rendererObject =
                WebViewRenderProcessImpl.forInvocationHandler(renderer);
        final WebViewRenderProcessClient client = mWebViewRenderProcessClient;
        if (mExecutor == null) {
            client.onRenderProcessUnresponsive(view, rendererObject);
        } else {
            mExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    client.onRenderProcessUnresponsive(view, rendererObject);
                }
            });
        }
    }

    /**
     * Invoked by chromium with arguments that need to be wrapped by support library adapter
     * objects.
     */
    @Override
    public final void onRendererResponsive(
            @NonNull final WebView view,
            @NonNull /* WebViewRenderer */ InvocationHandler renderer) {
        final WebViewRenderProcess rendererObject =
                WebViewRenderProcessImpl.forInvocationHandler(renderer);
        final WebViewRenderProcessClient client = mWebViewRenderProcessClient;
        if (mExecutor == null) {
            client.onRenderProcessResponsive(view, rendererObject);
        } else {
            mExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    client.onRenderProcessResponsive(view, rendererObject);
                }
            });
        }
    }
}