improve open in app feature
This commit is contained in:
+11
-6
@@ -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,
|
||||
|
||||
+1
-1
@@ -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) }
|
||||
|
||||
|
||||
+3
-1
@@ -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.
|
||||
*
|
||||
|
||||
+5
-4
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-28
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user