[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/fenix][tor-browser-81.1.1-10.0-1] 2 commits: Bug 34378: Port external helper app prompting



Title: GitLab

Matthew Finkel pushed to branch tor-browser-81.1.1-10.0-1 at The Tor Project / Applications / fenix

Commits:

2 changed files:

Changes:

  • app/src/main/java/org/mozilla/fenix/HomeActivity.kt
    ... ... @@ -4,6 +4,7 @@
    4 4
     
    
    5 5
     package org.mozilla.fenix
    
    6 6
     
    
    7
    +import android.app.PendingIntent
    
    7 8
     import android.content.BroadcastReceiver
    
    8 9
     import android.content.Context
    
    9 10
     import android.content.Intent
    
    ... ... @@ -45,6 +46,8 @@ import mozilla.components.browser.state.state.SessionState
    45 46
     import mozilla.components.browser.state.state.WebExtensionState
    
    46 47
     import mozilla.components.concept.engine.EngineSession
    
    47 48
     import mozilla.components.concept.engine.EngineView
    
    49
    +import mozilla.components.feature.app.links.RedirectDialogFragment
    
    50
    +import mozilla.components.feature.app.links.SimpleRedirectDialogFragment
    
    48 51
     import mozilla.components.feature.contextmenu.DefaultSelectionActionDelegate
    
    49 52
     import mozilla.components.feature.privatemode.notification.PrivateNotificationFeature
    
    50 53
     import mozilla.components.feature.search.BrowserStoreSearchAdapter
    
    ... ... @@ -58,6 +61,7 @@ import mozilla.components.support.ktx.kotlin.isUrl
    58 61
     import mozilla.components.support.ktx.kotlin.toNormalizedUrl
    
    59 62
     import mozilla.components.support.locale.LocaleAwareAppCompatActivity
    
    60 63
     import mozilla.components.support.utils.SafeIntent
    
    64
    +import mozilla.components.support.utils.TorUtils
    
    61 65
     import mozilla.components.support.utils.toSafeIntent
    
    62 66
     import mozilla.components.support.webextensions.WebExtensionPopupFeature
    
    63 67
     import org.mozilla.fenix.GleanMetrics.Metrics
    
    ... ... @@ -154,6 +158,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
    154 158
     
    
    155 159
         private lateinit var navigationToolbar: Toolbar
    
    156 160
     
    
    161
    +    private var dialog: RedirectDialogFragment? = null
    
    162
    +
    
    157 163
         final override fun onCreate(savedInstanceState: Bundle?) {
    
    158 164
             // Give Orbot the base Context
    
    159 165
             Prefs.setContext(applicationContext)
    
    ... ... @@ -387,6 +393,26 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
    387 393
             super.recreate()
    
    388 394
         }
    
    389 395
     
    
    396
    +    // Copied from mozac AppLinksFeature.kt
    
    397
    +    internal fun getOrCreateDialog(): RedirectDialogFragment {
    
    398
    +        val existingDialog = dialog
    
    399
    +        if (existingDialog != null) {
    
    400
    +            return existingDialog
    
    401
    +        }
    
    402
    +
    
    403
    +        SimpleRedirectDialogFragment.newInstance().also {
    
    404
    +            dialog = it
    
    405
    +            return it
    
    406
    +        }
    
    407
    +    }
    
    408
    +    private fun isAlreadyADialogCreated(): Boolean {
    
    409
    +        return findPreviousDialogFragment() != null
    
    410
    +    }
    
    411
    +
    
    412
    +    private fun findPreviousDialogFragment(): RedirectDialogFragment? {
    
    413
    +        return supportFragmentManager.findFragmentByTag(RedirectDialogFragment.FRAGMENT_TAG) as? RedirectDialogFragment
    
    414
    +    }
    
    415
    +
    
    390 416
         /**
    
    391 417
          * Handles intents received when the activity is open.
    
    392 418
          */
    
    ... ... @@ -394,6 +420,25 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
    394 420
             super.onNewIntent(intent)
    
    395 421
             intent ?: return
    
    396 422
     
    
    423
    +        val startIntent = intent.getParcelableExtra<PendingIntent>(TorUtils.TORBROWSER_START_ACTIVITY_PROMPT)
    
    424
    +        if (startIntent != null) {
    
    425
    +            if (startIntent.creatorPackage == applicationContext.packageName) {
    
    426
    +                val dialog = getOrCreateDialog()
    
    427
    +                dialog.onConfirmRedirect = {
    
    428
    +                    try {
    
    429
    +                        startIntent.send()
    
    430
    +                    } catch (error: PendingIntent.CanceledException) {
    
    431
    +                    }
    
    432
    +                }
    
    433
    +                dialog.onCancelRedirect = {}
    
    434
    +
    
    435
    +                if (!isAlreadyADialogCreated()) {
    
    436
    +                    dialog.showNow(supportFragmentManager, RedirectDialogFragment.FRAGMENT_TAG)
    
    437
    +                }
    
    438
    +            }
    
    439
    +            return
    
    440
    +        }
    
    441
    +
    
    397 442
             // Diagnostic breadcrumb for "Display already aquired" crash:
    
    398 443
             // https://github.com/mozilla-mobile/android-components/issues/7960
    
    399 444
             breadcrumb(
    

  • app/src/main/java/org/mozilla/fenix/share/ShareController.kt
    ... ... @@ -25,6 +25,7 @@ import mozilla.components.concept.sync.TabData
    25 25
     import mozilla.components.feature.accounts.push.SendTabUseCases
    
    26 26
     import mozilla.components.feature.share.RecentAppsStorage
    
    27 27
     import mozilla.components.support.ktx.kotlin.isExtensionUrl
    
    28
    +import mozilla.components.support.utils.TorUtils
    
    28 29
     import org.mozilla.fenix.R
    
    29 30
     import org.mozilla.fenix.components.FenixSnackbar
    
    30 31
     import org.mozilla.fenix.components.metrics.Event
    
    ... ... @@ -99,7 +100,7 @@ class DefaultShareController(
    99 100
             }
    
    100 101
     
    
    101 102
             val result = try {
    
    102
    -            context.startActivity(intent)
    
    103
    +            TorUtils.startActivityPrompt(context, intent)
    
    103 104
                 ShareController.Result.SUCCESS
    
    104 105
             } catch (e: SecurityException) {
    
    105 106
                 snackbar.setText(context.getString(R.string.share_error_snackbar))
    

  • _______________________________________________
    tor-commits mailing list
    tor-commits@xxxxxxxxxxxxxxxxxxxx
    https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits