From e8c52e6ab127dae71d51b7b54c98bfd724568de3 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 13 Apr 2019 19:52:24 -0400 Subject: Update user agent (#1400) * Rename user agent and update chrome for desktop, resolves #1387 * Rename more basic to desktop * Apply spotless --- .../frost/activities/WebOverlayActivity.kt | 12 ++++++------ .../com/pitchedapps/frost/debugger/OfflineWebsite.kt | 4 ++-- .../kotlin/com/pitchedapps/frost/facebook/FbConst.kt | 8 ++++---- .../pitchedapps/frost/facebook/requests/FbRequest.kt | 4 ++-- .../kotlin/com/pitchedapps/frost/utils/Downloader.kt | 6 +++--- .../main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 8 ++++---- .../com/pitchedapps/frost/views/FrostWebView.kt | 10 +++++----- .../kotlin/com/pitchedapps/frost/web/DebugWebView.kt | 4 ++-- .../frost/web/FrostUrlOverlayValidator.kt | 20 ++++++++++---------- .../kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 1 - 10 files changed, 38 insertions(+), 39 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index 1ea655d1..accf9d98 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -58,7 +58,7 @@ import com.pitchedapps.frost.enums.OverlayContext import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_BASIC +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.kotlin.subscribeDuringJob import com.pitchedapps.frost.services.FrostRunnable @@ -141,10 +141,10 @@ class FrostWebActivity : WebOverlayActivityBase(false) { } /** - * Variant that forces a basic user agent. This is largely internal, + * Variant that forces a desktop user agent. This is largely internal, * and is only necessary when we are launching from an existing [WebOverlayActivityBase] */ -class WebOverlayBasicActivity : WebOverlayActivityBase(true) +class WebOverlayDesktopActivity : WebOverlayActivityBase(true) /** * Internal overlay for the app; this is tied with the main task and is singleTop as opposed to singleInstance @@ -153,7 +153,7 @@ class WebOverlayActivity : WebOverlayActivityBase(false) @SuppressLint("Registered") @UseExperimental(ExperimentalCoroutinesApi::class) -open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseActivity(), +open class WebOverlayActivityBase(private val forceDesktopAgent: Boolean) : BaseActivity(), ActivityContract, FrostContentContainer, VideoViewHolder, FileChooserContract by FileChooserDelegate() { @@ -210,8 +210,8 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc } with(web) { - if (forceBasicAgent) //todo check; the webview already adds it dynamically - userAgentString = USER_AGENT_BASIC + if (forceDesktopAgent) //todo check; the webview already adds it dynamically + userAgentString = USER_AGENT_DESKTOP Prefs.prevId = Prefs.userId launch { if (userId != Prefs.userId) 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 30c812db..f128edcf 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_BASIC +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP 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_BASIC + private val userAgent: String = USER_AGENT_DESKTOP ) { /** 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 8bca6b67..f6316470 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -29,11 +29,11 @@ const val FB_LOGIN_URL = "${FB_URL_BASE}login" const val FB_HOME_URL = "${FB_URL_BASE}home.php" // Default user agent -const val USER_AGENT_FULL = +const val USER_AGENT_MOBILE = "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" -// Basic user agent; non mobile version -const val USER_AGENT_BASIC = - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" +// Desktop agent, for pages like messages +const val USER_AGENT_DESKTOP = + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.90 Safari/537.36" /** * 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 b49fd970..8a89b973 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_BASIC +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP 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>.withEmptyData(vararg key: String): List Context.launchWebOverlay fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl(url) -fun Context.launchWebOverlayBasic(url: String) = launchWebOverlayImpl(url) +fun Context.launchWebOverlayDesktop(url: String) = launchWebOverlayImpl(url) private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation( this, @@ -393,7 +393,7 @@ fun frostJsoup(cookie: String?, url: String) = Jsoup.connect(url).run { if (cookie.isNullOrBlank()) this else cookie(FACEBOOK_COM, cookie) - }.userAgent(USER_AGENT_BASIC).get()!! + }.userAgent(USER_AGENT_DESKTOP).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 37b2234d..cc8e3fbc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -29,8 +29,8 @@ import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.facebook.FB_HOME_URL import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_BASIC -import com.pitchedapps.frost.facebook.USER_AGENT_FULL +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP +import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE import com.pitchedapps.frost.fragments.WebFragment import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.frostDownload @@ -38,7 +38,7 @@ 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.shouldUseBasicAgent +import com.pitchedapps.frost.web.shouldUseDesktopAgent /** * Created by Allan Wang on 2017-05-29. @@ -66,8 +66,8 @@ class FrostWebView @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") override fun bind(container: FrostContentContainer): View { userAgentString = - if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseBasicAgent) USER_AGENT_BASIC - else USER_AGENT_FULL + if (parent.baseEnum == FbItem.MESSAGES || parent.baseUrl.shouldUseDesktopAgent) USER_AGENT_DESKTOP + else USER_AGENT_MOBILE 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 e278db80..6511ef9f 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_FULL +import com.pitchedapps.frost.facebook.USER_AGENT_MOBILE 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_FULL + settings.userAgentString = USER_AGENT_MOBILE setLayerType(View.LAYER_TYPE_HARDWARE, null) webViewClient = DebugClient() isDrawingCacheEnabled = true 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 24885fdf..81ade98f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -22,7 +22,7 @@ import com.pitchedapps.frost.activities.WebOverlayActivityBase import com.pitchedapps.frost.contracts.VideoViewHolder import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.facebook.USER_AGENT_BASIC +import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs @@ -32,7 +32,7 @@ import com.pitchedapps.frost.utils.isIndirectImageUrl import com.pitchedapps.frost.utils.isVideoUrl import com.pitchedapps.frost.utils.launchImageActivity import com.pitchedapps.frost.utils.launchWebOverlay -import com.pitchedapps.frost.utils.launchWebOverlayBasic +import com.pitchedapps.frost.utils.launchWebOverlayDesktop import com.pitchedapps.frost.views.FrostWebView /** @@ -76,15 +76,15 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean { if (!Prefs.overlayEnabled) return false if (context is WebOverlayActivityBase) { L.v { "Check web request from overlay" } - val shouldUseBasic = url.formattedFbUrl.shouldUseBasicAgent + val shouldUseDesktop = url.formattedFbUrl.shouldUseDesktopAgent //already overlay; manage user agent - if (userAgentString != USER_AGENT_BASIC && shouldUseBasic) { - L.i { "Switch to basic agent overlay" } - context.launchWebOverlayBasic(url) + if (userAgentString != USER_AGENT_DESKTOP && shouldUseDesktop) { + L.i { "Switch to desktop agent overlay" } + context.launchWebOverlayDesktop(url) return true } - if (userAgentString == USER_AGENT_BASIC && !shouldUseBasic) { - L.i { "Switch from basic agent" } + if (userAgentString == USER_AGENT_DESKTOP && !shouldUseDesktop) { + L.i { "Switch from desktop agent" } context.launchWebOverlay(url) return true } @@ -103,9 +103,9 @@ val messageWhitelist: Set = setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECENT, FbItem.FEED_TOP_STORIES) .mapTo(mutableSetOf(), FbItem::url) -val String.shouldUseBasicAgent: Boolean +val String.shouldUseDesktopAgent: Boolean get() = when { - contains("story.php") -> false // do not use basic for comment section + contains("story.php") -> false // do not use desktop for comment section contains("/events/") -> false // do not use for events (namely the map) contains("/messages") -> true // must use for messages else -> false // default to normal user agent 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 1c300b03..c27385fc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -35,7 +35,6 @@ import com.pitchedapps.frost.facebook.FB_USER_MATCHER import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.get import com.pitchedapps.frost.injectors.CssHider -import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs -- cgit v1.2.3