feat: android - set header and cookies also for loadAfterBefore

This commit is contained in:
Davide Ramo 2023-10-18 10:52:38 +02:00
parent 9075cc1c18
commit 5a8a2be76a
2 changed files with 28 additions and 13 deletions

View File

@ -187,12 +187,16 @@ public class InAppBrowser extends CordovaPlugin {
} }
final String target = t; final String target = t;
final HashMap<String, String> features = parseFeature(args.optString(2)); final HashMap<String, String> features = parseFeature(args.optString(2));
parseHeadersAndCookies(features);
LOG.d(LOG_TAG, "target = " + target); LOG.d(LOG_TAG, "target = " + target);
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
setCookies(clearAllCache, clearSessionCache, cookies);
String result = ""; String result = "";
// SELF // SELF
if (SELF.equals(target)) { if (SELF.equals(target)) {
@ -290,7 +294,7 @@ public class InAppBrowser extends CordovaPlugin {
} else { } else {
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false; ((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
} }
inAppWebView.loadUrl(url); inAppWebView.loadUrl(url,headers);
} }
}); });
@ -397,6 +401,18 @@ public class InAppBrowser extends CordovaPlugin {
closeDialog(); closeDialog();
} }
private void parseHeadersAndCookies(HashMap<String, String> features){
String headersSet = features.get(HEADERS);
if (headersSet != null) {
headers = deserializeMapOption(headersSet);
}
String cookiesSet = features.get(COOKIES);
if (cookiesSet != null) {
cookies = deserializeMapOption(cookiesSet);
}
}
/** /**
* Inject an object (script or style) into the InAppBrowser WebView. * Inject an object (script or style) into the InAppBrowser WebView.
* *
@ -732,16 +748,6 @@ public class InAppBrowser extends CordovaPlugin {
if (fullscreenSet != null) { if (fullscreenSet != null) {
fullscreen = fullscreenSet.equals("yes") ? true : false; fullscreen = fullscreenSet.equals("yes") ? true : false;
} }
String headersSet = features.get(HEADERS);
if (headersSet != null) {
headers = deserializeMapOption(headersSet);
}
String cookiesSet = features.get(COOKIES);
if (cookiesSet != null) {
cookies = deserializeMapOption(cookiesSet);
}
} }
final CordovaWebView thatWebView = this.webView; final CordovaWebView thatWebView = this.webView;
@ -1093,8 +1099,6 @@ public class InAppBrowser extends CordovaPlugin {
} }
}; };
setCookies(clearAllCache, clearSessionCache, cookies);
this.cordova.getActivity().runOnUiThread(runnable); this.cordova.getActivity().runOnUiThread(runnable);
return ""; return "";
} }

11
src/android/android.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="org.apache.cordova.inappbrowser" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>