From 5a8a2be76a9257c2591362a3e6a40b7d5e1c4dc6 Mon Sep 17 00:00:00 2001 From: Davide Ramo Date: Wed, 18 Oct 2023 10:52:38 +0200 Subject: [PATCH] feat: android - set header and cookies also for loadAfterBefore --- src/android/InAppBrowser.java | 30 +++++++++++++++++------------- src/android/android.iml | 11 +++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 src/android/android.iml diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 32a2d02..99184ad 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -187,12 +187,16 @@ public class InAppBrowser extends CordovaPlugin { } final String target = t; final HashMap features = parseFeature(args.optString(2)); + parseHeadersAndCookies(features); LOG.d(LOG_TAG, "target = " + target); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { + + setCookies(clearAllCache, clearSessionCache, cookies); + String result = ""; // SELF if (SELF.equals(target)) { @@ -290,7 +294,7 @@ public class InAppBrowser extends CordovaPlugin { } else { ((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false; } - inAppWebView.loadUrl(url); + inAppWebView.loadUrl(url,headers); } }); @@ -397,6 +401,18 @@ public class InAppBrowser extends CordovaPlugin { closeDialog(); } + private void parseHeadersAndCookies(HashMap 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. * @@ -732,16 +748,6 @@ public class InAppBrowser extends CordovaPlugin { if (fullscreenSet != null) { 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; @@ -1093,8 +1099,6 @@ public class InAppBrowser extends CordovaPlugin { } }; - setCookies(clearAllCache, clearSessionCache, cookies); - this.cordova.getActivity().runOnUiThread(runnable); return ""; } diff --git a/src/android/android.iml b/src/android/android.iml new file mode 100644 index 0000000..a242521 --- /dev/null +++ b/src/android/android.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file