ma1 pushed to branch firefox-android-115.2.1-13.5-1 at The Tor Project / Applications / firefox-android

Commits:

4 changed files:

Changes:

  • android-components/.buildconfig.yml
    ... ... @@ -1150,6 +1150,7 @@ projects:
    1150 1150
         - concept-tabstray
    
    1151 1151
         - concept-toolbar
    
    1152 1152
         - feature-session
    
    1153
    +    - feature-prompts
    
    1153 1154
         - feature-tabs
    
    1154 1155
         - lib-publicsuffixlist
    
    1155 1156
         - 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
    9 9
     /**
    
    10 10
      * Helper class to identify if a website has shown many dialogs.
    
    11 11
      */
    
    12
    -internal class PromptAbuserDetector {
    
    12
    +class PromptAbuserDetector(private val maxSuccessiveDialogSecondsLimit: Int = MAX_SUCCESSIVE_DIALOG_SECONDS_LIMIT) {
    
    13 13
     
    
    14 14
         internal var jsAlertCount = 0
    
    15 15
         internal var lastDialogShownAt = Date()
    
    ... ... @@ -43,7 +43,7 @@ internal class PromptAbuserDetector {
    43 43
             } else {
    
    44 44
                 val now = Date()
    
    45 45
                 val diffInSeconds = (now.time - lastDialogShownAt.time) / SECOND_MS
    
    46
    -            diffInSeconds < MAX_SUCCESSIVE_DIALOG_SECONDS_LIMIT
    
    46
    +            diffInSeconds < maxSuccessiveDialogSecondsLimit
    
    47 47
             }
    
    48 48
         }
    
    49 49
     
    

  • android-components/components/feature/sitepermissions/build.gradle
    ... ... @@ -58,6 +58,7 @@ dependencies {
    58 58
         implementation project(':concept-engine')
    
    59 59
         implementation project(':ui-icons')
    
    60 60
         implementation project(':support-ktx')
    
    61
    +    implementation project(':feature-prompts')
    
    61 62
         implementation project(':feature-tabs')
    
    62 63
     
    
    63 64
         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
    20 20
     import android.widget.ImageView
    
    21 21
     import android.widget.LinearLayout.LayoutParams
    
    22 22
     import android.widget.TextView
    
    23
    +import androidx.annotation.VisibleForTesting
    
    23 24
     import androidx.appcompat.app.AppCompatDialogFragment
    
    24 25
     import androidx.core.content.ContextCompat
    
    26
    +import mozilla.components.feature.prompts.dialog.PromptAbuserDetector
    
    25 27
     
    
    26 28
     internal const val KEY_SESSION_ID = "KEY_SESSION_ID"
    
    27 29
     internal const val KEY_TITLE = "KEY_TITLE"
    
    ... ... @@ -41,6 +43,9 @@ private const val KEY_PERMISSION_ID = "KEY_PERMISSION_ID"
    41 43
     
    
    42 44
     internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() {
    
    43 45
     
    
    46
    +    @VisibleForTesting
    
    47
    +    internal var promptAbuserDetector =
    
    48
    +        PromptAbuserDetector(maxSuccessiveDialogSecondsLimit = TIME_SHOWN_OFFSET_SECONDS)
    
    44 49
         // Safe Arguments
    
    45 50
     
    
    46 51
         private val safeArguments get() = requireNotNull(arguments)
    
    ... ... @@ -106,6 +111,8 @@ internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() {
    106 111
                 }
    
    107 112
             }
    
    108 113
     
    
    114
    +        promptAbuserDetector.updateJSDialogAbusedState()
    
    115
    +
    
    109 116
             return sheetDialog
    
    110 117
         }
    
    111 118
     
    
    ... ... @@ -159,8 +166,16 @@ internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() {
    159 166
             val negativeButton = rootView.findViewById<Button>(R.id.deny_button)
    
    160 167
     
    
    161 168
             positiveButton.setOnClickListener {
    
    162
    -            feature?.onPositiveButtonPress(permissionRequestId, sessionId, userSelectionCheckBox)
    
    163
    -            dismiss()
    
    169
    +            if (promptAbuserDetector.areDialogsBeingAbused()) {
    
    170
    +                promptAbuserDetector.updateJSDialogAbusedState()
    
    171
    +            } else {
    
    172
    +                feature?.onPositiveButtonPress(
    
    173
    +                    permissionRequestId,
    
    174
    +                    sessionId,
    
    175
    +                    userSelectionCheckBox,
    
    176
    +                )
    
    177
    +                dismiss()
    
    178
    +            }
    
    164 179
             }
    
    165 180
     
    
    166 181
             if (positiveButtonBackgroundColor != DEFAULT_VALUE) {
    
    ... ... @@ -255,5 +270,7 @@ internal open class SitePermissionsDialogFragment : AppCompatDialogFragment() {
    255 270
                 fragment.arguments = arguments
    
    256 271
                 return fragment
    
    257 272
             }
    
    273
    +
    
    274
    +        private const val TIME_SHOWN_OFFSET_SECONDS = 1
    
    258 275
         }
    
    259 276
     }