Skip to content

PrivacyPolicyActivity WebView does not route non http(s) links out of the WebView #164

@jim-daf

Description

@jim-daf

PrivacyPolicyActivity (opencloudApp/src/main/java/eu/opencloud/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 fails to load mailto:foo@example.com and the user sees a blank state.
  2. A non http(s) scheme that some other app on the device claims (tel:, geo:, intent:, market:) is just swallowed by the WebView instead of handing it to that app.

This is a normal pre-API-24 default, but on a modern build the privacy policy view stops being a useful escape hatch into the system browser / mail app.

Suggested fix

Override shouldOverrideUrlLoading so http(s) navigations stay in the WebView and any other scheme is routed out via Intent.ACTION_VIEW, with a try/catch for ActivityNotFoundException 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
    return try {
        startActivity(Intent(Intent.ACTION_VIEW, url).apply {
            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        })
        true
    } catch (e: ActivityNotFoundException) {
        false
    }
}

A PR with the change is at #165.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions