Bug 1858057 - Make WebExtensionPrompt available to the whole app.

fenix/120.0
Arturo Mejia 8 months ago committed by mergify[bot]
parent 971bf86d10
commit 4aafff2a59

@ -108,6 +108,7 @@ import org.mozilla.fenix.ext.hasTopDestination
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.setNavigationIcon
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.extension.WebExtensionPromptFeature
import org.mozilla.fenix.home.HomeFragmentDirections
import org.mozilla.fenix.home.intent.AssistIntentProcessor
import org.mozilla.fenix.home.intent.CrashReporterIntentProcessor
@ -194,6 +195,14 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
WebExtensionPopupObserver(components.core.store, ::openPopup)
}
val webExtensionPromptFeature by lazy {
WebExtensionPromptFeature(
store = components.core.store,
context = this@HomeActivity,
fragmentManager = supportFragmentManager,
)
}
private val extensionsProcessDisabledPromptObserver by lazy {
ExtensionsProcessDisabledController(this@HomeActivity, components.core.store)
}
@ -347,7 +356,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
supportActionBar?.hide()
lifecycle.addObservers(webExtensionPopupObserver, extensionsProcessDisabledPromptObserver, serviceWorkerSupport)
lifecycle.addObservers(
webExtensionPopupObserver,
extensionsProcessDisabledPromptObserver,
serviceWorkerSupport,
webExtensionPromptFeature,
)
if (shouldAddToRecentsScreen(intent)) {
intent.removeExtra(START_IN_RECENTS_SCREEN)

@ -25,7 +25,6 @@ import mozilla.components.feature.addons.AddonManager
import mozilla.components.feature.addons.AddonManagerException
import mozilla.components.feature.addons.ui.AddonsManagerAdapter
import mozilla.components.feature.addons.ui.AddonsManagerAdapterDelegate
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
@ -38,7 +37,6 @@ import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.runIfFragmentIsAttached
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.extension.WebExtensionPromptFeature
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.theme.ThemeManager
@ -50,7 +48,6 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management)
private var binding: FragmentAddOnsManagementBinding? = null
private val webExtensionPromptFeature = ViewBoundFeatureWrapper<WebExtensionPromptFeature>()
private var addons: List<Addon> = emptyList()
private var adapter: AddonsManagerAdapter? = null
@ -59,20 +56,11 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management)
super.onViewCreated(view, savedInstanceState)
binding = FragmentAddOnsManagementBinding.bind(view)
bindRecyclerView()
webExtensionPromptFeature.set(
feature = WebExtensionPromptFeature(
store = requireComponents.core.store,
context = requireContext(),
fragmentManager = parentFragmentManager,
onAddonChanged = {
runIfFragmentIsAttached {
adapter?.updateAddon(it)
}
},
),
owner = this,
view = view,
)
(activity as HomeActivity).webExtensionPromptFeature.onAddonChanged = {
runIfFragmentIsAttached {
adapter?.updateAddon(it)
}
}
}
override fun onResume() {
@ -85,6 +73,7 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management)
// letting go of the resources to avoid memory leak.
adapter = null
binding = null
(activity as HomeActivity).webExtensionPromptFeature.onAddonChanged = {}
}
private fun bindRecyclerView() {

@ -148,7 +148,6 @@ import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.runIfFragmentIsAttached
import org.mozilla.fenix.ext.secure
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.extension.WebExtensionPromptFeature
import org.mozilla.fenix.home.HomeScreenViewModel
import org.mozilla.fenix.home.SharedViewModel
import org.mozilla.fenix.perf.MarkersFragmentLifecycleCallbacks
@ -210,7 +209,6 @@ abstract class BaseBrowserFragment :
private val fullScreenFeature = ViewBoundFeatureWrapper<FullScreenFeature>()
private val swipeRefreshFeature = ViewBoundFeatureWrapper<SwipeRefreshFeature>()
private val webchannelIntegration = ViewBoundFeatureWrapper<FxaWebChannelFeature>()
private val webExtensionPromptFeature = ViewBoundFeatureWrapper<WebExtensionPromptFeature>()
private val sitePermissionWifiIntegration =
ViewBoundFeatureWrapper<SitePermissionsWifiIntegration>()
private val secureWindowFeature = ViewBoundFeatureWrapper<SecureWindowFeature>()
@ -922,16 +920,6 @@ abstract class BaseBrowserFragment :
owner = this,
view = view,
)
webExtensionPromptFeature.set(
feature = WebExtensionPromptFeature(
store = requireComponents.core.store,
context = requireContext(),
fragmentManager = parentFragmentManager,
),
owner = this,
view = view,
)
initializeEngineView(toolbarHeight)
}

@ -37,9 +37,15 @@ class WebExtensionPromptFeature(
private val store: BrowserStore,
private val context: Context,
private val fragmentManager: FragmentManager,
private val onAddonChanged: (Addon) -> Unit = {},
) : LifecycleAwareFeature {
/**
* (optional) callback invoked when an add-on was updated due to an interaction with a
* [WebExtensionPromptRequest].
* Won't be needed after https://bugzilla.mozilla.org/show_bug.cgi?id=1858484.
*/
var onAddonChanged: (Addon) -> Unit = {}
/**
* Whether or not an add-on installation is in progress.
*/

Loading…
Cancel
Save