aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt4
9 files changed, 27 insertions, 24 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt
index 8215de03..bc453250 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt
@@ -19,7 +19,7 @@ package com.pitchedapps.frost.debugger
import ca.allanwang.kau.logging.KauLoggerExtension
import ca.allanwang.kau.utils.copyFromInputStream
import com.pitchedapps.frost.facebook.FB_CSS_URL_MATCHER
-import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
+import com.pitchedapps.frost.facebook.USER_AGENT
import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.facebook.requests.call
import com.pitchedapps.frost.utils.createFreshDir
@@ -59,7 +59,7 @@ class OfflineWebsite(
* Directory that holds all the files
*/
val baseDir: File,
- private val userAgent: String = USER_AGENT_DESKTOP
+ private val userAgent: String = USER_AGENT
) {
/**
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
index 032ff31e..c01bce55 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
@@ -28,6 +28,13 @@ fun profilePictureUrl(id: Long) = "https://graph.facebook.com/$id/picture?type=l
const val FB_LOGIN_URL = "${FB_URL_BASE}login"
const val FB_HOME_URL = "${FB_URL_BASE}home.php"
+/*
+ * User agent candidates.
+ * For those building from source, you can feel free to set the used agent to one of these options.
+ * Following https://github.com/AllanWang/Frost-for-Facebook/pull/1531, we do not support multiple
+ * agents per login session.
+ */
+
// Default user agent
private const val USER_AGENT_MOBILE_CONST =
"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A3000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Mobile Safari/537.36"
@@ -35,8 +42,7 @@ private const val USER_AGENT_MOBILE_CONST =
private const val USER_AGENT_DESKTOP_CONST =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Safari/537.36"
-const val USER_AGENT_MOBILE = USER_AGENT_DESKTOP_CONST
-const val USER_AGENT_DESKTOP = USER_AGENT_DESKTOP_CONST
+const val USER_AGENT = USER_AGENT_DESKTOP_CONST
/**
* Animation transition delay, just to ensure that the styles
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
index 8a89b973..b948506f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
@@ -22,7 +22,7 @@ import com.pitchedapps.frost.facebook.FB_JSON_URL_MATCHER
import com.pitchedapps.frost.facebook.FB_REV_MATCHER
import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FB_USER_MATCHER
-import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
+import com.pitchedapps.frost.facebook.USER_AGENT
import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.kotlin.Flyweight
import com.pitchedapps.frost.utils.L
@@ -97,7 +97,7 @@ internal fun List<Pair<String, Any?>>.withEmptyData(vararg key: String): List<Pa
internal fun String?.requestBuilder(): Request.Builder {
val builder = Request.Builder()
- .header("User-Agent", USER_AGENT_DESKTOP)
+ .header("User-Agent", USER_AGENT)
if (this != null)
builder.header("Cookie", this)
// .cacheControl(CacheControl.FORCE_NETWORK)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
index b0012b0d..5e909b03 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt
@@ -31,7 +31,7 @@ import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.toast
import com.pitchedapps.frost.R
import com.pitchedapps.frost.db.CookieEntity
-import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
+import com.pitchedapps.frost.facebook.USER_AGENT
/**
* Created by Allan Wang on 2017-08-04.
@@ -41,7 +41,7 @@ import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
fun Context.frostDownload(
cookie: CookieEntity,
url: String?,
- userAgent: String = USER_AGENT_DESKTOP,
+ userAgent: String = USER_AGENT,
contentDisposition: String? = null,
mimeType: String? = null,
contentLength: Long = 0L
@@ -53,7 +53,7 @@ fun Context.frostDownload(
fun Context.frostDownload(
cookie: CookieEntity,
uri: Uri?,
- userAgent: String = USER_AGENT_DESKTOP,
+ userAgent: String = USER_AGENT,
contentDisposition: String? = null,
mimeType: String? = null,
contentLength: Long = 0L
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 9022d51f..c2f28a4b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -63,7 +63,7 @@ import com.pitchedapps.frost.facebook.FBCDN_NET
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.USER_AGENT
import com.pitchedapps.frost.facebook.formattedFbUri
import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.injectors.CssAssets
@@ -74,6 +74,7 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.apache.commons.text.StringEscapeUtils
import org.jsoup.Jsoup
+import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.io.File
import java.io.IOException
@@ -388,13 +389,13 @@ fun EmailBuilder.addFrostDetails() {
addItem("Locale", Locale.getDefault().displayName)
}
-fun frostJsoup(url: String) = frostJsoup(FbCookie.webCookie, url)
+fun frostJsoup(url: String): Document = frostJsoup(FbCookie.webCookie, url)
-fun frostJsoup(cookie: String?, url: String) =
+fun frostJsoup(cookie: String?, url: String): Document =
Jsoup.connect(url).run {
if (cookie.isNullOrBlank()) this
else cookie(FACEBOOK_COM, cookie)
- }.userAgent(USER_AGENT_DESKTOP).get()!!
+ }.userAgent(USER_AGENT).get()
fun Element.first(vararg select: String): Element? {
select.forEach {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
index cbcd1054..5b564102 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -31,9 +31,7 @@ import com.pitchedapps.frost.contracts.FrostContentParent
import com.pitchedapps.frost.db.FrostDatabase
import com.pitchedapps.frost.db.currentCookie
import com.pitchedapps.frost.facebook.FB_HOME_URL
-import com.pitchedapps.frost.facebook.FbItem
-import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP
-import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE
+import com.pitchedapps.frost.facebook.USER_AGENT
import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.ctxCoroutine
@@ -42,7 +40,6 @@ import com.pitchedapps.frost.web.FrostChromeClient
import com.pitchedapps.frost.web.FrostJSI
import com.pitchedapps.frost.web.FrostWebViewClient
import com.pitchedapps.frost.web.NestedWebView
-import com.pitchedapps.frost.web.shouldUseDesktopAgent
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
@@ -72,9 +69,7 @@ class FrostWebView @JvmOverloads constructor(
@SuppressLint("SetJavaScriptEnabled")
override fun bind(container: FrostContentContainer): View {
- userAgentString =
- if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseDesktopAgent) USER_AGENT_DESKTOP
- else USER_AGENT_MOBILE
+ userAgentString = USER_AGENT
with(settings) {
javaScriptEnabled = true
mediaPlaybackRequiresUserGesture = false // TODO check if we need this
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
index c66180ed..b71f9950 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
@@ -24,7 +24,7 @@ import android.util.AttributeSet
import android.view.View
import android.webkit.WebView
import ca.allanwang.kau.utils.withAlpha
-import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE
+import com.pitchedapps.frost.facebook.USER_AGENT
import com.pitchedapps.frost.injectors.CssHider
import com.pitchedapps.frost.injectors.jsInject
import com.pitchedapps.frost.utils.L
@@ -55,7 +55,7 @@ class DebugWebView @JvmOverloads constructor(
@SuppressLint("SetJavaScriptEnabled")
private fun setupWebview() {
settings.javaScriptEnabled = true
- settings.userAgentString = USER_AGENT_MOBILE
+ settings.userAgentString = USER_AGENT
setLayerType(View.LAYER_TYPE_HARDWARE, null)
webViewClient = DebugClient()
@Suppress("DEPRECATION")
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
index eec5a5dc..24608a8b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
@@ -85,6 +85,7 @@ val messageWhitelist: Set<String> =
setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECENT, FbItem.FEED_TOP_STORIES)
.mapTo(mutableSetOf(), FbItem::url)
+@Deprecated(message = "Should not be used in production as we only support one user agent at a time.")
val String.shouldUseDesktopAgent: Boolean
get() = when {
contains("story.php") -> false // do not use desktop for comment section
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
index 8e437c29..857c166d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -33,7 +33,7 @@ import com.pitchedapps.frost.db.CookieEntity
import com.pitchedapps.frost.facebook.FB_LOGIN_URL
import com.pitchedapps.frost.facebook.FB_USER_MATCHER
import com.pitchedapps.frost.facebook.FbCookie
-import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE
+import com.pitchedapps.frost.facebook.USER_AGENT
import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.injectors.CssHider
import com.pitchedapps.frost.injectors.jsInject
@@ -58,7 +58,7 @@ class LoginWebView @JvmOverloads constructor(
@SuppressLint("SetJavaScriptEnabled")
private fun setupWebview() {
settings.javaScriptEnabled = true
- settings.userAgentString = USER_AGENT_MOBILE
+ settings.userAgentString = USER_AGENT
setLayerType(View.LAYER_TYPE_HARDWARE, null)
webViewClient = LoginClient()
webChromeClient = LoginChromeClient()