mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
support request_internet_access again (#2988)
* support request_internet_access again * don't set fake proxy for apps with internet access * remove unnecessary imports and Rpc instance
This commit is contained in:
committed by
GitHub
parent
73479bf854
commit
7afef221a1
@@ -36,6 +36,12 @@ public class FullMsgActivity extends WebViewActivity
|
||||
ALWAYS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreCreate() {
|
||||
super.onPreCreate();
|
||||
setFakeProxy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle state, boolean ready) {
|
||||
super.onCreate(state, ready);
|
||||
|
||||
@@ -37,10 +37,7 @@ public class WebViewActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
protected WebView webView;
|
||||
|
||||
@Override
|
||||
protected void onPreCreate() {
|
||||
super.onPreCreate();
|
||||
|
||||
protected void setFakeProxy() {
|
||||
if (WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE)) {
|
||||
// Set proxy to non-routable address.
|
||||
ProxyConfig proxyConfig = new ProxyConfig.Builder()
|
||||
|
||||
@@ -155,6 +155,10 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
final JSONObject info = this.dcAppMsg.getWebxdcInfo();
|
||||
internetAccess = JsonUtils.optBoolean(info, "internet_access");
|
||||
|
||||
if (!internetAccess) {
|
||||
setFakeProxy();
|
||||
}
|
||||
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setAllowFileAccess(false);
|
||||
@@ -168,7 +172,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
webView.setNetworkAvailable(internetAccess); // this does not block network but sets `window.navigator.isOnline` in js land
|
||||
webView.addJavascriptInterface(new InternalJSApi(), "InternalJSApi");
|
||||
|
||||
webView.loadUrl(this.baseURL + "/webxdc_bootstrap324567869.html");
|
||||
webView.loadUrl(this.baseURL + (internetAccess? "/index.html" : "/webxdc_bootstrap324567869.html"));
|
||||
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
final DcChat chat = dcContext.getChat(dcAppMsg.getChatId());
|
||||
@@ -232,6 +236,10 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
|
||||
@Override
|
||||
protected boolean openOnlineUrl(String url) {
|
||||
if (internetAccess) {
|
||||
// internet access enabled, continue loading in the WebView
|
||||
return false;
|
||||
}
|
||||
if (url.startsWith("mailto:")) {
|
||||
return super.openOnlineUrl(url);
|
||||
}
|
||||
@@ -285,7 +293,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
res = new WebResourceResponse("text/plain", "UTF-8", targetStream);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !internetAccess) {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Content-Security-Policy",
|
||||
"default-src 'self'; "
|
||||
|
||||
Reference in New Issue
Block a user