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,
|
store = components.core.store,
|
||||||
sessionId = sessionId,
|
sessionId = sessionId,
|
||||||
fragmentManager = parentFragmentManager,
|
fragmentManager = parentFragmentManager,
|
||||||
launchInApp = {
|
|
||||||
components.core.prefs.getBoolean(
|
|
||||||
context?.getPreferenceKey(R.string.pref_key_launch_external_app),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
},
|
|
||||||
loadUrlUseCase = components.useCases.sessionUseCases.loadUrl,
|
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,
|
owner = this,
|
||||||
view = view,
|
view = view,
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ class Components(val profileApplicationContext: ProfileContext,
|
|||||||
val core by lazy { Core(profileApplicationContext, this, flutterEvents, extensionEvents) }
|
val core by lazy { Core(profileApplicationContext, this, flutterEvents, extensionEvents) }
|
||||||
val events by lazy { Events(flutterEvents) }
|
val events by lazy { Events(flutterEvents) }
|
||||||
val useCases by lazy { UseCases(profileApplicationContext, core.engine, core.store) }
|
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 features by lazy { Features(core.engine, core.store, addonEvents, tabContentEvents) }
|
||||||
val search by lazy { Search(profileApplicationContext, core, useCases) }
|
val search by lazy { Search(profileApplicationContext, core, useCases) }
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -79,7 +79,7 @@ class Core(
|
|||||||
val engineSettings by lazy {
|
val engineSettings by lazy {
|
||||||
DefaultSettings(
|
DefaultSettings(
|
||||||
//historyTrackingDelegate = HistoryDelegate(lazyHistoryStorage)
|
//historyTrackingDelegate = HistoryDelegate(lazyHistoryStorage)
|
||||||
requestInterceptor = AppRequestInterceptor(context),
|
requestInterceptor = requestInterceptor,
|
||||||
historyTrackingDelegate = HistoryDelegate(lazyHistoryStorage),
|
historyTrackingDelegate = HistoryDelegate(lazyHistoryStorage),
|
||||||
testingModeEnabled = false,
|
testingModeEnabled = false,
|
||||||
remoteDebuggingEnabled = false,
|
remoteDebuggingEnabled = false,
|
||||||
@@ -252,6 +252,8 @@ class Core(
|
|||||||
|
|
||||||
val permissionStorage by lazy { PermissionStorage(geckoSitePermissionsStorage) }
|
val permissionStorage by lazy { PermissionStorage(geckoSitePermissionsStorage) }
|
||||||
|
|
||||||
|
val requestInterceptor = AppRequestInterceptor(context)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a [TrackingProtectionPolicy] based on current preferences.
|
* Constructs a [TrackingProtectionPolicy] based on current preferences.
|
||||||
*
|
*
|
||||||
|
|||||||
+5
-4
@@ -8,6 +8,7 @@ import android.content.Context
|
|||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import eu.weblibre.flutter_mozilla_components.R
|
import eu.weblibre.flutter_mozilla_components.R
|
||||||
import eu.weblibre.flutter_mozilla_components.ext.getPreferenceKey
|
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.app.links.AppLinksInterceptor
|
||||||
import mozilla.components.feature.tabs.TabsUseCases
|
import mozilla.components.feature.tabs.TabsUseCases
|
||||||
|
|
||||||
@@ -16,16 +17,16 @@ import mozilla.components.feature.tabs.TabsUseCases
|
|||||||
*/
|
*/
|
||||||
class Services(
|
class Services(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
private val store: BrowserStore,
|
||||||
private val tabsUseCases: TabsUseCases,
|
private val tabsUseCases: TabsUseCases,
|
||||||
) {
|
) {
|
||||||
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
private val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
|
||||||
val appLinksInterceptor by lazy {
|
val appLinksInterceptor by lazy {
|
||||||
AppLinksInterceptor(
|
AppLinksInterceptor(
|
||||||
context,
|
context = context,
|
||||||
launchInApp = {
|
launchInApp = { true },
|
||||||
prefs.getBoolean(context.getPreferenceKey(R.string.pref_key_launch_external_app), false)
|
store = store,
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-28
@@ -28,34 +28,16 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
|
|||||||
isDirectNavigation: Boolean,
|
isDirectNavigation: Boolean,
|
||||||
isSubframeRequest: Boolean,
|
isSubframeRequest: Boolean,
|
||||||
): RequestInterceptor.InterceptionResponse? {
|
): RequestInterceptor.InterceptionResponse? {
|
||||||
|
return components.services.appLinksInterceptor.onLoadRequest(
|
||||||
return when (uri) {
|
engineSession,
|
||||||
// "about:privatebrowsing" -> {
|
uri,
|
||||||
// val page = PrivatePage.createPrivateBrowsingPage(context, uri)
|
lastUri,
|
||||||
// RequestInterceptor.InterceptionResponse.Content(page, encoding = "base64")
|
hasUserGesture,
|
||||||
// }
|
isSameDomain,
|
||||||
|
isRedirect,
|
||||||
// "about:crashes" -> {
|
isDirectNavigation,
|
||||||
// val intent = Intent(context, CrashListActivity::class.java)
|
isSubframeRequest,
|
||||||
// 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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onErrorRequest(
|
override fun onErrorRequest(
|
||||||
|
|||||||
Reference in New Issue
Block a user