Chromium Code Reviews| 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..fa8c634236de03391f5ec542f74aaf818ffbc216 |
| --- /dev/null |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java |
| @@ -0,0 +1,87 @@ |
| +// 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.SslErrorHandler; |
| + |
| +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 = SslError.SslErrorFromChromiumErrorCode(certError, cert, url); |
| + SslErrorHandler handler = new SslErrorHandler() { |
|
joth
2013/02/23 00:30:09
Oh... I don't think this will compile upstream :-/
|
| + @Override |
| + public void proceed() { |
| + postProceed(true); |
| + } |
| + @Override |
| + public void cancel() { |
| + postProceed(false); |
| + } |
| + private void postProceed(final boolean proceed) { |
| + post(new Runnable() { |
| + @Override |
| + public void run() { |
| + proceedSslError(proceed, id); |
| + } |
| + }); |
| + } |
| + }; |
| + mClient.onReceivedSslError(handler, 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); |
| +} |