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

オープン 初心者向け
#5,065 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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内にとどまり、その他のスキームは端末のハンドラーに渡され、既存のハンドラーが見つからない場合の動作も維持されれば完了です。

索引モデルが 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時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

owncloud/android のほかの issue

owncloud/android の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。