Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change out web_kit_cookie_manager
  • Loading branch information
bparrishMines committed Jun 22, 2022
commit a0d2d9a61676b72214084f9b7edd55f2a825c6fb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,52 @@
// found in the LICENSE file.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to switch this to the implementation of packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_cookie_manager.dart in commit a0d2d9a. webview_flutter references this class directly.


import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart';
import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart';

import 'web_kit_cookie_manager.dart';

/// Handles all cookie operations for the current platform.
/// Handles all cookie operations for the WebView platform.
class WKWebViewCookieManager extends WebViewCookieManagerPlatform {
final WebKitCookieManager _webKitManager = WebKitCookieManager();
/// Constructs a [WKWebViewCookieManager].
WKWebViewCookieManager({WKWebsiteDataStore? websiteDataStore})
: websiteDataStore =
websiteDataStore ?? WKWebsiteDataStore.defaultDataStore;

/// Manages stored data for [WKWebView]s.
final WKWebsiteDataStore websiteDataStore;

@override
Future<bool> clearCookies() => _webKitManager.clearCookies();
Future<bool> clearCookies() async {
return websiteDataStore.removeDataOfTypes(
<WKWebsiteDataType>{WKWebsiteDataType.cookies},
DateTime.fromMillisecondsSinceEpoch(0),
);
}

@override
Future<void> setCookie(WebViewCookie cookie) {
if (!_isValidPath(cookie.path)) {
throw ArgumentError(
'The path property for the provided cookie was not given a legal value.');
}
return _webKitManager.setCookie(cookie);

return websiteDataStore.httpCookieStore.setCookie(
NSHttpCookie.withProperties(
<NSHttpCookiePropertyKey, Object>{
NSHttpCookiePropertyKey.name: cookie.name,
NSHttpCookiePropertyKey.value: cookie.value,
NSHttpCookiePropertyKey.domain: cookie.domain,
NSHttpCookiePropertyKey.path: cookie.path,
},
),
);
}

bool _isValidPath(String path) {
// Permitted ranges based on RFC6265bis: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1
for (final int char in path.codeUnits) {
if ((char < 0x20 || char > 0x3A) && (char < 0x3C || char > 0x7E)) {
return false;
}
}
return true;
return !path.codeUnits.any(
(int char) {
return (char < 0x20 || char > 0x3A) && (char < 0x3C || char > 0x7E);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:mockito/mockito.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart';
import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart';
import 'package:webview_flutter_wkwebview/src/web_kit_cookie_manager.dart';
import 'package:webview_flutter_wkwebview/src/wkwebview_cookie_manager.dart';

import 'web_kit_cookie_manager_test.mocks.dart';

Expand All @@ -23,7 +23,7 @@ void main() {
late MockWKWebsiteDataStore mockWebsiteDataStore;
late MockWKHttpCookieStore mockWKHttpCookieStore;

late WebKitCookieManager cookieManager;
late WKWebViewCookieManager cookieManager;

setUp(() {
mockWebsiteDataStore = MockWKWebsiteDataStore();
Expand All @@ -32,7 +32,7 @@ void main() {
.thenReturn(mockWKHttpCookieStore);

cookieManager =
WebKitCookieManager(websiteDataStore: mockWebsiteDataStore);
WKWebViewCookieManager(websiteDataStore: mockWebsiteDataStore);
});

test('clearCookies', () async {
Expand Down

This file was deleted.