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

Aperta Adatta ai principianti
#5,065 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile, web-dev

Direzione di ricerca

Leggi owncloudApp/src/main/java/com/owncloud/android/presentation/settings/privacypolicy/PrivacyPolicyActivity.kt e l’helper esistente goToUrl(url) in ActivityExt.kt. Verifica come il suo WebView gestisce la navigazione dei link, quindi aggiungi o aggiorna test mirati se il progetto prevede test per questa activity. Il lavoro è completato quando i link HTTP(S) rimangono nel WebView e gli altri schemi vengono passati al gestore del dispositivo, mantenendo il comportamento esistente quando non è disponibile alcun gestore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Kotlin
Stelle
4.2k
Fork
3.1k
Merge medio
2g 1h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di owncloud/android

Tutte le issue di owncloud/android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.