diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-19 09:47:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-19 09:47:05 -0700 |
commit | 84bf883a47b956865d31b1b618d5495fcd7d4876 (patch) | |
tree | 0fb0f83af4862a127bca7d8451ef2c7188a08d83 /app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt | |
parent | 5d9a3fd7fb8f2f9d0f592c89446824980c9841c6 (diff) | |
download | frost-1.4.7.tar.gz frost-1.4.7.tar.bz2 frost-1.4.7.zip |
v1.4.7 (#195)v1.4.7
* Add try catch (#179)
* Add checks before injections (#180)
* Enhancement/url redirect manager (#182)
* Initial blacklist
* Move js checks to java
* Optimize imports and clean up request interceptor
* Misc (#190)
* Update play store description
* Finalize description
* Update kotlin and bg2 for custom themes
* Update to Android Studio 3.0 beta 2
* Update test dependencies and add logging to image activity
* Rename throwable to errorRef
* Update searchview and media picker through kau
* Update themes (#183)
* Theme content now found view
* Update verified bg and bg2 for transparent themes
* Fix check in star text
* Various fixes
* Create base svg sass images
* Feature/theme accent (#192)
* Add lots of theming components
* Optimize and add
* Update accents
* Misc 2 (#191)
* Add further checks for iab and remove generic error dialog
* Theme all snackbars
* Add dynamic media action tile
* Enhancement/media-camera-picker (#194)
* Update kau
* Update changelog
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt index 1a907f7f..2dfdda89 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt @@ -3,6 +3,8 @@ package com.pitchedapps.frost.web import android.webkit.WebResourceRequest import android.webkit.WebResourceResponse import android.webkit.WebView +import ca.allanwang.kau.kotlin.LazyContext +import ca.allanwang.kau.kotlin.lazyContext import ca.allanwang.kau.utils.use import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs @@ -19,41 +21,37 @@ import java.io.ByteArrayInputStream private val blankResource: WebResourceResponse by lazy { WebResourceResponse("text/plain", "utf-8", ByteArrayInputStream("".toByteArray())) } //these hosts will redirect to a blank resource -private val blacklistHost: Set<String> by lazy { - setOf( - "edge-chat.facebook.com" - ) -} +private val blacklistHost: Set<String> = + setOf( + "edge-chat.facebook.com" + ) //these hosts will return null and skip logging -private val whitelistHost: Set<String> by lazy { - setOf( - "static.xx.fbcdn.net", - "m.facebook.com", - "touch.facebook.com" - ) -} +private val whitelistHost: Set<String> = + setOf( + "static.xx.fbcdn.net", + "m.facebook.com", + "touch.facebook.com" + ) //these hosts will skip ad inspection //this list does not have to include anything from the two above -private val adWhitelistHost: Set<String> by lazy { - setOf( - "scontent-sea1-1.xx.fbcdn.net" - ) -} +private val adWhitelistHost: Set<String> = + setOf( + "scontent-sea1-1.xx.fbcdn.net" + ) -private var adblock: Set<String>? = null +private val adblock: LazyContext<Set<String>> = lazyContext { + it.assets.open("adblock.txt").bufferedReader().use { it.readLines().toSet() } +} -fun shouldFrostInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? { +fun WebView.shouldFrostInterceptRequest(request: WebResourceRequest): WebResourceResponse? { val httpUrl = HttpUrl.parse(request.url?.toString() ?: return null) ?: return null val host = httpUrl.host() val url = httpUrl.toString() if (blacklistHost.contains(host)) return blankResource if (whitelistHost.contains(host)) return null - if (!adWhitelistHost.contains(host)) { - if (adblock == null) adblock = view.context.assets.open("adblock.txt").bufferedReader().use { it.readLines().toSet() } - if (adblock?.any { url.contains(it) } ?: false) return blankResource - } + if (!adWhitelistHost.contains(host) && adblock(context).any { url.contains(it) }) return blankResource if (!shouldLoadImages && !Prefs.loadMediaOnMeteredNetwork && request.isMedia) return blankResource L.v("Intercept Request", "$host $url") return null |