Commit 34333db8 authored by Ehimare Okoyomon's avatar Ehimare Okoyomon Committed by Chromium LUCI CQ

[Android] Add PermissionDialogController dialog result reporting

Bug: 1158288
Change-Id: Ifa1084c6b4c606c1e0fa9900b78f44ffee60f784
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586351
Commit-Queue: Ehimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842327}
parent 1a8f8ee8
...@@ -13,6 +13,7 @@ import androidx.annotation.VisibleForTesting; ...@@ -13,6 +13,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.BuildInfo; import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.components.content_settings.ContentSettingValues;
import org.chromium.ui.modaldialog.DialogDismissalCause; import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties; import org.chromium.ui.modaldialog.ModalDialogProperties;
...@@ -52,6 +53,10 @@ public class PermissionDialogController ...@@ -52,6 +53,10 @@ public class PermissionDialogController
private PermissionDialogDelegate mDialogDelegate; private PermissionDialogDelegate mDialogDelegate;
private ModalDialogManager mModalDialogManager; private ModalDialogManager mModalDialogManager;
// Array with ints of type {@link ContentSettingsType}.
private int[] mLastPermissions;
private @ContentSettingValues int mLastResult;
// As the PermissionRequestManager handles queueing for a tab and only shows prompts for active // As the PermissionRequestManager handles queueing for a tab and only shows prompts for active
// tabs, we typically only have one request. This class only handles multiple requests at once // tabs, we typically only have one request. This class only handles multiple requests at once
// when either: // when either:
...@@ -89,6 +94,22 @@ public class PermissionDialogController ...@@ -89,6 +94,22 @@ public class PermissionDialogController
PermissionDialogController.getInstance().queueDialog(delegate); PermissionDialogController.getInstance().queueDialog(delegate);
} }
/**
* Returns whether this PropertyModel is for the permission dialog.
* @param model The PropertyModel to be checked.
*/
public static boolean isPermissionDialogModel(PropertyModel model) {
return model.get(ModalDialogProperties.CONTROLLER) instanceof PermissionDialogController;
}
public int[] getLastDialogPermissions() {
return mLastPermissions.clone();
}
public @ContentSettingValues int getLastDialogResult() {
return mLastResult;
}
/** /**
* Queues a modal permission dialog for display. If there are currently no dialogs on screen, it * Queues a modal permission dialog for display. If there are currently no dialogs on screen, it
* will be displayed immediately. Otherwise, it will be displayed as soon as the user responds * will be displayed immediately. Otherwise, it will be displayed as soon as the user responds
...@@ -115,7 +136,7 @@ public class PermissionDialogController ...@@ -115,7 +136,7 @@ public class PermissionDialogController
mState = State.NOT_SHOWING; mState = State.NOT_SHOWING;
} else { } else {
mDialogDelegate.onAccept(); mDialogDelegate.onAccept();
destroyDelegate(); destroyDelegate(ContentSettingValues.ALLOW);
} }
scheduleDisplay(); scheduleDisplay();
} }
...@@ -129,7 +150,7 @@ public class PermissionDialogController ...@@ -129,7 +150,7 @@ public class PermissionDialogController
mState = State.NOT_SHOWING; mState = State.NOT_SHOWING;
} else { } else {
mDialogDelegate.onDismiss(); mDialogDelegate.onDismiss();
destroyDelegate(); destroyDelegate(ContentSettingValues.BLOCK);
} }
scheduleDisplay(); scheduleDisplay();
} }
...@@ -152,7 +173,7 @@ public class PermissionDialogController ...@@ -152,7 +173,7 @@ public class PermissionDialogController
// TODO(timloh): This probably doesn't work, as this happens synchronously when creating // TODO(timloh): This probably doesn't work, as this happens synchronously when creating
// the PermissionPromptAndroid, so the PermissionRequestManager won't be ready yet. // the PermissionPromptAndroid, so the PermissionRequestManager won't be ready yet.
mDialogDelegate.onDismiss(); mDialogDelegate.onDismiss();
destroyDelegate(); destroyDelegate(ContentSettingValues.DEFAULT);
return; return;
} }
...@@ -260,7 +281,7 @@ public class PermissionDialogController ...@@ -260,7 +281,7 @@ public class PermissionDialogController
assert mState == State.PROMPT_OPEN; assert mState == State.PROMPT_OPEN;
mDialogDelegate.onDismiss(); mDialogDelegate.onDismiss();
} }
destroyDelegate(); destroyDelegate(ContentSettingValues.BLOCK);
scheduleDisplay(); scheduleDisplay();
} }
} }
...@@ -284,7 +305,11 @@ public class PermissionDialogController ...@@ -284,7 +305,11 @@ public class PermissionDialogController
} }
} }
private void destroyDelegate() { private void destroyDelegate(@ContentSettingValues int result) {
if (result != ContentSettingValues.DEFAULT) {
mLastPermissions = mDialogDelegate.getContentSettingsTypes();
mLastResult = result;
}
mDialogDelegate.destroy(); mDialogDelegate.destroy();
mDialogDelegate = null; mDialogDelegate = null;
mState = State.NOT_SHOWING; mState = State.NOT_SHOWING;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment