From a739d5a9e5175ae2370b4f04d5d3e2217e6031be Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Tue, 14 May 2019 10:15:00 -0700 Subject: [PATCH] For #2336 - Pass EngineSession to TP adjustment fun --- .../org/mozilla/fenix/AppRequestInterceptor.kt | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt b/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt index cc46171cc..f9802686e 100644 --- a/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt +++ b/app/src/main/java/org/mozilla/fenix/AppRequestInterceptor.kt @@ -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) } }