public class

WebResourceErrorImpl

extends WebResourceErrorCompat

 java.lang.Object

androidx.webkit.WebResourceErrorCompat

↳androidx.webkit.internal.WebResourceErrorImpl

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

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

Summary

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

publicWebResourceErrorImpl(WebResourceError error)

Methods
public abstract java.lang.CharSequencegetDescription()

Gets the string describing the error.

public abstract intgetErrorCode()

Gets the error code of the error.

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

Constructors

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

public WebResourceErrorImpl(WebResourceError error)

Methods

public abstract int getErrorCode()

Gets the error code of the error. The code corresponds to one of the ERROR_* constants in .

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

Returns:

The error code of the error

public abstract java.lang.CharSequence getDescription()

Gets the string describing the error. Descriptions are localized, and thus can be used for communicating the problem to the user.

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

Returns:

The description of the error

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.WebResourceError;

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

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

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

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

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

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

    public WebResourceErrorImpl(@NonNull WebResourceError error) {
        mFrameworksImpl = error;
    }

    @RequiresApi(23)
    private WebResourceError getFrameworksImpl() {
        if (mFrameworksImpl == null) {
            mFrameworksImpl = WebViewGlueCommunicator.getCompatConverter().convertWebResourceError(
                    Proxy.getInvocationHandler(mBoundaryInterface));
        }
        return mFrameworksImpl;
    }

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

    @Override
    public int getErrorCode() {
        final ApiFeature.M feature = WebViewFeatureInternal.WEB_RESOURCE_ERROR_GET_CODE;
        if (feature.isSupportedByFramework()) {
            return ApiHelperForM.getErrorCode(getFrameworksImpl());
        } else if (feature.isSupportedByWebView()) {
            return getBoundaryInterface().getErrorCode();
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    @NonNull
    @Override
    public CharSequence getDescription() {
        final ApiFeature.M feature = WebViewFeatureInternal.WEB_RESOURCE_ERROR_GET_DESCRIPTION;
        if (feature.isSupportedByFramework()) {
            return ApiHelperForM.getDescription(getFrameworksImpl());
        } else if (feature.isSupportedByWebView()) {
            return getBoundaryInterface().getDescription();
        }
        throw WebViewFeatureInternal.getUnsupportedOperationException();
    }
}