Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ import com.duckduckgo.savedsites.api.models.SavedSitesNames
import com.duckduckgo.savedsites.impl.bookmarks.BookmarksBottomSheetDialog
import com.duckduckgo.savedsites.impl.bookmarks.FaviconPromptSheet
import com.duckduckgo.savedsites.impl.dialogs.EditSavedSiteDialogFragment
import com.duckduckgo.serp.logos.api.SerpLogoScreens.*
import com.duckduckgo.serp.logos.api.SerpLogoScreens.EasterEggLogoScreen
import com.duckduckgo.serp.logos.api.SerpLogos
import com.duckduckgo.site.permissions.api.SitePermissionsDialogLauncher
import com.duckduckgo.site.permissions.api.SitePermissionsGrantedListener
Expand Down Expand Up @@ -599,6 +599,9 @@ class BrowserTabFragment :
@Inject
lateinit var omnibarFeatureRepository: OmnibarFeatureRepository

@Inject
lateinit var webViewCompatTestHelper: WebViewCompatTestHelper

/**
* We use this to monitor whether the user was seeing the in-context Email Protection signup prompt
* This is needed because the activity stack will be cleared if an external link is opened in our browser
Expand Down Expand Up @@ -3246,6 +3249,9 @@ class BrowserTabFragment :
onInContextEmailProtectionSignupPromptShown = { showNativeInContextEmailProtectionSignupPrompt() },
)
configureWebViewForBlobDownload(it)
lifecycleScope.launch {
webViewCompatTestHelper.configureWebViewForWebViewCompatTest(it)
}
configureWebViewForAutofill(it)
printInjector.addJsInterface(it) { viewModel.printFromWebView() }
autoconsent.addJsInterface(it, autoconsentCallback)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2025 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.browser

import com.duckduckgo.app.browser.webview.WebViewCompatFeature
import com.duckduckgo.app.browser.webview.WebViewCompatFeatureSettings
import com.duckduckgo.browser.api.webviewcompat.WebViewCompatWrapper
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.FragmentScope
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.moshi.Moshi
import dagger.SingleInstanceIn
import kotlinx.coroutines.withContext
import javax.inject.Inject

private const val delay = "\$DELAY$"
private const val postInitialPing = "\$POST_INITIAL_PING$"
private const val replyToNativeMessages = "\$REPLY_TO_NATIVE_MESSAGES$"

interface WebViewCompatTestHelper {
suspend fun configureWebViewForWebViewCompatTest(webView: DuckDuckGoWebView)
}

@ContributesBinding(FragmentScope::class)
@SingleInstanceIn(FragmentScope::class)
class RealWebViewCompatTestHelper @Inject constructor(
private val dispatchers: DispatcherProvider,
private val webViewCompatFeature: WebViewCompatFeature,
private val webViewCompatWrapper: WebViewCompatWrapper,
moshi: Moshi,
) : WebViewCompatTestHelper {

private val adapter = moshi.adapter(WebViewCompatFeatureSettings::class.java)

override suspend fun configureWebViewForWebViewCompatTest(webView: DuckDuckGoWebView) {
val script = withContext(dispatchers.io()) {
if (!webViewCompatFeature.self().isEnabled()) return@withContext null

val webViewCompatSettings = webViewCompatFeature.self().getSettings()?.let {
adapter.fromJson(it)
}
webView.resources?.openRawResource(R.raw.webviewcompat_test_script)?.bufferedReader().use { it?.readText() }.orEmpty()
.replace(delay, webViewCompatSettings?.jsInitialPingDelay?.toString() ?: "0")
.replace(postInitialPing, webViewCompatFeature.jsSendsInitialPing().isEnabled().toString())
.replace(replyToNativeMessages, webViewCompatFeature.jsRepliesToNativeMessages().isEnabled().toString())
} ?: return

withContext(dispatchers.main()) {
webViewCompatWrapper.addDocumentStartJavaScript(webView, script, setOf("*"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.browser.webview

import com.duckduckgo.anvil.annotations.ContributesRemoteFeature
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.feature.toggles.api.Toggle
import com.duckduckgo.feature.toggles.api.Toggle.DefaultFeatureValue

@ContributesRemoteFeature(
scope = AppScope::class,
featureName = "webViewCompat",
)
interface WebViewCompatFeature {

@Toggle.DefaultValue(DefaultFeatureValue.FALSE)
fun self(): Toggle

@Toggle.DefaultValue(DefaultFeatureValue.FALSE)
fun jsSendsInitialPing(): Toggle

@Toggle.DefaultValue(DefaultFeatureValue.FALSE)
fun jsRepliesToNativeMessages(): Toggle
}

data class WebViewCompatFeatureSettings(
val jsInitialPingDelay: Long = 0,
)
Loading