This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter_wkwebview] Add support for cookie manager #5203
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b6ca5e
add cookie manager
bparrishMines a1ea194
docs
bparrishMines a183681
fix test
bparrishMines 54c05a0
fix webkit test
bparrishMines 1a7bb90
remove unsupported types
bparrishMines 3a83c87
functional programming
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_cookie_manager.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
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'; | ||
|
||
/// Handles all cookie operations for the WebView platform. | ||
class WebKitCookieManager extends WebViewCookieManagerPlatform { | ||
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. In the WebKit library, the |
||
/// Constructs a [WebKitCookieManager]. | ||
WebKitCookieManager({WKWebsiteDataStore? websiteDataStore}) | ||
: websiteDataStore = | ||
websiteDataStore ?? WKWebsiteDataStore.defaultDataStore; | ||
|
||
/// Manages stored data for [WKWebView]s. | ||
final WKWebsiteDataStore websiteDataStore; | ||
|
||
@override | ||
Future<bool> clearCookies() async { | ||
return websiteDataStore.removeDataOfTypes( | ||
<WKWebsiteDataTypes>{WKWebsiteDataTypes.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 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 | ||
return !path.codeUnits.any( | ||
(int char) { | ||
return (char < 0x20 || char > 0x3A) && (char < 0x3C || char > 0x7E); | ||
}, | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This Objective-C method doesn't return a
bool
, but I decided to just add this feature for simplicity of addingCookieManager.setCookie
.