@@ -1041,60 +1041,58 @@ class BrowserTabFragment :
10411041 override fun onActivityCreated (savedInstanceState : Bundle ? ) {
10421042 super .onActivityCreated(savedInstanceState)
10431043
1044- lifecycleScope.launch {
1045- omnibar = Omnibar (
1046- omnibarType = settingsDataStore.omnibarType,
1047- binding = binding,
1048- isUnifiedOmnibarEnabled = omnibarRepository.isUnifiedOmnibarLayoutEnabled,
1049- )
1050- webViewContainer = binding.webViewContainer
1051- viewModel.registerWebViewListener(webViewClient, webChromeClient)
1052- configureWebView()
1053- configureSwipeRefresh()
1054- configureAutoComplete()
1055- configureNewTab()
1056- initPrivacyProtectionsPopup()
1057- createPopupMenu()
1058-
1059- configureNavigationBar()
1060- configureOmnibar()
1061-
1062- configureObservers()
1063-
1064- if (savedInstanceState == null ) {
1065- viewModel.onViewReady()
1066- viewModel.setIsCustomTab(tabDisplayedInCustomTabScreen)
1067- messageFromPreviousTab?.let {
1068- processMessage(it)
1069- }
1070- } else {
1071- viewModel.onViewRecreated()
1044+ omnibar = Omnibar (
1045+ omnibarType = settingsDataStore.omnibarType,
1046+ binding = binding,
1047+ isUnifiedOmnibarEnabled = omnibarRepository.isUnifiedOmnibarLayoutEnabled,
1048+ )
1049+
1050+ webViewContainer = binding.webViewContainer
1051+ configureObservers()
1052+ viewModel.registerWebViewListener(webViewClient, webChromeClient)
1053+ configureWebView()
1054+ configureSwipeRefresh()
1055+ configureAutoComplete()
1056+ configureNewTab()
1057+ initPrivacyProtectionsPopup()
1058+ createPopupMenu()
1059+
1060+ configureNavigationBar()
1061+ configureOmnibar()
1062+
1063+ if (savedInstanceState == null ) {
1064+ viewModel.onViewReady()
1065+ viewModel.setIsCustomTab(tabDisplayedInCustomTabScreen)
1066+ messageFromPreviousTab?.let {
1067+ processMessage(it)
10721068 }
1069+ } else {
1070+ viewModel.onViewRecreated()
1071+ }
10731072
1074- lifecycle.addObserver(
1075- @SuppressLint(" NoLifecycleObserver" ) // we don't observe app lifecycle
1076- object : DefaultLifecycleObserver {
1077- override fun onStop (owner : LifecycleOwner ) {
1078- if (isVisible) {
1079- if (viewModel.browserViewState.value?.maliciousSiteBlocked != true ) {
1080- updateOrDeleteWebViewPreview()
1081- }
1073+ lifecycle.addObserver(
1074+ @SuppressLint(" NoLifecycleObserver" ) // we don't observe app lifecycle
1075+ object : DefaultLifecycleObserver {
1076+ override fun onStop (owner : LifecycleOwner ) {
1077+ if (isVisible) {
1078+ if (viewModel.browserViewState.value?.maliciousSiteBlocked != true ) {
1079+ updateOrDeleteWebViewPreview()
10821080 }
10831081 }
1084- },
1085- )
1086-
1087- childFragmentManager.findFragmentByTag(ADD_SAVED_SITE_FRAGMENT_TAG )?.let { dialog ->
1088- (dialog as EditSavedSiteDialogFragment ).listener = viewModel
1089- dialog.deleteBookmarkListener = viewModel
1090- }
1082+ }
1083+ },
1084+ )
10911085
1092- if (swipingTabsFeature.isEnabled) {
1093- disableSwipingOutsideTheOmnibar()
1094- }
1086+ childFragmentManager.findFragmentByTag(ADD_SAVED_SITE_FRAGMENT_TAG )?.let { dialog ->
1087+ (dialog as EditSavedSiteDialogFragment ).listener = viewModel
1088+ dialog.deleteBookmarkListener = viewModel
1089+ }
10951090
1096- launchDownloadMessagesJob()
1091+ if (swipingTabsFeature.isEnabled) {
1092+ disableSwipingOutsideTheOmnibar()
10971093 }
1094+
1095+ launchDownloadMessagesJob()
10981096 }
10991097
11001098 private fun updateOrDeleteWebViewPreview () {
@@ -2103,9 +2101,7 @@ class BrowserTabFragment :
21032101 }
21042102
21052103 is Command .ResetHistory -> {
2106- lifecycleScope.launch {
2107- resetWebView()
2108- }
2104+ resetWebView()
21092105 }
21102106
21112107 is Command .LaunchPrivacyPro -> {
@@ -3186,7 +3182,7 @@ class BrowserTabFragment :
31863182 }
31873183
31883184 @SuppressLint(" SetJavaScriptEnabled" )
3189- private suspend fun configureWebView () {
3185+ private fun configureWebView () {
31903186 if (! onboardingDesignExperimentManager.isBuckEnrolledAndEnabled()) {
31913187 binding.daxDialogOnboardingCtaContent.layoutTransition = LayoutTransition ()
31923188 binding.daxDialogOnboardingCtaContent.layoutTransition.enableTransitionType(LayoutTransition .CHANGING )
@@ -3211,8 +3207,10 @@ class BrowserTabFragment :
32113207 it.clearSslPreferences()
32123208
32133209 it.settings.apply {
3214- clientBrandHintProvider.setDefault(this )
3215- webViewClient.clientProvider = clientBrandHintProvider
3210+ lifecycleScope.launch {
3211+ clientBrandHintProvider.setDefault(this @apply)
3212+ webViewClient.clientProvider = clientBrandHintProvider
3213+ }
32163214 userAgentString = userAgentProvider.userAgent()
32173215 javaScriptEnabled = true
32183216 domStorageEnabled = true
@@ -3275,11 +3273,14 @@ class BrowserTabFragment :
32753273 onSignedInEmailProtectionPromptShown = { viewModel.showEmailProtectionChooseEmailPrompt() },
32763274 onInContextEmailProtectionSignupPromptShown = { showNativeInContextEmailProtectionSignupPrompt() },
32773275 )
3278- configureWebViewForBlobDownload(it)
3279- webViewCompatTestHelper.configureWebViewForWebViewCompatTest(
3280- it,
3281- isBlobDownloadWebViewFeatureEnabled(it),
3282- )
3276+ lifecycleScope.launch {
3277+ configureWebViewForBlobDownload(it)
3278+ webViewCompatTestHelper.configureWebViewForWebViewCompatTest(
3279+ it,
3280+ isBlobDownloadWebViewFeatureEnabled(it),
3281+ )
3282+ }
3283+
32833284 configureWebViewForAutofill(it)
32843285 printInjector.addJsInterface(it) { viewModel.printFromWebView() }
32853286 autoconsent.addJsInterface(it, autoconsentCallback)
@@ -3315,9 +3316,11 @@ class BrowserTabFragment :
33153316 )
33163317 }
33173318
3318- WebView .setWebContentsDebuggingEnabled(withContext(dispatchers.io()) { webContentDebugging.isEnabled() })
3319+ lifecycleScope.launch {
3320+ WebView .setWebContentsDebuggingEnabled(withContext(dispatchers.io()) { webContentDebugging.isEnabled() })
33193321
3320- webView?.let { passkeyInitializer.configurePasskeySupport(it) }
3322+ webView?.let { passkeyInitializer.configurePasskeySupport(it) }
3323+ }
33213324 }
33223325
33233326 private fun screenLock (data : JsCallbackData ) {
@@ -4072,7 +4075,7 @@ class BrowserTabFragment :
40724075 return viewModel.onUserPressedBack(isCustomTab)
40734076 }
40744077
4075- private suspend fun resetWebView () {
4078+ private fun resetWebView () {
40764079 destroyWebView()
40774080 configureWebView()
40784081 }
0 commit comments