mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/6229 - Remove all tab options from custom tab context menu
This commit is contained in:
parent
0a59e87224
commit
6f4fd33912
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.browser
|
package org.mozilla.fenix.browser
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
@ -73,12 +74,12 @@ import org.mozilla.fenix.components.toolbar.ToolbarIntegration
|
|||||||
import org.mozilla.fenix.downloads.DownloadService
|
import org.mozilla.fenix.downloads.DownloadService
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.enterToImmersiveMode
|
import org.mozilla.fenix.ext.enterToImmersiveMode
|
||||||
|
import org.mozilla.fenix.ext.getRootView
|
||||||
import org.mozilla.fenix.ext.metrics
|
import org.mozilla.fenix.ext.metrics
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
import org.mozilla.fenix.ext.sessionsOfType
|
import org.mozilla.fenix.ext.sessionsOfType
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.ext.getRootView
|
|
||||||
import org.mozilla.fenix.isInExperiment
|
import org.mozilla.fenix.isInExperiment
|
||||||
import org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior
|
import org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior
|
||||||
import org.mozilla.fenix.settings.SupportUtils
|
import org.mozilla.fenix.settings.SupportUtils
|
||||||
@ -235,16 +236,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
|
|||||||
feature = ContextMenuFeature(
|
feature = ContextMenuFeature(
|
||||||
fragmentManager = parentFragmentManager,
|
fragmentManager = parentFragmentManager,
|
||||||
store = store,
|
store = store,
|
||||||
candidates = ContextMenuCandidate.defaultCandidates(
|
candidates = getContextMenuCandidates(context, view),
|
||||||
context,
|
|
||||||
context.components.useCases.tabsUseCases,
|
|
||||||
context.components.useCases.contextMenuUseCases,
|
|
||||||
view,
|
|
||||||
FenixSnackbarDelegate(
|
|
||||||
view,
|
|
||||||
if (getSessionById()?.isCustomTabSession() == true) null else nestedScrollQuickAction
|
|
||||||
)
|
|
||||||
),
|
|
||||||
engineView = view.engineView,
|
engineView = view.engineView,
|
||||||
useCases = context.components.useCases.contextMenuUseCases,
|
useCases = context.components.useCases.contextMenuUseCases,
|
||||||
customTabId = customTabSessionId
|
customTabId = customTabSessionId
|
||||||
@ -404,6 +396,14 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of context menu items [ContextMenuCandidate] for the context menu
|
||||||
|
*/
|
||||||
|
protected abstract fun getContextMenuCandidates(
|
||||||
|
context: Context,
|
||||||
|
view: View
|
||||||
|
): List<ContextMenuCandidate>
|
||||||
|
|
||||||
private fun adjustBackgroundAndNavigate(directions: NavDirections) {
|
private fun adjustBackgroundAndNavigate(directions: NavDirections) {
|
||||||
context?.let {
|
context?.let {
|
||||||
swipeRefresh?.background = ColorDrawable(Color.TRANSPARENT)
|
swipeRefresh?.background = ColorDrawable(Color.TRANSPARENT)
|
||||||
@ -521,7 +521,8 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
|
|||||||
if (session.source == Session.Source.ACTION_VIEW) {
|
if (session.source == Session.Source.ACTION_VIEW) {
|
||||||
sessionManager.remove(session)
|
sessionManager.remove(session)
|
||||||
} else {
|
} else {
|
||||||
val isLastSession = sessionManager.sessionsOfType(private = session.private).count() == 1
|
val isLastSession =
|
||||||
|
sessionManager.sessionsOfType(private = session.private).count() == 1
|
||||||
sessionManager.remove(session, true)
|
sessionManager.remove(session, true)
|
||||||
return !isLastSession // Jump to tab overview if last session was removed
|
return !isLastSession // Jump to tab overview if last session was removed
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.browser
|
package org.mozilla.fenix.browser
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -23,6 +24,7 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.transition.TransitionInflater
|
import androidx.transition.TransitionInflater
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import kotlinx.android.synthetic.main.fragment_browser.*
|
||||||
import kotlinx.android.synthetic.main.fragment_browser.view.*
|
import kotlinx.android.synthetic.main.fragment_browser.view.*
|
||||||
import kotlinx.android.synthetic.main.tracking_protection_onboarding_popup.view.*
|
import kotlinx.android.synthetic.main.tracking_protection_onboarding_popup.view.*
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
@ -32,6 +34,7 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import mozilla.appservices.places.BookmarkRoot
|
import mozilla.appservices.places.BookmarkRoot
|
||||||
import mozilla.components.browser.session.Session
|
import mozilla.components.browser.session.Session
|
||||||
|
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
||||||
import mozilla.components.feature.readerview.ReaderViewFeature
|
import mozilla.components.feature.readerview.ReaderViewFeature
|
||||||
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
|
||||||
@ -50,11 +53,11 @@ import org.mozilla.fenix.components.toolbar.BrowserToolbarController
|
|||||||
import org.mozilla.fenix.components.toolbar.BrowserToolbarViewInteractor
|
import org.mozilla.fenix.components.toolbar.BrowserToolbarViewInteractor
|
||||||
import org.mozilla.fenix.components.toolbar.QuickActionSheetAction
|
import org.mozilla.fenix.components.toolbar.QuickActionSheetAction
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
|
import org.mozilla.fenix.ext.getDimenInDip
|
||||||
import org.mozilla.fenix.ext.increaseTapArea
|
import org.mozilla.fenix.ext.increaseTapArea
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.ext.getDimenInDip
|
|
||||||
import org.mozilla.fenix.home.sessioncontrol.SessionControlChange
|
import org.mozilla.fenix.home.sessioncontrol.SessionControlChange
|
||||||
import org.mozilla.fenix.home.sessioncontrol.TabCollection
|
import org.mozilla.fenix.home.sessioncontrol.TabCollection
|
||||||
import org.mozilla.fenix.mvi.getManagedEmitter
|
import org.mozilla.fenix.mvi.getManagedEmitter
|
||||||
@ -391,13 +394,28 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
|
|||||||
val xOffset = it.dimen(R.dimen.tp_onboarding_x_offset)
|
val xOffset = it.dimen(R.dimen.tp_onboarding_x_offset)
|
||||||
|
|
||||||
// Positioning the popup above the tp anchor.
|
// Positioning the popup above the tp anchor.
|
||||||
val yOffset = -containerHeight - (browserToolbarView.view.height / THREE * 2) + triangleHeight
|
val yOffset =
|
||||||
|
-containerHeight - (browserToolbarView.view.height / THREE * 2) + triangleHeight
|
||||||
|
|
||||||
trackingOnboarding.showAsDropDown(tpIcon, xOffset, yOffset)
|
trackingOnboarding.showAsDropDown(tpIcon, xOffset, yOffset)
|
||||||
it.settings().incrementTrackingProtectionOnboardingCount()
|
it.settings().incrementTrackingProtectionOnboardingCount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getContextMenuCandidates(
|
||||||
|
context: Context,
|
||||||
|
view: View
|
||||||
|
): List<ContextMenuCandidate> = ContextMenuCandidate.defaultCandidates(
|
||||||
|
context,
|
||||||
|
context.components.useCases.tabsUseCases,
|
||||||
|
context.components.useCases.contextMenuUseCases,
|
||||||
|
view,
|
||||||
|
FenixSnackbarDelegate(
|
||||||
|
view,
|
||||||
|
nestedScrollQuickAction
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
private fun shouldShowTrackingProtectionOnboarding(session: Session) =
|
private fun shouldShowTrackingProtectionOnboarding(session: Session) =
|
||||||
context?.settings()?.shouldShowTrackingProtectionOnboarding ?: false &&
|
context?.settings()?.shouldShowTrackingProtectionOnboarding ?: false &&
|
||||||
session.trackerBlockingEnabled && session.trackersBlocked.isNotEmpty()
|
session.trackerBlockingEnabled && session.trackersBlocked.isNotEmpty()
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.browser
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.View
|
||||||
|
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
||||||
|
import mozilla.components.feature.contextmenu.ContextMenuUseCases
|
||||||
|
import mozilla.components.feature.contextmenu.DefaultSnackbarDelegate
|
||||||
|
|
||||||
|
class CustomTabContextMenuCandidate {
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Returns the default list of context menu candidates for custom tabs/external apps.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
fun defaultCandidates(
|
||||||
|
context: Context,
|
||||||
|
contextMenuUseCases: ContextMenuUseCases,
|
||||||
|
snackBarParentView: View,
|
||||||
|
snackbarDelegate: ContextMenuCandidate.SnackbarDelegate = DefaultSnackbarDelegate()
|
||||||
|
): List<ContextMenuCandidate> = listOf(
|
||||||
|
ContextMenuCandidate.createCopyLinkCandidate(
|
||||||
|
context,
|
||||||
|
snackBarParentView,
|
||||||
|
snackbarDelegate
|
||||||
|
),
|
||||||
|
ContextMenuCandidate.createShareLinkCandidate(context),
|
||||||
|
ContextMenuCandidate.createSaveImageCandidate(context, contextMenuUseCases),
|
||||||
|
ContextMenuCandidate.createCopyImageLocationCandidate(
|
||||||
|
context,
|
||||||
|
snackBarParentView,
|
||||||
|
snackbarDelegate
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.customtabs
|
package org.mozilla.fenix.customtabs
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
@ -14,6 +15,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|||||||
import mozilla.components.browser.session.Session
|
import mozilla.components.browser.session.Session
|
||||||
import mozilla.components.concept.engine.manifest.WebAppManifestParser
|
import mozilla.components.concept.engine.manifest.WebAppManifestParser
|
||||||
import mozilla.components.concept.engine.manifest.getOrNull
|
import mozilla.components.concept.engine.manifest.getOrNull
|
||||||
|
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
||||||
import mozilla.components.feature.pwa.ext.getTrustedScope
|
import mozilla.components.feature.pwa.ext.getTrustedScope
|
||||||
import mozilla.components.feature.pwa.ext.trustedOrigins
|
import mozilla.components.feature.pwa.ext.trustedOrigins
|
||||||
import mozilla.components.feature.pwa.feature.WebAppActivityFeature
|
import mozilla.components.feature.pwa.feature.WebAppActivityFeature
|
||||||
@ -25,6 +27,8 @@ import mozilla.components.support.base.feature.BackHandler
|
|||||||
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.browser.BaseBrowserFragment
|
import org.mozilla.fenix.browser.BaseBrowserFragment
|
||||||
|
import org.mozilla.fenix.browser.CustomTabContextMenuCandidate
|
||||||
|
import org.mozilla.fenix.browser.FenixSnackbarDelegate
|
||||||
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.components
|
||||||
@ -76,7 +80,8 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
|
|||||||
updateLayoutMargins(inFullScreen = !toolbarVisible)
|
updateLayoutMargins(inFullScreen = !toolbarVisible)
|
||||||
},
|
},
|
||||||
owner = this,
|
owner = this,
|
||||||
view = toolbar)
|
view = toolbar
|
||||||
|
)
|
||||||
|
|
||||||
if (manifest != null) {
|
if (manifest != null) {
|
||||||
activity.lifecycle.addObserver(
|
activity.lifecycle.addObserver(
|
||||||
@ -143,11 +148,11 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
|
|||||||
val directions =
|
val directions =
|
||||||
ExternalAppBrowserFragmentDirections
|
ExternalAppBrowserFragmentDirections
|
||||||
.actionExternalAppBrowserFragmentToTrackingProtectionPanelDialogFragment(
|
.actionExternalAppBrowserFragmentToTrackingProtectionPanelDialogFragment(
|
||||||
sessionId = session.id,
|
sessionId = session.id,
|
||||||
url = session.url,
|
url = session.url,
|
||||||
trackingProtectionEnabled = session.trackerBlockingEnabled,
|
trackingProtectionEnabled = session.trackerBlockingEnabled,
|
||||||
gravity = getAppropriateLayoutGravity()
|
gravity = getAppropriateLayoutGravity()
|
||||||
)
|
)
|
||||||
nav(R.id.externalAppBrowserFragment, directions)
|
nav(R.id.externalAppBrowserFragment, directions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,5 +166,18 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getContextMenuCandidates(
|
||||||
|
context: Context,
|
||||||
|
view: View
|
||||||
|
): List<ContextMenuCandidate> = CustomTabContextMenuCandidate.defaultCandidates(
|
||||||
|
context,
|
||||||
|
context.components.useCases.contextMenuUseCases,
|
||||||
|
view,
|
||||||
|
FenixSnackbarDelegate(
|
||||||
|
view,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
override fun getAppropriateLayoutGravity() = Gravity.TOP
|
override fun getAppropriateLayoutGravity() = Gravity.TOP
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user