You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NoteDirectEditFragment WebView navigates itself for off-server links #3191
NoteDirectEditFragment (app/src/main/java/it/niedermann/owncloud/notes/edit/NoteDirectEditFragment.kt) loads the Nextcloud Text editor for the user's account and configures the WebViewClient with onReceivedError and onReceivedSslError overrides but no shouldOverrideUrlLoading.
When the rendered editor contains links (a markdown link to another site, a mention to a user on a different Nextcloud server, a mailto: in a frontmatter table) and the user taps one, the WebView navigates itself to that URL. The edit session is lost and the user is now stuck in a non-editor page inside a fragment that was only set up to render the editor.
Most Nextcloud Android surfaces (Files, Talk, ...) handle this by keeping same-server URLs inside the WebView and routing everything else out via Intent.ACTION_VIEW.
Suggested fix
Override shouldOverrideUrlLoading:
If the URL starts with the current account URL, return false so it stays in the WebView.
Otherwise, dispatch Intent.ACTION_VIEW and wrap the launch in try/catch (ActivityNotFoundException) so a device with no handler for the scheme does not crash the fragment.
overridefunshouldOverrideUrlLoading(view:WebView?, request:WebResourceRequest?): Boolean {
val url = request?.url ?:returnfalseval scheme = url.scheme?.lowercase()
val accountUrl = runCatching { account.url }.getOrNull()
if ((scheme =="http"|| scheme =="https") &&
accountUrl !=null&& url.toString().startsWith(accountUrl)
) {
returnfalse
}
returntry {
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
}
}
Activity