-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[webview_flutter] Implement getCookies #10833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
115fecc
ca32485
bf04b65
bb96ade
f79d7e8
f3186cb
088ccda
7bc3de2
04995bd
1a11291
1317fc6
a3ffce3
29c8059
4f0c549
b38e3e7
a1623e3
a54dc43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,4 +86,12 @@ class WebViewCookieManager { | |
| /// | ||
| /// This is a no op on iOS versions below 11. | ||
| Future<void> setCookie(WebViewCookie cookie) => platform.setCookie(cookie); | ||
|
|
||
| /// Gets a list of existing cookie for specified domain from all | ||
| /// WebView instances of the application. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here as the platform implementation. Is this true that it retrieves cookies for all WebView instances and not the associated one: https://developer.apple.com/documentation/webkit/wkhttpcookiestore/getallcookies(_:)#Discussion |
||
| /// | ||
| /// Each platform can have different url requirements. Please check individual | ||
| /// platform implementation for details | ||
| Future<List<WebViewCookie>> getCookies({required Uri domain}) => | ||
| platform.getCookies(domain); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
| // Autogenerated from Pigeon (v26.1.4), do not edit directly. | ||
| // Autogenerated from Pigeon (v26.1.5), do not edit directly. | ||
| // See also: https://pub.dev/packages/pigeon | ||
| @file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") | ||
|
|
||
|
|
@@ -155,10 +155,6 @@ class AndroidWebkitLibraryPigeonInstanceManager( | |
| */ | ||
| fun <T> remove(identifier: Long): T? { | ||
| logWarningIfFinalizationListenerHasStopped() | ||
| val instance: Any? = getInstance(identifier) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this needs to be manually added back in, but this can wait for the implementation PR. |
||
| if (instance is WebViewProxyApi.WebViewPlatformView) { | ||
| instance.destroy() | ||
| } | ||
| return strongInstances.remove(identifier) as T? | ||
| } | ||
|
|
||
|
|
@@ -1519,6 +1515,18 @@ abstract class PigeonApiCookieManager( | |
| accept: Boolean | ||
| ) | ||
|
|
||
| /** | ||
| * Gets all the cookies for the given URL. | ||
| * | ||
| * This may return multiple key-value pairs if multiple cookies are associated with this URL, in | ||
| * which case each cookie will be delimited by "; " characters (semicolon followed by a space). | ||
| * Each key-value pair will be of the form "key=value". | ||
| * | ||
| * Note: Any cookies set with the "Partitioned" attribute will only be returned for the top-level | ||
| * partition of url. | ||
| */ | ||
| abstract fun getCookies(pigeon_instance: android.webkit.CookieManager, url: String): String? | ||
|
|
||
| companion object { | ||
| @Suppress("LocalVariableName") | ||
| fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCookieManager?) { | ||
|
|
@@ -1621,6 +1629,29 @@ abstract class PigeonApiCookieManager( | |
| channel.setMessageHandler(null) | ||
| } | ||
| } | ||
| run { | ||
| val channel = | ||
| BasicMessageChannel<Any?>( | ||
| binaryMessenger, | ||
| "dev.flutter.pigeon.webview_flutter_android.CookieManager.getCookies", | ||
| codec) | ||
| if (api != null) { | ||
| channel.setMessageHandler { message, reply -> | ||
| val args = message as List<Any?> | ||
| val pigeon_instanceArg = args[0] as android.webkit.CookieManager | ||
| val urlArg = args[1] as String | ||
| val wrapped: List<Any?> = | ||
| try { | ||
| listOf(api.getCookies(pigeon_instanceArg, urlArg)) | ||
| } catch (exception: Throwable) { | ||
| AndroidWebkitLibraryPigeonUtils.wrapError(exception) | ||
| } | ||
| reply.reply(wrapped) | ||
| } | ||
| } else { | ||
| channel.setMessageHandler(null) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import android.webkit.CookieManager; | ||
| import android.webkit.ValueCallback; | ||
|
|
@@ -64,4 +65,35 @@ public void setAcceptThirdPartyCookies() { | |
|
|
||
| verify(instance).setAcceptThirdPartyCookies(webView, accept); | ||
| } | ||
|
|
||
| @Test | ||
| public void getCookies_returnsCookieString() { | ||
| final PigeonApiCookieManager api = new TestProxyApiRegistrar().getPigeonApiCookieManager(); | ||
|
|
||
| final CookieManager instance = mock(CookieManager.class); | ||
| final String domain = "https://flutter.dev"; | ||
| final String cookieValue = "session=12345"; | ||
|
|
||
| // Mock the CookieManager to return the cookie string | ||
| when(instance.getCookie(domain)).thenReturn(cookieValue); | ||
|
|
||
| final String result = api.getCookies(instance, domain); | ||
|
|
||
| assertEquals(cookieValue, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void getCookies_returnsEmptyStringIfNull() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should now be removable due to the change from #10833 |
||
| final PigeonApiCookieManager api = new TestProxyApiRegistrar().getPigeonApiCookieManager(); | ||
|
|
||
| final CookieManager instance = mock(CookieManager.class); | ||
| final String domain = "https://flutter.dev"; | ||
|
|
||
| // Mock the CookieManager to return null | ||
| when(instance.getCookie(domain)).thenReturn(null); | ||
|
|
||
| final String result = api.getCookies(instance, domain); | ||
|
|
||
| assertEquals("", result); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: