| Index: chrome/android/java/src/org/chromium/chrome/browser/permissions/PermissionDialogController.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/permissions/PermissionDialogController.java b/chrome/android/java/src/org/chromium/chrome/browser/permissions/PermissionDialogController.java
|
| index 2ebd1f03349e5cdd82927b33bb54aacc7d3d1dbd..08410ebd7ed7babd9e142fce0978f7812a1a58a2 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/permissions/PermissionDialogController.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/permissions/PermissionDialogController.java
|
| @@ -33,11 +33,21 @@ import java.util.List;
|
| * visible on the screen at once. Any additional request for a modal permissions dialog is queued,
|
| * and will be displayed once the user responds to the current dialog.
|
| */
|
| -public class PermissionDialogController {
|
| +public class PermissionDialogController implements AndroidPermissionRequester.RequestDelegate {
|
| private AlertDialog mDialog;
|
| private SwitchCompat mSwitchView;
|
| + private PermissionDialogDelegate mDialogDelegate;
|
| private List<PermissionDialogDelegate> mRequestQueue;
|
|
|
| + /** Whether a decision has been made for the current dialog. */
|
| + private Decision mDecision;
|
| +
|
| + private enum Decision {
|
| + NOT_DECIDED,
|
| + ACCEPTED,
|
| + CANCELED
|
| + }
|
| +
|
| // Static holder to ensure safe initialization of the singleton instance.
|
| private static class Holder {
|
| private static final PermissionDialogController sInstance =
|
| @@ -50,6 +60,7 @@ public class PermissionDialogController {
|
|
|
| private PermissionDialogController() {
|
| mRequestQueue = new LinkedList<>();
|
| + mDecision = Decision.NOT_DECIDED;
|
| }
|
|
|
| /**
|
| @@ -83,14 +94,27 @@ public class PermissionDialogController {
|
| return mDialog;
|
| }
|
|
|
| + @Override
|
| + public void onAndroidPermissionAccepted() {
|
| + mDialogDelegate.onAccept(mSwitchView.isChecked());
|
| + scheduleDisplay();
|
| + }
|
| +
|
| + @Override
|
| + public void onAndroidPermissionCanceled() {
|
| + mDialogDelegate.onDismiss();
|
| + scheduleDisplay();
|
| + }
|
| +
|
| /**
|
| * Shows the dialog asking the user for a web API permission.
|
| */
|
| public void showDialog() {
|
| if (mRequestQueue.isEmpty()) return;
|
|
|
| - final PermissionDialogDelegate delegate = mRequestQueue.remove(0);
|
| - Activity activity = delegate.getActivity();
|
| + mDecision = Decision.NOT_DECIDED;
|
| + mDialogDelegate = mRequestQueue.remove(0);
|
| + Activity activity = mDialogDelegate.getActivity();
|
| LayoutInflater inflater = LayoutInflater.from(activity);
|
| View view = inflater.inflate(R.layout.permission_dialog, null);
|
| AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogTheme);
|
| @@ -100,17 +124,18 @@ public class PermissionDialogController {
|
| mDialog.setCanceledOnTouchOutside(false);
|
|
|
| TextView messageTextView = (TextView) view.findViewById(R.id.text);
|
| - messageTextView.setText(prepareMainMessageString(delegate));
|
| + messageTextView.setText(prepareMainMessageString(mDialogDelegate));
|
| messageTextView.setVisibility(View.VISIBLE);
|
| - messageTextView.announceForAccessibility(delegate.getMessageText());
|
| - messageTextView.setCompoundDrawablesWithIntrinsicBounds(delegate.getDrawableId(), 0, 0, 0);
|
| + messageTextView.announceForAccessibility(mDialogDelegate.getMessageText());
|
| + messageTextView.setCompoundDrawablesWithIntrinsicBounds(
|
| + mDialogDelegate.getDrawableId(), 0, 0, 0);
|
| messageTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
| mSwitchView = (SwitchCompat) view.findViewById(R.id.permission_dialog_persist_toggle);
|
| mSwitchView.setChecked(true);
|
| TextView toggleTextView =
|
| (TextView) view.findViewById(R.id.permission_dialog_persist_message);
|
| - if (delegate.shouldShowPersistenceToggle()) {
|
| + if (mDialogDelegate.shouldShowPersistenceToggle()) {
|
| mSwitchView.setVisibility(View.VISIBLE);
|
| String toggleMessage =
|
| mDialog.getContext().getString(R.string.permission_prompt_persist_text);
|
| @@ -128,20 +153,19 @@ public class PermissionDialogController {
|
| // Set the buttons to call the appropriate delegate methods. When the dialog is dismissed,
|
| // the delegate's native pointers are freed, and the next queued dialog (if any) is
|
| // displayed.
|
| - mDialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
| - delegate.getPrimaryButtonText(),
|
| + mDialog.setButton(DialogInterface.BUTTON_POSITIVE, mDialogDelegate.getPrimaryButtonText(),
|
| new DialogInterface.OnClickListener() {
|
| @Override
|
| public void onClick(DialogInterface dialog, int id) {
|
| - delegate.onAccept(mSwitchView.isChecked());
|
| + mDecision = Decision.ACCEPTED;
|
| }
|
| });
|
|
|
| - mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, delegate.getSecondaryButtonText(),
|
| + mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mDialogDelegate.getSecondaryButtonText(),
|
| new DialogInterface.OnClickListener() {
|
| @Override
|
| public void onClick(DialogInterface dialog, int id) {
|
| - delegate.onCancel(mSwitchView.isChecked());
|
| + mDecision = Decision.CANCELED;
|
| }
|
| });
|
|
|
| @@ -151,8 +175,29 @@ public class PermissionDialogController {
|
| @Override
|
| public void onDismiss(DialogInterface dialog) {
|
| mDialog = null;
|
| - delegate.onDismiss();
|
| - scheduleDisplay();
|
| + if (mDecision == Decision.ACCEPTED) {
|
| + // Request Android permissions if necessary. This will call back into either
|
| + // onAndroidPermissionAccepted or onAndroidPermissionCanceled, which will
|
| + // schedule the next permission dialog.
|
| + AndroidPermissionRequester requester = new AndroidPermissionRequester(
|
| + mDialogDelegate.getWindow(), PermissionDialogController.this,
|
| + mDialogDelegate.getContentSettings());
|
| + if (requester.shouldSkipPermissionRequest()) {
|
| + onAndroidPermissionAccepted();
|
| + } else {
|
| + requester.requestAndroidPermissions();
|
| + }
|
| + } else {
|
| + // Otherwise, run the necessary delegate callback immediately and schedule the
|
| + // next dialog.
|
| + if (mDecision == Decision.CANCELED) {
|
| + mDialogDelegate.onCancel(mSwitchView.isChecked());
|
| + } else {
|
| + mDialogDelegate.onDismiss();
|
| + }
|
| + mDialogDelegate.destroy();
|
| + scheduleDisplay();
|
| + }
|
| }
|
| });
|
|
|
| @@ -176,6 +221,7 @@ public class PermissionDialogController {
|
| fullString.setSpan(new ClickableSpan() {
|
| @Override
|
| public void onClick(View view) {
|
| + mDecision = NOT_DECIDED;
|
| delegate.onLinkClicked();
|
| if (mDialog != null) mDialog.dismiss();
|
| }
|
|
|