2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

Closes #15816 - Attempt to handle 'allowInPrivate..' pref with detached context

This commit is contained in:
Grisha Kruglov 2020-10-13 14:34:20 -07:00 committed by Arturo Mejia
parent 21a67de947
commit 655a5cbf54

View File

@ -35,6 +35,7 @@ import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.theme.ThemeManager
import java.lang.ref.WeakReference
import java.util.concurrent.CancellationException import java.util.concurrent.CancellationException
/** /**
@ -169,7 +170,15 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management)
private fun showInstallationDialog(addon: Addon) { private fun showInstallationDialog(addon: Addon) {
if (!isInstallationInProgress && !hasExistingAddonInstallationDialogFragment()) { if (!isInstallationInProgress && !hasExistingAddonInstallationDialogFragment()) {
requireComponents.analytics.metrics.track(Event.AddonInstalled(addon.id)) requireComponents.analytics.metrics.track(Event.AddonInstalled(addon.id))
val addonCollectionProvider = requireContext().components.addonCollectionProvider val context = requireContext()
val addonCollectionProvider = context.components.addonCollectionProvider
// Fragment may not be attached to the context anymore during onConfirmButtonClicked handling,
// but we still want to be able to process user selection of the 'allowInPrivateBrowsing' pref.
// This is a best-effort attempt to do so - retain a weak reference to the application context
// (to avoid a leak), which we attempt to use to access addonManager.
// See https://github.com/mozilla-mobile/fenix/issues/15816
val weakApplicationContext: WeakReference<Context> = WeakReference(context)
val dialog = AddonInstallationDialogFragment.newInstance( val dialog = AddonInstallationDialogFragment.newInstance(
addon = addon, addon = addon,
@ -189,7 +198,7 @@ class AddonsManagementFragment : Fragment(R.layout.fragment_add_ons_management)
), ),
onConfirmButtonClicked = { _, allowInPrivateBrowsing -> onConfirmButtonClicked = { _, allowInPrivateBrowsing ->
if (allowInPrivateBrowsing) { if (allowInPrivateBrowsing) {
requireContext().components.addonManager.setAddonAllowedInPrivateBrowsing( weakApplicationContext.get()?.components?.addonManager?.setAddonAllowedInPrivateBrowsing(
addon, addon,
allowInPrivateBrowsing, allowInPrivateBrowsing,
onSuccess = { onSuccess = {