diff --git a/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt b/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt
index 7c167b47d0..b14badb260 100644
--- a/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt
+++ b/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt
@@ -19,16 +19,26 @@ import org.mozilla.fenix.ext.isOnline
class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
override fun onLoadRequest(
- session: EngineSession,
- uri: String
+ engineSession: EngineSession,
+ uri: String,
+ hasUserGesture: Boolean,
+ isSameDomain: Boolean
): RequestInterceptor.InterceptionResponse? {
- adjustTrackingProtection(context, session)
+ adjustTrackingProtection(context, engineSession)
+ var result: RequestInterceptor.InterceptionResponse? = null
+
// WebChannel-driven authentication does not require a separate redirect interceptor.
- return if (context.isInExperiment(Experiments.asFeatureWebChannelsDisabled)) {
- context.components.services.accountsAuthFeature.interceptor.onLoadRequest(session, uri)
- } else {
- null
+ if (context.isInExperiment(Experiments.asFeatureWebChannelsDisabled)) {
+ result = context.components.services.accountsAuthFeature.interceptor.onLoadRequest(
+ engineSession, uri, hasUserGesture, isSameDomain)
}
+
+ if (result == null) {
+ result = context.components.services.appLinksInterceptor.onLoadRequest(
+ engineSession, uri, hasUserGesture, isSameDomain)
+ }
+
+ return result
}
private fun adjustTrackingProtection(context: Context, session: EngineSession) {
diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
index 34a6a4c480..8537893736 100644
--- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
+++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
@@ -78,6 +78,7 @@ import org.mozilla.fenix.downloads.DownloadNotificationBottomSheetDialog
import org.mozilla.fenix.downloads.DownloadService
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.enterToImmersiveMode
+import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.getRootView
import org.mozilla.fenix.ext.hideToolbar
import org.mozilla.fenix.ext.metrics
@@ -304,8 +305,10 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
context,
sessionManager = sessionManager,
sessionId = customTabSessionId,
- interceptLinkClicks = true,
- fragmentManager = parentFragmentManager
+ fragmentManager = parentFragmentManager,
+ launchInApp = { context.settings().preferences.getBoolean(
+ context.getPreferenceKey(R.string.pref_key_open_links_in_external_app), false)
+ }
),
owner = this,
view = view
@@ -403,9 +406,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
url: String,
triggeredByRedirect: Boolean,
triggeredByWebContent: Boolean
- ): Boolean {
+ ) {
browserToolbarView.expand()
- return false
}
}, owner = viewLifecycleOwner)
diff --git a/app/src/main/java/org/mozilla/fenix/components/Services.kt b/app/src/main/java/org/mozilla/fenix/components/Services.kt
index bc049d13fc..58fca93fa9 100644
--- a/app/src/main/java/org/mozilla/fenix/components/Services.kt
+++ b/app/src/main/java/org/mozilla/fenix/components/Services.kt
@@ -10,12 +10,16 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.components.feature.accounts.FirefoxAccountsAuthFeature
+import mozilla.components.feature.app.links.AppLinksInterceptor
import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.support.ktx.android.content.hasCamera
import org.mozilla.fenix.Experiments
import org.mozilla.fenix.NavGraphDirections
+import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
+import org.mozilla.fenix.ext.getPreferenceKey
+import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.isInExperiment
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.test.Mockable
@@ -28,6 +32,7 @@ class Services(
private val context: Context,
private val accountManager: FxaAccountManager
) {
+
val fxaRedirectUrl = FxaServer.redirectUrl(context)
val accountsAuthFeature by lazy {
@@ -42,6 +47,17 @@ class Services(
}
}
+ val appLinksInterceptor by lazy {
+ AppLinksInterceptor(
+ context,
+ interceptLinkClicks = true,
+ launchInApp = {
+ context.settings().preferences.getBoolean(
+ context.getPreferenceKey(R.string.pref_key_open_links_in_external_app), false)
+ }
+ )
+ }
+
/**
* Launches the sign in and pairing custom tab from any screen in the app.
* @param context the current Context
diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt
index b278bb1eff..20627e1e9e 100644
--- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt
+++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt
@@ -233,7 +233,7 @@ class DefaultBrowserToolbarController(
sessionManager.selectedSession?.let {
val redirect = getRedirect.invoke(it.url)
redirect.appIntent?.flags = Intent.FLAG_ACTIVITY_NEW_TASK
- appLinksUseCases.openAppLink.invoke(redirect)
+ appLinksUseCases.openAppLink.invoke(redirect.appIntent)
}
}
ToolbarMenu.Item.Bookmark -> {
diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
index 7cbfcca507..573af72c0b 100644
--- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
+++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
@@ -43,6 +43,7 @@ class Settings private constructor(
const val autoBounceMaximumCount = 2
const val trackingProtectionOnboardingMaximumCount = 2
const val FENIX_PREFERENCES = "fenix_preferences"
+
private const val BLOCKED_INT = 0
private const val ASK_TO_ALLOW_INT = 1
private const val CFR_COUNT_CONDITION_FOCUS_INSTALLED = 1
diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml
index 5da7b31892..2e62e07293 100644
--- a/app/src/main/res/values/preference_keys.xml
+++ b/app/src/main/res/values/preference_keys.xml
@@ -119,6 +119,7 @@
pref_key_open_links_in_a_private_tab
+ pref_key_open_links_in_external_app
pref_key_bounce_quick_action
diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt
index 39d6c5e1c8..ed6c77418d 100644
--- a/buildSrc/src/main/java/Dependencies.kt
+++ b/buildSrc/src/main/java/Dependencies.kt
@@ -35,7 +35,7 @@ object Versions {
const val androidx_work = "2.2.0"
const val google_material = "1.1.0-beta01"
- const val mozilla_android_components = "26.0.0-SNAPSHOT"
+ const val mozilla_android_components = "27.0.0-SNAPSHOT"
// Note that android-components also depends on application-services,
// and in fact is our main source of appservices-related functionality.
// The version number below tracks the application-services version