public class

WebViewProviderAdapter

extends java.lang.Object

 java.lang.Object

↳androidx.webkit.internal.WebViewProviderAdapter

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 for WebViewProviderBoundaryInterface providing the functionality expected of WebViewCompat, this adapter is the support library version of .

Summary

Constructors
publicWebViewProviderAdapter(org.chromium.support_lib_boundary.WebViewProviderBoundaryInterface impl)

Methods
public ScriptHandlerImpladdDocumentStartJavaScript(java.lang.String script, java.lang.String allowedOriginRules[])

Adapter method for WebViewCompat

public voidaddWebMessageListener(java.lang.String jsObjectName, java.lang.String allowedOriginRules[], WebViewCompat.WebMessageListener listener)

Adapter method for WebViewCompat.

public WebMessagePortCompatcreateWebMessageChannel()

Adapter method for WebViewCompat.createWebMessageChannel(WebView).

public ProfilegetProfile()

Adapter method for WebViewCompat.getProfile(WebView).

public WebChromeClientgetWebChromeClient()

Adapter method for WebViewCompat.

public WebViewClientgetWebViewClient()

Adapter method for WebViewCompat.

public WebViewRenderProcessgetWebViewRenderProcess()

Adapter method for WebViewCompat.

public WebViewRenderProcessClientgetWebViewRenderProcessClient()

Adapter method for WebViewCompat.

public voidinsertVisualStateCallback(long requestId, WebViewCompat.VisualStateCallback callback)

Adapter method WebViewCompat.insertVisualStateCallback().

public booleanisAudioMuted()

Adapter method for WebViewCompat.isAudioMuted(WebView).

public voidpostWebMessage(WebMessageCompat message, Uri targetOrigin)

Adapter method for WebViewCompat.postWebMessage(WebView, WebMessageCompat, Uri).

public voidremoveWebMessageListener(java.lang.String jsObjectName)

Adapter method for WebViewCompat.

public voidsetAudioMuted(boolean mute)

Adapter method for WebViewCompat.setAudioMuted(WebView, boolean).

public voidsetProfileWithName(java.lang.String profileName)

Adapter method for WebViewCompat.setProfile(WebView, String).

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

Adapter method for WebViewCompat.

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

Constructors

public WebViewProviderAdapter(org.chromium.support_lib_boundary.WebViewProviderBoundaryInterface impl)

Methods

public void insertVisualStateCallback(long requestId, WebViewCompat.VisualStateCallback callback)

Adapter method WebViewCompat.insertVisualStateCallback().

public WebMessagePortCompat createWebMessageChannel()

Adapter method for WebViewCompat.createWebMessageChannel(WebView).

public void postWebMessage(WebMessageCompat message, Uri targetOrigin)

Adapter method for WebViewCompat.postWebMessage(WebView, WebMessageCompat, Uri).

public void addWebMessageListener(java.lang.String jsObjectName, java.lang.String allowedOriginRules[], WebViewCompat.WebMessageListener listener)

Adapter method for WebViewCompat.

public ScriptHandlerImpl addDocumentStartJavaScript(java.lang.String script, java.lang.String allowedOriginRules[])

Adapter method for WebViewCompat

public void removeWebMessageListener(java.lang.String jsObjectName)

Adapter method for WebViewCompat.

public WebViewClient getWebViewClient()

Adapter method for WebViewCompat.

public WebChromeClient getWebChromeClient()

Adapter method for WebViewCompat.

public WebViewRenderProcess getWebViewRenderProcess()

Adapter method for WebViewCompat.

public WebViewRenderProcessClient getWebViewRenderProcessClient()

Adapter method for WebViewCompat.

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

Adapter method for WebViewCompat.

public void setProfileWithName(java.lang.String profileName)

Adapter method for WebViewCompat.setProfile(WebView, String).

public Profile getProfile()

Adapter method for WebViewCompat.getProfile(WebView).

public boolean isAudioMuted()

Adapter method for WebViewCompat.isAudioMuted(WebView).

public void setAudioMuted(boolean mute)

Adapter method for WebViewCompat.setAudioMuted(WebView, boolean).

Source

/*
 * Copyright 2018 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.net.Uri;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.webkit.Profile;
import androidx.webkit.WebMessageCompat;
import androidx.webkit.WebMessagePortCompat;
import androidx.webkit.WebViewCompat;
import androidx.webkit.WebViewRenderProcess;
import androidx.webkit.WebViewRenderProcessClient;

import org.chromium.support_lib_boundary.ProfileBoundaryInterface;
import org.chromium.support_lib_boundary.WebViewProviderBoundaryInterface;
import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;

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

/**
 * Adapter for WebViewProviderBoundaryInterface providing the functionality expected of
 * WebViewCompat, this adapter is the support library version of
 * {@link android.webkit.WebViewProvider}.
 */
@SuppressWarnings("JavadocReference") // WebViewProvider is hidden.
public class WebViewProviderAdapter {
    WebViewProviderBoundaryInterface mImpl;

    public WebViewProviderAdapter(@NonNull WebViewProviderBoundaryInterface impl) {
        mImpl = impl;
    }

    /**
     * Adapter method WebViewCompat.insertVisualStateCallback().
     */
    public void insertVisualStateCallback(
            long requestId, @NonNull WebViewCompat.VisualStateCallback callback) {
        mImpl.insertVisualStateCallback(requestId,
                BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
                        new VisualStateCallbackAdapter(callback)));
    }

    /**
     * Adapter method for {@link WebViewCompat#createWebMessageChannel(WebView)}.
     */
    @NonNull
    public WebMessagePortCompat[] createWebMessageChannel() {
        InvocationHandler[] invocationHandlers = mImpl.createWebMessageChannel();
        WebMessagePortCompat[] messagePorts = new WebMessagePortCompat[invocationHandlers.length];
        for (int n = 0; n < invocationHandlers.length; n++) {
            messagePorts[n] = new WebMessagePortImpl(invocationHandlers[n]);
        }
        return messagePorts;
    }

    /**
     * Adapter method for {@link WebViewCompat#postWebMessage(WebView, WebMessageCompat, Uri)}.
     */
    public void postWebMessage(@NonNull WebMessageCompat message, @NonNull Uri targetOrigin) {
        mImpl.postMessageToMainFrame(
                BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
                        new WebMessageAdapter(message)), targetOrigin);
    }

    /**
     * Adapter method for {@link WebViewCompat#addWebMessageListener(android.webkit.WebView,
     * String, List<String>, androidx.webkit.WebViewCompat.WebMessageListener)}.
     */
    public void addWebMessageListener(@NonNull String jsObjectName,
            @NonNull String[] allowedOriginRules,
            @NonNull WebViewCompat.WebMessageListener listener) {
        mImpl.addWebMessageListener(jsObjectName, allowedOriginRules,
                BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
                        new WebMessageListenerAdapter(listener)));
    }

    /**
     * Adapter method for {@link WebViewCompat#addWebMessageListener(android.webkit.WebView,
     * String, Set)}
     */
    public @NonNull ScriptHandlerImpl addDocumentStartJavaScript(
            @NonNull String script, @NonNull String[] allowedOriginRules) {
        return ScriptHandlerImpl.toScriptHandler(
                mImpl.addDocumentStartJavaScript(script, allowedOriginRules));
    }

    /**
     * Adapter method for {@link WebViewCompat#removeWebMessageListener(String)}.
     */
    public void removeWebMessageListener(@NonNull String jsObjectName) {
        mImpl.removeWebMessageListener(jsObjectName);
    }

    /**
     * Adapter method for {@link WebViewCompat#getWebViewClient()}.
     */
    @NonNull
    public WebViewClient getWebViewClient() {
        return mImpl.getWebViewClient();
    }

    /**
     * Adapter method for {@link WebViewCompat#getWebChromeClient()}.
     */
    @Nullable
    public WebChromeClient getWebChromeClient() {
        return mImpl.getWebChromeClient();
    }

    /**
     * Adapter method for {@link WebViewCompat#getWebViewRenderer()}.
     */
    @Nullable
    public WebViewRenderProcess getWebViewRenderProcess() {
        return WebViewRenderProcessImpl.forInvocationHandler(mImpl.getWebViewRenderer());
    }

    /**
     * Adapter method for {@link WebViewCompat#getWebViewRendererClient()}.
     */
    @Nullable
    public WebViewRenderProcessClient getWebViewRenderProcessClient() {
        InvocationHandler handler = mImpl.getWebViewRendererClient();
        if (handler == null) return null;
        return ((WebViewRenderProcessClientAdapter)
                BoundaryInterfaceReflectionUtil.getDelegateFromInvocationHandler(
                        handler)).getWebViewRenderProcessClient();
    }

    /**
     * Adapter method for {@link WebViewCompat#setWebViewRendererClient(WebViewRendererClient)}.
     */
    // WebViewRenderProcessClient is a callback class, so it should be last. See
    // https://issuetracker.google.com/issues/139770271.
    @SuppressLint("LambdaLast")
    public void setWebViewRenderProcessClient(@Nullable Executor executor,
            @Nullable WebViewRenderProcessClient webViewRenderProcessClient) {
        InvocationHandler handler = webViewRenderProcessClient != null
                ? BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
                        new WebViewRenderProcessClientAdapter(executor, webViewRenderProcessClient))
                : null;
        mImpl.setWebViewRendererClient(handler);
    }

    /**
     * Adapter method for {@link WebViewCompat#setProfile(WebView, String)}.
     */
    public void setProfileWithName(@NonNull String profileName) {
        mImpl.setProfile(profileName);
    }

    /**
     * Adapter method for {@link WebViewCompat#getProfile(WebView)}.
     */
    @NonNull
    public Profile getProfile() {
        ProfileBoundaryInterface profile = BoundaryInterfaceReflectionUtil.castToSuppLibClass(
                ProfileBoundaryInterface.class, mImpl.getProfile());

        return new ProfileImpl(profile);
    }

    /**
     * Adapter method for {@link WebViewCompat#isAudioMuted(WebView)}.
     */
    public boolean isAudioMuted() {
        return mImpl.isAudioMuted();
    }

    /**
     * Adapter method for {@link WebViewCompat#setAudioMuted(WebView, boolean)}.
     */
    public void setAudioMuted(boolean mute) {
        mImpl.setAudioMuted(mute);
    }
}