| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionInfoBar.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/PermissionInfoBar.java
|
| similarity index 78%
|
| copy from chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java
|
| copy to chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionInfoBar.java
|
| index 6947d3d16ec538b59e2f11004dfabc222e8f6a8c..c434effdfff91ef47813fbf5c7eb40e63ba300b6 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/ConfirmInfoBar.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionInfoBar.java
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -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;
|
| @@ -24,19 +25,13 @@ import org.chromium.ui.base.WindowAndroid;
|
| import org.chromium.ui.base.WindowAndroid.PermissionCallback;
|
|
|
| /**
|
| - * An infobar that presents the user with several buttons.
|
| + * An infobar used for prompting the user to grant a web API permission.
|
| *
|
| - * TODO(newt): merge this into InfoBar.java.
|
| */
|
| -public class ConfirmInfoBar extends InfoBar {
|
| - /** Text shown on the primary button, e.g. "OK". */
|
| - private final String mPrimaryButtonText;
|
| +public class PermissionInfoBar extends ConfirmInfoBar {
|
|
|
| - /** Text shown on the secondary button, e.g. "Cancel".*/
|
| - private final String mSecondaryButtonText;
|
| -
|
| - /** 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;
|
|
|
| @@ -47,12 +42,24 @@ public class ConfirmInfoBar extends InfoBar {
|
| */
|
| private SparseArray<String> mContentSettingsToPermissionsMap;
|
|
|
| - protected ConfirmInfoBar(int iconDrawableId, Bitmap iconBitmap, String message,
|
| + protected PermissionInfoBar(int iconDrawableId, Bitmap iconBitmap, String message,
|
| String linkText, String primaryButtonText, String secondaryButtonText) {
|
| - super(iconDrawableId, iconBitmap, message);
|
| - mPrimaryButtonText = primaryButtonText;
|
| - mSecondaryButtonText = secondaryButtonText;
|
| - mLinkText = linkText;
|
| + super(iconDrawableId, iconBitmap, message, linkText, primaryButtonText,
|
| + secondaryButtonText);
|
| + mShowPersistenceToggle = false;
|
| + }
|
| +
|
| + @Override
|
| + public void createContent(InfoBarLayout layout) {
|
| + super.createContent(layout);
|
| +
|
| + if (mShowPersistenceToggle) {
|
| + InfoBarControlLayout controlLayout = layout.addControlLayout();
|
| + String description =
|
| + layout.getContext().getString(R.string.permission_infobar_persist_text);
|
| + controlLayout.addSwitch(
|
| + 0, 0, description, R.id.permission_infobar_persist_toggle, true);
|
| + }
|
| }
|
|
|
| /**
|
| @@ -72,24 +79,14 @@ public class ConfirmInfoBar extends InfoBar {
|
| mContentSettingsToPermissionsMap = generatePermissionsMapping(contentSettings);
|
| }
|
|
|
| - @Override
|
| - public void createContent(InfoBarLayout layout) {
|
| - setButtons(layout, mPrimaryButtonText, mSecondaryButtonText);
|
| - if (mLinkText != null) layout.setMessageLinkText(mLinkText);
|
| - }
|
| -
|
| /**
|
| - * If your custom infobar overrides this function, YOU'RE PROBABLY DOING SOMETHING WRONG.
|
| - *
|
| - * Adds buttons to the infobar. This should only be overridden in cases where an infobar
|
| - * requires adding something other than a button for its secondary View on the bottom row
|
| - * (almost never).
|
| + * Specifies whether or not this infobar should display a toggle asking the user if they want to
|
| + * save their choice.
|
| *
|
| - * @param primaryText Text to display on the primary button.
|
| - * @param secondaryText Text to display on the secondary button. May be null.
|
| + * @param showPersistenceToggle True if the toggle should be displayed.
|
| */
|
| - protected void setButtons(InfoBarLayout layout, String primaryText, String secondaryText) {
|
| - layout.setButtons(primaryText, secondaryText);
|
| + private void setShowPersistenceToggle(boolean showPersistenceToggle) {
|
| + mShowPersistenceToggle = showPersistenceToggle;
|
| }
|
|
|
| private static boolean hasPermission(Context context, String permission) {
|
| @@ -210,12 +207,24 @@ public class ConfirmInfoBar extends InfoBar {
|
| }
|
|
|
| private void onButtonClickedInternal(boolean isPrimaryButton) {
|
| - int action = isPrimaryButton ? ActionType.OK : ActionType.CANCEL;
|
| - onButtonClicked(action);
|
| + super.onButtonClicked(isPrimaryButton);
|
| + }
|
| +
|
| + /**
|
| + * Returns true if the persist switch exists and is toggled on.
|
| + */
|
| + @CalledByNative
|
| + private boolean isPersistSwitchOn() {
|
| + SwitchCompat persistSwitch = (SwitchCompat) getView().findViewById(
|
| + R.id.permission_infobar_persist_toggle);
|
| + if (mShowPersistenceToggle && persistSwitch != null) {
|
| + return persistSwitch.isChecked();
|
| + }
|
| + return false;
|
| }
|
|
|
| /**
|
| - * Creates and begins the process for showing a ConfirmInfoBar.
|
| + * Creates and begins the process for showing a PermissionInfoBar.
|
| * @param windowAndroid The owning window for the infobar.
|
| * @param enumeratedIconId ID corresponding to the icon that will be shown for the infobar.
|
| * The ID must have been mapped using the ResourceMapper class before
|
| @@ -227,16 +236,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,
|
| + private static PermissionInfoBar 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);
|
| + PermissionInfoBar infoBar = new PermissionInfoBar(drawableId, iconBitmap, message, linkText,
|
| + buttonOk, buttonCancel);
|
| infoBar.setContentSettings(windowAndroid, contentSettings);
|
| + infoBar.setShowPersistenceToggle(showPersistenceToggle);
|
|
|
| return infoBar;
|
| }
|
|
|