ma1 pushed to branch firefox-android-115.2.1-13.5-1 at The Tor Project / Applications / firefox-android
Commits: 6271d708 by hackademix at 2024-07-09T14:38:08+02:00 Bug 1836786 - Improve prompts a=dmeehan - BP, tor-browser#42693
Note (ma1): backporting needed to update feature-sitepermissions dependency, relocate the PromptAbuserDetector import, de-internalize the class and patch its constructor, because of the refactorings happened in Bug 1903828.
- - - - -
4 changed files:
- android-components/.buildconfig.yml - android-components/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/dialog/PromptAbuserDetector.kt - android-components/components/feature/sitepermissions/build.gradle - android-components/components/feature/sitepermissions/src/main/java/mozilla/components/feature/sitepermissions/SitePermissionsDialogFragment.kt
Changes:
===================================== android-components/.buildconfig.yml ===================================== @@ -1150,6 +1150,7 @@ projects: - concept-tabstray - concept-toolbar - feature-session + - feature-prompts - feature-tabs - lib-publicsuffixlist - lib-state
===================================== android-components/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/dialog/PromptAbuserDetector.kt ===================================== @@ -9,7 +9,7 @@ import java.util.Date /** * Helper class to identify if a website has shown many dialogs. */ -internal class PromptAbuserDetector { +class PromptAbuserDetector(private val maxSuccessiveDialogSecondsLimit: Int = MAX_SUCCESSIVE_DIALOG_SECONDS_LIMIT) {
internal var jsAlertCount = 0 internal var lastDialogShownAt = Date() @@ -43,7 +43,7 @@ internal class PromptAbuserDetector { } else { val now = Date() val diffInSeconds = (now.time - lastDialogShownAt.time) / SECOND_MS - diffInSeconds < MAX_SUCCESSIVE_DIALOG_SECONDS_LIMIT + diffInSeconds < maxSuccessiveDialogSecondsLimit } }
===================================== android-components/components/feature/sitepermissions/build.gradle ===================================== @@ -58,6 +58,7 @@ dependencies { implementation project(':concept-engine') implementation project(':ui-icons') implementation project(':support-ktx') + implementation project(':feature-prompts') implementation project(':feature-tabs')
implementation ComponentsDependencies.kotlin_coroutines
===================================== android-components/components/feature/sitepermissions/src/main/java/mozilla/components/feature/sitepermissions/SitePermissionsDialogFragment.kt ===================================== @@ -20,8 +20,10 @@ import android.widget.CheckBox import android.widget.ImageView import android.widget.LinearLayout.LayoutParams import android.widget.TextView +import androidx.annotation.VisibleForTesting import androidx.appcompat.app.AppCompatDialogFragment import androidx.core.content.ContextCompat +import mozilla.components.feature.prompts.dialog.PromptAbuserDetector
internal const val KEY_SESSION_ID = "KEY_SESSION_ID" internal const val KEY_TITLE = "KEY_TITLE" @@ -41,6 +43,9 @@ private const val KEY_PERMISSION_ID = "KEY_PERMISSION_ID"
internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() {
+ @VisibleForTesting + internal var promptAbuserDetector = + PromptAbuserDetector(maxSuccessiveDialogSecondsLimit = TIME_SHOWN_OFFSET_SECONDS) // Safe Arguments
private val safeArguments get() = requireNotNull(arguments) @@ -106,6 +111,8 @@ internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() { } }
+ promptAbuserDetector.updateJSDialogAbusedState() + return sheetDialog }
@@ -159,8 +166,16 @@ internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() { val negativeButton = rootView.findViewById<Button>(R.id.deny_button)
positiveButton.setOnClickListener { - feature?.onPositiveButtonPress(permissionRequestId, sessionId, userSelectionCheckBox) - dismiss() + if (promptAbuserDetector.areDialogsBeingAbused()) { + promptAbuserDetector.updateJSDialogAbusedState() + } else { + feature?.onPositiveButtonPress( + permissionRequestId, + sessionId, + userSelectionCheckBox, + ) + dismiss() + } }
if (positiveButtonBackgroundColor != DEFAULT_VALUE) { @@ -255,5 +270,7 @@ internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() { fragment.arguments = arguments return fragment } + + private const val TIME_SHOWN_OFFSET_SECONDS = 1 } }
View it on GitLab: https://gitlab.torproject.org/tpo/applications/firefox-android/-/commit/6271...