Fix crash while trying to load client certificate

Provide default implementation for PKCS11AuthenticationManager to fix
null pointer crash. Clean-up client certificate api as now we use
chromium's implementation for the same.

Change-Id: I10c69b5d168e03ffb3fd9767bd17d5374e161111
diff --git a/src/com/android/browser/Browser.java b/src/com/android/browser/Browser.java
index 6fb8ca2..8270cfb 100644
--- a/src/com/android/browser/Browser.java
+++ b/src/com/android/browser/Browser.java
@@ -27,6 +27,7 @@
 
 import org.chromium.chrome.browser.ChromiumApplication;
 import org.chromium.chrome.browser.PKCS11AuthenticationManager;
+import org.codeaurora.swe.SWEEmptyPKCS11AuthenticationManager;
 
 import org.codeaurora.swe.Engine;
 
@@ -126,7 +127,7 @@
 
     @Override
     protected PKCS11AuthenticationManager getPKCS11AuthenticationManager() {
-        return null;
+        return new SWEEmptyPKCS11AuthenticationManager();
     }
 
     @Override
diff --git a/src/com/android/browser/KeyChainLookup.java b/src/com/android/browser/KeyChainLookup.java
deleted file mode 100644
index 5bd86b5..0000000
--- a/src/com/android/browser/KeyChainLookup.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 201 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 com.android.browser;
-
-import android.content.Context;
-import android.os.AsyncTask;
-import android.security.KeyChain;
-import android.security.KeyChainException;
-import org.codeaurora.swe.ClientCertRequestHandler;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-
-final class KeyChainLookup extends AsyncTask<Void, Void, Void> {
-    private final Context mContext;
-    private final ClientCertRequestHandler mHandler;
-    private final String mAlias;
-    KeyChainLookup(Context context, ClientCertRequestHandler handler, String alias) {
-        mContext = context.getApplicationContext();
-        mHandler = handler;
-        mAlias = alias;
-    }
-    @Override protected Void doInBackground(Void... params) {
-        PrivateKey privateKey;
-        X509Certificate[] certificateChain;
-        try {
-            privateKey = KeyChain.getPrivateKey(mContext, mAlias);
-            certificateChain = KeyChain.getCertificateChain(mContext, mAlias);
-        } catch (InterruptedException e) {
-            mHandler.ignore();
-            return null;
-        } catch (KeyChainException e) {
-            mHandler.ignore();
-            return null;
-        }
-        mHandler.proceed(privateKey, certificateChain);
-        return null;
-    }
-}
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index f533f6c..bb1ec9d 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -64,7 +64,6 @@
 
 import org.codeaurora.swe.BrowserCommandLine;
 import org.codeaurora.swe.BrowserDownloadListener;
-import org.codeaurora.swe.ClientCertRequestHandler;
 import org.codeaurora.swe.HttpAuthHandler;
 import org.codeaurora.swe.WebBackForwardList;
 import org.codeaurora.swe.WebChromeClient;
@@ -490,45 +489,6 @@
         }
 
         /**
-         * Displays client certificate request to the user.
-         */
-        @Override
-        public void onReceivedClientCertRequest(final WebView view,
-                final ClientCertRequestHandler handler, final String host_and_port) {
-            if (!mInForeground) {
-                handler.ignore();
-                return;
-            }
-            int colon = host_and_port.lastIndexOf(':');
-            String host;
-            int port;
-            if (colon == -1) {
-                host = host_and_port;
-                port = -1;
-            } else {
-                String portString = host_and_port.substring(colon + 1);
-                try {
-                    port = Integer.parseInt(portString);
-                    host = host_and_port.substring(0, colon);
-                } catch  (NumberFormatException e) {
-                    host = host_and_port;
-                    port = -1;
-                }
-            }
-            KeyChain.choosePrivateKeyAlias(
-                    mWebViewController.getActivity(), new KeyChainAliasCallback() {
-                        @Override
-                        public void alias(String alias) {
-                            if (alias == null) {
-                                handler.cancel();
-                                return;
-                            }
-                            new KeyChainLookup(mContext, handler, alias).execute();
-                        }
-                    }, null, null, host, port, null);
-        }
-
-        /**
          * Handles an HTTP authentication request.
          *
          * @param handler The authentication handler
diff --git a/tests/src/com/android/browser/PopularUrlsTest.java b/tests/src/com/android/browser/PopularUrlsTest.java
index 908ee68..0070948 100644
--- a/tests/src/com/android/browser/PopularUrlsTest.java
+++ b/tests/src/com/android/browser/PopularUrlsTest.java
@@ -25,7 +25,6 @@
 import android.test.ActivityInstrumentationTestCase2;
 import android.text.TextUtils;
 import android.util.Log;
-import android.webkit.ClientCertRequestHandler;
 import android.webkit.DownloadListener;
 import android.webkit.HttpAuthHandler;
 import android.webkit.JsPromptResult;
@@ -230,16 +229,6 @@
             }
 
             /**
-             * Ignores and logs SSL client certificate requests.
-             */
-            @Override
-            public void onReceivedClientCertRequest(WebView view, ClientCertRequestHandler handler,
-                    String host_and_port) {
-                Log.w(TAG, "SSL client certificate request: " + host_and_port);
-                handler.cancel();
-            }
-
-            /**
              * Ignores http auth with dummy username and password
              */
             @Override
diff --git a/tests/src/com/android/browser/TestWebViewClient.java b/tests/src/com/android/browser/TestWebViewClient.java
index 7b77448..c092c96 100644
--- a/tests/src/com/android/browser/TestWebViewClient.java
+++ b/tests/src/com/android/browser/TestWebViewClient.java
@@ -22,7 +22,6 @@
 import android.view.KeyEvent;
 import android.webkit.WebViewClientClassicExt;
 
-import org.codeaurora.swe.ClientCertRequestHandler;
 import org.codeaurora.swe.HttpAuthHandler;
 import org.codeaurora.swe.SslErrorHandler;
 import org.codeaurora.swe.WebView;
@@ -104,17 +103,6 @@
 
   /** {@inheritDoc} */
   @Override
-  public void onReceivedClientCertRequest(WebView view, ClientCertRequestHandler handler,
-          String host_and_port) {
-    if (mWrappedClient instanceof WebViewClientClassicExt) {
-      ((WebViewClientClassicExt) mWrappedClient).onReceivedClientCertRequest(view, handler, host_and_port);
-    } else {
-      super.onReceivedClientCertRequest(view, handler, host_and_port);
-    }
-  }
-
-  /** {@inheritDoc} */
-  @Override
   public void onReceivedHttpAuthRequest(WebView view,
           HttpAuthHandler handler, String host, String realm) {
       mWrappedClient.onReceivedHttpAuthRequest(view, handler, host, realm);