diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt index 61df102b..b3d92086 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt @@ -289,13 +289,18 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit store = components.core.store, sessionId = sessionId, fragmentManager = parentFragmentManager, - launchInApp = { - components.core.prefs.getBoolean( - context?.getPreferenceKey(R.string.pref_key_launch_external_app), - false - ) - }, loadUrlUseCase = components.useCases.sessionUseCases.loadUrl, + launchInApp = { true }, + shouldPrompt = { true }, + failedToLaunchAction = { fallbackUrl -> + fallbackUrl?.let { + val appLinksUseCases = components.useCases.appLinksUseCases + val getRedirect = appLinksUseCases.appLinkRedirect + val redirect = getRedirect.invoke(fallbackUrl) + redirect.appIntent?.flags = Intent.FLAG_ACTIVITY_NEW_TASK + appLinksUseCases.openAppLink.invoke(redirect.appIntent) + } + }, ), owner = this, view = view, diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/Components.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/Components.kt index ce4205f5..f8aa3f9c 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/Components.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/Components.kt @@ -45,7 +45,7 @@ class Components(val profileApplicationContext: ProfileContext, val core by lazy { Core(profileApplicationContext, this, flutterEvents, extensionEvents) } val events by lazy { Events(flutterEvents) } val useCases by lazy { UseCases(profileApplicationContext, core.engine, core.store) } - val services by lazy { Services(profileApplicationContext, useCases.tabsUseCases) } + val services by lazy { Services(profileApplicationContext, core.store, useCases.tabsUseCases) } val features by lazy { Features(core.engine, core.store, addonEvents, tabContentEvents) } val search by lazy { Search(profileApplicationContext, core, useCases) } diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt index d0744f3e..cc2f8f8f 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt @@ -79,7 +79,7 @@ class Core( val engineSettings by lazy { DefaultSettings( //historyTrackingDelegate = HistoryDelegate(lazyHistoryStorage) - requestInterceptor = AppRequestInterceptor(context), + requestInterceptor = requestInterceptor, historyTrackingDelegate = HistoryDelegate(lazyHistoryStorage), testingModeEnabled = false, remoteDebuggingEnabled = false, @@ -252,6 +252,8 @@ class Core( val permissionStorage by lazy { PermissionStorage(geckoSitePermissionsStorage) } + val requestInterceptor = AppRequestInterceptor(context) + /** * Constructs a [TrackingProtectionPolicy] based on current preferences. * diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Services.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Services.kt index 91dd2b63..72c1b489 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Services.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Services.kt @@ -8,6 +8,7 @@ import android.content.Context import androidx.preference.PreferenceManager import eu.weblibre.flutter_mozilla_components.R import eu.weblibre.flutter_mozilla_components.ext.getPreferenceKey +import mozilla.components.browser.state.store.BrowserStore import mozilla.components.feature.app.links.AppLinksInterceptor import mozilla.components.feature.tabs.TabsUseCases @@ -16,16 +17,16 @@ import mozilla.components.feature.tabs.TabsUseCases */ class Services( private val context: Context, + private val store: BrowserStore, private val tabsUseCases: TabsUseCases, ) { private val prefs = PreferenceManager.getDefaultSharedPreferences(context) val appLinksInterceptor by lazy { AppLinksInterceptor( - context, - launchInApp = { - prefs.getBoolean(context.getPreferenceKey(R.string.pref_key_launch_external_app), false) - }, + context = context, + launchInApp = { true }, + store = store, ) } } diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/interceptor/AppRequestInterceptor.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/interceptor/AppRequestInterceptor.kt index 332ab3ee..0d7bd7a8 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/interceptor/AppRequestInterceptor.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/interceptor/AppRequestInterceptor.kt @@ -28,34 +28,16 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor { isDirectNavigation: Boolean, isSubframeRequest: Boolean, ): RequestInterceptor.InterceptionResponse? { - - return when (uri) { -// "about:privatebrowsing" -> { -// val page = PrivatePage.createPrivateBrowsingPage(context, uri) -// RequestInterceptor.InterceptionResponse.Content(page, encoding = "base64") -// } - -// "about:crashes" -> { -// val intent = Intent(context, CrashListActivity::class.java) -// intent.addFlags(FLAG_ACTIVITY_NEW_TASK) -// context.startActivity(intent) -// -// RequestInterceptor.InterceptionResponse.Url("about:blank") -// } - - else -> { - components.services.appLinksInterceptor.onLoadRequest( - engineSession, - uri, - lastUri, - hasUserGesture, - isSameDomain, - isRedirect, - isDirectNavigation, - isSubframeRequest, - ) - } - } + return components.services.appLinksInterceptor.onLoadRequest( + engineSession, + uri, + lastUri, + hasUserGesture, + isSameDomain, + isRedirect, + isDirectNavigation, + isSubframeRequest, + ) } override fun onErrorRequest(