... |
... |
@@ -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(
|