enforce context wrapping everywhere
This commit is contained in:
+37
-12
@@ -124,7 +124,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
webAuthnFeature
|
webAuthnFeature
|
||||||
)
|
)
|
||||||
|
|
||||||
protected abstract fun createEngine(components: Components) : EngineView
|
protected abstract fun createEngine(components: Components): EngineView
|
||||||
|
|
||||||
private lateinit var requestDownloadPermissionsLauncher: ActivityResultLauncher<Array<String>>
|
private lateinit var requestDownloadPermissionsLauncher: ActivityResultLauncher<Array<String>>
|
||||||
private lateinit var requestSitePermissionsLauncher: ActivityResultLauncher<Array<String>>
|
private lateinit var requestSitePermissionsLauncher: ActivityResultLauncher<Array<String>>
|
||||||
@@ -205,8 +205,12 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
FrameLayout.LayoutParams.MATCH_PARENT
|
FrameLayout.LayoutParams.MATCH_PARENT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val profileContext =
|
||||||
|
ProfileContext(requireContext(), components.profileApplicationContext.relativePath)
|
||||||
|
|
||||||
val engineView = createEngine(components)
|
val engineView = createEngine(components)
|
||||||
val originalContext = ActivityContextWrapper.getOriginalContext(requireActivity())
|
val originalContext = ActivityContextWrapper.getOriginalContext(requireActivity())
|
||||||
|
?.let { ProfileContext(it, components.profileApplicationContext.relativePath) }
|
||||||
val engineNativeView = engineView.asView()
|
val engineNativeView = engineView.asView()
|
||||||
engineNativeView.layoutParams = layoutParams
|
engineNativeView.layoutParams = layoutParams
|
||||||
|
|
||||||
@@ -275,11 +279,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
|
|
||||||
appLinksFeature.set(
|
appLinksFeature.set(
|
||||||
feature = AppLinksFeature(
|
feature = AppLinksFeature(
|
||||||
context = requireContext(),
|
context = profileContext,
|
||||||
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) },
|
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,
|
||||||
),
|
),
|
||||||
owner = this,
|
owner = this,
|
||||||
@@ -298,7 +307,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
requestPromptsPermissionsLauncher.launch(permissions)
|
requestPromptsPermissionsLauncher.launch(permissions)
|
||||||
},
|
},
|
||||||
androidPhotoPicker = AndroidPhotoPicker(
|
androidPhotoPicker = AndroidPhotoPicker(
|
||||||
requireContext(),
|
profileContext,
|
||||||
singleMediaPicker,
|
singleMediaPicker,
|
||||||
multipleMediaPicker,
|
multipleMediaPicker,
|
||||||
),
|
),
|
||||||
@@ -309,7 +318,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
|
|
||||||
sitePermissionsFeature.set(
|
sitePermissionsFeature.set(
|
||||||
feature = SitePermissionsFeature(
|
feature = SitePermissionsFeature(
|
||||||
context = requireContext(),
|
context = profileContext,
|
||||||
sessionId = sessionId,
|
sessionId = sessionId,
|
||||||
storage = components.core.geckoSitePermissionsStorage,
|
storage = components.core.geckoSitePermissionsStorage,
|
||||||
fragmentManager = parentFragmentManager,
|
fragmentManager = parentFragmentManager,
|
||||||
@@ -329,7 +338,11 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
onNeedToRequestPermissions = { permissions ->
|
onNeedToRequestPermissions = { permissions ->
|
||||||
requestSitePermissionsLauncher.launch(permissions)
|
requestSitePermissionsLauncher.launch(permissions)
|
||||||
},
|
},
|
||||||
onShouldShowRequestPermissionRationale = { shouldShowRequestPermissionRationale(it) },
|
onShouldShowRequestPermissionRationale = {
|
||||||
|
shouldShowRequestPermissionRationale(
|
||||||
|
it
|
||||||
|
)
|
||||||
|
},
|
||||||
store = components.core.store,
|
store = components.core.store,
|
||||||
),
|
),
|
||||||
owner = this,
|
owner = this,
|
||||||
@@ -339,7 +352,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
webExtensionPromptFeature.set(
|
webExtensionPromptFeature.set(
|
||||||
feature = WebExtensionPromptFeature(
|
feature = WebExtensionPromptFeature(
|
||||||
store = components.core.store,
|
store = components.core.store,
|
||||||
context = requireContext(),
|
context = profileContext,
|
||||||
fragmentManager = parentFragmentManager,
|
fragmentManager = parentFragmentManager,
|
||||||
),
|
),
|
||||||
owner = this,
|
owner = this,
|
||||||
@@ -397,7 +410,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
|
|
||||||
readerViewFeature.set(
|
readerViewFeature.set(
|
||||||
feature = ReaderViewIntegration(
|
feature = ReaderViewIntegration(
|
||||||
requireContext(),
|
profileContext,
|
||||||
components.core.engine,
|
components.core.engine,
|
||||||
components.core.store,
|
components.core.store,
|
||||||
binding.readerViewBar,
|
binding.readerViewBar,
|
||||||
@@ -421,7 +434,11 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
)
|
)
|
||||||
|
|
||||||
thumbnailsFeature.set(
|
thumbnailsFeature.set(
|
||||||
feature = BrowserThumbnails(requireContext(), components.engineView!!, components.core.store),
|
feature = BrowserThumbnails(
|
||||||
|
profileContext,
|
||||||
|
components.engineView!!,
|
||||||
|
components.core.store
|
||||||
|
),
|
||||||
owner = this,
|
owner = this,
|
||||||
view = view,
|
view = view,
|
||||||
)
|
)
|
||||||
@@ -447,7 +464,10 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openPopup(webExtensionState: WebExtensionState) {
|
private fun openPopup(webExtensionState: WebExtensionState) {
|
||||||
val intent = Intent(components.profileApplicationContext, WebExtensionActionPopupActivity::class.java)
|
val intent = Intent(
|
||||||
|
components.profileApplicationContext,
|
||||||
|
WebExtensionActionPopupActivity::class.java
|
||||||
|
)
|
||||||
intent.putExtra("web_extension_id", webExtensionState.id)
|
intent.putExtra("web_extension_id", webExtensionState.id)
|
||||||
intent.putExtra("web_extension_name", webExtensionState.name)
|
intent.putExtra("web_extension_name", webExtensionState.name)
|
||||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
@@ -456,7 +476,11 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@Suppress("LongMethod")
|
@Suppress("LongMethod")
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View {
|
||||||
_binding = FragmentBrowserBinding.inflate(inflater, container, false)
|
_binding = FragmentBrowserBinding.inflate(inflater, container, false)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
@@ -480,7 +504,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
return backButtonHandler.any { it.onBackPressed() }
|
return backButtonHandler.any { it.onBackPressed() }
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun onHomePressed(): Boolean =pictureInPictureFeature?.onHomePressed() ?: false
|
final override fun onHomePressed(): Boolean = pictureInPictureFeature?.onHomePressed() ?: false
|
||||||
|
|
||||||
override fun onPictureInPictureModeChanged(enabled: Boolean) {
|
override fun onPictureInPictureModeChanged(enabled: Boolean) {
|
||||||
pictureInPictureFeature?.onPictureInPictureModeChanged(enabled)
|
pictureInPictureFeature?.onPictureInPictureModeChanged(enabled)
|
||||||
@@ -521,6 +545,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|||||||
putString(SESSION_ID_KEY, sessionId)
|
putString(SESSION_ID_KEY, sessionId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -18,7 +18,8 @@ import mozilla.components.support.base.feature.UserInteractionHandler
|
|||||||
*/
|
*/
|
||||||
class BrowserFragment() : BaseBrowserFragment(), UserInteractionHandler {
|
class BrowserFragment() : BaseBrowserFragment(), UserInteractionHandler {
|
||||||
override fun createEngine(components: Components): EngineView {
|
override fun createEngine(components: Components): EngineView {
|
||||||
return components.core.engine.createView(components.profileApplicationContext).apply {
|
val profileContext = ProfileContext(requireContext(), components.profileApplicationContext.relativePath)
|
||||||
|
return components.core.engine.createView(profileContext).apply {
|
||||||
selectionActionDelegate = components.selectionAction
|
selectionActionDelegate = components.selectionAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ import mozilla.components.feature.downloads.FileSizeFormatter
|
|||||||
import mozilla.components.support.base.android.NotificationsDelegate
|
import mozilla.components.support.base.android.NotificationsDelegate
|
||||||
import mozilla.components.support.base.log.Log
|
import mozilla.components.support.base.log.Log
|
||||||
|
|
||||||
class Components(val profileApplicationContext: Context,
|
class Components(val profileApplicationContext: ProfileContext,
|
||||||
val flutterEvents: GeckoStateEvents,
|
val flutterEvents: GeckoStateEvents,
|
||||||
val readerViewController: ReaderViewController,
|
val readerViewController: ReaderViewController,
|
||||||
val selectionAction: SelectionActionDelegate,
|
val selectionAction: SelectionActionDelegate,
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ object GlobalComponents {
|
|||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
fun setUp(
|
fun setUp(
|
||||||
applicationContext: Context,
|
applicationContext: ProfileContext,
|
||||||
flutterEvents: GeckoStateEvents,
|
flutterEvents: GeckoStateEvents,
|
||||||
readerViewController: ReaderViewController,
|
readerViewController: ReaderViewController,
|
||||||
selectionAction: SelectionActionDelegate,
|
selectionAction: SelectionActionDelegate,
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ import android.os.Build
|
|||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class ProfileContext(private val base: Context, private val relativePath: String) :
|
class ProfileContext(private val base: Context, val relativePath: String) :
|
||||||
ContextWrapper(base) {
|
ContextWrapper(base) {
|
||||||
|
|
||||||
private val subfolderRoot =
|
private val subfolderRoot =
|
||||||
|
|||||||
+5
-1
@@ -15,6 +15,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import eu.weblibre.flutter_mozilla_components.Components
|
import eu.weblibre.flutter_mozilla_components.Components
|
||||||
import eu.weblibre.flutter_mozilla_components.GlobalComponents
|
import eu.weblibre.flutter_mozilla_components.GlobalComponents
|
||||||
|
import eu.weblibre.flutter_mozilla_components.ProfileContext
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -76,8 +77,11 @@ class AddonsFragment : Fragment(), AddonsManagerAdapterDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun bindRecyclerView(rootView: View) {
|
private fun bindRecyclerView(rootView: View) {
|
||||||
|
val profileContext = ProfileContext(requireContext(), components.profileApplicationContext.relativePath)
|
||||||
|
|
||||||
recyclerView = rootView.findViewById(R.id.add_ons_list)
|
recyclerView = rootView.findViewById(R.id.add_ons_list)
|
||||||
recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
recyclerView.layoutManager = LinearLayoutManager(profileContext)
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
addons = components.core.addonManager.getAddons()
|
addons = components.core.addonManager.getAddons()
|
||||||
|
|||||||
Reference in New Issue
Block a user