mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
webxdc: allow internal pages and open some known schemes externally
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user