From 6b53b3dc2ee589d6b8c0ed0b852744dc9e3430bb Mon Sep 17 00:00:00 2001 From: Martin Williams Date: Tue, 2 Jul 2024 21:24:45 +0100 Subject: [PATCH] Fetch WebView - whitelist URLs --- .../microbit/ui/activity/FetchActivity.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java b/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java index d35a506..26e28b4 100644 --- a/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java +++ b/app/src/main/java/com/samsung/microbit/ui/activity/FetchActivity.java @@ -867,6 +867,13 @@ private void displayUpdateDeviceName() { searchDrawable.setDeviceName(deviceName); } + private void openURL( String url) { + logi( "openURL: " + url); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse( url)); + startActivity(intent); + } + /** * Display WebView */ @@ -896,8 +903,22 @@ private void displayHtmlInit() { mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - Log.v(TAG, "shouldOverrideUrlLoading: " + url); - return false; + logi( "shouldOverrideUrlLoading: " + url); + Uri uri = Uri.parse( url); + String scheme = uri.getScheme(); + if ( scheme != null) { + logi( "scheme: " + scheme); + if ( scheme.compareToIgnoreCase( "file") == 0) { + String path = displayHtmlGetPath().toLowerCase(); + if ( url.toLowerCase().contains( path)) { + return false; + } + openURL( url); + return true; + } + } + openURL( url); + return true; } @Override @@ -1048,9 +1069,9 @@ private void displayHtmlLoad() { private void displayHtmlGoBack() { if (displayHtmlGetURL().equals(mWebView.getUrl())) { - activityCancelled(); - } else if (!mWebView.canGoBack()) { - activityCancelled(); + activityComplete(); + } else if ( !mWebView.canGoBack()) { + activityComplete(); } else { mWebView.goBack(); }