1
0
Fork 0

For #2336 - Pass EngineSession to TP adjustment fun

master
Emily Kager 2019-05-14 10:15:00 -07:00 committed by Emily Kager
parent 43a4b1b77c
commit a739d5a9e5
1 changed files with 5 additions and 13 deletions

View File

@ -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)
}
}