Add: Block file downloads in Casono Browser
This commit is contained in:
+28
@@ -192,6 +192,13 @@ public class CasinoBrowserController {
|
|||||||
WebView webView = new WebView();
|
WebView webView = new WebView();
|
||||||
WebEngine engine = webView.getEngine();
|
WebEngine engine = webView.getEngine();
|
||||||
|
|
||||||
|
engine.locationProperty().addListener((obs, oldUrl, newUrl) -> {
|
||||||
|
if (isDownloadUrl(newUrl)) {
|
||||||
|
LOGGER.warn("Download navigation blocked: " + newUrl);
|
||||||
|
engine.getLoadWorker().cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
engine.setJavaScriptEnabled(false);
|
engine.setJavaScriptEnabled(false);
|
||||||
|
|
||||||
configurePopupBlocker(engine);
|
configurePopupBlocker(engine);
|
||||||
@@ -633,6 +640,15 @@ public class CasinoBrowserController {
|
|||||||
URI uri = new URI(url);
|
URI uri = new URI(url);
|
||||||
String scheme = uri.getScheme();
|
String scheme = uri.getScheme();
|
||||||
|
|
||||||
|
String fullUrl = uri.toString();
|
||||||
|
|
||||||
|
if (isDownloadUrl(fullUrl)) {
|
||||||
|
securityLabel.setText("BLOCKED DOWNLOAD");
|
||||||
|
|
||||||
|
LOGGER.warn("Download blocked: " + fullUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ("file".equalsIgnoreCase(scheme)) {
|
if ("file".equalsIgnoreCase(scheme)) {
|
||||||
Path allowed =
|
Path allowed =
|
||||||
Paths.get(
|
Paths.get(
|
||||||
@@ -725,4 +741,16 @@ public class CasinoBrowserController {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a given URL points to a downloadable file based on its extension.
|
||||||
|
*
|
||||||
|
* @param url the URL to check
|
||||||
|
* @return true if the URL is likely a download link, false otherwise
|
||||||
|
*/
|
||||||
|
private static boolean isDownloadUrl(String url) {
|
||||||
|
if (url == null) return false;
|
||||||
|
|
||||||
|
return url.matches(".*\\.(exe|zip|dmg|msi|apk|jar|pdf)(\\?.*)?$");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user