public class

SafeBrowsingResponseImpl

extends SafeBrowsingResponseCompat

 java.lang.Object

androidx.webkit.SafeBrowsingResponseCompat

↳androidx.webkit.internal.SafeBrowsingResponseImpl

Gradle dependencies

compile group: 'androidx.webkit', name: 'webkit', version: '1.5.0-alpha01'

  • groupId: androidx.webkit
  • artifactId: webkit
  • version: 1.5.0-alpha01

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

Androidx artifact mapping:

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

Overview

Implementation of SafeBrowsingResponseCompat. This class uses either the framework, the WebView APK, or both, to implement SafeBrowsingResponseCompat functionality.

Summary

Constructors
publicSafeBrowsingResponseImpl(java.lang.reflect.InvocationHandler invocationHandler)

publicSafeBrowsingResponseImpl(SafeBrowsingResponse response)

Methods
public abstract voidbackToSafety(boolean report)

Act as if the user clicked the "back to safety" button.

public abstract voidproceed(boolean report)

Act as if the user clicked the "visit this unsafe site" button.

public abstract voidshowInterstitial(boolean allowReporting)

Display the default interstitial.

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

Constructors

public SafeBrowsingResponseImpl(java.lang.reflect.InvocationHandler invocationHandler)

public SafeBrowsingResponseImpl(SafeBrowsingResponse response)

Methods

public abstract void showInterstitial(boolean allowReporting)

Display the default interstitial.

This method should only be called if WebViewFeature.isFeatureSupported(String) returns true for WebViewFeature.SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL.

Parameters:

allowReporting: true if the interstitial should show a reporting checkbox.

public abstract void proceed(boolean report)

Act as if the user clicked the "visit this unsafe site" button.

This method should only be called if WebViewFeature.isFeatureSupported(String) returns true for WebViewFeature.SAFE_BROWSING_RESPONSE_PROCEED.

Parameters:

report: true to enable Safe Browsing reporting.

public abstract void backToSafety(boolean report)

Act as if the user clicked the "back to safety" button.

This method should only be called if WebViewFeature.isFeatureSupported(String) returns true for WebViewFeature.SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY.

Parameters:

report: true to enable Safe Browsing reporting.

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.webkit.SafeBrowsingResponse;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.webkit.SafeBrowsingResponseCompat;

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

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Implementation of {@link SafeBrowsingResponseCompat}.
 * This class uses either the framework, the WebView APK, or both, to implement
 * {@link SafeBrowsingResponseCompat} functionality.
 *
 */
public class SafeBrowsingResponseImpl extends SafeBrowsingResponseCompat {
    /**
     * Frameworks implementation - do not use this directly, instead use
     * {@link #getFrameworksImpl()} to ensure this variable has been instantiated correctly.
     */
    private SafeBrowsingResponse mFrameworksImpl;

    /**
     * Support library glue implementation - do not use this directly, instead use
     * {@link #getBoundaryInterface()} to ensure this variable has been instantiated correctly.
     */
    private SafeBrowsingResponseBoundaryInterface mBoundaryInterface;

    public SafeBrowsingResponseImpl(@NonNull InvocationHandler invocationHandler) {
        mBoundaryInterface = BoundaryInterfaceReflectionUtil.castToSuppLibClass(
                SafeBrowsingResponseBoundaryInterface.class, invocationHandler);
    }

    public SafeBrowsingResponseImpl(@NonNull SafeBrowsingResponse response) {
        mFrameworksImpl = response;
    }

    @RequiresApi(27)
    private SafeBrowsingResponse getFrameworksImpl() {
        if (mFrameworksImpl == null) {
            mFrameworksImpl =
                    WebViewGlueCommunicator.getCompatConverter().convertSafeBrowsingResponse(
                            Proxy.getInvocationHandler(mBoundaryInterface));
        }
        return mFrameworksImpl;
    }

    private SafeBrowsingResponseBoundaryInterface getBoundaryInterface() {
        if (mBoundaryInterface == null) {
            mBoundaryInterface = BoundaryInterfaceReflectionUtil.castToSuppLibClass(
                    SafeBrowsingResponseBoundaryInterface.class,
                    WebViewGlueCommunicator.getCompatConverter().convertSafeBrowsingResponse(
                            mFrameworksImpl));
        }
        return mBoundaryInterface;
    }

    @Override
    public void showInterstitial(boolean allowReporting) {
        final ApiFeature.O_MR1 feature =
                WebViewFeatureInternal.SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL;
        if (feature.isSupportedByFramework()) {
            ApiHelperForOMR1.showInterstitial(getFrameworksImpl(), allowReporting);
        } else if (feature.isSupportedByWebView()) {
            getBoundaryInterface().showInterstitial(allowReporting);
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    @Override
    public void proceed(boolean report) {
        final ApiFeature.O_MR1 feature = WebViewFeatureInternal.SAFE_BROWSING_RESPONSE_PROCEED;
        if (feature.isSupportedByFramework()) {
            ApiHelperForOMR1.proceed(getFrameworksImpl(), report);
        } else if (feature.isSupportedByWebView()) {
            getBoundaryInterface().proceed(report);
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    @Override
    public void backToSafety(boolean report) {
        final ApiFeature.O_MR1 feature =
                WebViewFeatureInternal.SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY;
        if (feature.isSupportedByFramework()) {
            ApiHelperForOMR1.backToSafety(getFrameworksImpl(), report);
        } else if (feature.isSupportedByWebView()) {
            getBoundaryInterface().backToSafety(report);
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }
}