mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/1134: Set UA to GeckoView 69.0 for whitelisted domains
This commit is contained in:
parent
197eabd0c6
commit
8f7da1d247
@ -9,6 +9,7 @@ import mozilla.components.browser.errorpages.ErrorPages
|
||||
import mozilla.components.browser.errorpages.ErrorType
|
||||
import mozilla.components.concept.engine.EngineSession
|
||||
import mozilla.components.concept.engine.request.RequestInterceptor
|
||||
import org.mozilla.fenix.browser.UserAgentRewriter
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.exceptions.ExceptionDomains
|
||||
import org.mozilla.fenix.ext.components
|
||||
@ -18,17 +19,20 @@ import java.net.URL
|
||||
|
||||
class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
|
||||
override fun onLoadRequest(session: EngineSession, uri: String): RequestInterceptor.InterceptionResponse? {
|
||||
adjustTrackingProtection(uri, context, session)
|
||||
val host = try {
|
||||
URL(uri).host
|
||||
} catch (e: MalformedURLException) {
|
||||
uri
|
||||
}
|
||||
|
||||
UserAgentRewriter.maybeRewriteUserAgent(session, host)
|
||||
|
||||
adjustTrackingProtection(host, context, session)
|
||||
// Accounts uses interception to check for a "success URL" in the sign-in flow to finalize authentication.
|
||||
return context.components.services.accountsAuthFeature.interceptor.onLoadRequest(session, uri)
|
||||
}
|
||||
|
||||
private fun adjustTrackingProtection(url: String, context: Context, session: EngineSession) {
|
||||
val host = try {
|
||||
URL(url).host
|
||||
} catch (e: MalformedURLException) {
|
||||
url
|
||||
}
|
||||
private fun adjustTrackingProtection(host: String, context: Context, session: EngineSession) {
|
||||
val trackingProtectionException = ExceptionDomains.load(context).contains(host)
|
||||
val trackingProtectionEnabled = Settings.getInstance(context).shouldUseTrackingProtection
|
||||
if (trackingProtectionException || !trackingProtectionEnabled) {
|
||||
|
@ -0,0 +1,37 @@
|
||||
package org.mozilla.fenix.browser
|
||||
|
||||
import android.os.Build.VERSION.RELEASE
|
||||
import mozilla.components.concept.engine.EngineSession
|
||||
import mozilla.components.support.ktx.kotlin.sha1
|
||||
|
||||
/**
|
||||
* Utility to rewrite the User-Agent header for requests to whitelisted domains.
|
||||
*
|
||||
* Follow up: https://github.com/mozilla-mobile/fenix/issues/3341
|
||||
*/
|
||||
object UserAgentRewriter {
|
||||
|
||||
/**
|
||||
* Updates the User-Agent based on the [whitelistUaFilter] to set the [userAgentGecko69] value.
|
||||
*/
|
||||
fun maybeRewriteUserAgent(session: EngineSession, host: String) {
|
||||
session.settings.userAgentString = if (whitelistUaFilter.contains(host.sha1())) {
|
||||
userAgentGecko69
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The white-listed domains.
|
||||
*/
|
||||
private val whitelistUaFilter = setOf(
|
||||
"1b12ecd917215146f79a0ac5e01b3059faadab47",
|
||||
"a486f819018512f60a8a66324e51be0e1118a91d"
|
||||
)
|
||||
|
||||
/**
|
||||
* The User-Agent to use for the white-listed domains.
|
||||
*/
|
||||
private val userAgentGecko69 = "Mozilla/5.0 (Android $RELEASE; Mobile; rv:69.0) Gecko/69.0 Firefox/69.0"
|
||||
}
|
Loading…
Reference in New Issue
Block a user