Webxdc fixes (#2458)

This now fixes all the checks in the `test webxdc`, see the
Delta Chat group
This commit is contained in:
Hocuri
2023-01-31 18:30:53 +01:00
committed by GitHub
parent 38be87ee8e
commit 8281bf9489
2 changed files with 120 additions and 5 deletions
+107
View File
@@ -0,0 +1,107 @@
<!DOCTYPE html>
<html>
<head>
<style>
html,
body {
margin: 0;
padding: 0;
}
.iframe-container {
overflow: hidden;
height: 100vh;
width: 100vw;
position: relative;
}
.iframe-container iframe {
border: 0;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
#progress {
width: 100%;
}
</style>
</head>
<body>
<div id="loading">
<progress id="progress" max="100" value="0"></progress>
</div>
<div class="iframe-container">
<iframe id="frame"></iframe>
</div>
<iframe id="test-isolated-sandbox-context" style="display: none"></iframe>
<script>
const thisUnchangable = (async () => {
const connections = [];
const loadingProgress = document.getElementById("progress");
const loadingDiv = document.getElementById("loading");
const iframe = document.getElementById("frame");
const isolatedContextTest = document.getElementById(
"test-isolated-sandbox-context"
);
const cert = {
certificates: [
await RTCPeerConnection.generateCertificate({
name: "ECDSA",
namedCurve: "P-256",
}),
],
};
try {
for (let i = 0; i < 50; i++) {
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
connections.push(new RTCPeerConnection(cert));
loadingProgress.value = i;
await new Promise((res) => setTimeout(res));
}
try {
connections.push(new RTCPeerConnection());
console.log("Error: was able to create more than 500 connections");
loadingDiv.innerText =
"Error: was not able to block webrtc ERROR_A";
} catch (error) {
try {
new isolatedContextTest.contentWindow.RTCPeerConnection();
console.log(
"Error: was able to create more than 500 connections, iframe is probably isolated"
);
loadingDiv.innerText =
"Error: was not able to block webrtc ERROR_C";
} catch (error) {
loadingDiv.innerHTML = "";
iframe.src = "index.html";
iframe.contentWindow.webxdc_internal = window.webxdc_internal;
iframe.contentWindow.webxdc = window.webxdc;
}
}
} catch (error) {
console.log(
"error loading, should crash / close webxdc activity",
error
);
loadingDiv.innerText = "Error: was not able to block webrtc ERROR_B";
}
return Object.freeze({
len: () => {
return connections.length;
},
});
})();
</script>
</body>
</html>
@@ -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);
}