From 8281bf948931704790b53fa00a78356fc5a7d909 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Tue, 31 Jan 2023 18:30:53 +0100 Subject: [PATCH] Webxdc fixes (#2458) This now fixes all the checks in the `test webxdc`, see the Delta Chat group --- res/raw/webxdc_wrapper.html | 107 ++++++++++++++++++ .../securesms/WebxdcActivity.java | 18 ++- 2 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 res/raw/webxdc_wrapper.html diff --git a/res/raw/webxdc_wrapper.html b/res/raw/webxdc_wrapper.html new file mode 100644 index 000000000..a34781c50 --- /dev/null +++ b/res/raw/webxdc_wrapper.html @@ -0,0 +1,107 @@ + + + + + + +
+ +
+
+ +
+ + + + diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index 352473a06..a9fc0ba0c 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -40,6 +40,7 @@ import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.Util; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcEventDelegate { @@ -121,6 +122,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(false); webSettings.setBlockNetworkLoads(!internetAccess); + webView.setNetworkAvailable(internetAccess); webSettings.setAllowContentAccess(false); webSettings.setGeolocationEnabled(false); webSettings.setAllowFileAccessFromFileURLs(false); @@ -129,7 +131,17 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE webSettings.setDomStorageEnabled(true); webView.addJavascriptInterface(new InternalJSApi(), "InternalJSApi"); - webView.loadUrl(this.baseURL + "/index.html"); + + InputStream bootstrap_stream = getResources().openRawResource(R.raw.webxdc_wrapper); + byte[] bootstrap_bytes = new byte[0]; + try { + bootstrap_bytes = new byte[bootstrap_stream.available()]; + bootstrap_stream.read(bootstrap_bytes); + String bootstrapHtml = new String(bootstrap_bytes); + webView.loadDataWithBaseURL(this.baseURL + "/webxdc_bootstrap324567869.html", bootstrapHtml, "text/html", "UTF-8", null); + } catch (IOException e) { + e.printStackTrace(); + } Util.runOnAnyBackgroundThread(() -> { final DcChat chat = dcContext.getChat(dcAppMsg.getChatId()); @@ -170,10 +182,6 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE @Override protected boolean openOnlineUrl(String url) { - if (url.startsWith(baseURL +"/")) { - // internal page, continue loading in the WebView - return false; - } if (url.startsWith("mailto:")) { return super.openOnlineUrl(url); }