@@ -182,7 +182,6 @@ import com.duckduckgo.app.browser.webshare.WebViewCompatWebShareChooser
182182import com.duckduckgo.app.browser.webview.WebContentDebugging
183183import com.duckduckgo.app.browser.webview.WebViewBlobDownloadFeature
184184import com.duckduckgo.app.browser.webview.WebViewCompatFeature
185- import com.duckduckgo.app.browser.webview.WebViewCompatFeatureSettings
186185import com.duckduckgo.app.browser.webview.safewebview.SafeWebViewFeature
187186import com.duckduckgo.app.cta.ui.BrokenSitePromptDialogCta
188187import com.duckduckgo.app.cta.ui.Cta
@@ -344,8 +343,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
344343import com.google.android.material.bottomsheet.BottomSheetDialogFragment
345344import com.google.android.material.snackbar.BaseTransientBottomBar
346345import com.google.android.material.snackbar.Snackbar
347- import com.squareup.moshi.Moshi
348- import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
349346import kotlinx.coroutines.CoroutineScope
350347import kotlinx.coroutines.Job
351348import kotlinx.coroutines.SupervisorJob
@@ -605,6 +602,9 @@ class BrowserTabFragment :
605602 @Inject
606603 lateinit var webViewCompatFeature: WebViewCompatFeature
607604
605+ @Inject
606+ lateinit var webViewCompatTestHelper: WebViewCompatTestHelper
607+
608608 /* *
609609 * We use this to monitor whether the user was seeing the in-context Email Protection signup prompt
610610 * This is needed because the activity stack will be cleared if an external link is opened in our browser
@@ -3224,7 +3224,9 @@ class BrowserTabFragment :
32243224 onInContextEmailProtectionSignupPromptShown = { showNativeInContextEmailProtectionSignupPrompt() },
32253225 )
32263226 configureWebViewForBlobDownload(it)
3227- configureWebViewForWebViewCompatTest(it)
3227+ lifecycleScope.launch {
3228+ webViewCompatTestHelper.configureWebViewForWebViewCompatTest(it)
3229+ }
32283230 configureWebViewForAutofill(it)
32293231 printInjector.addJsInterface(it) { viewModel.printFromWebView() }
32303232 autoconsent.addJsInterface(it, autoconsentCallback)
@@ -3347,32 +3349,6 @@ class BrowserTabFragment :
33473349 daxDialogIntroBubble.root.gone()
33483350 }
33493351
3350- private var proxy: JavaScriptReplyProxy ? = null
3351-
3352- private val delay = " \$ DELAY$"
3353- private val postInitialPing = " \$ POST_INITIAL_PING$"
3354- private val replyToNativeMessages = " \$ REPLY_TO_NATIVE_MESSAGES$"
3355-
3356- private fun configureWebViewForWebViewCompatTest (webView : DuckDuckGoWebView ) {
3357- lifecycleScope.launch(dispatchers.main()) {
3358- val script = withContext(dispatchers.io()) {
3359- if (! webViewCompatFeature.self().isEnabled()) return @withContext null
3360-
3361- val moshi = Moshi .Builder ().add(KotlinJsonAdapterFactory ()).build()
3362- val adapter = moshi.adapter(WebViewCompatFeatureSettings ::class .java)
3363- val webViewCompatSettings = webViewCompatFeature.self().getSettings()?.let {
3364- adapter.fromJson(it)
3365- }
3366- context?.resources?.openRawResource(R .raw.webviewcompat_test_script)?.bufferedReader().use { it?.readText() }.orEmpty()
3367- .replace(delay, webViewCompatSettings?.jsInitialPingDelay?.toString() ? : " 0" )
3368- .replace(postInitialPing, webViewCompatFeature.jsSendsInitialPing().isEnabled().toString())
3369- .replace(replyToNativeMessages, webViewCompatFeature.jsRepliesToNativeMessages().isEnabled().toString())
3370- } ? : return @launch
3371-
3372- webViewCompatWrapper.addDocumentStartJavaScript(webView, script, setOf (" *" ))
3373- }
3374- }
3375-
33763352 @SuppressLint(" AddDocumentStartJavaScriptUsage" )
33773353 private fun configureWebViewForBlobDownload (webView : DuckDuckGoWebView ) {
33783354 lifecycleScope.launch(dispatchers.main()) {
0 commit comments