Skip to content

Commit e4e4e16

Browse files
committed
Don't check featuresRequestHeader from main in renderOmnibarViewState
1 parent f2b9eaa commit e4e4e16

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,9 @@ class BrowserTabViewModel @Inject constructor(
11921192
}
11931193

11941194
site?.nextUrl = urlToNavigate
1195-
command.value = NavigationCommand.Navigate(urlToNavigate, getUrlHeaders(urlToNavigate))
1195+
viewModelScope.launch {
1196+
command.value = NavigationCommand.Navigate(urlToNavigate, getUrlHeaders(urlToNavigate))
1197+
}
11961198
}
11971199
}
11981200

@@ -1217,7 +1219,7 @@ class BrowserTabViewModel @Inject constructor(
12171219
currentAutoCompleteViewState().copy(showSuggestions = false, showFavorites = false, searchResults = AutoCompleteResult("", emptyList()))
12181220
}
12191221

1220-
private fun getUrlHeaders(url: String?): Map<String, String> = url?.let { customHeadersProvider.getCustomHeaders(it) } ?: emptyMap()
1222+
private suspend fun getUrlHeaders(url: String?): Map<String, String> = url?.let { customHeadersProvider.getCustomHeaders(it) } ?: emptyMap()
12211223

12221224
private fun extractVerticalParameter(currentUrl: String?): String? {
12231225
val url = currentUrl ?: return null
@@ -2769,7 +2771,9 @@ class BrowserTabViewModel @Inject constructor(
27692771
if (desktopSiteRequested && uri.isMobileSite) {
27702772
val desktopUrl = uri.toDesktopUri().toString()
27712773
logcat(INFO) { "Original URL $url - attempting $desktopUrl with desktop site UA string" }
2772-
command.value = NavigationCommand.Navigate(desktopUrl, getUrlHeaders(desktopUrl))
2774+
viewModelScope.launch {
2775+
command.value = NavigationCommand.Navigate(desktopUrl, getUrlHeaders(desktopUrl))
2776+
}
27732777
} else {
27742778
command.value = NavigationCommand.Refresh
27752779
}
@@ -3139,7 +3143,9 @@ class BrowserTabViewModel @Inject constructor(
31393143

31403144
fun nonHttpAppLinkClicked(appLink: NonHttpAppLink) {
31413145
if (nonHttpAppLinkChecker.isPermitted(appLink.intent)) {
3142-
command.value = HandleNonHttpAppLink(appLink, getUrlHeaders(appLink.fallbackUrl))
3146+
viewModelScope.launch {
3147+
command.value = HandleNonHttpAppLink(appLink, getUrlHeaders(appLink.fallbackUrl))
3148+
}
31433149
}
31443150
}
31453151

common/common-utils/src/main/java/com/duckduckgo/common/utils/plugins/headers/CustomHeadersProvider.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package com.duckduckgo.common.utils.plugins.headers
1818

1919
import com.duckduckgo.anvil.annotations.ContributesPluginPoint
20+
import com.duckduckgo.common.utils.DispatcherProvider
2021
import com.duckduckgo.common.utils.plugins.PluginPoint
2122
import com.duckduckgo.di.scopes.AppScope
2223
import com.squareup.anvil.annotations.ContributesBinding
24+
import kotlinx.coroutines.withContext
2325
import javax.inject.Inject
2426

2527
interface CustomHeadersProvider {
@@ -29,7 +31,7 @@ interface CustomHeadersProvider {
2931
* @param url The url of the request.
3032
* @return A [Map] of headers.
3133
*/
32-
fun getCustomHeaders(url: String): Map<String, String>
34+
suspend fun getCustomHeaders(url: String): Map<String, String>
3335

3436
/**
3537
* A plugin point for custom headers that should be added to all requests.
@@ -50,13 +52,16 @@ interface CustomHeadersProvider {
5052
@ContributesBinding(AppScope::class)
5153
class RealCustomHeadersProvider @Inject constructor(
5254
private val customHeadersPluginPoint: PluginPoint<CustomHeadersProvider.CustomHeadersPlugin>,
55+
private val dispatcherProvider: DispatcherProvider,
5356
) : CustomHeadersProvider {
5457

55-
override fun getCustomHeaders(url: String): Map<String, String> {
56-
val customHeaders = mutableMapOf<String, String>()
57-
customHeadersPluginPoint.getPlugins().forEach {
58-
customHeaders.putAll(it.getHeaders(url))
58+
override suspend fun getCustomHeaders(url: String): Map<String, String> {
59+
return withContext(dispatcherProvider.io()) {
60+
val customHeaders = mutableMapOf<String, String>()
61+
customHeadersPluginPoint.getPlugins().forEach {
62+
customHeaders.putAll(it.getHeaders(url))
63+
}
64+
return@withContext customHeaders.toMap()
5965
}
60-
return customHeaders.toMap()
6166
}
6267
}

0 commit comments

Comments
 (0)