Skip to content

Commit

Permalink
Fetch WebView - whitelist URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
martinwork committed Jul 2, 2024
1 parent 13ccc6a commit 6b53b3d
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 6b53b3d

Please sign in to comment.