Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cjybyjk/41b195e3b281d15a49eff8a5d4571657 to your computer and use it in GitHub Desktop.
Save cjybyjk/41b195e3b281d15a49eff8a5d4571657 to your computer and use it in GitHub Desktop.
0001-Jelly-don-t-load-url-with-third-app-scheme-in-webvie.patch
From c7f763d27e0abc458d83dd2147d70e9bb7799075 Mon Sep 17 00:00:00 2001
From: cjybyjk <cjybyjk@zjnu.edu.cn>
Date: Tue, 19 Jan 2021 13:26:43 +0800
Subject: [PATCH] Jelly: don't load url with third app scheme in webview
- shouldOverrideUrlLoading: check url in all frames
- startActivityForUrl: always return true, even if the Activity can't be found
Signed-off-by: cjybyjk <cjybyjk@zjnu.edu.cn>
Change-Id: I984c19bd3d9e7402dfedde38e4a9faca52ce0dcc
---
.../org/lineageos/jelly/webview/WebClient.kt | 29 +++++++++----------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/app/src/main/java/org/lineageos/jelly/webview/WebClient.kt b/app/src/main/java/org/lineageos/jelly/webview/WebClient.kt
index 3d5d816..9859b7d 100644
--- a/app/src/main/java/org/lineageos/jelly/webview/WebClient.kt
+++ b/app/src/main/java/org/lineageos/jelly/webview/WebClient.kt
@@ -54,20 +54,18 @@ internal class WebClient(private val mUrlBarController: UrlBarController) : WebV
}
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
- if (request.isForMainFrame) {
- val webViewExt = view as WebViewExt
- val url = request.url.toString()
- val needsLookup = (request.hasGesture()
- || !TextUtils.equals(url, webViewExt.lastLoadedUrl))
- if (!webViewExt.isIncognito
- && needsLookup
- && !request.isRedirect
- && startActivityForUrl(view, url)) {
- return true
- } else if (webViewExt.requestHeaders.isNotEmpty()) {
- webViewExt.followUrl(url)
- return true
- }
+ val webViewExt = view as WebViewExt
+ val url = request.url.toString()
+ val needsLookup = (request.hasGesture()
+ || !TextUtils.equals(url, webViewExt.lastLoadedUrl))
+ if (!webViewExt.isIncognito
+ && needsLookup
+ && !request.isRedirect
+ && startActivityForUrl(view, url)) {
+ return true
+ } else if (webViewExt.requestHeaders.isNotEmpty()) {
+ webViewExt.followUrl(url)
+ return true
}
return false
}
@@ -125,12 +123,11 @@ internal class WebClient(private val mUrlBarController: UrlBarController) : WebV
}
try {
context.startActivity(intent)
- return true
} catch (e: ActivityNotFoundException) {
Snackbar.make(view, context.getString(R.string.error_no_activity_found),
Snackbar.LENGTH_LONG).show()
}
- return false
+ return true
}
private fun makeHandlerChooserIntent(context: Context, intent: Intent, url: String): Intent? {
--
2.29.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment