Skip to content

Commit

Permalink
Fix beforeload for Android <= 7 (#427)
Browse files Browse the repository at this point in the history
* Fix beforeload for Android <= 7
* Change Android version check conditional
  • Loading branch information
Ralph Gutkowski authored and purplecabbage committed Jun 12, 2019
1 parent a162bd9 commit 94fec84
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public class InAppBrowser extends CordovaPlugin {
private String footerColor = "";
private String beforeload = "";
private String[] allowedSchemes;
private InAppBrowserClient currentClient;

/**
* Executes the request and returns PluginResult.
Expand Down Expand Up @@ -264,7 +265,12 @@ else if (action.equals("loadAfterBeforeload")) {
@SuppressLint("NewApi")
@Override
public void run() {
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
currentClient.waitForBeforeload = false;
inAppWebView.setWebViewClient(currentClient);
} else {
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
}
inAppWebView.loadUrl(url);
}
});
Expand Down Expand Up @@ -964,8 +970,8 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
}

});
WebViewClient client = new InAppBrowserClient(thatWebView, edittext, beforeload);
inAppWebView.setWebViewClient(client);
currentClient = new InAppBrowserClient(thatWebView, edittext, beforeload);
inAppWebView.setWebViewClient(currentClient);
WebSettings settings = inAppWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
Expand Down Expand Up @@ -1200,7 +1206,9 @@ public boolean shouldOverrideUrlLoading(String url, String method) {
boolean useBeforeload = false;
String errorMessage = null;

if(beforeload.equals("yes")
if (beforeload.equals("yes") && method == null) {
useBeforeload = true;
}else if(beforeload.equals("yes")
//TODO handle POST requests then this condition can be removed:
&& !method.equals("POST"))
{
Expand Down

0 comments on commit 94fec84

Please sign in to comment.