public class

ProxyControllerImpl

extends ProxyController

 java.lang.Object

androidx.webkit.ProxyController

↳androidx.webkit.internal.ProxyControllerImpl

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 ProxyController.

Summary

Constructors
publicProxyControllerImpl()

Methods
public abstract voidclearProxyOverride(java.util.concurrent.Executor executor, java.lang.Runnable listener)

Clears the proxy settings.

public static java.lang.StringproxyRulesToStringArray(java.util.List<ProxyConfig.ProxyRule> proxyRuleList)

Converts a ProxyRule List into a String array.

public abstract voidsetProxyOverride(ProxyConfig proxyConfig, java.util.concurrent.Executor executor, java.lang.Runnable listener)

Sets ProxyConfig which will be used by all WebViews in the app.

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

Constructors

public ProxyControllerImpl()

Methods

public abstract void setProxyOverride(ProxyConfig proxyConfig, java.util.concurrent.Executor executor, java.lang.Runnable listener)

Sets ProxyConfig which will be used by all WebViews in the app. URLs that match patterns in the bypass list will not be directed to any proxy. Instead, the request will be made directly to the origin specified by the URL. Network connections are not guaranteed to immediately use the new proxy setting; wait for the listener before loading a page. This listener will be called in the provided executor.

Note: calling setProxyOverride will cause any existing system wide setting to be ignored.

Parameters:

proxyConfig: Proxy config to be applied
executor: Executor for the listener to be executed in
listener: Listener called when the proxy setting change has been applied

public abstract void clearProxyOverride(java.util.concurrent.Executor executor, java.lang.Runnable listener)

Clears the proxy settings. Network connections are not guaranteed to immediately use the new proxy setting; wait for the listener before loading a page. This listener will be called in the provided executor.

Parameters:

executor: Executor for the listener to be executed in
listener: Listener called when the proxy setting change has been applied

public static java.lang.String proxyRulesToStringArray(java.util.List<ProxyConfig.ProxyRule> proxyRuleList)

Converts a ProxyRule List into a String array.

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 androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.webkit.ProxyConfig;
import androidx.webkit.ProxyConfig.ProxyRule;
import androidx.webkit.ProxyController;

import org.chromium.support_lib_boundary.ProxyControllerBoundaryInterface;

import java.util.List;
import java.util.concurrent.Executor;

/**
 * Implementation of {@link ProxyController}.
 */
public class ProxyControllerImpl extends ProxyController {
    private ProxyControllerBoundaryInterface mBoundaryInterface;

    @Override
    public void setProxyOverride(@NonNull ProxyConfig proxyConfig, @NonNull Executor executor,
            @NonNull Runnable listener) {
        ApiFeature.NoFramework proxyOverride = WebViewFeatureInternal.PROXY_OVERRIDE;
        ApiFeature.NoFramework reverseBypass = WebViewFeatureInternal.PROXY_OVERRIDE_REVERSE_BYPASS;

        // A 2D String array representation is required by reflection
        String[][] proxyRuleArray = proxyRulesToStringArray(proxyConfig.getProxyRules());
        String[] bypassRuleArray = proxyConfig.getBypassRules().toArray(new String[0]);

        if (proxyOverride.isSupportedByWebView() && !proxyConfig.isReverseBypassEnabled()) {
            getBoundaryInterface().setProxyOverride(
                    proxyRuleArray, bypassRuleArray, listener, executor);
        } else if (proxyOverride.isSupportedByWebView() && reverseBypass.isSupportedByWebView()) {
            getBoundaryInterface().setProxyOverride(
                    proxyRuleArray,
                    bypassRuleArray,
                    listener,
                    executor,
                    proxyConfig.isReverseBypassEnabled());
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    @Override
    public void clearProxyOverride(@NonNull Executor executor, @NonNull Runnable listener) {
        ApiFeature.NoFramework feature = WebViewFeatureInternal.PROXY_OVERRIDE;
        if (feature.isSupportedByWebView()) {
            getBoundaryInterface().clearProxyOverride(listener, executor);
        } else {
            throw WebViewFeatureInternal.getUnsupportedOperationException();
        }
    }

    /**
     * Converts a ProxyRule List into a String array.
     */
    @NonNull
    @VisibleForTesting
    public static String[][] proxyRulesToStringArray(@NonNull List<ProxyRule> proxyRuleList) {
        String[][] proxyRuleArray = new String[proxyRuleList.size()][2];
        for (int i = 0; i < proxyRuleList.size(); i++) {
            proxyRuleArray[i][0] = proxyRuleList.get(i).getSchemeFilter();
            proxyRuleArray[i][1] = proxyRuleList.get(i).getUrl();
        }
        return proxyRuleArray;
    }

    private ProxyControllerBoundaryInterface getBoundaryInterface() {
        if (mBoundaryInterface == null) {
            mBoundaryInterface = WebViewGlueCommunicator.getFactory().getProxyController();
        }
        return mBoundaryInterface;
    }
}