Skip to content

Commit 75bc8f0

Browse files
committed
enforce context wrapping everywhere
1 parent 8960b2c commit 75bc8f0

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
124124
webAuthnFeature
125125
)
126126

127-
protected abstract fun createEngine(components: Components) : EngineView
127+
protected abstract fun createEngine(components: Components): EngineView
128128

129129
private lateinit var requestDownloadPermissionsLauncher: ActivityResultLauncher<Array<String>>
130130
private lateinit var requestSitePermissionsLauncher: ActivityResultLauncher<Array<String>>
@@ -205,8 +205,12 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
205205
FrameLayout.LayoutParams.MATCH_PARENT
206206
)
207207

208+
val profileContext =
209+
ProfileContext(requireContext(), components.profileApplicationContext.relativePath)
210+
208211
val engineView = createEngine(components)
209212
val originalContext = ActivityContextWrapper.getOriginalContext(requireActivity())
213+
?.let { ProfileContext(it, components.profileApplicationContext.relativePath) }
210214
val engineNativeView = engineView.asView()
211215
engineNativeView.layoutParams = layoutParams
212216

@@ -275,11 +279,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
275279

276280
appLinksFeature.set(
277281
feature = AppLinksFeature(
278-
context = requireContext(),
282+
context = profileContext,
279283
store = components.core.store,
280284
sessionId = sessionId,
281285
fragmentManager = parentFragmentManager,
282-
launchInApp = { components.core.prefs.getBoolean(context?.getPreferenceKey(R.string.pref_key_launch_external_app), false) },
286+
launchInApp = {
287+
components.core.prefs.getBoolean(
288+
context?.getPreferenceKey(R.string.pref_key_launch_external_app),
289+
false
290+
)
291+
},
283292
loadUrlUseCase = components.useCases.sessionUseCases.loadUrl,
284293
),
285294
owner = this,
@@ -298,7 +307,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
298307
requestPromptsPermissionsLauncher.launch(permissions)
299308
},
300309
androidPhotoPicker = AndroidPhotoPicker(
301-
requireContext(),
310+
profileContext,
302311
singleMediaPicker,
303312
multipleMediaPicker,
304313
),
@@ -309,7 +318,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
309318

310319
sitePermissionsFeature.set(
311320
feature = SitePermissionsFeature(
312-
context = requireContext(),
321+
context = profileContext,
313322
sessionId = sessionId,
314323
storage = components.core.geckoSitePermissionsStorage,
315324
fragmentManager = parentFragmentManager,
@@ -329,7 +338,11 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
329338
onNeedToRequestPermissions = { permissions ->
330339
requestSitePermissionsLauncher.launch(permissions)
331340
},
332-
onShouldShowRequestPermissionRationale = { shouldShowRequestPermissionRationale(it) },
341+
onShouldShowRequestPermissionRationale = {
342+
shouldShowRequestPermissionRationale(
343+
it
344+
)
345+
},
333346
store = components.core.store,
334347
),
335348
owner = this,
@@ -339,7 +352,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
339352
webExtensionPromptFeature.set(
340353
feature = WebExtensionPromptFeature(
341354
store = components.core.store,
342-
context = requireContext(),
355+
context = profileContext,
343356
fragmentManager = parentFragmentManager,
344357
),
345358
owner = this,
@@ -397,7 +410,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
397410

398411
readerViewFeature.set(
399412
feature = ReaderViewIntegration(
400-
requireContext(),
413+
profileContext,
401414
components.core.engine,
402415
components.core.store,
403416
binding.readerViewBar,
@@ -421,7 +434,11 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
421434
)
422435

423436
thumbnailsFeature.set(
424-
feature = BrowserThumbnails(requireContext(), components.engineView!!, components.core.store),
437+
feature = BrowserThumbnails(
438+
profileContext,
439+
components.engineView!!,
440+
components.core.store
441+
),
425442
owner = this,
426443
view = view,
427444
)
@@ -447,7 +464,10 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
447464
}
448465

449466
private fun openPopup(webExtensionState: WebExtensionState) {
450-
val intent = Intent(components.profileApplicationContext, WebExtensionActionPopupActivity::class.java)
467+
val intent = Intent(
468+
components.profileApplicationContext,
469+
WebExtensionActionPopupActivity::class.java
470+
)
451471
intent.putExtra("web_extension_id", webExtensionState.id)
452472
intent.putExtra("web_extension_name", webExtensionState.name)
453473
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
@@ -456,7 +476,11 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
456476

457477
@CallSuper
458478
@Suppress("LongMethod")
459-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
479+
override fun onCreateView(
480+
inflater: LayoutInflater,
481+
container: ViewGroup?,
482+
savedInstanceState: Bundle?
483+
): View {
460484
_binding = FragmentBrowserBinding.inflate(inflater, container, false)
461485
return binding.root
462486
}
@@ -480,7 +504,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
480504
return backButtonHandler.any { it.onBackPressed() }
481505
}
482506

483-
final override fun onHomePressed(): Boolean =pictureInPictureFeature?.onHomePressed() ?: false
507+
final override fun onHomePressed(): Boolean = pictureInPictureFeature?.onHomePressed() ?: false
484508

485509
override fun onPictureInPictureModeChanged(enabled: Boolean) {
486510
pictureInPictureFeature?.onPictureInPictureModeChanged(enabled)
@@ -521,6 +545,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
521545
putString(SESSION_ID_KEY, sessionId)
522546
}
523547
}
548+
524549
override fun onDestroyView() {
525550
super.onDestroyView()
526551

packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BrowserFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import mozilla.components.support.base.feature.UserInteractionHandler
1818
*/
1919
class BrowserFragment() : BaseBrowserFragment(), UserInteractionHandler {
2020
override fun createEngine(components: Components): EngineView {
21-
return components.core.engine.createView(components.profileApplicationContext).apply {
21+
val profileContext = ProfileContext(requireContext(), components.profileApplicationContext.relativePath)
22+
return components.core.engine.createView(profileContext).apply {
2223
selectionActionDelegate = components.selectionAction
2324
}
2425
}

packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/Components.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import mozilla.components.feature.downloads.FileSizeFormatter
3131
import mozilla.components.support.base.android.NotificationsDelegate
3232
import mozilla.components.support.base.log.Log
3333

34-
class Components(val profileApplicationContext: Context,
34+
class Components(val profileApplicationContext: ProfileContext,
3535
val flutterEvents: GeckoStateEvents,
3636
val readerViewController: ReaderViewController,
3737
val selectionAction: SelectionActionDelegate,

packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/GlobalComponents.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object GlobalComponents {
5454

5555
@OptIn(DelicateCoroutinesApi::class)
5656
fun setUp(
57-
applicationContext: Context,
57+
applicationContext: ProfileContext,
5858
flutterEvents: GeckoStateEvents,
5959
readerViewController: ReaderViewController,
6060
selectionAction: SelectionActionDelegate,

packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/ProfileContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import android.os.Build
77
import androidx.annotation.RequiresApi
88
import java.io.File
99

10-
class ProfileContext(private val base: Context, private val relativePath: String) :
10+
class ProfileContext(private val base: Context, val relativePath: String) :
1111
ContextWrapper(base) {
1212

1313
private val subfolderRoot =

packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/AddonsFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
1515
import androidx.recyclerview.widget.RecyclerView
1616
import eu.weblibre.flutter_mozilla_components.Components
1717
import eu.weblibre.flutter_mozilla_components.GlobalComponents
18+
import eu.weblibre.flutter_mozilla_components.ProfileContext
1819
import kotlinx.coroutines.CoroutineScope
1920
import kotlinx.coroutines.Dispatchers
2021
import kotlinx.coroutines.launch
@@ -76,8 +77,11 @@ class AddonsFragment : Fragment(), AddonsManagerAdapterDelegate {
7677
}
7778

7879
private fun bindRecyclerView(rootView: View) {
80+
val profileContext = ProfileContext(requireContext(), components.profileApplicationContext.relativePath)
81+
7982
recyclerView = rootView.findViewById(R.id.add_ons_list)
80-
recyclerView.layoutManager = LinearLayoutManager(requireContext())
83+
recyclerView.layoutManager = LinearLayoutManager(profileContext)
84+
8185
scope.launch {
8286
try {
8387
addons = components.core.addonManager.getAddons()

0 commit comments

Comments
 (0)