|
|
|
@ -17,12 +17,12 @@ import java.net.URL
|
|
|
|
|
|
|
|
|
|
class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
|
|
|
|
|
override fun onLoadRequest(session: EngineSession, uri: String): RequestInterceptor.InterceptionResponse? {
|
|
|
|
|
adjustTrackingProtection(uri, context)
|
|
|
|
|
adjustTrackingProtection(uri, 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) {
|
|
|
|
|
private fun adjustTrackingProtection(url: String, context: Context, session: EngineSession) {
|
|
|
|
|
val host = try {
|
|
|
|
|
URL(url).host
|
|
|
|
|
} catch (e: MalformedURLException) {
|
|
|
|
@ -30,21 +30,13 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
|
|
|
|
|
}
|
|
|
|
|
val trackingProtectionException = ExceptionDomains.load(context).contains(host)
|
|
|
|
|
val trackingProtectionEnabled = Settings.getInstance(context).shouldUseTrackingProtection
|
|
|
|
|
val core = context.components.core
|
|
|
|
|
if (trackingProtectionException || !trackingProtectionEnabled) {
|
|
|
|
|
with(core.sessionManager) {
|
|
|
|
|
selectedSession?.let {
|
|
|
|
|
getEngineSession(it)?.disableTrackingProtection()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
session.disableTrackingProtection()
|
|
|
|
|
} else {
|
|
|
|
|
val core = context.components.core
|
|
|
|
|
val policy = core.createTrackingProtectionPolicy(normalMode = true)
|
|
|
|
|
core.engine.settings.trackingProtectionPolicy = policy
|
|
|
|
|
with(core.sessionManager) {
|
|
|
|
|
selectedSession?.let {
|
|
|
|
|
getEngineSession(it)?.enableTrackingProtection(policy)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
session.enableTrackingProtection(policy)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|