From 6f819b2dbf413a91dc83524ab6340fcb9bb6e508 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Fri, 10 Nov 2023 14:13:06 +0100 Subject: [PATCH] Updated return value for CookieManager.setCookie method to be Future --- CHANGELOG.md | 1 + .../flutter_inappwebview/MyCookieManager.java | 8 ++++---- lib/src/cookie_manager.dart | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c89e528..df781e6d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 6.0.0-beta.26 +- Updated return value for `CookieManager.setCookie` method to be `Future`. The return value indicates whether the cookie was set successfully. - Merged "feat(ios): optional tradeoff to fix ios input delay" [#1665](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1665) (thanks to [andreasgangso](https://github.com/andreasgangso)) - Merged "Fix ios multiple flutter presenting error" [#1736](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1736) (thanks to [AlexT84](https://github.com/AlexT84)) - Merged "fix cert parsing for ios 12" [#1822](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1822) (thanks to [darkang3lz92](https://github.com/darkang3lz92)) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/MyCookieManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/MyCookieManager.java index 4161d784..d2e26a97 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/MyCookieManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/MyCookieManager.java @@ -180,8 +180,8 @@ public class MyCookieManager extends ChannelDelegateImpl { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setCookie(url, cookieValue, new ValueCallback() { @Override - public void onReceiveValue(Boolean aBoolean) { - result.success(true); + public void onReceiveValue(Boolean successful) { + result.success(successful); } }); cookieManager.flush(); @@ -297,7 +297,7 @@ public class MyCookieManager extends ChannelDelegateImpl { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.setCookie(url, cookieValue, new ValueCallback() { @Override - public void onReceiveValue(Boolean aBoolean) { + public void onReceiveValue(Boolean successful) { result.success(true); } }); @@ -364,7 +364,7 @@ public class MyCookieManager extends ChannelDelegateImpl { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.removeAllCookies(new ValueCallback() { @Override - public void onReceiveValue(Boolean aBoolean) { + public void onReceiveValue(Boolean successful) { result.success(true); } }); diff --git a/lib/src/cookie_manager.dart b/lib/src/cookie_manager.dart index 546c236a..65f35142 100755 --- a/lib/src/cookie_manager.dart +++ b/lib/src/cookie_manager.dart @@ -65,6 +65,9 @@ class CookieManager { ///[webViewController] could be used if you need to set a session-only cookie using JavaScript (so [isHttpOnly] cannot be set, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies) ///on the current URL of the [WebView] managed by that controller when you need to target iOS below 11, MacOS below 10.13 and Web platform. In this case the [url] parameter is ignored. /// + ///The return value indicates whether the cookie was set successfully. + ///Note that it will return always `true` for Web platform, iOS below 11.0 and MacOS below 10.13. + /// ///**NOTE for iOS below 11.0 and MacOS below 10.13**: If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [HeadlessInAppWebView] ///to set the cookie (session-only cookie won't work! In that case, you should set also [expiresDate] or [maxAge]). /// @@ -77,7 +80,7 @@ class CookieManager { ///- iOS ([Official API - WKHTTPCookieStore.setCookie](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882007-setcookie)) ///- MacOS ([Official API - WKHTTPCookieStore.setCookie](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882007-setcookie)) ///- Web - Future setCookie( + Future setCookie( {required WebUri url, required String name, required String value, @@ -110,7 +113,7 @@ class CookieManager { isSecure: isSecure, sameSite: sameSite, webViewController: webViewController); - return; + return true; } Map args = {}; @@ -125,7 +128,7 @@ class CookieManager { args.putIfAbsent('isHttpOnly', () => isHttpOnly); args.putIfAbsent('sameSite', () => sameSite?.toNativeValue()); - await _channel.invokeMethod('setCookie', args); + return await _channel.invokeMethod('setCookie', args); } Future _setCookieWithJavaScript(