aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-08-15 13:46:41 -0700
committerGitHub <noreply@github.com>2017-08-15 13:46:41 -0700
commit19ec9b543e15fe453b576f1b38994b3f8692054f (patch)
tree99600f87160b492de453a7f249bf3b258b5ef990 /app/src
parent203305e1890f9e23caa80d7ad6921767f830a4da (diff)
downloadfrost-19ec9b543e15fe453b576f1b38994b3f8692054f.tar.gz
frost-19ec9b543e15fe453b576f1b38994b3f8692054f.tar.bz2
frost-19ec9b543e15fe453b576f1b38994b3f8692054f.zip
Add checks before injections (#180)
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt17
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt14
3 files changed, 21 insertions, 15 deletions
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 e79816f3..ad9340d7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -172,10 +172,13 @@ fun Context.createPrivateMediaFile(extension: String) = createPrivateMediaFile("
* @returns {@code true} if activity is resolved, {@code false} otherwise
*/
fun Context.resolveActivityForUri(uri: Uri): Boolean {
- if (uri.toString().contains(FACEBOOK_COM) && !uri.toString().contains("intent:")) return false //ignore response as we will be triggering ourself
+ if (uri.toString().isFacebookUrl && !uri.toString().contains("intent:")) return false //ignore response as we will be triggering ourself
val intent = Intent(Intent.ACTION_VIEW, uri)
if (intent.resolveActivity(packageManager) == null) return false
startActivity(intent)
return true
}
+inline val String?.isFacebookUrl
+ get() = this != null && this.contains(FACEBOOK_COM)
+
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 5f679c65..2ebf2c0c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
@@ -51,7 +51,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient
if (url == null) return
L.i("FWV Loading", url)
refreshObservable.onNext(true)
- if (!url.contains(FACEBOOK_COM)) return
+ if (!url.isFacebookUrl) return
if (url.contains("logout.php")) FbCookie.logout(Prefs.userId, { launchLogin(view.context) })
else if (url.contains("login.php")) FbCookie.reset({ launchLogin(view.context) })
}
@@ -71,18 +71,19 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient
override fun onPageCommitVisible(view: WebView, url: String?) {
super.onPageCommitVisible(view, url)
injectBackgroundColor()
- view.jsInject(
- CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
- CssHider.HEADER,
- CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO),
- Prefs.themeInjector,
- CssHider.NON_RECENT.maybe(webCore.url?.contains("?sk=h_chr") ?: false))
+ if (url.isFacebookUrl)
+ view.jsInject(
+ CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
+ CssHider.HEADER,
+ CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO),
+ Prefs.themeInjector,
+ CssHider.NON_RECENT.maybe(webCore.url?.contains("?sk=h_chr") ?: false))
}
override fun onPageFinished(view: WebView, url: String?) {
url ?: return
L.i("Page finished", url)
- if (!url.contains(FACEBOOK_COM)) {
+ if (!url.isFacebookUrl) {
refreshObservable.onNext(false)
return
}
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 aea25337..038eaaad 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -15,6 +15,7 @@ import com.pitchedapps.frost.injectors.CssHider
import com.pitchedapps.frost.injectors.jsInject
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.isFacebookUrl
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
@@ -55,17 +56,18 @@ class LoginWebView @JvmOverloads constructor(
override fun onPageFinished(view: WebView, url: String?) {
super.onPageFinished(view, url)
- val containsFacebook = url?.contains(FACEBOOK_COM) ?: false
checkForLogin(url) { id, cookie -> loginCallback(CookieModel(id, "", cookie)) }
- view.jsInject(CssHider.HEADER.maybe(containsFacebook),
- CssHider.CORE.maybe(containsFacebook),
- Prefs.themeInjector.maybe(containsFacebook),
- callback = { if (!view.isVisible) view.fadeIn(offset = WEB_LOAD_DELAY) })
+ if (url.isFacebookUrl)
+ view.jsInject(CssHider.HEADER,
+ CssHider.CORE,
+ Prefs.themeInjector,
+ callback = { if (!view.isVisible) view.fadeIn(offset = WEB_LOAD_DELAY) })
+ else if (!view.isVisible) view.fadeIn()
}
fun checkForLogin(url: String?, onFound: (id: Long, cookie: String) -> Unit) {
doAsync {
- if (url == null || !url.contains(FACEBOOK_COM)) return@doAsync
+ if (!url.isFacebookUrl) return@doAsync
val cookie = CookieManager.getInstance().getCookie(url) ?: return@doAsync
L.d("Checking cookie for login", cookie)
val id = userMatcher.find(cookie)?.groups?.get(1)?.value?.toLong() ?: return@doAsync