diff options
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt | 12 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 14 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt | 21 | ||||
-rw-r--r-- | app/src/main/play/en-US/whatsnew | 3 | ||||
-rw-r--r-- | app/src/main/res/xml/frost_changelog.xml | 2 | ||||
-rw-r--r-- | docs/Changelog.md | 1 |
6 files changed, 41 insertions, 12 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt index 6208f401..16cbc9c8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt @@ -16,6 +16,7 @@ */ package com.pitchedapps.frost.facebook +import android.net.Uri import com.pitchedapps.frost.utils.L import java.net.URLDecoder import java.nio.charset.StandardCharsets @@ -28,6 +29,12 @@ import java.nio.charset.StandardCharsets inline val String.formattedFbUrl: String get() = FbUrlFormatter(this).toString() +inline val Uri.formattedFbUri: Uri + get() { + val url = toString() + return if (url.startsWith("http")) Uri.parse(url.formattedFbUrl) else this + } + class FbUrlFormatter(url: String) { private val queries = mutableMapOf<String, String>() private val cleaned: String @@ -72,7 +79,10 @@ class FbUrlFormatter(url: String) { } discardableQueries.forEach { queries.remove(it) } if (cleanedUrl.startsWith("/")) cleanedUrl = FB_URL_BASE + cleanedUrl.substring(1) - cleanedUrl = cleanedUrl.replaceFirst(".facebook.com//", ".facebook.com/") //sometimes we are given a bad url + cleanedUrl = cleanedUrl.replaceFirst( + ".facebook.com//", + ".facebook.com/" + ) //sometimes we are given a bad url L.v { "Formatted url from $url to $cleanedUrl" } return cleanedUrl } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index 8544aac3..0367457e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -65,6 +65,7 @@ import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.FbUrlFormatter.Companion.VIDEO_REDIRECT import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP +import com.pitchedapps.frost.facebook.formattedFbUri import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.injectors.CssAssets import com.pitchedapps.frost.injectors.JsAssets @@ -270,9 +271,16 @@ fun Context.createPrivateMediaFile(extension: String) = createPrivateMediaFile(" */ fun Context.resolveActivityForUri(uri: Uri): Boolean { val url = uri.toString() - if (url.isFacebookUrl && !url.isExplicitIntent) return false - val intent = Intent(Intent.ACTION_VIEW, uri) - if (intent.resolveActivity(packageManager) == null) return false + if (url.isFacebookUrl && !url.isExplicitIntent) { + return false + } + val intent = Intent( + Intent.ACTION_VIEW, + uri.formattedFbUri + ) + if (intent.resolveActivity(packageManager) == null) { + return false + } startActivity(intent) return true } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index 85914f33..ecedc997 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -54,7 +54,10 @@ import kotlinx.coroutines.channels.SendChannel */ open class BaseWebViewClient : WebViewClient() { - override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? = + override fun shouldInterceptRequest( + view: WebView, + request: WebResourceRequest + ): WebResourceResponse? = view.shouldFrostInterceptRequest(request) } @@ -173,12 +176,18 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { view.context.resolveActivityForUri(request.url) return true } - if (path.startsWith("/composer/")) return launchRequest(request) - if (url.isImageUrl) - return launchImage(url.formattedFbUrl) - if (url.isIndirectImageUrl) + if (path.startsWith("/composer/")) { + return launchRequest(request) + } + if (url.isIndirectImageUrl) { return launchImage(url.formattedFbUrl, cookie = FbCookie.webCookie) - if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) return true + } + if (url.isImageUrl) { + return launchImage(url.formattedFbUrl) + } + if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) { + return true + } return super.shouldOverrideUrlLoading(view, request) } } diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index d2b73404..a9aab7e3 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -2,4 +2,5 @@ v2.3.2 * Disable auto feed refresh by default and add setting to re-enable it * Update theme -* Disable bugsnag completely when opting out of analytics
\ No newline at end of file +* Disable bugsnag completely when opting out of analytics +* Filter urls before sending to other apps
\ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 09bb9d2e..21140984 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -11,7 +11,7 @@ <item text="Disable auto feed refresh by default and add setting to re-enable it" /> <item text="Update theme" /> <item text="Disable bugsnag completely when opting out of analytics" /> - <item text="" /> + <item text="Filter urls before sending to other apps" /> <item text="" /> <item text="" /> diff --git a/docs/Changelog.md b/docs/Changelog.md index 949eb8d4..a04a5f2c 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4,6 +4,7 @@ * Disable auto feed refresh by default and add setting to re-enable it * Update theme * Disable bugsnag completely when opting out of analytics +* Filter urls before sending to other apps ## v2.3.1 * Hide all story panels if enabled |