From a6243384bc87548fd91fef5593f569c53750563b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 29 Aug 2017 13:49:54 -0400 Subject: Miscellaneous fixes (#223) * Disable js dialogs for headless webviews * Update logging * Fix sharing theme * Add buddylist to drawer and theme update * Blacklist sharer.php from launching in overlay * Add whitelist for message related links --- .../pitchedapps/frost/activities/MainActivity.kt | 3 ++- .../pitchedapps/frost/web/FrostChromeClients.kt | 24 ++++++++++++++++++---- .../frost/web/FrostUrlOverlayValidator.kt | 8 +++++++- .../com/pitchedapps/frost/web/FrostWebView.kt | 2 +- .../pitchedapps/frost/web/HeadlessHtmlExtractor.kt | 2 +- .../com/pitchedapps/frost/web/SearchWebView.kt | 16 +++++++-------- 6 files changed, 38 insertions(+), 17 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt index 80dbc3dc..29bc350b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt @@ -89,7 +89,7 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract, var firstLoadFinished = false set(value) { if (field && value) return //both vals are already true - L.d("First fragment load has finished") + L.i("First fragment load has finished") field = value if (value && hiddenSearchView == null) { hiddenSearchView = SearchWebView(this, this) @@ -295,6 +295,7 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract, primaryFrostItem(FbItem.PHOTOS) primaryFrostItem(FbItem.GROUPS) primaryFrostItem(FbItem.FRIENDS) + primaryFrostItem(FbItem.CHAT) primaryFrostItem(FbItem.PAGES) divider() primaryFrostItem(FbItem.EVENTS) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt index 386c5339..b469659b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt @@ -19,10 +19,27 @@ import io.reactivex.subjects.Subject */ /** - * Nothing more than a client without logging + * Fully quiet client that disables any prompts relating to the UI + * (as nothing is attached) */ -class QuietChromeClient : WebChromeClient() { +class HeadlessChromeClient : WebChromeClient() { + override fun onConsoleMessage(consoleMessage: ConsoleMessage) = true + + override fun onJsAlert(view: WebView, url: String?, message: String?, result: JsResult): Boolean { + result.cancel() + return true + } + + override fun onJsConfirm(view: WebView, url: String?, message: String?, result: JsResult): Boolean { + result.cancel() + return true + } + + override fun onJsPrompt(view: WebView, url: String?, message: String?, defaultValue: String?, result: JsPromptResult): Boolean { + result.cancel() + return true + } } /** @@ -59,8 +76,7 @@ class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() { override fun onGeolocationPermissionsShowPrompt(origin: String, callback: GeolocationPermissions.Callback) { L.i("Requesting geolocation") - context.kauRequestPermissions(PERMISSION_ACCESS_FINE_LOCATION) { - granted, _ -> + context.kauRequestPermissions(PERMISSION_ACCESS_FINE_LOCATION) { granted, _ -> L.i("Geolocation response received; ${if (granted) "granted" else "denied"}") callback(origin, granted, 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 0a1878b3..29d2e991 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -1,6 +1,7 @@ package com.pitchedapps.frost.web import android.content.Context +import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.isFacebookUrl @@ -42,7 +43,12 @@ fun Context.requestWebOverlay(url: String): Boolean { return true } +/** + * If the url contains any one of the whitelist segments, switch to the chat overlay + */ +val messageWhitelist = setOf(FbItem.MESSAGES.url, FbItem.CHAT.url) + /** * The following components should never be launched in a new overlay */ -val overlayBlacklist = setOf("messages/?pageNum", "photoset_token") \ No newline at end of file +val overlayBlacklist = setOf("messages/?pageNum", "photoset_token", "sharer.php") \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt index 89ad766d..2cd31a57 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -59,7 +59,7 @@ class FrostWebView @JvmOverloads constructor( baseEnum = enum with(settings) { javaScriptEnabled = true - if (url.contains("facebook.com/message")) + if (messageWhitelist.any { url.contains(it) }) userAgentString = USER_AGENT_BASIC allowFileAccess = true textZoom = Prefs.webTextScaling diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt index 50f2f6bc..471731dd 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt @@ -62,7 +62,7 @@ private class HeadlessHtmlExtractor( settings.javaScriptEnabled = true settings.userAgentString = USER_AGENT_BASIC webViewClient = HeadlessWebViewClient(url, injector) // basic client that loads our JS once the page has loaded - webChromeClient = QuietChromeClient() // basic client that disables logging + webChromeClient = HeadlessChromeClient() addJavascriptInterface(HtmlJSI(), "Frost") loadUrl(url) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt index da6d8ad3..dc2bd8af 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt @@ -39,9 +39,9 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co * Contains the last item's href (search more) as well as the number of items found * This holder is synchronized */ - var previousResult: Pair = Pair("", 0) + private var previousResult: Pair = Pair("", 0) - fun saveResultFrame(result: List, String>>) { + private fun saveResultFrame(result: List, String>>) { synchronized(previousResult) { previousResult = Pair(result.last().second, result.size) } @@ -49,10 +49,11 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co @SuppressLint("SetJavaScriptEnabled") private fun setupWebview() { + L.i("Begin SearchWebView setup") settings.javaScriptEnabled = true settings.userAgentString = USER_AGENT_BASIC webViewClient = HeadlessWebViewClient("Search", JsAssets.SEARCH) - webChromeClient = QuietChromeClient() + webChromeClient = HeadlessChromeClient() addJavascriptInterface(SearchJSI(), "Frost") searchSubject.debounce(300, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.newThread()) .map { @@ -60,8 +61,7 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co L.d(doc.getElementById("main-search_input")?.html()) val searchQuery = doc.getElementById("main-search-input")?.text() ?: "Null input" L.d("Search query", searchQuery) - doc.select("a:not([rel*='keywords(']):not([href=#])[rel]").map { - element -> + doc.select("a:not([rel*='keywords(']):not([href=#])[rel]").map { element -> //split text into separate items L.v("Search element", element.attr("href")) val texts = element.select("div").map { it.text() }.filter { !it.isNullOrBlank() } @@ -72,12 +72,10 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co } .filter { it.isNotEmpty() } .filter { Pair(it.last().second, it.size) != previousResult } - .subscribe { - content: List, String>> -> + .subscribe { content: List, String>> -> saveResultFrame(content) L.d("Search element count ${content.size}") - contract.emitSearchResponse(content.map { - (texts, href) -> + contract.emitSearchResponse(content.map { (texts, href) -> SearchItem(href, texts[0], texts.getOrNull(1)) }) } -- cgit v1.2.3