[webview_flutter] Platform implementations for getCookies #11037#11386
[webview_flutter] Platform implementations for getCookies #11037#11386khaled-0 wants to merge 15 commits intoflutter:mainfrom
Conversation
Caveats: Domain name can not be null
swift-format reformatted the entire HTTPCookieStoreProxyAPITests.swift
GCC_TREAT_WARNINGS_AS_ERRORS = YES (no-shit)
…r.getCookies instead of document.cookie
…nsistent across platforms
…tter_platform_interface 2.14.0 -> 2.15.1
There was a problem hiding this comment.
Code Review
This pull request implements the getCookies method for PlatformWebViewCookieManager in both the Android and WKWebView packages. The changes include updated Pigeon definitions, native implementations for cookie retrieval, and updates to the example application to utilize the new API. Feedback identifies a bug in Android cookie parsing when values contain equals signs, incorrect domain matching logic in the WKWebView implementation that violates RFC 6265, and a missing nullability annotation in the Android native code. Typographical errors in the changelogs were also noted.
| final List<String> cookieValue = cookie.split('='); | ||
| webViewCookies.add( | ||
| WebViewCookie( | ||
| name: cookieValue.first, | ||
| value: cookieValue.last, | ||
| domain: url.toString(), | ||
| ), | ||
| ); |
There was a problem hiding this comment.
The current cookie parsing logic is incorrect if a cookie's value contains an equals sign (=). Using cookie.split('=') and taking cookieValue.last will only capture the part of the value after the last =.
To correctly parse the cookie, you should take everything after the first = as the value.
| final List<String> cookieValue = cookie.split('='); | |
| webViewCookies.add( | |
| WebViewCookie( | |
| name: cookieValue.first, | |
| value: cookieValue.last, | |
| domain: url.toString(), | |
| ), | |
| ); | |
| final List<String> cookieParts = cookie.split('='); | |
| webViewCookies.add( | |
| WebViewCookie( | |
| name: cookieParts.first, | |
| value: cookieParts.skip(1).join('='), | |
| domain: url.toString(), | |
| ), | |
| ); |
packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_cookie_manager.dart
Show resolved
Hide resolved
...r_android/android/src/main/java/io/flutter/plugins/webviewflutter/CookieManagerProxyApi.java
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md
Outdated
Show resolved
Hide resolved
8257284 to
2f01b98
Compare
List which issues are fixed by this PR. You must list at least one issue.
#10833 #11037
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2