public class

ScriptReferenceImpl

extends ScriptReferenceCompat

 java.lang.Object

androidx.webkit.ScriptReferenceCompat

↳androidx.webkit.internal.ScriptReferenceImpl

Overview

Internal implementation of .

Summary

Methods
public voidremove()

Removes the corresponding script from WebView.

public static ScriptReferenceImpltoScriptReferenceCompat(java.lang.reflect.InvocationHandler invocationHandler)

Create an AndroidX ScriptReference from the given InvocationHandler.

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

Methods

public static ScriptReferenceImpl toScriptReferenceCompat(java.lang.reflect.InvocationHandler invocationHandler)

Create an AndroidX ScriptReference from the given InvocationHandler.

public void remove()

Removes the corresponding script from WebView.

Source

/*
 * Copyright 2020 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 androidx.annotation.NonNull;
import androidx.webkit.ScriptReferenceCompat;

import org.chromium.support_lib_boundary.ScriptReferenceBoundaryInterface;
import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;

import java.lang.reflect.InvocationHandler;

/**
 * Internal implementation of {@link androidx.webkit.ScriptReference}.
 */
public class ScriptReferenceImpl extends ScriptReferenceCompat {
    private ScriptReferenceBoundaryInterface mBoundaryInterface;

    private ScriptReferenceImpl(@NonNull ScriptReferenceBoundaryInterface boundaryInterface) {
        mBoundaryInterface = boundaryInterface;
    }

    /**
     * Create an AndroidX ScriptReference from the given InvocationHandler.
     */
    public static @NonNull ScriptReferenceImpl toScriptReferenceCompat(
            @NonNull /* ScriptReference */ InvocationHandler invocationHandler) {
        final ScriptReferenceBoundaryInterface boundaryInterface =
                BoundaryInterfaceReflectionUtil.castToSuppLibClass(
                        ScriptReferenceBoundaryInterface.class, invocationHandler);
        return new ScriptReferenceImpl(boundaryInterface);
    }

    /**
     * Removes the corresponding script from WebView.
     */
    @Override
    public void remove() {
        // If this method is called, the feature must exist, so no need to check feature
        // DOCUMENT_START_JAVASCRIPT.
        mBoundaryInterface.remove();
    }
}