From 4cc28a0ef19670980e098c1808f668b0ae7cc4e8 Mon Sep 17 00:00:00 2001 From: dimitris Date: Sat, 16 May 2026 14:46:38 +0200 Subject: [PATCH] fix(direct-edit): route off-server links out of the editor WebView The direct-edit WebView loads the Nextcloud Text editor for the user's account but never overrides shouldOverrideUrlLoading, so any link the editor renders (mentions to other users, file references, embedded images, mailto: in a markdown table) navigates the editor WebView itself and breaks the edit session. Override shouldOverrideUrlLoading to keep navigations whose URL starts with the current account URL inside the WebView and route everything else out via Intent.ACTION_VIEW. Wrap the launch in try/catch so a missing handler does not crash the Fragment. --- .../notes/edit/NoteDirectEditFragment.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt index 95b76550d..a4809394a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt @@ -7,6 +7,8 @@ package it.niedermann.owncloud.notes.edit import android.annotation.SuppressLint +import android.content.ActivityNotFoundException +import android.content.Intent import android.net.http.SslError import android.os.Bundle import android.util.Log @@ -302,6 +304,30 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded { super.onReceivedSslError(view, handler, error) } } + + override fun shouldOverrideUrlLoading( + view: WebView?, + request: WebResourceRequest?, + ): Boolean { + val url = request?.url ?: return false + val scheme = url.scheme?.lowercase() + val accountUrl = runCatching { account.url }.getOrNull() + if ((scheme == "http" || scheme == "https") && + accountUrl != null && url.toString().startsWith(accountUrl) + ) { + return false + } + return try { + val intent = Intent(Intent.ACTION_VIEW, url).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + startActivity(intent) + true + } catch (e: ActivityNotFoundException) { + Log.w(TAG, "No app available to open $url", e) + true + } + } } }