Skip to content

Commit

Permalink
[Android] Add a delay to webapp install button accept
Browse files Browse the repository at this point in the history
This adds a short delay before buttons in the
Add to Homescreen/Install webapp dialog accept
clicks.

It also adds tracking for multiple clicks to
mirror the behavior on the Desktop side, as
per input_event_activation_protector.cc.

(cherry picked from commit 35f44be)

Bug: 1452230
Change-Id: I44d5df24659f9438528c766fe1c0058ea597369b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4664276
Reviewed-by: Lijin Shen <lazzzis@google.com>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: Ella Ge <eirage@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1166456}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4677337
Cr-Commit-Position: refs/branch-heads/5845@{#428}
Cr-Branched-From: 5a5dff6-refs/heads/main@{#1160321}
  • Loading branch information
Finnur Thorarinsson authored and Chromium LUCI CQ committed Jul 12, 2023
1 parent e33e78b commit 6702549
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class ModalDialogView extends BoundedLinearLayout implements View.OnClick
private Runnable mOnTouchFilteredCallback;
private ViewGroup mFooterContainer;
private TextView mFooterMessageView;
private long mEnterAnimationMidpointTimestamp = -1;
private long mStartProtectingButtonTimestamp = -1;
// The duration for which dialog buttons should not react to any tap event after this view is
// displayed to prevent potentially unintentional user interactions. A value of zero turns off
// this kind of tap-jacking protection.
Expand Down Expand Up @@ -144,11 +144,17 @@ private boolean isWithinButtonTapProtectionPeriod() {
if (mButtonTapProtectionDurationMs == 0) return false;

// The view has not even started animating yet.
if (mEnterAnimationMidpointTimestamp < 0) return true;
if (mStartProtectingButtonTimestamp < 0) return true;

// Calculate whether we are still within the button protection period and reset the timer to
// prevent further tapjacking vectors.
long timestamp = TimeUtils.elapsedRealtimeMillis();
boolean shortEventAfterLastEvent =
timestamp <= mStartProtectingButtonTimestamp + mButtonTapProtectionDurationMs;
mStartProtectingButtonTimestamp = timestamp;

// True if not showing for sufficient time.
return TimeUtils.elapsedRealtimeMillis()
<= mEnterAnimationMidpointTimestamp + mButtonTapProtectionDurationMs;
return shortEventAfterLastEvent;
}

/**
Expand All @@ -158,8 +164,7 @@ private boolean isWithinButtonTapProtectionPeriod() {
void onEnterAnimationStarted(long animationDuration) {
// Start button protection as soon as dialog is presented, but timer is kicked off in the
// middle of the animation.
mEnterAnimationMidpointTimestamp =
TimeUtils.elapsedRealtimeMillis() + animationDuration / 2;
mStartProtectingButtonTimestamp = TimeUtils.elapsedRealtimeMillis() + animationDuration / 2;
}

/**
Expand Down
1 change: 1 addition & 0 deletions components/webapps/browser/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ android_library("java") {
"//third_party/androidx:androidx_annotation_annotation_java",
"//third_party/androidx:androidx_recyclerview_recyclerview_java",
"//ui/android:ui_no_recycler_view_java",
"//ui/android:ui_utils_java",
"//url:gurl_java",
]
srcjar_deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import androidx.annotation.VisibleForTesting;

import org.chromium.base.ContextUtils;
import org.chromium.ui.UiUtils;
import org.chromium.ui.base.ViewUtils;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
Expand Down Expand Up @@ -129,6 +130,8 @@ public void afterTextChanged(Editable editableText) {
R.string.cancel)
.with(ModalDialogProperties.CUSTOM_VIEW, mParentView)
.with(ModalDialogProperties.CANCEL_ON_TOUCH_OUTSIDE, true)
.with(ModalDialogProperties.BUTTON_TAP_PROTECTION_PERIOD_MS,
UiUtils.PROMPT_INPUT_PROTECTION_SHORT_DELAY_MS)
.build();
mModalDialogManager.showDialog(mDialogModel, ModalDialogManager.ModalDialogType.TAB);
}
Expand Down

0 comments on commit 6702549

Please sign in to comment.