| Index: android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
|
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bac8eee6967c0272e010c6e9a045640588ce6e62
|
| --- /dev/null
|
| +++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
|
| @@ -0,0 +1,75 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.android_webview;
|
| +
|
| +import android.net.http.SslCertificate;
|
| +import android.net.http.SslError;
|
| +import android.webkit.ValueCallback;
|
| +
|
| +import org.chromium.base.CalledByNative;
|
| +import org.chromium.base.JNINamespace;
|
| +import org.chromium.base.ThreadUtils;
|
| +
|
| +/**
|
| + * This class handles the JNI communication logic for the the AwContentsClient class.
|
| + * Both the Java and the native peers of AwContentsClientBridge are owned by the
|
| + * corresponding AwContents instances. This class and its native peer are connected
|
| + * via weak references. The native AwContentsClientBridge sets up and clear these weak
|
| + * references.
|
| + */
|
| +@JNINamespace("android_webview")
|
| +public class AwContentsClientBridge {
|
| +
|
| + private AwContentsClient mClient;
|
| + // The native peer of this object.
|
| + private int mNativeContentsClientBridge;
|
| +
|
| + public AwContentsClientBridge(AwContentsClient client) {
|
| + assert client != null;
|
| + mClient = client;
|
| + }
|
| +
|
| + // Used by the native peer to set/reset a weak ref to the native peer.
|
| + @CalledByNative
|
| + private void setNativeContentsClientBridge(int nativeContentsClientBridge) {
|
| + mNativeContentsClientBridge = nativeContentsClientBridge;
|
| + }
|
| +
|
| + // If returns false, the request is immediately canceled, and any call to proceedSslError
|
| + // has no effect. If returns true, the request should be canceled or proceeded using
|
| + // proceedSslError().
|
| + // Unlike the webview classic, we do not keep keep a database of certificates that
|
| + // are allowed by the user, because this functionality is already handled via
|
| + // ssl_policy in native layers.
|
| + @CalledByNative
|
| + private boolean allowCertificateError(int certError, byte[] derBytes, final String url,
|
| + final int id) {
|
| + final SslCertificate cert = SslUtil.getCertificateFromDerBytes(derBytes);
|
| + if (cert == null) {
|
| + // if the certificate or the client is null, cancel the request
|
| + return false;
|
| + }
|
| + final SslError sslError = SslUtil.SslErrorFromNetErrorCode(certError, cert, url);
|
| + ValueCallback callback = new ValueCallback<Boolean>() {
|
| + @Override
|
| + public void onReceiveValue(Boolean value) {
|
| + proceedSslError(value.booleanValue(), id);
|
| + }
|
| + };
|
| + mClient.onReceivedSslError(callback, sslError);
|
| + return true;
|
| + }
|
| +
|
| + private void proceedSslError(boolean proceed, int id) {
|
| + if (mNativeContentsClientBridge == 0) return;
|
| + nativeProceedSslError(mNativeContentsClientBridge, proceed, id);
|
| + }
|
| +
|
| + //--------------------------------------------------------------------------------------------
|
| + // Native methods
|
| + //--------------------------------------------------------------------------------------------
|
| + private native void nativeProceedSslError(int nativeAwContentsClientBridge, boolean proceed,
|
| + int id);
|
| +}
|
|
|