diff --git a/jni/deltachat-core-rust b/jni/deltachat-core-rust index 41e18ae2d..c5f81271b 160000 --- a/jni/deltachat-core-rust +++ b/jni/deltachat-core-rust @@ -1 +1 @@ -Subproject commit 41e18ae2deae85342cb0ac28281659eab03e93e7 +Subproject commit c5f81271b85bd01b9be47ddc437b419546ff7cc2 diff --git a/src/org/thoughtcrime/securesms/WebxdcActivity.java b/src/org/thoughtcrime/securesms/WebxdcActivity.java index a2170344c..8565652a5 100644 --- a/src/org/thoughtcrime/securesms/WebxdcActivity.java +++ b/src/org/thoughtcrime/securesms/WebxdcActivity.java @@ -48,8 +48,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE private DcMsg dcAppMsg; private String baseURL; private String sourceCodeUrl = ""; - - + private boolean internetAccess = false; public static void openWebxdcActivity(Context context, DcMsg instance) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -116,10 +115,13 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE // also a random-id is not that useful for debugging) this.baseURL = "https://acc" + dcContext.getAccountId() + "-msg" + appMessageId + ".localhost"; + final JSONObject info = this.dcAppMsg.getWebxdcInfo(); + internetAccess = JsonUtils.optBoolean(info, "internet_access"); + WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setAllowFileAccess(false); - webSettings.setBlockNetworkLoads(true); + webSettings.setBlockNetworkLoads(!internetAccess); webSettings.setAllowContentAccess(false); webSettings.setGeolocationEnabled(false); webSettings.setAllowFileAccessFromFileURLs(false); @@ -129,7 +131,13 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE webView.addJavascriptInterface(new InternalJSApi(), "InternalJSApi"); webView.loadUrl(this.baseURL + "/index.html"); - updateTitleAndMenu(); + + Util.runOnAnyBackgroundThread(() -> { + final DcChat chat = dcContext.getChat(dcAppMsg.getChatId()); + Util.runOnMain(() -> { + updateTitleAndMenu(info, chat); + }); + }); } @Override @@ -189,6 +197,9 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE } else { byte[] blob = this.dcAppMsg.getWebxdcBlob(path); if (blob == null) { + if (internetAccess) { + return null; // do not intercept request + } throw new Exception("\"" + path + "\" not found"); } String ext = MediaUtil.getFileExtensionFromUrl(path); @@ -217,26 +228,25 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE Log.i(TAG, "handleEvent"); webView.loadUrl("javascript:window.__webxdcUpdate();"); } else if ((eventId == DcContext.DC_EVENT_MSGS_CHANGED && event.getData2Int() == dcAppMsg.getId())) { - updateTitleAndMenu(); + Util.runOnAnyBackgroundThread(() -> { + final JSONObject info = dcAppMsg.getWebxdcInfo(); + final DcChat chat = dcContext.getChat(dcAppMsg.getChatId()); + Util.runOnMain(() -> { + updateTitleAndMenu(info, chat); + }); + }); } } - private void updateTitleAndMenu() { - Util.runOnAnyBackgroundThread(() -> { - final JSONObject info = this.dcAppMsg.getWebxdcInfo(); + private void updateTitleAndMenu(JSONObject info, DcChat chat) { final String docName = JsonUtils.optString(info, "document"); final String xdcName = JsonUtils.optString(info, "name"); - final String chatName = WebxdcActivity.this.dcContext.getChat(WebxdcActivity.this.dcAppMsg.getChatId()).getName(); final String currSourceCodeUrl = JsonUtils.optString(info, "source_code_url"); - - Util.runOnMain(() -> { - getSupportActionBar().setTitle((docName.isEmpty() ? xdcName : docName) + " – " + chatName); - if (!sourceCodeUrl.equals(currSourceCodeUrl)) { - sourceCodeUrl = currSourceCodeUrl; - invalidateOptionsMenu(); - } - }); - }); + getSupportActionBar().setTitle((docName.isEmpty() ? xdcName : docName) + " – " + chat.getName()); + if (!sourceCodeUrl.equals(currSourceCodeUrl)) { + sourceCodeUrl = currSourceCodeUrl; + invalidateOptionsMenu(); + } } public static void addToHomeScreen(Activity activity, int msgId) { @@ -255,7 +265,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE ShortcutInfoCompat shortcutInfoCompat = new ShortcutInfoCompat.Builder(context, "xdc-" + dcContext.getAccountId() + "-" + msgId) .setShortLabel(docName.isEmpty() ? xdcName : docName) - .setIcon(IconCompat.createWithAdaptiveBitmap(bitmap)) + .setIcon(IconCompat.createWithBitmap(bitmap)) // createWithAdaptiveBitmap() removes decorations but cuts out a too small circle and defamiliarize the icon too much .setIntents(getWebxdcIntentWithParentStack(context, msgId)) .build(); diff --git a/src/org/thoughtcrime/securesms/util/JsonUtils.java b/src/org/thoughtcrime/securesms/util/JsonUtils.java index d87691fc0..e868566de 100644 --- a/src/org/thoughtcrime/securesms/util/JsonUtils.java +++ b/src/org/thoughtcrime/securesms/util/JsonUtils.java @@ -54,6 +54,14 @@ public class JsonUtils { } } + public static boolean optBoolean(JSONObject obj, String name) { + try { + return obj.optBoolean(name); + } catch(Exception e) { + return false; + } + } + public static class SaneJSONObject { private final JSONObject delegate;