Bug 1063831 - Support tracking protection in Site Identity popup UI r=margaret

This commit is contained in:
Mark Finkle 2014-11-11 15:03:46 -05:00
Родитель 8c6640e639
Коммит 6a8621ed0d
3 изменённых файлов: 110 добавлений и 23 удалений

Просмотреть файл

@ -476,6 +476,13 @@ just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY loaded_mixed_content_message "This page is displaying content that isn\'t secure."> <!ENTITY loaded_mixed_content_message "This page is displaying content that isn\'t secure.">
<!ENTITY blocked_mixed_content_message_top "&brandShortName; has blocked content that isn\'t secure."> <!ENTITY blocked_mixed_content_message_top "&brandShortName; has blocked content that isn\'t secure.">
<!ENTITY blocked_mixed_content_message_bottom "Most websites will still work properly even when this content is blocked."> <!ENTITY blocked_mixed_content_message_bottom "Most websites will still work properly even when this content is blocked.">
<!-- Tracking content notifications in site identity popup -->
<!ENTITY loaded_tracking_content_message "This page is tracking your online activity.">
<!ENTITY blocked_tracking_content_message_top "&brandShortName; has blocked this page from tracking your online activity.">
<!ENTITY blocked_tracking_content_message_bottom "Most websites will still work properly even when online tracking is blocked.">
<!-- Common mixed and tracking content strings in site identity popup -->
<!ENTITY learn_more "Learn More"> <!ENTITY learn_more "Learn More">
<!ENTITY enable_protection "Enable protection"> <!ENTITY enable_protection "Enable protection">
<!ENTITY disable_protection "Disable protection"> <!ENTITY disable_protection "Disable protection">

Просмотреть файл

@ -412,6 +412,9 @@
<string name="loaded_mixed_content_message">&loaded_mixed_content_message;</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_top">&blocked_mixed_content_message_top;</string>
<string name="blocked_mixed_content_message_bottom">&blocked_mixed_content_message_bottom;</string> <string name="blocked_mixed_content_message_bottom">&blocked_mixed_content_message_bottom;</string>
<string name="loaded_tracking_content_message">&loaded_tracking_content_message;</string>
<string name="blocked_tracking_content_message_top">&blocked_tracking_content_message_top;</string>
<string name="blocked_tracking_content_message_bottom">&blocked_tracking_content_message_bottom;</string>
<string name="learn_more">&learn_more;</string> <string name="learn_more">&learn_more;</string>
<string name="enable_protection">&enable_protection;</string> <string name="enable_protection">&enable_protection;</string>
<string name="disable_protection">&disable_protection;</string> <string name="disable_protection">&disable_protection;</string>

Просмотреть файл

@ -9,6 +9,8 @@ import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent; import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.SiteIdentity; import org.mozilla.gecko.SiteIdentity;
import org.mozilla.gecko.SiteIdentity.SecurityMode; import org.mozilla.gecko.SiteIdentity.SecurityMode;
import org.mozilla.gecko.SiteIdentity.MixedMode;
import org.mozilla.gecko.SiteIdentity.TrackingMode;
import org.mozilla.gecko.widget.ArrowPopup; import org.mozilla.gecko.widget.ArrowPopup;
import org.mozilla.gecko.widget.DoorHanger; import org.mozilla.gecko.widget.DoorHanger;
import org.mozilla.gecko.widget.DoorHanger.OnButtonClickListener; import org.mozilla.gecko.widget.DoorHanger.OnButtonClickListener;
@ -34,6 +36,9 @@ public class SiteIdentityPopup extends ArrowPopup {
private static final String MIXED_CONTENT_SUPPORT_URL = private static final String MIXED_CONTENT_SUPPORT_URL =
"https://support.mozilla.org/kb/how-does-insecure-content-affect-safety-android"; "https://support.mozilla.org/kb/how-does-insecure-content-affect-safety-android";
private static final String TRACKING_CONTENT_SUPPORT_URL =
"https://support.mozilla.org/kb/how-does-insecure-content-affect-safety-android";
private SiteIdentity mSiteIdentity; private SiteIdentity mSiteIdentity;
private LinearLayout mIdentity; private LinearLayout mIdentity;
@ -42,6 +47,7 @@ public class SiteIdentityPopup extends ArrowPopup {
private TextView mVerifier; private TextView mVerifier;
private DoorHanger mMixedContentNotification; private DoorHanger mMixedContentNotification;
private DoorHanger mTrackingContentNotification;
private final OnButtonClickListener mButtonClickListener; private final OnButtonClickListener mButtonClickListener;
@ -68,13 +74,14 @@ public class SiteIdentityPopup extends ArrowPopup {
mVerifier = (TextView) mIdentity.findViewById(R.id.verifier); mVerifier = (TextView) mIdentity.findViewById(R.id.verifier);
} }
private void updateUi() { private void updateIdentity() {
if (!mInflated) { if (!mInflated) {
init(); init();
} }
if (mSiteIdentity.getSecurityMode() == SecurityMode.MIXED_CONTENT_LOADED || final MixedMode mixedMode = mSiteIdentity.getMixedMode();
mSiteIdentity.getSecurityMode() == SecurityMode.MIXED_CONTENT_BLOCKED) { final TrackingMode trackingMode = mSiteIdentity.getTrackingMode();
if (mixedMode != MixedMode.UNKNOWN || trackingMode != TrackingMode.UNKNOWN) {
// Hide the identity data if there isn't valid site identity data. // 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 // Set some top padding on the popup content to create a of light blue
// between the popup arrow and the mixed content notification. // between the popup arrow and the mixed content notification.
@ -106,27 +113,22 @@ public class SiteIdentityPopup extends ArrowPopup {
removeMixedContentNotification(); removeMixedContentNotification();
mMixedContentNotification = new DoorHanger(mContext, DoorHanger.Theme.DARK); mMixedContentNotification = new DoorHanger(mContext, DoorHanger.Theme.DARK);
int icon;
String message; String message;
if (blocked) { if (blocked) {
icon = R.drawable.shield_doorhanger;
message = mContext.getString(R.string.blocked_mixed_content_message_top) + "\n\n" + message = mContext.getString(R.string.blocked_mixed_content_message_top) + "\n\n" +
mContext.getString(R.string.blocked_mixed_content_message_bottom); mContext.getString(R.string.blocked_mixed_content_message_bottom);
} else { } else {
icon = R.drawable.warning_doorhanger;
message = mContext.getString(R.string.loaded_mixed_content_message); message = mContext.getString(R.string.loaded_mixed_content_message);
} }
mMixedContentNotification.setIcon(icon);
mMixedContentNotification.setMessage(message); mMixedContentNotification.setMessage(message);
mMixedContentNotification.addLink(mContext.getString(R.string.learn_more), MIXED_CONTENT_SUPPORT_URL, "\n\n"); mMixedContentNotification.addLink(mContext.getString(R.string.learn_more), MIXED_CONTENT_SUPPORT_URL, "\n\n");
if (blocked) { addNotificationButtons(mMixedContentNotification, blocked);
mMixedContentNotification.setIcon(R.drawable.shield_doorhanger);
mMixedContentNotification.addButton(mContext.getString(R.string.disable_protection),
"disable", mButtonClickListener);
mMixedContentNotification.addButton(mContext.getString(R.string.keep_blocking),
"keepBlocking", mButtonClickListener);
} else {
mMixedContentNotification.setIcon(R.drawable.warning_doorhanger);
mMixedContentNotification.addButton(mContext.getString(R.string.enable_protection),
"enable", mButtonClickListener);
}
mContent.addView(mMixedContentNotification); mContent.addView(mMixedContentNotification);
} }
@ -138,6 +140,47 @@ public class SiteIdentityPopup extends ArrowPopup {
} }
} }
private void addTrackingContentNotification(boolean blocked) {
// Remove any existing tracking content notification.
removeTrackingContentNotification();
mTrackingContentNotification = new DoorHanger(mContext, DoorHanger.Theme.DARK);
int icon;
String message;
if (blocked) {
icon = R.drawable.shield_doorhanger;
message = mContext.getString(R.string.blocked_tracking_content_message_top) + "\n\n" +
mContext.getString(R.string.blocked_tracking_content_message_bottom);
} else {
icon = R.drawable.warning_doorhanger;
message = mContext.getString(R.string.loaded_tracking_content_message);
}
mTrackingContentNotification.setIcon(icon);
mTrackingContentNotification.setMessage(message);
mTrackingContentNotification.addLink(mContext.getString(R.string.learn_more), TRACKING_CONTENT_SUPPORT_URL, "\n\n");
addNotificationButtons(mTrackingContentNotification, blocked);
mContent.addView(mTrackingContentNotification);
}
private void removeTrackingContentNotification() {
if (mTrackingContentNotification != null) {
mContent.removeView(mTrackingContentNotification);
mTrackingContentNotification = null;
}
}
private void addNotificationButtons(DoorHanger dh, boolean blocked) {
if (blocked) {
dh.addButton(mContext.getString(R.string.disable_protection), "disable", mButtonClickListener);
dh.addButton(mContext.getString(R.string.keep_blocking), "keepBlocking", mButtonClickListener);
} else {
dh.addButton(mContext.getString(R.string.enable_protection), "enable", mButtonClickListener);
}
}
/* /*
* @param identityData A JSONObject that holds the current tab's identity data. * @param identityData A JSONObject that holds the current tab's identity data.
*/ */
@ -152,26 +195,58 @@ public class SiteIdentityPopup extends ArrowPopup {
return; return;
} }
final SecurityMode mode = mSiteIdentity.getSecurityMode(); final SecurityMode identityMode = mSiteIdentity.getSecurityMode();
if (mode == SecurityMode.UNKNOWN) { final MixedMode mixedMode = mSiteIdentity.getMixedMode();
Log.e(LOGTAG, "Can't show site identity popup in non-identified state"); 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");
return; return;
} }
updateUi(); updateIdentity();
if (mode == SecurityMode.MIXED_CONTENT_LOADED || if (mixedMode != MixedMode.UNKNOWN) {
mode == SecurityMode.MIXED_CONTENT_BLOCKED) { addMixedContentNotification(mixedMode == MixedMode.MIXED_CONTENT_BLOCKED);
addMixedContentNotification(mode == SecurityMode.MIXED_CONTENT_BLOCKED);
} }
if (trackingMode != TrackingMode.UNKNOWN) {
addTrackingContentNotification(trackingMode == TrackingMode.TRACKING_CONTENT_BLOCKED);
}
showDividers();
super.show(); super.show();
} }
// Show the right dividers
private void showDividers() {
final int count = mContent.getChildCount();
DoorHanger lastVisibleDoorHanger = null;
for (int i = 0; i < count; i++) {
final View child = mContent.getChildAt(i);
if (!(child instanceof DoorHanger)) {
continue;
}
DoorHanger dh = (DoorHanger) child;
dh.showDivider();
if (dh.getVisibility() == View.VISIBLE) {
lastVisibleDoorHanger = dh;
}
}
if (lastVisibleDoorHanger != null) {
lastVisibleDoorHanger.hideDivider();
}
}
@Override @Override
public void dismiss() { public void dismiss() {
super.dismiss(); super.dismiss();
removeMixedContentNotification(); removeMixedContentNotification();
removeTrackingContentNotification();
} }
private class PopupButtonListener implements OnButtonClickListener { private class PopupButtonListener implements OnButtonClickListener {
@ -179,11 +254,13 @@ public class SiteIdentityPopup extends ArrowPopup {
public void onButtonClick(DoorHanger dh, String tag) { public void onButtonClick(DoorHanger dh, String tag) {
try { try {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
data.put("allowMixedContent", tag.equals("disable")); String allowType = (dh == mMixedContentNotification ? "allowMixedContent" : "allowTrackingContent");
data.put(allowType, tag.equals("disable"));
GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Reload", data.toString()); GeckoEvent e = GeckoEvent.createBroadcastEvent("Session:Reload", data.toString());
GeckoAppShell.sendEventToGecko(e); GeckoAppShell.sendEventToGecko(e);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOGTAG, "Exception creating message to enable/disable mixed content blocking", e); Log.e(LOGTAG, "Exception creating message to enable/disable content blocking", e);
} }
dismiss(); dismiss();