Show SSL state on favicon and site settings

Change-Id: I2f74f8caa8b8e4aaee7d78895287bdd7d69f758f
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 82402c1..debf6f8 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -997,10 +997,6 @@
     // getter/setters for privacy_security_preferences.xml
     // -----------------------------
 
-    public boolean showSecurityWarnings() {
-        return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
-    }
-
     public boolean doNotTrack() {
         boolean dntVal;
         if (DoNotTrackRestriction.getInstance().isEnabled()) {
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 09dbc3c..8c88c7d 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -86,7 +86,6 @@
 import org.codeaurora.swe.CookieSyncManager;
 import org.codeaurora.swe.Engine;
 import org.codeaurora.swe.HttpAuthHandler;
-import org.codeaurora.swe.SslErrorHandler;
 import org.codeaurora.swe.WebSettings;
 import org.codeaurora.swe.WebView;
 import org.codeaurora.swe.WebBackForwardList;
@@ -195,7 +194,6 @@
     private UrlHandler mUrlHandler;
     private UploadHandler mUploadHandler;
     private IntentHandler mIntentHandler;
-    private PageDialogsHandler mPageDialogsHandler;
     private NetworkStateHandler mNetworkHandler;
 
     private Message mAutoFillSetupMessage;
@@ -271,7 +269,6 @@
 
         mUrlHandler = new UrlHandler(this);
         mIntentHandler = new IntentHandler(mActivity, this);
-        mPageDialogsHandler = new PageDialogsHandler(mActivity, this);
 
         startHandler();
         mBookmarksObserver = new ContentObserver(mHandler) {
@@ -712,9 +709,6 @@
             mActivity.closeOptionsMenu();
             mHandler.sendMessageDelayed(mHandler.obtainMessage(OPEN_MENU), 100);
         }
-        if (mPageDialogsHandler != null) {
-            mPageDialogsHandler.onConfigurationChanged(config);
-        }
         mUi.onConfigurationChanged(config);
     }
 
@@ -1202,9 +1196,7 @@
         if (username != null && password != null) {
             handler.proceed(username, password);
         } else {
-            if (tab.inForeground() /*&& !handler.suppressDialog()*/) {
-                mPageDialogsHandler.showHttpAuthentication(tab, handler, host, realm);
-            } else {
+            if (!tab.inForeground()) {
                 handler.cancel();
             }
         }
@@ -1244,12 +1236,6 @@
         return mUi.getVideoLoadingProgressView();
     }
 
-    @Override
-    public void showSslCertificateOnError(WebView view, SslErrorHandler handler,
-            SslError error) {
-        mPageDialogsHandler.showSSLCertificateOnError(view, handler, error);
-    }
-
     // helper method
 
     /*
@@ -2403,7 +2389,6 @@
 
     @Override
     public void showPageInfo() {
-        mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(), false, null);
     }
 
     @Override
diff --git a/src/com/android/browser/NavigationBarBase.java b/src/com/android/browser/NavigationBarBase.java
index a92090d..ce65f16 100644
--- a/src/com/android/browser/NavigationBarBase.java
+++ b/src/com/android/browser/NavigationBarBase.java
@@ -28,7 +28,6 @@
 import android.graphics.Color;
 import android.net.Uri;
 import android.net.http.SslCertificate;
-import android.net.http.SslError;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
@@ -94,8 +93,6 @@
     private static final int WEBREFINER_COUNTER_MSG_DELAY = 3000;
     private Handler mHandler;
 
-    private Tab.SecurityState mSecurityState = Tab.SecurityState.SECURITY_STATE_NOT_SECURE;
-
     private static final String noSitePrefs[] = {
             "browser://",
             "about:",
@@ -166,8 +163,7 @@
     }
 
     public void setSecurityState(Tab.SecurityState securityState) {
-        mSecurityState = securityState;
-        switch (mSecurityState) {
+        switch (securityState) {
             case SECURITY_STATE_SECURE:
                 mFaviconTile.setTrustLevel(SiteTileView.TRUST_TRUSTED);
                 mFaviconTile.setBadgeHasCertIssues(false);
@@ -321,34 +317,12 @@
         bundle.putParcelable(SiteSpecificPreferencesFragment.EXTRA_SECURITY_CERT,
                 SslCertificate.saveState(wv.getCertificate()));
 
-        SslError error = mUiController.getCurrentTab().getSslCertificateError();
-        if (error != null) {
-            int certError = 0;
-            if (error.hasError(SslError.SSL_DATE_INVALID)) {
-                certError |= (1 << SslError.SSL_DATE_INVALID);
-            }
-
-            if (error.hasError(SslError.SSL_EXPIRED)) {
-                certError |= (1 << SslError.SSL_EXPIRED);
-            }
-
-            if (error.hasError(SslError.SSL_IDMISMATCH)) {
-                certError |= (1 << SslError.SSL_IDMISMATCH);
-            }
-
-            if (error.hasError(SslError.SSL_INVALID)) {
-                certError |= (1 << SslError.SSL_INVALID);
-            }
-
-            if (error.hasError(SslError.SSL_NOTYETVALID)) {
-                certError |= (1 << SslError.SSL_NOTYETVALID);
-            }
-
-            if (error.hasError(SslError.SSL_UNTRUSTED)) {
-                certError |= (1 << SslError.SSL_UNTRUSTED);
-            }
-
-            bundle.putInt(SiteSpecificPreferencesFragment.EXTRA_SECURITY_CERT_ERR, certError);
+        Tab.SecurityState securityState = Tab.getWebViewSecurityState(
+                mUiController.getCurrentTab().getWebView());
+        if (securityState == Tab.SecurityState.SECURITY_STATE_MIXED) {
+            bundle.putBoolean(SiteSpecificPreferencesFragment.EXTRA_SECURITY_CERT_MIXED, true);
+        } else if (securityState == Tab.SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
+            bundle.putBoolean(SiteSpecificPreferencesFragment.EXTRA_SECURITY_CERT_BAD, true);
         }
 
         Bitmap favicon = mUiController.getCurrentTopWebView().getFavicon();
@@ -732,7 +706,7 @@
         mFaviconTile.setTrustLevel(SiteTileView.TRUST_UNKNOWN);
         mFaviconTile.setBadgeHasCertIssues(false);
         mFaviconTile.replaceFavicon(mDefaultFavicon);
-        mSecurityState = Tab.SecurityState.SECURITY_STATE_NOT_SECURE;
+        setSecurityState(Tab.SecurityState.SECURITY_STATE_NOT_SECURE);
         mHandler.removeMessages(WEBREFINER_COUNTER_MSG);
         mHandler.sendEmptyMessageDelayed(WEBREFINER_COUNTER_MSG,
                 WEBREFINER_COUNTER_MSG_DELAY);
diff --git a/src/com/android/browser/PageDialogsHandler.java b/src/com/android/browser/PageDialogsHandler.java
deleted file mode 100644
index af54000..0000000
--- a/src/com/android/browser/PageDialogsHandler.java
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
- * Copyright (C) 2010 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.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.net.http.SslCertificate;
-import android.net.http.SslError;
-import android.view.LayoutInflater;
-import android.view.View;
-import org.codeaurora.swe.HttpAuthHandler;
-import org.codeaurora.swe.SslErrorHandler;
-import org.codeaurora.swe.WebRefiner;
-import org.codeaurora.swe.WebView;
-
-import com.android.browser.reflect.ReflectHelper;
-import com.android.browser.R;
-
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-/**
- * Displays page info
- *
- */
-public class PageDialogsHandler {
-
-    private Context mContext;
-    private Controller mController;
-    private boolean mPageInfoFromShowSSLCertificateOnError;
-    private String mUrlCertificateOnError;
-    private Tab mPageInfoView;
-    private AlertDialog mPageInfoDialog;
-
-    // as SSLCertificateOnError has different style for landscape / portrait,
-    // we have to re-open it when configuration changed
-    private AlertDialog mSSLCertificateOnErrorDialog;
-    private WebView mSSLCertificateOnErrorView;
-    private SslErrorHandler mSSLCertificateOnErrorHandler;
-    private SslError mSSLCertificateOnErrorError;
-
-    // as SSLCertificate has different style for landscape / portrait, we
-    // have to re-open it when configuration changed
-    private AlertDialog mSSLCertificateDialog;
-    private Tab mSSLCertificateView;
-    private HttpAuthenticationDialog mHttpAuthenticationDialog;
-
-    public PageDialogsHandler(Context context, Controller controller) {
-        mContext = context;
-        mController = controller;
-    }
-
-    public void onConfigurationChanged(Configuration config) {
-        if (mPageInfoDialog != null) {
-            mPageInfoDialog.dismiss();
-            showPageInfo(mPageInfoView,
-                         mPageInfoFromShowSSLCertificateOnError,
-                         mUrlCertificateOnError);
-        }
-        if (mSSLCertificateDialog != null) {
-            mSSLCertificateDialog.dismiss();
-            showSSLCertificate(mSSLCertificateView);
-        }
-        if (mSSLCertificateOnErrorDialog != null) {
-            mSSLCertificateOnErrorDialog.dismiss();
-            showSSLCertificateOnError(mSSLCertificateOnErrorView,
-                                      mSSLCertificateOnErrorHandler,
-                                      mSSLCertificateOnErrorError);
-        }
-        if (mHttpAuthenticationDialog != null) {
-            mHttpAuthenticationDialog.reshow();
-        }
-    }
-
-    /**
-     * Displays an http-authentication dialog.
-     */
-    void showHttpAuthentication(final Tab tab, final HttpAuthHandler handler, String host, String realm) {
-        mHttpAuthenticationDialog = new HttpAuthenticationDialog(mContext, host, realm);
-        mHttpAuthenticationDialog.setOkListener(new HttpAuthenticationDialog.OkListener() {
-            public void onOk(String host, String realm, String username, String password) {
-                setHttpAuthUsernamePassword(host, realm, username, password);
-                handler.proceed(username, password);
-                mHttpAuthenticationDialog = null;
-            }
-        });
-        mHttpAuthenticationDialog.setCancelListener(new HttpAuthenticationDialog.CancelListener() {
-            public void onCancel() {
-                handler.cancel();
-                mController.onUpdatedSecurityState(tab);
-                mHttpAuthenticationDialog = null;
-            }
-        });
-        mHttpAuthenticationDialog.show();
-    }
-
-    /**
-     * Set HTTP authentication password.
-     *
-     * @param host The host for the password
-     * @param realm The realm for the password
-     * @param username The username for the password. If it is null, it means
-     *            password can't be saved.
-     * @param password The password
-     */
-    public void setHttpAuthUsernamePassword(String host, String realm,
-                                            String username,
-                                            String password) {
-        WebView w = mController.getCurrentTopWebView();
-        if (w != null && BrowserSettings.getInstance().rememberPasswords()) {
-            w.setHttpAuthUsernamePassword(host, realm, username, password);
-        }
-    }
-
-    /**
-     * Displays a page-info dialog.
-     * @param tab The tab to show info about
-     * @param fromShowSSLCertificateOnError The flag that indicates whether
-     * this dialog was opened from the SSL-certificate-on-error dialog or
-     * not. This is important, since we need to know whether to return to
-     * the parent dialog or simply dismiss.
-     * @param urlCertificateOnError The URL that invokes SSLCertificateError.
-     * Null when fromShowSSLCertificateOnError is false.
-     */
-    void showPageInfo(final Tab tab,
-            final boolean fromShowSSLCertificateOnError,
-            final String urlCertificateOnError) {
-        if (tab == null) return;
-        final LayoutInflater factory = LayoutInflater.from(mContext);
-
-        final View pageInfoView = factory.inflate(R.layout.page_info, null);
-
-        final WebView view = tab.getWebView();
-
-        String url = fromShowSSLCertificateOnError ? urlCertificateOnError : tab.getUrl();
-        String title = tab.getTitle();
-
-        if (url == null) {
-            url = "";
-        }
-        if (title == null) {
-            title = "";
-        }
-
-        ((TextView) pageInfoView.findViewById(R.id.address)).setText(url);
-        ((TextView) pageInfoView.findViewById(R.id.title)).setText(title);
-
-        if (WebRefiner.isInitialized() && view != null) {
-            (pageInfoView.findViewById(R.id.web_refiner_info)).setVisibility(View.VISIBLE);
-            int count = WebRefiner.getInstance().getBlockedURLCount(view);
-            String msg = String.valueOf(count) + " requests blocked on this page";
-            ((TextView) pageInfoView.findViewById(R.id.web_refiner_blocked_status)).setText(msg);
-        } else {
-            (pageInfoView.findViewById(R.id.web_refiner_info)).setVisibility(View.INVISIBLE);
-        }
-
-        mPageInfoView = tab;
-        mPageInfoFromShowSSLCertificateOnError = fromShowSSLCertificateOnError;
-        mUrlCertificateOnError = urlCertificateOnError;
-
-        AlertDialog.Builder alertDialogBuilder =
-            new AlertDialog.Builder(mContext)
-            .setTitle(R.string.page_info)
-            .setIcon(android.R.drawable.ic_dialog_info)
-            .setView(pageInfoView)
-            .setPositiveButton(
-                R.string.ok,
-                new DialogInterface.OnClickListener() {
-                    public void onClick(DialogInterface dialog,
-                                        int whichButton) {
-                        mPageInfoDialog = null;
-                        mPageInfoView = null;
-
-                        // if we came here from the SSL error dialog
-                        if (fromShowSSLCertificateOnError) {
-                            // go back to the SSL error dialog
-                            showSSLCertificateOnError(
-                                mSSLCertificateOnErrorView,
-                                mSSLCertificateOnErrorHandler,
-                                mSSLCertificateOnErrorError);
-                        }
-                    }
-                })
-            .setOnCancelListener(
-                new DialogInterface.OnCancelListener() {
-                    public void onCancel(DialogInterface dialog) {
-                        mPageInfoDialog = null;
-                        mPageInfoView = null;
-
-                        // if we came here from the SSL error dialog
-                        if (fromShowSSLCertificateOnError) {
-                            // go back to the SSL error dialog
-                            showSSLCertificateOnError(
-                                mSSLCertificateOnErrorView,
-                                mSSLCertificateOnErrorHandler,
-                                mSSLCertificateOnErrorError);
-                        }
-                    }
-                });
-
-        // if we have a main top-level page SSL certificate set or a certificate
-        // error
-        if (fromShowSSLCertificateOnError ||
-                (view != null && view.getCertificate() != null)) {
-            // add a 'View Certificate' button
-            alertDialogBuilder.setNeutralButton(
-                R.string.view_certificate,
-                new DialogInterface.OnClickListener() {
-                    public void onClick(DialogInterface dialog,
-                                        int whichButton) {
-                        mPageInfoDialog = null;
-                        mPageInfoView = null;
-
-                        // if we came here from the SSL error dialog
-                        if (fromShowSSLCertificateOnError) {
-                            // go back to the SSL error dialog
-                            showSSLCertificateOnError(
-                                mSSLCertificateOnErrorView,
-                                mSSLCertificateOnErrorHandler,
-                                mSSLCertificateOnErrorError);
-                        } else {
-                            // otherwise, display the top-most certificate from
-                            // the chain
-                            showSSLCertificate(tab);
-                        }
-                    }
-                });
-        }
-
-        mPageInfoDialog = alertDialogBuilder.show();
-    }
-
-    /**
-     * Displays the main top-level page SSL certificate dialog
-     * (accessible from the Page-Info dialog).
-     * @param tab The tab to show certificate for.
-     */
-    private void showSSLCertificate(final Tab tab) {
-
-        SslCertificate cert = tab.getWebView().getCertificate();
-        if (cert == null) {
-            return;
-        }
-
-        mSSLCertificateView = tab;
-        mSSLCertificateDialog = createSslCertificateDialog(cert, tab.getSslCertificateError())
-                .setPositiveButton(R.string.ok,
-                        new DialogInterface.OnClickListener() {
-                            public void onClick(DialogInterface dialog,
-                                    int whichButton) {
-                                mSSLCertificateDialog = null;
-                                mSSLCertificateView = null;
-
-                                showPageInfo(tab, false, null);
-                            }
-                        })
-                .setOnCancelListener(
-                        new DialogInterface.OnCancelListener() {
-                            public void onCancel(DialogInterface dialog) {
-                                mSSLCertificateDialog = null;
-                                mSSLCertificateView = null;
-
-                                showPageInfo(tab, false, null);
-                            }
-                        })
-                .show();
-    }
-
-    /**
-     * Displays the SSL error certificate dialog.
-     * @param view The target web-view.
-     * @param handler The SSL error handler responsible for cancelling the
-     * connection that resulted in an SSL error or proceeding per user request.
-     * @param error The SSL error object.
-     */
-    void showSSLCertificateOnError(
-            final WebView view, final SslErrorHandler handler,
-            final SslError error) {
-
-        SslCertificate cert = error.getCertificate();
-        if (cert == null) {
-            return;
-        }
-
-        mSSLCertificateOnErrorHandler = handler;
-        mSSLCertificateOnErrorView = view;
-        mSSLCertificateOnErrorError = error;
-        mSSLCertificateOnErrorDialog = createSslCertificateDialog(cert, error)
-                .setPositiveButton(R.string.ok,
-                        new DialogInterface.OnClickListener() {
-                            public void onClick(DialogInterface dialog,
-                                    int whichButton) {
-                                mSSLCertificateOnErrorDialog = null;
-                                mSSLCertificateOnErrorView = null;
-                                mSSLCertificateOnErrorHandler = null;
-                                mSSLCertificateOnErrorError = null;
-
-                                ((BrowserWebView) view).getWebViewClient().
-                                        onReceivedSslError(view, handler, error);
-                            }
-                        })
-                 .setNeutralButton(R.string.page_info_view,
-                        new DialogInterface.OnClickListener() {
-                            public void onClick(DialogInterface dialog,
-                                    int whichButton) {
-                                mSSLCertificateOnErrorDialog = null;
-
-                                // do not clear the dialog state: we will
-                                // need to show the dialog again once the
-                                // user is done exploring the page-info details
-
-                                showPageInfo(mController.getTabControl()
-                                        .getTabFromView(view),
-                                        true,
-                                        error.getUrl());
-                            }
-                        })
-                .setOnCancelListener(
-                        new DialogInterface.OnCancelListener() {
-                            public void onCancel(DialogInterface dialog) {
-                                mSSLCertificateOnErrorDialog = null;
-                                mSSLCertificateOnErrorView = null;
-                                mSSLCertificateOnErrorHandler = null;
-                                mSSLCertificateOnErrorError = null;
-
-                                ((BrowserWebView) view).getWebViewClient().
-                                        onReceivedSslError(view, handler, error);
-                            }
-                        })
-                .show();
-    }
-
-    private static View inflateCertificateView(SslCertificate certificate, Context ctx) {
-        Object[] params = {ctx};
-        Class[] type = new Class[] {Context.class};
-        return (View)ReflectHelper.invokeMethod(certificate, "inflateCertificateView",type, params);
-    }
-
-    public static AlertDialog.Builder createSslCertificateDialog(Context ctx,
-                                                                 SslCertificate certificate,
-                                                                 SslError error) {
-        View certificateView = inflateCertificateView(certificate, ctx);
-        Resources res = Resources.getSystem();
-        // load 'android.R.placeholder' via introspection, since it's not a public resource ID
-        int placeholder_id = res.getIdentifier("placeholder", "id", "android");
-        final LinearLayout placeholder =
-                (LinearLayout)certificateView.findViewById(placeholder_id);
-
-        LayoutInflater factory = LayoutInflater.from(ctx);
-        int iconId;
-
-        if (error == null) {
-            iconId = R.drawable.ic_dialog_browser_certificate_secure;
-            LinearLayout table = (LinearLayout)factory.inflate(R.layout.ssl_success, placeholder);
-            TextView successString = (TextView)table.findViewById(R.id.success);
-            successString.setText(R.string.ssl_certificate_is_valid);
-        } else {
-            iconId = R.drawable.ic_dialog_browser_certificate_partially_secure;
-            if (error.hasError(SslError.SSL_UNTRUSTED)) {
-                addError(factory, placeholder, R.string.ssl_untrusted);
-            }
-            if (error.hasError(SslError.SSL_IDMISMATCH)) {
-                addError(factory, placeholder, R.string.ssl_mismatch);
-            }
-            if (error.hasError(SslError.SSL_EXPIRED)) {
-                addError(factory, placeholder, R.string.ssl_expired);
-            }
-            if (error.hasError(SslError.SSL_NOTYETVALID)) {
-                addError(factory, placeholder, R.string.ssl_not_yet_valid);
-            }
-            if (error.hasError(SslError.SSL_DATE_INVALID)) {
-                addError(factory, placeholder, R.string.ssl_date_invalid);
-            }
-            if (error.hasError(SslError.SSL_INVALID)) {
-                addError(factory, placeholder, R.string.ssl_invalid);
-            }
-            // The SslError should always have at least one type of error and we
-            // should explicitly handle every type of error it supports. We
-            // therefore expect the condition below to never be hit. We use it
-            // as as safety net in case a new error type is added to SslError
-            // without the logic above being updated accordingly.
-            if (placeholder.getChildCount() == 0) {
-                addError(factory, placeholder, R.string.ssl_unknown);
-            }
-        }
-
-        return new AlertDialog.Builder(ctx)
-                .setTitle(R.string.ssl_certificate)
-                .setIcon(iconId)
-                .setView(certificateView);
-    }
-
-    /*
-     * Creates an AlertDialog to display the given certificate. If error is
-     * null, text is added to state that the certificae is valid and the icon
-     * is set accordingly. If error is non-null, it must relate to the supplied
-     * certificate. In this case, error is used to add text describing the
-     * problems with the certificate and a different icon is used.
-     */
-    private AlertDialog.Builder createSslCertificateDialog(SslCertificate certificate,
-            SslError error) {
-        return createSslCertificateDialog(mContext, certificate, error);
-    }
-
-    private static void addError(LayoutInflater inflater, LinearLayout parent, int error) {
-        TextView textView = (TextView) inflater.inflate(R.layout.ssl_warning,
-                parent, false);
-        textView.setText(error);
-        parent.addView(textView);
-    }
-}
diff --git a/src/com/android/browser/PreloadController.java b/src/com/android/browser/PreloadController.java
index 12dc156..8bccf2f 100644
--- a/src/com/android/browser/PreloadController.java
+++ b/src/com/android/browser/PreloadController.java
@@ -20,13 +20,11 @@
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.net.Uri;
-import android.net.http.SslError;
 import android.os.Message;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.View;
 import org.codeaurora.swe.HttpAuthHandler;
-import org.codeaurora.swe.SslErrorHandler;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient.CustomViewCallback;
 import org.codeaurora.swe.WebView;
@@ -181,12 +179,6 @@
     }
 
     @Override
-    public void showSslCertificateOnError(WebView view,
-                                    SslErrorHandler handler, SslError error) {
-        if (LOGD_ENABLED) Log.d(LOGTAG, "showSslCertificateOnError()");
-    }
-
-    @Override
     public void onUserCanceledSsl(Tab tab) {
         if (LOGD_ENABLED) Log.d(LOGTAG, "onUserCanceledSsl()");
     }
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 1642568..a86b2e6 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -36,7 +36,6 @@
 import android.graphics.PorterDuffXfermode;
 import android.graphics.Rect;
 import android.net.Uri;
-import android.net.http.SslError;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -48,7 +47,6 @@
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.ViewStub;
 import android.webkit.ConsoleMessage;
 import android.webkit.URLUtil;
 import android.webkit.WebResourceResponse;
@@ -68,7 +66,6 @@
 import org.codeaurora.swe.BrowserDownloadListener;
 import org.codeaurora.swe.ClientCertRequestHandler;
 import org.codeaurora.swe.HttpAuthHandler;
-import org.codeaurora.swe.SslErrorHandler;
 import org.codeaurora.swe.WebBackForwardList;
 import org.codeaurora.swe.WebChromeClient;
 import org.codeaurora.swe.WebView;
@@ -226,7 +223,6 @@
         String mTitle;
         SecurityState mSecurityState;
         // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
-        SslError mSslCertificateError;
         Bitmap mFavicon;
         boolean mIsBookmarkedSite;
         boolean mIncognito;
@@ -246,11 +242,7 @@
         PageState(Context c, boolean incognito, String url, Bitmap favicon) {
             mIncognito = incognito;
             mOriginalUrl = mUrl = url;
-            if (URLUtil.isHttpsUrl(url)) {
-                mSecurityState = SecurityState.SECURITY_STATE_SECURE;
-            } else {
-                mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
-            }
+            mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
             mFavicon = favicon;
         }
 
@@ -303,6 +295,20 @@
         return (index & 0xffffff);
     }
 
+    public static SecurityState getWebViewSecurityState(WebView view) {
+        switch (view.getSecurityLevel()) {
+            case WebView.SecurityLevel.EV_SECURE:
+            case WebView.SecurityLevel.SECURE:
+                return SecurityState.SECURITY_STATE_SECURE;
+            case WebView.SecurityLevel.SECURITY_ERROR:
+                return SecurityState.SECURITY_STATE_BAD_CERTIFICATE;
+            case WebView.SecurityLevel.SECURITY_POLICY_WARNING:
+            case WebView.SecurityLevel.SECURITY_WARNING:
+                return SecurityState.SECURITY_STATE_MIXED;
+        }
+        return SecurityState.SECURITY_STATE_NOT_SECURE;
+    }
+
     // -------------------------------------------------------------------------
     // WebViewClient implementation for the main WebView
     // -------------------------------------------------------------------------
@@ -359,6 +365,7 @@
             }
             syncCurrentState(view, url);
             mWebViewController.onPageFinished(Tab.this);
+            setSecurityState(getWebViewSecurityState(view));
         }
 
         @Override
@@ -483,74 +490,6 @@
         }
 
         /**
-         * Displays SSL error(s) dialog to the user.
-         */
-        @Override
-        public void onReceivedSslError(final WebView view,
-                final SslErrorHandler handler, final SslError error) {
-            if (!mInForeground) {
-                handler.cancel();
-                setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
-                return;
-            }
-            if (mSettings.showSecurityWarnings()) {
-                new AlertDialog.Builder(mContext)
-                    .setTitle(R.string.security_warning)
-                    .setMessage(R.string.ssl_warnings_header)
-                    .setIconAttribute(android.R.attr.alertDialogIcon)
-                    .setPositiveButton(R.string.ssl_continue,
-                        new DialogInterface.OnClickListener() {
-                            @Override
-                            public void onClick(DialogInterface dialog,
-                                    int whichButton) {
-                                handler.proceed();
-                                handleProceededAfterSslError(error);
-                            }
-                        })
-                    .setNeutralButton(R.string.view_certificate,
-                        new DialogInterface.OnClickListener() {
-                            @Override
-                            public void onClick(DialogInterface dialog,
-                                    int whichButton) {
-                                mWebViewController.showSslCertificateOnError(
-                                        view, handler, error);
-                            }
-                        })
-                    .setNegativeButton(R.string.ssl_go_back,
-                        new DialogInterface.OnClickListener() {
-                            @Override
-                            public void onClick(DialogInterface dialog,
-                                    int whichButton) {
-                                dialog.cancel();
-                            }
-                        })
-                    .setOnCancelListener(
-                        new DialogInterface.OnCancelListener() {
-                            @Override
-                            public void onCancel(DialogInterface dialog) {
-                                handler.cancel();
-                                setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
-                                mWebViewController.onUserCanceledSsl(Tab.this);
-                            }
-                        })
-                    .show();
-            } else {
-                handler.proceed();
-            }
-        }
-
-        /**
-         * Called when an SSL error occurred while loading a resource, but the
-         * WebView but chose to proceed anyway based on a decision retained
-         * from a previous response to onReceivedSslError(). We update our
-         * security state to reflect this.
-         */
-        @Override
-        public void onProceededAfterSslError(WebView view, SslError error) {
-            handleProceededAfterSslError(error);
-        }
-
-        /**
          * Displays client certificate request to the user.
          */
         @Override
@@ -751,7 +690,6 @@
             // In case we stop when loading an HTTPS page from an HTTP page
             // but before a provisional load occurred
             mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
-            mCurrentState.mSslCertificateError = null;
         }
         mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
     }
@@ -1177,16 +1115,6 @@
             return mClient.shouldOverrideUrlLoading(view, url);
         }
         @Override
-        public void onReceivedSslError(WebView view, SslErrorHandler handler,
-                SslError error) {
-            mClient.onReceivedSslError(view, handler, error);
-        }
-        @Override
-        public void onReceivedClientCertRequest(WebView view,
-                ClientCertRequestHandler handler, String host_and_port) {
-            mClient.onReceivedClientCertRequest(view, handler, host_and_port);
-        }
-        @Override
         public void onReceivedHttpAuthRequest(WebView view,
                 HttpAuthHandler handler, String host, String realm) {
             mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
@@ -1792,7 +1720,6 @@
      */
     private void setSecurityState(SecurityState securityState) {
         mCurrentState.mSecurityState = securityState;
-        mCurrentState.mSslCertificateError = null;
         mWebViewController.onUpdatedSecurityState(this);
     }
 
@@ -1803,15 +1730,6 @@
         return mCurrentState.mSecurityState;
     }
 
-    /**
-     * Gets the SSL certificate error, if any, for the page's main resource.
-     * This is only non-null when the security state is
-     * SECURITY_STATE_BAD_CERTIFICATE.
-     */
-    SslError getSslCertificateError() {
-        return mCurrentState.mSslCertificateError;
-    }
-
     int getLoadProgress() {
         if (mInPageLoad) {
             return mPageLoadProgress;
@@ -2148,18 +2066,6 @@
         return builder.toString();
     }
 
-    private void handleProceededAfterSslError(SslError error) {
-        if (error.getUrl().equals(mCurrentState.mUrl)) {
-            // The security state should currently be SECURITY_STATE_SECURE.
-            setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
-            mCurrentState.mSslCertificateError = error;
-        } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
-            // The page's main resource is secure and this error is for a
-            // sub-resource.
-            setSecurityState(SecurityState.SECURITY_STATE_MIXED);
-        }
-    }
-
     // dertermines if the tab contains a dislled page
     public boolean isDistilled() {
         if (!BrowserCommandLine.hasSwitch("reader-mode")) {
diff --git a/src/com/android/browser/WebViewController.java b/src/com/android/browser/WebViewController.java
index e68f9bf..f7b926e 100644
--- a/src/com/android/browser/WebViewController.java
+++ b/src/com/android/browser/WebViewController.java
@@ -20,15 +20,12 @@
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.net.Uri;
-import android.net.http.SslError;
 import android.os.Message;
 import android.view.KeyEvent;
 import android.view.View;
 import org.codeaurora.swe.HttpAuthHandler;
-import org.codeaurora.swe.SslErrorHandler;
 import android.webkit.ValueCallback;
 import android.webkit.WebChromeClient.CustomViewCallback;
-import org.codeaurora.swe.WebChromeClient;
 import org.codeaurora.swe.WebView;
 
 import java.util.List;
@@ -85,9 +82,6 @@
 
     View getVideoLoadingProgressView();
 
-    void showSslCertificateOnError(WebView view, SslErrorHandler handler,
-            SslError error);
-
     void onUserCanceledSsl(Tab tab);
 
     void onUpdatedSecurityState(Tab tab);
diff --git a/src/com/android/browser/preferences/SiteSpecificPreferencesFragment.java b/src/com/android/browser/preferences/SiteSpecificPreferencesFragment.java
index 275a5c3..1a764a9 100644
--- a/src/com/android/browser/preferences/SiteSpecificPreferencesFragment.java
+++ b/src/com/android/browser/preferences/SiteSpecificPreferencesFragment.java
@@ -32,32 +32,36 @@
 import android.app.ActionBar;
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.content.Context;
 import android.content.DialogInterface;
+import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
 import android.net.http.SslCertificate;
-import android.net.http.SslError;
 import android.os.Bundle;
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.PreferenceCategory;
 import android.preference.PreferenceScreen;
 import android.preference.TwoStatePreference;
+import android.text.Html;
 import android.text.TextUtils;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.webkit.ValueCallback;
 import android.widget.Button;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.android.browser.BrowserLocationListPreference;
-import com.android.browser.BrowserLocationSwitchPreference;
 import com.android.browser.BrowserSettings;
 import com.android.browser.NavigationBarBase;
-import com.android.browser.PageDialogsHandler;
 import com.android.browser.PreferenceKeys;
 import com.android.browser.R;
+import com.android.browser.reflect.ReflectHelper;
 
 import org.codeaurora.swe.PermissionsServiceFactory;
 import org.codeaurora.swe.WebRefiner;
@@ -65,7 +69,6 @@
 
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.text.Normalizer;
 import java.util.Arrays;
 import java.util.EnumMap;
 import java.util.Formatter;
@@ -82,7 +85,8 @@
     public static final String EXTRA_WEB_REFINER_TRACKER_INFO = "website_refiner_tracker_info";
     public static final String EXTRA_WEB_REFINER_MALWARE_INFO = "website_refiner_malware_info";
     public static final String EXTRA_SECURITY_CERT = "website_security_cert";
-    public static final String EXTRA_SECURITY_CERT_ERR = "website_security_cert_err";
+    public static final String EXTRA_SECURITY_CERT_BAD = "website_security_cert_bad";
+    public static final String EXTRA_SECURITY_CERT_MIXED = "website_security_cert_mixed";
 
     private PermissionsServiceFactory.PermissionsService.OriginInfo mOriginInfo;
     private PermissionsServiceFactory.PermissionsService mPermServ;
@@ -94,7 +98,7 @@
     private int mIconColor = 0;
 
     private SslCertificate mSslCert;
-    private SslError mSslError;
+    private int mSslState;
 
     private static class SiteSecurityViewFactory {
         private class SiteSecurityView {
@@ -280,53 +284,72 @@
                 pref.setSelectable(true);
             }
 
-            int certErrors = args.getInt(EXTRA_SECURITY_CERT_ERR, 0);
-
-            if (certErrors == 0) {
+            boolean certBad = args.getBoolean(EXTRA_SECURITY_CERT_BAD, false);
+            boolean certMix = args.getBoolean(EXTRA_SECURITY_CERT_MIXED, false);
+            if (!certBad && !certMix) {
+                final String string = getString(R.string.pref_valid_cert);
                 mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.INFO,
-                        getString(R.string.pref_valid_cert));
+                        string);
+                mSslState = 0;
+            } else if (certMix) {
+                mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.WARNING,
+                        getString(R.string.pref_warning_cert));
+                mSslState = 1;
             } else {
-                mSslError = new SslError(-1, mSslCert, mOriginText);
-
-                if ((certErrors & (1 << SslError.SSL_DATE_INVALID)) != 0) {
-                    mSslError.addError(SslError.SSL_DATE_INVALID);
-                    mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.ERROR,
-                            getString(R.string.pref_invalid_cert));
-                }
-
-                if ((certErrors & (1 << SslError.SSL_EXPIRED)) != 0) {
-                    mSslError.addError(SslError.SSL_EXPIRED);
-                    mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.ERROR,
-                            getString(R.string.pref_invalid_cert));
-                }
-
-                if ((certErrors & (1 << SslError.SSL_IDMISMATCH)) != 0) {
-                    mSslError.addError(SslError.SSL_IDMISMATCH);
-                    mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.ERROR,
-                            getString(R.string.pref_invalid_cert));
-                }
-
-                if ((certErrors & (1 << SslError.SSL_INVALID)) != 0) {
-                    mSslError.addError(SslError.SSL_INVALID);
-                    mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.ERROR,
-                            getString(R.string.pref_invalid_cert));
-                }
-
-                if ((certErrors & (1 << SslError.SSL_NOTYETVALID)) != 0) {
-                    mSslError.addError(SslError.SSL_NOTYETVALID);
-                    mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.WARNING,
-                            getString(R.string.pref_warning_cert));
-                }
-
-                if ((certErrors & (1 << SslError.SSL_UNTRUSTED)) != 0) {
-                    mSslError.addError(SslError.SSL_UNTRUSTED);
-                    mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.WARNING,
-                            getString(R.string.pref_warning_cert));
-                }
+                mSecurityViews.appendText(SiteSecurityViewFactory.ViewType.ERROR,
+                        getString(R.string.pref_invalid_cert));
+                mSslState = 2;
             }
         }
     }
 
+    private AlertDialog.Builder createSslCertificateDialog(Context ctx,
+                                                           SslCertificate certificate) {
+        Object[] params = {ctx};
+        Class[] type = new Class[] {Context.class};
+        View certificateView = (View) ReflectHelper.invokeMethod(certificate,
+                "inflateCertificateView", type, params);
+        Resources res = Resources.getSystem();
+        // load 'android.R.placeholder' via introspection, since it's not a public resource ID
+        int placeholder_id = res.getIdentifier("placeholder", "id", "android");
+        final LinearLayout placeholder =
+                (LinearLayout)certificateView.findViewById(placeholder_id);
+
+        LayoutInflater factory = LayoutInflater.from(ctx);
+        int iconId = R.drawable.ic_cert_trusted;
+        TextView textView;
+
+        switch (mSslState) {
+            case 0:
+                iconId = R.drawable.ic_cert_trusted;
+                LinearLayout table = (LinearLayout)factory.inflate(R.layout.ssl_success, placeholder);
+                textView = (TextView)table.findViewById(R.id.success);
+                textView.setText(R.string.ssl_certificate_is_valid);
+                break;
+            case 1:
+                iconId = R.drawable.ic_cert_untrusted;
+                textView = (TextView) factory.inflate(R.layout.ssl_warning, placeholder, false);
+                textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_sp_level_warning,
+                        0, 0, 0);
+                textView.setText(R.string.ssl_unknown);
+                placeholder.addView(textView);
+                break;
+            case 2:
+                iconId = R.drawable.ic_cert_avoid;
+                textView = (TextView) factory.inflate(R.layout.ssl_warning, placeholder, false);
+                textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_sp_level_severe,
+                        0, 0, 0);
+                textView.setText(R.string.ssl_invalid);
+                placeholder.addView(textView);
+                break;
+        }
+
+        return new AlertDialog.Builder(ctx)
+                .setTitle(R.string.ssl_certificate)
+                .setIcon(iconId)
+                .setView(certificateView);
+    }
+
     private void setActionBarTitle(String url) {
         if (mBar != null) {
             mBar.setTitle("  " + url);
@@ -644,7 +667,7 @@
     @Override
     public void onClick(View v) {
         if (v.getId() == R.id.site_security_info) {
-            PageDialogsHandler.createSslCertificateDialog(getActivity(),mSslCert, mSslError)
+            createSslCertificateDialog(getActivity(), mSslCert)
                     .setPositiveButton(R.string.ok, null)
                     .show();
         }