mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-11 13:11:01 +00:00
And also add CustomTabsServiceStore
This commit is contained in:
parent
78ac6fc912
commit
e9fd6892ba
@ -344,15 +344,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
|
|||||||
toolbar.visibility = View.VISIBLE
|
toolbar.visibility = View.VISIBLE
|
||||||
nestedScrollQuickAction.visibility = View.VISIBLE
|
nestedScrollQuickAction.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
view.swipeRefresh.apply {
|
updateLayoutMargins(inFullScreen)
|
||||||
val (topMargin, bottomMargin) = if (inFullScreen) 0 to 0 else getEngineMargins()
|
|
||||||
(layoutParams as CoordinatorLayout.LayoutParams).setMargins(
|
|
||||||
0,
|
|
||||||
topMargin,
|
|
||||||
0,
|
|
||||||
bottomMargin
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
owner = this,
|
owner = this,
|
||||||
view = view
|
view = view
|
||||||
@ -526,6 +518,13 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
|
|||||||
*/
|
*/
|
||||||
protected abstract fun getAppropriateLayoutGravity(): Int
|
protected abstract fun getAppropriateLayoutGravity(): Int
|
||||||
|
|
||||||
|
protected fun updateLayoutMargins(inFullScreen: Boolean) {
|
||||||
|
view?.swipeRefresh?.apply {
|
||||||
|
val (topMargin, bottomMargin) = if (inFullScreen) 0 to 0 else getEngineMargins()
|
||||||
|
(layoutParams as CoordinatorLayout.LayoutParams).setMargins(0, topMargin, 0, bottomMargin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the site permissions rules based on user settings.
|
* Updates the site permissions rules based on user settings.
|
||||||
*/
|
*/
|
||||||
|
@ -25,6 +25,7 @@ import mozilla.components.concept.engine.Engine
|
|||||||
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
|
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
|
||||||
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
|
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
|
||||||
import mozilla.components.concept.fetch.Client
|
import mozilla.components.concept.fetch.Client
|
||||||
|
import mozilla.components.feature.customtabs.store.CustomTabsServiceStore
|
||||||
import mozilla.components.feature.media.MediaFeature
|
import mozilla.components.feature.media.MediaFeature
|
||||||
import mozilla.components.feature.media.RecordingDevicesNotificationFeature
|
import mozilla.components.feature.media.RecordingDevicesNotificationFeature
|
||||||
import mozilla.components.feature.media.state.MediaStateMachine
|
import mozilla.components.feature.media.state.MediaStateMachine
|
||||||
@ -83,6 +84,11 @@ class Core(private val context: Context) {
|
|||||||
BrowserStore()
|
BrowserStore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The [CustomTabsServiceStore] holds global custom tabs related data.
|
||||||
|
*/
|
||||||
|
val customTabsStore by lazy { CustomTabsServiceStore() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The session manager component provides access to a centralized registry of
|
* The session manager component provides access to a centralized registry of
|
||||||
* all browser sessions (i.e. tabs). It is initialized here to persist and restore
|
* all browser sessions (i.e. tabs). It is initialized here to persist and restore
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package org.mozilla.fenix.customtabs
|
package org.mozilla.fenix.customtabs
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
@ -25,11 +24,10 @@ import org.mozilla.fenix.ext.settings
|
|||||||
import org.mozilla.fenix.theme.ThemeManager
|
import org.mozilla.fenix.theme.ThemeManager
|
||||||
|
|
||||||
class CustomTabsIntegration(
|
class CustomTabsIntegration(
|
||||||
context: Context,
|
|
||||||
sessionManager: SessionManager,
|
sessionManager: SessionManager,
|
||||||
toolbar: BrowserToolbar,
|
toolbar: BrowserToolbar,
|
||||||
sessionId: String,
|
sessionId: String,
|
||||||
activity: Activity?,
|
activity: Activity,
|
||||||
quickActionbar: NestedScrollView,
|
quickActionbar: NestedScrollView,
|
||||||
engineLayout: View,
|
engineLayout: View,
|
||||||
onItemTapped: (ToolbarMenu.Item) -> Unit = {}
|
onItemTapped: (ToolbarMenu.Item) -> Unit = {}
|
||||||
@ -59,24 +57,24 @@ class CustomTabsIntegration(
|
|||||||
|
|
||||||
val task = LottieCompositionFactory
|
val task = LottieCompositionFactory
|
||||||
.fromRawRes(
|
.fromRawRes(
|
||||||
context,
|
activity,
|
||||||
ThemeManager.resolveAttribute(R.attr.shieldLottieFile, context)
|
ThemeManager.resolveAttribute(R.attr.shieldLottieFile, activity)
|
||||||
)
|
)
|
||||||
task.addListener { result ->
|
task.addListener { result ->
|
||||||
val lottieDrawable = LottieDrawable()
|
val lottieDrawable = LottieDrawable()
|
||||||
lottieDrawable.composition = result
|
lottieDrawable.composition = result
|
||||||
toolbar.displayTrackingProtectionIcon =
|
toolbar.displayTrackingProtectionIcon =
|
||||||
context.settings.shouldUseTrackingProtection && FeatureFlags.etpCategories
|
activity.settings.shouldUseTrackingProtection && FeatureFlags.etpCategories
|
||||||
toolbar.displaySeparatorView = false
|
toolbar.displaySeparatorView = false
|
||||||
|
|
||||||
toolbar.setTrackingProtectionIcons(
|
toolbar.setTrackingProtectionIcons(
|
||||||
iconOnNoTrackersBlocked = AppCompatResources.getDrawable(
|
iconOnNoTrackersBlocked = AppCompatResources.getDrawable(
|
||||||
context,
|
activity,
|
||||||
R.drawable.ic_tracking_protection_enabled
|
R.drawable.ic_tracking_protection_enabled
|
||||||
)!!,
|
)!!,
|
||||||
iconOnTrackersBlocked = lottieDrawable,
|
iconOnTrackersBlocked = lottieDrawable,
|
||||||
iconDisabledForSite = AppCompatResources.getDrawable(
|
iconDisabledForSite = AppCompatResources.getDrawable(
|
||||||
context,
|
activity,
|
||||||
R.drawable.ic_tracking_protection_disabled
|
R.drawable.ic_tracking_protection_disabled
|
||||||
)!!
|
)!!
|
||||||
)
|
)
|
||||||
@ -85,7 +83,7 @@ class CustomTabsIntegration(
|
|||||||
|
|
||||||
private val customTabToolbarMenu by lazy {
|
private val customTabToolbarMenu by lazy {
|
||||||
CustomTabToolbarMenu(
|
CustomTabToolbarMenu(
|
||||||
context,
|
activity,
|
||||||
sessionManager,
|
sessionManager,
|
||||||
sessionId,
|
sessionId,
|
||||||
onItemTapped = onItemTapped
|
onItemTapped = onItemTapped
|
||||||
@ -98,8 +96,8 @@ class CustomTabsIntegration(
|
|||||||
sessionId,
|
sessionId,
|
||||||
menuBuilder = customTabToolbarMenu.menuBuilder,
|
menuBuilder = customTabToolbarMenu.menuBuilder,
|
||||||
menuItemIndex = START_OF_MENU_ITEMS_INDEX,
|
menuItemIndex = START_OF_MENU_ITEMS_INDEX,
|
||||||
window = activity?.window,
|
window = activity.window,
|
||||||
closeListener = { activity?.finish() }
|
closeListener = { activity.finish() }
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
|
@ -10,4 +10,5 @@ import org.mozilla.fenix.ext.components
|
|||||||
|
|
||||||
class CustomTabsService : AbstractCustomTabsService() {
|
class CustomTabsService : AbstractCustomTabsService() {
|
||||||
override val engine: Engine by lazy { applicationContext.components.core.engine }
|
override val engine: Engine by lazy { applicationContext.components.core.engine }
|
||||||
|
override val customTabsServiceStore by lazy { applicationContext.components.core.customTabsStore }
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ import kotlinx.android.synthetic.main.fragment_browser.view.*
|
|||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||||
import mozilla.components.browser.session.Session
|
import mozilla.components.browser.session.Session
|
||||||
|
import mozilla.components.feature.pwa.ext.trustedOrigins
|
||||||
|
import mozilla.components.feature.pwa.feature.WebAppHideToolbarFeature
|
||||||
import mozilla.components.feature.sitepermissions.SitePermissions
|
import mozilla.components.feature.sitepermissions.SitePermissions
|
||||||
import mozilla.components.lib.state.ext.consumeFrom
|
import mozilla.components.lib.state.ext.consumeFrom
|
||||||
import mozilla.components.support.base.feature.BackHandler
|
import mozilla.components.support.base.feature.BackHandler
|
||||||
@ -19,6 +21,7 @@ import org.mozilla.fenix.R
|
|||||||
import org.mozilla.fenix.browser.BaseBrowserFragment
|
import org.mozilla.fenix.browser.BaseBrowserFragment
|
||||||
import org.mozilla.fenix.components.toolbar.BrowserToolbarController
|
import org.mozilla.fenix.components.toolbar.BrowserToolbarController
|
||||||
import org.mozilla.fenix.components.toolbar.BrowserToolbarInteractor
|
import org.mozilla.fenix.components.toolbar.BrowserToolbarInteractor
|
||||||
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
|
|
||||||
@ -30,14 +33,16 @@ import org.mozilla.fenix.ext.requireComponents
|
|||||||
class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
|
class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
|
||||||
|
|
||||||
private val customTabsIntegration = ViewBoundFeatureWrapper<CustomTabsIntegration>()
|
private val customTabsIntegration = ViewBoundFeatureWrapper<CustomTabsIntegration>()
|
||||||
|
private val hideToolbarFeature = ViewBoundFeatureWrapper<WebAppHideToolbarFeature>()
|
||||||
|
|
||||||
override fun initializeUI(view: View): Session? {
|
override fun initializeUI(view: View): Session? {
|
||||||
return super.initializeUI(view)?.also {
|
return super.initializeUI(view)?.also {
|
||||||
|
val activity = requireActivity()
|
||||||
|
val components = activity.components
|
||||||
|
|
||||||
customTabSessionId?.let { customTabSessionId ->
|
customTabSessionId?.let { customTabSessionId ->
|
||||||
customTabsIntegration.set(
|
customTabsIntegration.set(
|
||||||
feature = CustomTabsIntegration(
|
feature = CustomTabsIntegration(
|
||||||
requireContext(),
|
|
||||||
requireComponents.core.sessionManager,
|
requireComponents.core.sessionManager,
|
||||||
toolbar,
|
toolbar,
|
||||||
customTabSessionId,
|
customTabSessionId,
|
||||||
@ -48,11 +53,36 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
|
|||||||
),
|
),
|
||||||
owner = this,
|
owner = this,
|
||||||
view = view)
|
view = view)
|
||||||
|
|
||||||
|
hideToolbarFeature.set(
|
||||||
|
feature = WebAppHideToolbarFeature(
|
||||||
|
requireComponents.core.sessionManager,
|
||||||
|
toolbar,
|
||||||
|
customTabSessionId,
|
||||||
|
emptyList()
|
||||||
|
) { toolbarVisible ->
|
||||||
|
updateLayoutMargins(inFullScreen = !toolbarVisible)
|
||||||
|
},
|
||||||
|
owner = this,
|
||||||
|
view = toolbar)
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeFrom(browserStore) {
|
consumeFrom(browserStore) {
|
||||||
browserToolbarView.update(it)
|
browserToolbarView.update(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
consumeFrom(components.core.customTabsStore) { state ->
|
||||||
|
getSessionById()
|
||||||
|
?.let { session -> session.customTabConfig?.sessionToken }
|
||||||
|
?.let { token -> state.tabs[token] }
|
||||||
|
?.let { tabState ->
|
||||||
|
hideToolbarFeature.withFeature {
|
||||||
|
it.onTrustedScopesChange(tabState.trustedOrigins)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLayoutMargins(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user