From 224201a77f2c6615da4a896125802b2b79cecbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asiel=20D=C3=ADaz=20Ben=C3=ADtez?= Date: Sun, 28 Apr 2024 00:00:58 +0200 Subject: [PATCH] fix openOnlineUrl(), mailto/openpgp4fpr has to open externally (#3008) * fix openOnlineUrl(), mailto/openpgp4fpr has to open externally * Update src/org/thoughtcrime/securesms/WebxdcActivity.java Co-authored-by: bjoern * Update src/org/thoughtcrime/securesms/WebxdcActivity.java Co-authored-by: bjoern --------- Co-authored-by: bjoern --- .../thoughtcrime/securesms/WebViewActivity.java | 1 + src/org/thoughtcrime/securesms/WebxdcActivity.java | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/WebViewActivity.java b/src/org/thoughtcrime/securesms/WebViewActivity.java index a89bbafbc..c1b118f4e 100644 --- a/src/org/thoughtcrime/securesms/WebViewActivity.java +++ b/src/org/thoughtcrime/securesms/WebViewActivity.java @@ -62,6 +62,7 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity webView = findViewById(R.id.webview); webView.setWebViewClient(new WebViewClient() { + // IMPORTANT: this is will likely not be called inside iframes. // `shouldOverrideUrlLoading()` is called when the user clicks a URL, // returning `true` causes the WebView to abort loading the URL, // returning `false` causes the WebView to continue loading the URL as usual. diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index 03111d3eb..3ff719b61 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -266,18 +266,16 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE } } + // This is usually only called when internetAccess == true or for mailto/openpgp4fpr scheme, + // because when internetAccess == false, the page is loaded inside an iframe, + // and WebViewClient.shouldOverrideUrlLoading is not called for HTTP(S) links inside the iframe @Override protected boolean openOnlineUrl(String url) { - if (internetAccess) { - // internet access enabled, continue loading in the WebView - return false; - } - if (url.startsWith("mailto:")) { + Log.i(TAG, "openOnlineUrl: " + url); + if (url.startsWith("mailto:") || url.startsWith("openpgp4fpr:")) { return super.openOnlineUrl(url); } - - Toast.makeText(this, "Please embed needed resources.", Toast.LENGTH_LONG).show(); - return true; // returning `true` causes the WebView to abort loading + return !internetAccess; // returning `false` continues loading in WebView; returning `true` let WebView abort loading } @Override