Chromium Code Reviews| 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..92a11dc8b1b5144c58d83d6671b55b030afdc0b2 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, the infobar appears, it |
|
gone
2017/04/04 20:39:43
"the infobar appears" now reads really weirdly.
Charlie Harrison
2017/04/05 13:31:31
Oops, fixed it up.
|
| + * explains 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,18 @@ 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(); |
|
gone
2017/04/04 20:39:43
newline before this, move the comment from 69 abov
Charlie Harrison
2017/04/05 13:31:31
Done.
|
| + // Ensure that the button does not resize when switching text. |
| + mButton.setEms(Math.max(mOKButtonText.length(), mReloadButtonText.length())); |
|
gone
2017/04/04 20:39:44
I'm not sure this is the right call to be making;
Charlie Harrison
2017/04/05 13:31:31
Thanks for the tip, but I tried to use measureText
gone
2017/04/05 18:33:29
Sadly that's all I can think of. I'll revisit thi
Charlie Harrison
2017/04/05 19:06:09
Ok, let me add a TODO and open up a bug to track t
|
| } else { |
| String link = layout.getContext().getString(R.string.details_link); |
| layout.setMessage(mMessage); |
| @@ -57,4 +80,16 @@ public class SubresourceFilterExperimentalInfoBar extends ConfirmInfoBar { |
| mShowExplanation = true; |
| replaceView(createView()); |
| } |
| + |
| + @Override |
| + public void onButtonClicked(final boolean isPrimaryButton) { |
| + onButtonClicked(mReloadIsToggled ? ActionType.CANCEL : ActionType.OK); |
| + } |
| + |
| + // OnCheckedChangeListener: |
| + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
|
gone
2017/04/04 20:39:44
In javaland, you don't need to say where it came f
Charlie Harrison
2017/04/05 13:31:31
Done.
|
| + assert mButton != null; |
| + mButton.setText(isChecked ? mReloadButtonText : mOKButtonText); |
| + mReloadIsToggled = isChecked; |
| + } |
| } |