Bug 1078508: Add "unknown site identity" popup. r=lucasr

This commit is contained in:
Michael Comella 2014-11-18 17:32:26 -08:00
parent bdab27d933
commit b061c16321
5 changed files with 136 additions and 65 deletions

View File

@ -474,6 +474,8 @@ substitution variables. If it is difficult to translate the sense of the string
with that structure, consider a translation which ignores the preceding domain and
just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY identity_run_by "which is run by">
<!ENTITY identity_no_info "This website does not supply identity information.">
<!ENTITY identity_not_encrypted "Your connection to this website is not encrypted.">
<!-- Mixed content notifications in site identity popup -->
<!ENTITY loaded_mixed_content_message "This page is displaying content that isn\'t secure.">

View File

@ -15,45 +15,53 @@
android:src="@drawable/larry"
android:paddingRight="@dimen/doorhanger_padding"/>
<LinearLayout android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="vertical">
<FrameLayout android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:text="@string/identity_connected_to"/>
<include layout="@layout/site_identity_unknown" />
<TextView android:id="@+id/host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="@color/doorhanger_text"
android:textStyle="bold"/>
<LinearLayout android:id="@+id/site_identity_known_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:text="@string/identity_run_by"
android:paddingTop="12dip"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:text="@string/identity_connected_to"/>
<TextView android:id="@+id/owner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/doorhanger_text"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView android:id="@+id/host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="@color/doorhanger_text"
android:textStyle="bold"/>
<TextView android:id="@+id/verifier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:paddingTop="12dip"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:text="@string/identity_run_by"
android:paddingTop="12dip"/>
</LinearLayout>
<TextView android:id="@+id/owner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/doorhanger_text"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView android:id="@+id/verifier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:paddingTop="12dip"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/site_identity_unknown_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:text="@string/identity_no_info"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/doorhanger_text"
android:text="@string/identity_not_encrypted"
android:paddingTop="12dip"/>
</LinearLayout>

View File

@ -411,6 +411,8 @@
<!-- Site identity popup -->
<string name="identity_connected_to">&identity_connected_to;</string>
<string name="identity_run_by">&identity_run_by;</string>
<string name="identity_no_info">&identity_no_info;</string>
<string name="identity_not_encrypted">&identity_not_encrypted;</string>
<string name="loaded_mixed_content_message">&loaded_mixed_content_message;</string>
<string name="blocked_mixed_content_message_top">&blocked_mixed_content_message_top;</string>
<string name="blocked_mixed_content_message_bottom">&blocked_mixed_content_message_bottom;</string>

View File

@ -4,6 +4,7 @@
package org.mozilla.gecko.toolbar;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.R;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
@ -11,10 +12,11 @@ import org.mozilla.gecko.SiteIdentity;
import org.mozilla.gecko.SiteIdentity.SecurityMode;
import org.mozilla.gecko.SiteIdentity.MixedMode;
import org.mozilla.gecko.SiteIdentity.TrackingMode;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.widget.ArrowPopup;
import org.mozilla.gecko.widget.DoorHanger;
import org.mozilla.gecko.widget.DoorHanger.OnButtonClickListener;
import org.json.JSONException;
import org.json.JSONObject;
@ -42,6 +44,10 @@ public class SiteIdentityPopup extends ArrowPopup {
private SiteIdentity mSiteIdentity;
private LinearLayout mIdentity;
private LinearLayout mIdentityKnownContainer;
private LinearLayout mIdentityUnknownContainer;
private TextView mHost;
private TextView mOwner;
private TextView mVerifier;
@ -69,43 +75,68 @@ public class SiteIdentityPopup extends ArrowPopup {
mIdentity = (LinearLayout) inflater.inflate(R.layout.site_identity, null);
mContent.addView(mIdentity);
mHost = (TextView) mIdentity.findViewById(R.id.host);
mOwner = (TextView) mIdentity.findViewById(R.id.owner);
mVerifier = (TextView) mIdentity.findViewById(R.id.verifier);
mIdentityKnownContainer =
(LinearLayout) mIdentity.findViewById(R.id.site_identity_known_container);
mIdentityUnknownContainer =
(LinearLayout) mIdentity.findViewById(R.id.site_identity_unknown_container);
mHost = (TextView) mIdentityKnownContainer.findViewById(R.id.host);
mOwner = (TextView) mIdentityKnownContainer.findViewById(R.id.owner);
mVerifier = (TextView) mIdentityKnownContainer.findViewById(R.id.verifier);
}
private void updateIdentity() {
private void updateIdentity(final SiteIdentity siteIdentity) {
if (!mInflated) {
init();
}
final MixedMode mixedMode = mSiteIdentity.getMixedMode();
final TrackingMode trackingMode = mSiteIdentity.getTrackingMode();
final MixedMode mixedMode = siteIdentity.getMixedMode();
final TrackingMode trackingMode = siteIdentity.getTrackingMode();
if (mixedMode != MixedMode.UNKNOWN || trackingMode != TrackingMode.UNKNOWN) {
// Hide the identity data if there isn't valid site identity data.
// Set some top padding on the popup content to create a of light blue
// between the popup arrow and the mixed content notification.
mContent.setPadding(0, (int) mContext.getResources().getDimension(R.dimen.identity_padding_top), 0, 0);
mIdentity.setVisibility(View.GONE);
} else {
mHost.setText(mSiteIdentity.getHost());
String owner = mSiteIdentity.getOwner();
// Supplemental data is optional.
final String supplemental = mSiteIdentity.getSupplemental();
if (!TextUtils.isEmpty(supplemental)) {
owner += "\n" + supplemental;
}
mOwner.setText(owner);
final String verifier = mSiteIdentity.getVerifier();
final String encrypted = mSiteIdentity.getEncrypted();
mVerifier.setText(verifier + "\n" + encrypted);
mContent.setPadding(0, 0, 0, 0);
mIdentity.setVisibility(View.VISIBLE);
return;
}
mIdentity.setVisibility(View.VISIBLE);
mContent.setPadding(0, 0, 0, 0);
final boolean isIdentityKnown = (siteIdentity.getSecurityMode() != SecurityMode.UNKNOWN);
toggleIdentityKnownContainerVisibility(isIdentityKnown);
if (isIdentityKnown) {
updateIdentityInformation(siteIdentity);
}
}
private void toggleIdentityKnownContainerVisibility(final boolean isIdentityKnown) {
if (isIdentityKnown) {
mIdentityKnownContainer.setVisibility(View.VISIBLE);
mIdentityUnknownContainer.setVisibility(View.GONE);
} else {
mIdentityKnownContainer.setVisibility(View.GONE);
mIdentityUnknownContainer.setVisibility(View.VISIBLE);
}
}
private void updateIdentityInformation(final SiteIdentity siteIdentity) {
mHost.setText(siteIdentity.getHost());
String owner = siteIdentity.getOwner();
// Supplemental data is optional.
final String supplemental = siteIdentity.getSupplemental();
if (!TextUtils.isEmpty(supplemental)) {
owner += "\n" + supplemental;
}
mOwner.setText(owner);
final String verifier = siteIdentity.getVerifier();
final String encrypted = siteIdentity.getEncrypted();
mVerifier.setText(verifier + "\n" + encrypted);
}
private void addMixedContentNotification(boolean blocked) {
@ -195,20 +226,22 @@ public class SiteIdentityPopup extends ArrowPopup {
return;
}
final SecurityMode identityMode = mSiteIdentity.getSecurityMode();
final MixedMode mixedMode = mSiteIdentity.getMixedMode();
final TrackingMode trackingMode = mSiteIdentity.getTrackingMode();
if (identityMode == SecurityMode.UNKNOWN && mixedMode == MixedMode.UNKNOWN && trackingMode == TrackingMode.UNKNOWN) {
Log.e(LOGTAG, "Can't show site identity popup in a completely unknown state");
// about: has an unknown SiteIdentity in code, but showing "This
// site's identity is unknown" is misleading! So don't show a popup.
final Tab selectedTab = Tabs.getInstance().getSelectedTab();
if (selectedTab != null && AboutPages.isAboutPage(selectedTab.getURL())) {
Log.d(LOGTAG, "We don't show site identity popups for about: pages");
return;
}
updateIdentity();
updateIdentity(mSiteIdentity);
final MixedMode mixedMode = mSiteIdentity.getMixedMode();
if (mixedMode != MixedMode.UNKNOWN) {
addMixedContentNotification(mixedMode == MixedMode.MIXED_CONTENT_BLOCKED);
}
final TrackingMode trackingMode = mSiteIdentity.getTrackingMode();
if (trackingMode != TrackingMode.UNKNOWN) {
addTrackingContentNotification(trackingMode == TrackingMode.TRACKING_CONTENT_BLOCKED);
}