[BUG] PrivacyPolicyActivity WebView does not route non http(s) links out of the WebView

未关闭 适合新手
#5,065 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, kotlin
领域
mobile, web-dev

调研方向

阅读 owncloudApp/src/main/java/com/owncloud/android/presentation/settings/privacypolicy/PrivacyPolicyActivity.kt 和 ActivityExt.kt 中现有的辅助函数 goToUrl(url)。检查其 WebView 如何处理链接导航;如果项目包含针对该 activity 的测试覆盖,则添加或更新有针对性的测试。完成标准是:HTTP(S) 链接仍在 WebView 中打开,其他 scheme 则交由设备处理程序处理,并保留现有的处理程序缺失时的行为。

由索引模型根据 Issue 内容生成。

描述

Contributions are welcome Type:bug

PrivacyPolicyActivity (owncloudApp/src/main/java/com/owncloud/android/presentation/settings/privacypolicy/PrivacyPolicyActivity.kt) sets up its WebViewClient with only an onReceivedError override:

webViewClient = object : WebViewClient() {
    override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {
        showMessageInSnackbar(message = getString(R.string.privacy_policy_error) + description)
    }
}

Because shouldOverrideUrlLoading is not overridden, every link the privacy policy page renders is loaded by the WebView itself. That has two visible effects:

  1. A mailto: link in the policy text opens nothing. The WebView tries to load mailto:[email protected] itself, fails, and the mail app never opens.
  2. Any other non http(s) scheme that an app on the device could handle (tel:, geo:, intent:, market:) is swallowed by the WebView the same way instead of being handed to that app.

The page is remote (url_privacy_policy, https://owncloud.com/android-app-privacy-policy/ by default, and a branded build can point it somewhere else), so which links it contains is outside the app's control.

Suggested fix

Override shouldOverrideUrlLoading so http(s) navigations stay in the WebView and any other scheme is routed out. ActivityExt.kt already has goToUrl(url), which launches Intent.ACTION_VIEW inside a try/catch for ActivityNotFoundException and shows the file_list_no_app_for_perform_action snackbar, so a missing handler does not crash the Activity:

override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
    val url = request?.url ?: return false
    val scheme = url.scheme?.lowercase()
    if (scheme == "http" || scheme == "https") return false
    goToUrl(url.toString())
    return true
}

The same gap was fixed in the OpenCloud fork of this app in opencloud-eu/android#165.

主要语言
Kotlin
星标
4.2k
派生
3.1k
平均合并
2 天 1 小时
30 天内合并 PR
13

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

owncloud/android 的其他 Issue

查看 owncloud/android 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。