| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/SubresourceFilterExperimentalInfoBar.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/SubresourceFilterExperimentalInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/SubresourceFilterExperimentalInfoBar.java
|
| index 17e2fb109b8e4b975ab7be52c89a409efd547b41..ff2b97b47daee1879190b96fa5232dec6218363a 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/SubresourceFilterExperimentalInfoBar.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/SubresourceFilterExperimentalInfoBar.java
|
| @@ -4,39 +4,51 @@
|
|
|
| package org.chromium.chrome.browser.infobar;
|
|
|
| +import android.support.v7.widget.SwitchCompat;
|
| +import android.view.View;
|
| +import android.widget.CompoundButton;
|
| +import android.widget.CompoundButton.OnCheckedChangeListener;
|
| +
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ResourceId;
|
| +import org.chromium.ui.widget.ButtonCompat;
|
|
|
| /**
|
| - * After user proceed through Safe Browsing warning interstitials that are displayed when the site
|
| - * ahead contains deceptive embedded content, the infobar appears, it explains the user that some
|
| - * subresources were filtered and presents the "Detals" link. If the link is pressed full infobar
|
| - * with detailed text and the action buttons appears, it gives the user an ability to reload the
|
| - * page with the content we've blocked previously.
|
| + * This infobar appears when the user proceeds through a Safe Browsing warning interstitial that is
|
| + * displayed when the site ahead contains deceptive embedded content. It explains to the user that
|
| + * some subresources were filtered and presents the "Details" link. If the link is pressed, the full
|
| + * infobar with detailed text, toggle, and action button appears. The toggle gives the user an
|
| + * ability to reload the page with the content we've blocked previously.
|
| */
|
| -public class SubresourceFilterExperimentalInfoBar extends ConfirmInfoBar {
|
| +public class SubresourceFilterExperimentalInfoBar
|
| + extends ConfirmInfoBar implements OnCheckedChangeListener {
|
| private final String mMessage;
|
| private final String mFollowUpMessage;
|
| private final String mOKButtonText;
|
| private final String mReloadButtonText;
|
| + private final String mToggleText;
|
| private boolean mShowExplanation;
|
| + private boolean mReloadIsToggled;
|
| + private ButtonCompat mButton;
|
|
|
| @CalledByNative
|
| private static InfoBar show(int enumeratedIconId, String message, String oKButtonText,
|
| - String reloadButtonText, String followUpMessage) {
|
| + String reloadButtonText, String toggleText, String followUpMessage) {
|
| return new SubresourceFilterExperimentalInfoBar(
|
| ResourceId.mapToDrawableId(enumeratedIconId), message, oKButtonText,
|
| - reloadButtonText, followUpMessage);
|
| + reloadButtonText, toggleText, followUpMessage);
|
| }
|
|
|
| private SubresourceFilterExperimentalInfoBar(int iconDrawbleId, String message,
|
| - String oKButtonText, String reloadButtonText, String followUpMessage) {
|
| + String oKButtonText, String reloadButtonText, String toggleText,
|
| + String followUpMessage) {
|
| super(iconDrawbleId, null, message, null, null, null); //, oKButtonText, reloadButtonText);
|
| mFollowUpMessage = followUpMessage;
|
| mMessage = message;
|
| mOKButtonText = oKButtonText;
|
| mReloadButtonText = reloadButtonText;
|
| + mToggleText = toggleText;
|
| }
|
|
|
| @Override
|
| @@ -44,7 +56,21 @@ public class SubresourceFilterExperimentalInfoBar extends ConfirmInfoBar {
|
| super.createContent(layout);
|
| if (mShowExplanation) {
|
| layout.setMessage(mFollowUpMessage);
|
| - setButtons(layout, mOKButtonText, mReloadButtonText);
|
| + setButtons(layout, mOKButtonText, null);
|
| + InfoBarControlLayout controlLayout = layout.addControlLayout();
|
| +
|
| + // Add a toggle button and ensure the button text is changed when the toggle changes.
|
| + View switchView = controlLayout.addSwitch(
|
| + 0, 0, mToggleText, R.id.subresource_filter_infobar_toggle, false);
|
| + SwitchCompat toggle =
|
| + (SwitchCompat) switchView.findViewById(R.id.subresource_filter_infobar_toggle);
|
| + toggle.setOnCheckedChangeListener(this);
|
| + mButton = layout.getPrimaryButton();
|
| +
|
| + // Ensure that the button does not resize when switching text.
|
| + // TODO(csharrison,dfalcantara): setMinEms is wrong. Code should measure both pieces of
|
| + // text and set the min width using those measurements. See crbug.com/708719.
|
| + mButton.setMinEms(Math.max(mOKButtonText.length(), mReloadButtonText.length()));
|
| } else {
|
| String link = layout.getContext().getString(R.string.details_link);
|
| layout.setMessage(mMessage);
|
| @@ -57,4 +83,16 @@ public class SubresourceFilterExperimentalInfoBar extends ConfirmInfoBar {
|
| mShowExplanation = true;
|
| replaceView(createView());
|
| }
|
| +
|
| + @Override
|
| + public void onButtonClicked(final boolean isPrimaryButton) {
|
| + onButtonClicked(mReloadIsToggled ? ActionType.CANCEL : ActionType.OK);
|
| + }
|
| +
|
| + @Override
|
| + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
| + assert mButton != null;
|
| + mButton.setText(isChecked ? mReloadButtonText : mOKButtonText);
|
| + mReloadIsToggled = isChecked;
|
| + }
|
| }
|
|
|