Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit a0d2d9a

Browse files
committed
change out web_kit_cookie_manager
1 parent 19657bb commit a0d2d9a

File tree

4 files changed

+35
-134
lines changed

4 files changed

+35
-134
lines changed

packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_cookie_manager.dart

Lines changed: 0 additions & 54 deletions
This file was deleted.

packages/webview_flutter/webview_flutter_wkwebview/lib/src/wkwebview_cookie_manager.dart

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,52 @@
33
// found in the LICENSE file.
44

55
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
6+
import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart';
7+
import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart';
68

7-
import 'web_kit_cookie_manager.dart';
8-
9-
/// Handles all cookie operations for the current platform.
9+
/// Handles all cookie operations for the WebView platform.
1010
class WKWebViewCookieManager extends WebViewCookieManagerPlatform {
11-
final WebKitCookieManager _webKitManager = WebKitCookieManager();
11+
/// Constructs a [WKWebViewCookieManager].
12+
WKWebViewCookieManager({WKWebsiteDataStore? websiteDataStore})
13+
: websiteDataStore =
14+
websiteDataStore ?? WKWebsiteDataStore.defaultDataStore;
15+
16+
/// Manages stored data for [WKWebView]s.
17+
final WKWebsiteDataStore websiteDataStore;
1218

1319
@override
14-
Future<bool> clearCookies() => _webKitManager.clearCookies();
20+
Future<bool> clearCookies() async {
21+
return websiteDataStore.removeDataOfTypes(
22+
<WKWebsiteDataType>{WKWebsiteDataType.cookies},
23+
DateTime.fromMillisecondsSinceEpoch(0),
24+
);
25+
}
1526

1627
@override
1728
Future<void> setCookie(WebViewCookie cookie) {
1829
if (!_isValidPath(cookie.path)) {
1930
throw ArgumentError(
2031
'The path property for the provided cookie was not given a legal value.');
2132
}
22-
return _webKitManager.setCookie(cookie);
33+
34+
return websiteDataStore.httpCookieStore.setCookie(
35+
NSHttpCookie.withProperties(
36+
<NSHttpCookiePropertyKey, Object>{
37+
NSHttpCookiePropertyKey.name: cookie.name,
38+
NSHttpCookiePropertyKey.value: cookie.value,
39+
NSHttpCookiePropertyKey.domain: cookie.domain,
40+
NSHttpCookiePropertyKey.path: cookie.path,
41+
},
42+
),
43+
);
2344
}
2445

2546
bool _isValidPath(String path) {
2647
// Permitted ranges based on RFC6265bis: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1
27-
for (final int char in path.codeUnits) {
28-
if ((char < 0x20 || char > 0x3A) && (char < 0x3C || char > 0x7E)) {
29-
return false;
30-
}
31-
}
32-
return true;
48+
return !path.codeUnits.any(
49+
(int char) {
50+
return (char < 0x20 || char > 0x3A) && (char < 0x3C || char > 0x7E);
51+
},
52+
);
3353
}
3454
}

packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:mockito/mockito.dart';
88
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
99
import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart';
1010
import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart';
11-
import 'package:webview_flutter_wkwebview/src/web_kit_cookie_manager.dart';
11+
import 'package:webview_flutter_wkwebview/src/wkwebview_cookie_manager.dart';
1212

1313
import 'web_kit_cookie_manager_test.mocks.dart';
1414

@@ -23,7 +23,7 @@ void main() {
2323
late MockWKWebsiteDataStore mockWebsiteDataStore;
2424
late MockWKHttpCookieStore mockWKHttpCookieStore;
2525

26-
late WebKitCookieManager cookieManager;
26+
late WKWebViewCookieManager cookieManager;
2727

2828
setUp(() {
2929
mockWebsiteDataStore = MockWKWebsiteDataStore();
@@ -32,7 +32,7 @@ void main() {
3232
.thenReturn(mockWKHttpCookieStore);
3333

3434
cookieManager =
35-
WebKitCookieManager(websiteDataStore: mockWebsiteDataStore);
35+
WKWebViewCookieManager(websiteDataStore: mockWebsiteDataStore);
3636
});
3737

3838
test('clearCookies', () async {

packages/webview_flutter/webview_flutter_wkwebview/test/src/wkwebview_cookie_manager_test.dart

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)