diff options
29 files changed, 99 insertions, 657 deletions
diff --git a/res/drawable-hdpi/ic_deco_secure_partial.png b/res/drawable-hdpi/ic_deco_secure_partial.png Binary files differdeleted file mode 100644 index 24ba10e5..00000000 --- a/res/drawable-hdpi/ic_deco_secure_partial.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_dialog_browser_certificate_partially_secure.png b/res/drawable-hdpi/ic_dialog_browser_certificate_partially_secure.png Binary files differdeleted file mode 100644 index 3aa358bf..00000000 --- a/res/drawable-hdpi/ic_dialog_browser_certificate_partially_secure.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_dialog_browser_certificate_secure.png b/res/drawable-hdpi/ic_dialog_browser_certificate_secure.png Binary files differdeleted file mode 100644 index f0563955..00000000 --- a/res/drawable-hdpi/ic_dialog_browser_certificate_secure.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_dialog_browser_security_bad.png b/res/drawable-hdpi/ic_dialog_browser_security_bad.png Binary files differdeleted file mode 100644 index f5d8e52f..00000000 --- a/res/drawable-hdpi/ic_dialog_browser_security_bad.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_dialog_browser_security_good.png b/res/drawable-hdpi/ic_dialog_browser_security_good.png Binary files differdeleted file mode 100644 index a990705a..00000000 --- a/res/drawable-hdpi/ic_dialog_browser_security_good.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_deco_secure_partial.png b/res/drawable-mdpi/ic_deco_secure_partial.png Binary files differdeleted file mode 100644 index 14ef32d0..00000000 --- a/res/drawable-mdpi/ic_deco_secure_partial.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_dialog_browser_certificate_partially_secure.png b/res/drawable-mdpi/ic_dialog_browser_certificate_partially_secure.png Binary files differdeleted file mode 100644 index b91fb837..00000000 --- a/res/drawable-mdpi/ic_dialog_browser_certificate_partially_secure.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_dialog_browser_certificate_secure.png b/res/drawable-mdpi/ic_dialog_browser_certificate_secure.png Binary files differdeleted file mode 100644 index 86c70045..00000000 --- a/res/drawable-mdpi/ic_dialog_browser_certificate_secure.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_dialog_browser_security_bad.png b/res/drawable-mdpi/ic_dialog_browser_security_bad.png Binary files differdeleted file mode 100644 index 7439b51c..00000000 --- a/res/drawable-mdpi/ic_dialog_browser_security_bad.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_dialog_browser_security_good.png b/res/drawable-mdpi/ic_dialog_browser_security_good.png Binary files differdeleted file mode 100644 index 83f18967..00000000 --- a/res/drawable-mdpi/ic_dialog_browser_security_good.png +++ /dev/null diff --git a/res/drawable-xhdpi/ic_deco_secure_partial.png b/res/drawable-xhdpi/ic_deco_secure_partial.png Binary files differdeleted file mode 100644 index 86c59935..00000000 --- a/res/drawable-xhdpi/ic_deco_secure_partial.png +++ /dev/null diff --git a/res/drawable-xhdpi/ic_dialog_browser_certificate_partially_secure.png b/res/drawable-xhdpi/ic_dialog_browser_certificate_partially_secure.png Binary files differdeleted file mode 100644 index 37c0b91c..00000000 --- a/res/drawable-xhdpi/ic_dialog_browser_certificate_partially_secure.png +++ /dev/null diff --git a/res/drawable-xhdpi/ic_dialog_browser_certificate_secure.png b/res/drawable-xhdpi/ic_dialog_browser_certificate_secure.png Binary files differdeleted file mode 100644 index 036eba67..00000000 --- a/res/drawable-xhdpi/ic_dialog_browser_certificate_secure.png +++ /dev/null diff --git a/res/drawable-xhdpi/ic_dialog_browser_security_bad.png b/res/drawable-xhdpi/ic_dialog_browser_security_bad.png Binary files differdeleted file mode 100644 index 1e3068bf..00000000 --- a/res/drawable-xhdpi/ic_dialog_browser_security_bad.png +++ /dev/null diff --git a/res/drawable-xhdpi/ic_dialog_browser_security_good.png b/res/drawable-xhdpi/ic_dialog_browser_security_good.png Binary files differdeleted file mode 100644 index e8badf65..00000000 --- a/res/drawable-xhdpi/ic_dialog_browser_security_good.png +++ /dev/null diff --git a/res/drawable-xxhdpi/ic_cert_avoid.png b/res/drawable-xxhdpi/ic_cert_avoid.png Binary files differnew file mode 100644 index 00000000..812a6272 --- /dev/null +++ b/res/drawable-xxhdpi/ic_cert_avoid.png diff --git a/res/drawable-xxhdpi/ic_cert_trusted.png b/res/drawable-xxhdpi/ic_cert_trusted.png Binary files differnew file mode 100644 index 00000000..55e37f3e --- /dev/null +++ b/res/drawable-xxhdpi/ic_cert_trusted.png diff --git a/res/drawable-xxhdpi/ic_cert_untrusted.png b/res/drawable-xxhdpi/ic_cert_untrusted.png Binary files differnew file mode 100644 index 00000000..0bddf180 --- /dev/null +++ b/res/drawable-xxhdpi/ic_cert_untrusted.png diff --git a/res/layout/ssl_success.xml b/res/layout/ssl_success.xml index fb148529..6fbedc46 100644 --- a/res/layout/ssl_success.xml +++ b/res/layout/ssl_success.xml @@ -24,7 +24,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="center" - android:src="@drawable/ic_dialog_browser_security_good" + android:src="@drawable/ic_sp_level_good" android:layout_marginStart="20dip" android:layout_marginBottom="12dip" /> diff --git a/res/layout/ssl_warning.xml b/res/layout/ssl_warning.xml index 9471943c..5a9b1417 100644 --- a/res/layout/ssl_warning.xml +++ b/res/layout/ssl_warning.xml @@ -19,7 +19,6 @@ android:id="@+id/warning" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:drawableStart="@drawable/ic_dialog_browser_security_bad" android:drawablePadding="6dip" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_marginStart="12dip" diff --git a/res/values/strings.xml b/res/values/strings.xml index e2205d18..5ab4736b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -423,7 +423,8 @@ <item>"Blocked %1$s and %2$s. "</item> <item>"Blocked %1$s, %2$s and $3$s. "</item> </string-array> - <string name="pref_valid_cert">Site has a valid SSL certificate.</string> + <string name="pref_valid_cert" + >Valid SSL certificate. Communication is encrypted and identity is verified.</string> <string name="pref_invalid_cert">Site has an invalid SSL certificate.</string> <string name="pref_warning_cert">Site SSL certificate has warnings.</string> <!-- Label for option that when clicked opens the AutoFill settings screen. Also used as the title of that AutoFill Settings screen. [CHAR-LIMIT=32] --> diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 82402c17..debf6f8a 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -997,10 +997,6 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, // 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 09dbc3c4..8c88c7d2 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -86,7 +86,6 @@ import org.codeaurora.swe.CookieManager; 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 @@ public class Controller private UrlHandler mUrlHandler; private UploadHandler mUploadHandler; private IntentHandler mIntentHandler; - private PageDialogsHandler mPageDialogsHandler; private NetworkStateHandler mNetworkHandler; private Message mAutoFillSetupMessage; @@ -271,7 +269,6 @@ public class Controller mUrlHandler = new UrlHandler(this); mIntentHandler = new IntentHandler(mActivity, this); - mPageDialogsHandler = new PageDialogsHandler(mActivity, this); startHandler(); mBookmarksObserver = new ContentObserver(mHandler) { @@ -712,9 +709,6 @@ public class Controller mActivity.closeOptionsMenu(); mHandler.sendMessageDelayed(mHandler.obtainMessage(OPEN_MENU), 100); } - if (mPageDialogsHandler != null) { - mPageDialogsHandler.onConfigurationChanged(config); - } mUi.onConfigurationChanged(config); } @@ -1202,9 +1196,7 @@ public class Controller 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 @@ public class Controller return mUi.getVideoLoadingProgressView(); } - @Override - public void showSslCertificateOnError(WebView view, SslErrorHandler handler, - SslError error) { - mPageDialogsHandler.showSSLCertificateOnError(view, handler, error); - } - // helper method /* @@ -2403,7 +2389,6 @@ public class Controller @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 a92090d6..ce65f16c 100644 --- a/src/com/android/browser/NavigationBarBase.java +++ b/src/com/android/browser/NavigationBarBase.java @@ -28,7 +28,6 @@ import android.graphics.BitmapFactory; 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 @@ public class NavigationBarBase extends LinearLayout implements 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 class NavigationBarBase extends LinearLayout implements } 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 @@ public class NavigationBarBase extends LinearLayout implements 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 @@ public class NavigationBarBase extends LinearLayout implements 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 af54000f..00000000 --- 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 12dc1562..8bccf2f6 100644 --- a/src/com/android/browser/PreloadController.java +++ b/src/com/android/browser/PreloadController.java @@ -20,13 +20,11 @@ import android.app.Activity; 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 @@ public class PreloadController implements WebViewController { } @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 1642568c..a86b2e6d 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -36,7 +36,6 @@ import android.graphics.PorterDuff; 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.util.Log; 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.BrowserCommandLine; 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 @@ class Tab implements PictureListener { 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 @@ class Tab implements PictureListener { 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 @@ class Tab implements PictureListener { 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 @@ class Tab implements PictureListener { } syncCurrentState(view, url); mWebViewController.onPageFinished(Tab.this); + setSecurityState(getWebViewSecurityState(view)); } @Override @@ -483,74 +490,6 @@ class Tab implements PictureListener { } /** - * 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 @@ class Tab implements PictureListener { // 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 @@ class Tab implements PictureListener { 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 @@ class Tab implements PictureListener { */ private void setSecurityState(SecurityState securityState) { mCurrentState.mSecurityState = securityState; - mCurrentState.mSslCertificateError = null; mWebViewController.onUpdatedSecurityState(this); } @@ -1803,15 +1730,6 @@ class Tab implements PictureListener { 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 @@ class Tab implements PictureListener { 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 e68f9bfd..f7b926ef 100644 --- a/src/com/android/browser/WebViewController.java +++ b/src/com/android/browser/WebViewController.java @@ -20,15 +20,12 @@ import android.app.Activity; 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 @@ public interface WebViewController { 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 275a5c3a..1a764a9b 100644 --- a/src/com/android/browser/preferences/SiteSpecificPreferencesFragment.java +++ b/src/com/android/browser/preferences/SiteSpecificPreferencesFragment.java @@ -32,32 +32,36 @@ package com.android.browser.preferences; 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 org.codeaurora.swe.util.ColorUtils; 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 class SiteSpecificPreferencesFragment extends SWEPreferenceFragment 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 @@ public class SiteSpecificPreferencesFragment extends SWEPreferenceFragment private int mIconColor = 0; private SslCertificate mSslCert; - private SslError mSslError; + private int mSslState; private static class SiteSecurityViewFactory { private class SiteSecurityView { @@ -280,53 +284,72 @@ public class SiteSpecificPreferencesFragment extends SWEPreferenceFragment 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 @@ public class SiteSpecificPreferencesFragment extends SWEPreferenceFragment @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(); } |