From 47190896d2972be83bd4d09754fe237941c99433 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Tue, 3 May 2022 06:36:23 -0400 Subject: [PATCH] webxdc: allow internal pages and open some known schemes externally --- src/org/thoughtcrime/securesms/WebViewActivity.java | 12 +++++++----- src/org/thoughtcrime/securesms/WebxdcActivity.java | 9 +++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/WebViewActivity.java b/src/org/thoughtcrime/securesms/WebViewActivity.java index f23f2d016..5a048103b 100644 --- a/src/org/thoughtcrime/securesms/WebViewActivity.java +++ b/src/org/thoughtcrime/securesms/WebViewActivity.java @@ -48,7 +48,8 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity webView = findViewById(R.id.webview); webView.setWebViewClient(new WebViewClient() { // `shouldOverrideUrlLoading()` is called when the user clicks a URL, - // returning `true` means, the URL is passed to `loadUrl()`, `false` aborts loading. + // returning `true` causes the WebView to abort loading the URL, + // returning `false` causes the WebView to continue loading the URL as usual. // the method is not called for POST request nor for on-page-links. // // nb: from API 24, `shouldOverrideUrlLoading(String)` is deprecated and @@ -64,9 +65,8 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity case "https": case "mailto": case "openpgp4fpr": - openOnlineUrl(url); - // URL opened externally, returning `true` causes the WebView to abort loading - return true; + // open URL externally + return openOnlineUrl(url); } } // by returning `true`, we also abort loading other URLs in our WebView; @@ -271,12 +271,14 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity } } - protected void openOnlineUrl(String url) { + protected boolean openOnlineUrl(String url) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.no_browser_installed, Toast.LENGTH_LONG).show(); } + // returning `true` causes the WebView to abort loading + return true; } protected WebResourceResponse interceptRequest(String url) { diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index 239efcfb7..6774f654b 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -35,6 +35,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE private static final String TAG = WebxdcActivity.class.getSimpleName(); private DcContext dcContext; private DcMsg dcAppMsg; + private String baseURL; public static void openWebxdcActivity(Context context, DcMsg instance) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -105,8 +106,12 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE } @Override - protected void openOnlineUrl(String url) { - Toast.makeText(this, "Please embed needed resources.", Toast.LENGTH_LONG).show(); + protected boolean openOnlineUrl(String url) { + if (url.startsWith(baseURL +"/")) { + // internal page, continue loading in the WebView + return false; + } + return super.openOnlineUrl(url); } @Override