Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java |
| index 6947d3d16ec538b59e2f11004dfabc222e8f6a8c..dbece846cfaf9309975d6680e41543a86928a296 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java |
| @@ -11,6 +11,7 @@ import android.content.pm.PackageManager; |
| import android.graphics.Bitmap; |
| import android.os.Process; |
| import android.support.v7.app.AlertDialog; |
| +import android.support.v7.widget.SwitchCompat; |
| import android.util.SparseArray; |
| import android.view.View; |
| import android.widget.TextView; |
| @@ -38,6 +39,9 @@ public class ConfirmInfoBar extends InfoBar { |
| /** Text shown on the link, e.g. "Learn more". */ |
| private final String mLinkText; |
| + /** Whether or not to show a toggle for opting out of persisting the decision. */ |
| + private boolean mShowPersistenceToggle; |
| + |
| private WindowAndroid mWindowAndroid; |
| /** |
| @@ -52,6 +56,7 @@ public class ConfirmInfoBar extends InfoBar { |
| super(iconDrawableId, iconBitmap, message); |
| mPrimaryButtonText = primaryButtonText; |
| mSecondaryButtonText = secondaryButtonText; |
| + mShowPersistenceToggle = false; |
| mLinkText = linkText; |
| } |
| @@ -72,10 +77,27 @@ public class ConfirmInfoBar extends InfoBar { |
| mContentSettingsToPermissionsMap = generatePermissionsMapping(contentSettings); |
| } |
| + /** |
| + * Specifies whether or not this infobar should display a toggle asking the user if they want to |
| + * save their choice. |
| + * |
| + * @param showPersistenceToggle True if the toggle should be displayed. |
| + */ |
| + private void setShowPersistenceToggle(boolean showPersistenceToggle) { |
|
gone
2016/08/08 23:04:02
Yeah, you shouldn't put this here. It's a specifi
|
| + mShowPersistenceToggle = showPersistenceToggle; |
| + } |
| + |
| @Override |
| public void createContent(InfoBarLayout layout) { |
| setButtons(layout, mPrimaryButtonText, mSecondaryButtonText); |
| if (mLinkText != null) layout.setMessageLinkText(mLinkText); |
| + |
| + if (mShowPersistenceToggle) { |
| + InfoBarControlLayout controlLayout = layout.addControlLayout(); |
| + String description = |
| + layout.getContext().getString(R.string.confirm_infobar_persist_text); |
| + controlLayout.addSwitch(0, 0, description, R.id.confirm_infobar_persist_toggle, true); |
| + } |
| } |
| /** |
| @@ -211,7 +233,9 @@ public class ConfirmInfoBar extends InfoBar { |
| private void onButtonClickedInternal(boolean isPrimaryButton) { |
| int action = isPrimaryButton ? ActionType.OK : ActionType.CANCEL; |
| - onButtonClicked(action); |
| + SwitchCompat persistSwitch = (SwitchCompat) getView().findViewById( |
| + R.id.confirm_infobar_persist_toggle); |
| + onButtonClicked(action, persistSwitch.isChecked()); |
| } |
| /** |
| @@ -227,16 +251,19 @@ public class ConfirmInfoBar extends InfoBar { |
| * @param buttonOk String to display on the OK button. |
| * @param buttonCancel String to display on the Cancel button. |
| * @param contentSettings The list of ContentSettingTypes being requested by this infobar. |
| + * @param showPersistenceToggle Whether or not a toggle to opt-out of persisting a decision |
| + * should be displayed. |
| */ |
| @CalledByNative |
| private static ConfirmInfoBar create(WindowAndroid windowAndroid, int enumeratedIconId, |
| Bitmap iconBitmap, String message, String linkText, String buttonOk, |
| - String buttonCancel, int[] contentSettings) { |
| + String buttonCancel, int[] contentSettings, boolean showPersistenceToggle) { |
| int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); |
| - ConfirmInfoBar infoBar = new ConfirmInfoBar( |
| - drawableId, iconBitmap, message, linkText, buttonOk, buttonCancel); |
| + ConfirmInfoBar infoBar = new ConfirmInfoBar(drawableId, iconBitmap, message, linkText, |
| + buttonOk, buttonCancel); |
| infoBar.setContentSettings(windowAndroid, contentSettings); |
| + infoBar.setShowPersistenceToggle(showPersistenceToggle); |
| return infoBar; |
| } |