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.7k
[webview_flutter] Add supporting interfaces for setting cookies to platform interface. #4555
Merged
fluttergithubbot
merged 10 commits into
flutter:master
from
Baseflow:webview_flutter/set_cookies_platform
Dec 2, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9950ee5
Added cookie manager to interface.
BeMacized 0577815
Added iOS implementation for new CookieManager.
BeMacized 2e3dba3
Update pubspec
BeMacized 4816d71
Revert accidental push of ios changes
BeMacized 34c680e
Update deprecation notice
BeMacized 44eca64
Merge branch 'master' into webview_flutter/set_cookies_platform
BeMacized 0d0f281
Fix analysis issues
BeMacized 490da19
Enforce extending class for cookie manager platform interface
BeMacized 6f9742a
Process PR feedback
BeMacized c7067c0
Process PR feedback
BeMacized 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
6 changes: 6 additions & 0 deletions
6
packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md
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
50 changes: 50 additions & 0 deletions
50
...webview_flutter_platform_interface/lib/src/platform_interface/webview_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,50 @@ | ||
| // 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:plugin_platform_interface/plugin_platform_interface.dart'; | ||
| import 'package:webview_flutter_platform_interface/src/types/webview_cookie.dart'; | ||
|
|
||
| /// Interface for a platform implementation of a cookie manager. | ||
| /// | ||
| /// Platform implementations should extend this class rather than implement it as `webview_flutter` | ||
| /// does not consider newly added methods to be breaking changes. Extending this class | ||
| /// (using `extends`) ensures that the subclass will get the default implementation, while | ||
| /// platform implementations that `implements` this interface will be broken by newly added | ||
| /// [WebViewCookieManagerPlatform] methods. | ||
| abstract class WebViewCookieManagerPlatform extends PlatformInterface { | ||
| /// Constructs a WebViewCookieManagerPlatform. | ||
| WebViewCookieManagerPlatform() : super(token: _token); | ||
|
|
||
| static final Object _token = Object(); | ||
|
|
||
| static WebViewCookieManagerPlatform? _instance; | ||
|
|
||
| /// The instance of [WebViewCookieManagerPlatform] to use. | ||
| static WebViewCookieManagerPlatform? get instance => _instance; | ||
|
|
||
| /// Platform-specific plugins should set this with their own platform-specific | ||
| /// class that extends [WebViewCookieManagerPlatform] when they register themselves. | ||
| static set instance(WebViewCookieManagerPlatform? instance) { | ||
| if (instance == null) { | ||
| throw AssertionError( | ||
| 'Platform interfaces can only be set to a non-null instance'); | ||
| } | ||
| PlatformInterface.verifyToken(instance, _token); | ||
| _instance = instance; | ||
| } | ||
|
|
||
| /// Clears all cookies for all [WebView] instances. | ||
| /// | ||
| /// Returns true if cookies were present before clearing, else false. | ||
| Future<bool> clearCookies() { | ||
| throw UnimplementedError( | ||
| 'clearCookies is not implemented on the current platform'); | ||
| } | ||
|
|
||
| /// Sets a cookie for all [WebView] instances. | ||
| Future<void> setCookie(WebViewCookie cookie) { | ||
| throw UnimplementedError( | ||
| 'setCookie is not implemented on the current platform'); | ||
| } | ||
| } |
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
49 changes: 49 additions & 0 deletions
49
...ages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.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,49 @@ | ||
| // 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. | ||
|
|
||
| /// A cookie that can be set globally for all web views | ||
| /// using [WebViewCookieManagerPlatform]. | ||
| class WebViewCookie { | ||
| /// Constructs a new [WebViewCookie]. | ||
| const WebViewCookie( | ||
| {required this.name, | ||
| required this.value, | ||
| required this.domain, | ||
| this.path = '/'}); | ||
|
|
||
| /// The cookie-name of the cookie. | ||
| /// | ||
| /// Its value should match "cookie-name" in RFC6265bis: | ||
| /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 | ||
| final String name; | ||
|
|
||
| /// The cookie-value of the cookie. | ||
| /// | ||
| /// Its value should match "cookie-value" in RFC6265bis: | ||
| /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 | ||
| final String value; | ||
|
|
||
| /// The domain-value of the cookie. | ||
| /// | ||
| /// Its value should match "domain-value" in RFC6265bis: | ||
| /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 | ||
| final String domain; | ||
|
|
||
| /// The path-value of the cookie. | ||
| /// Is set to `/` in the constructor by default. | ||
| /// | ||
| /// Its value should match "path-value" in RFC6265bis: | ||
| /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 | ||
| final String path; | ||
|
|
||
| /// Serializes the [WebViewCookie] to a Map<String, String>. | ||
| Map<String, String> toJson() { | ||
| return <String, String>{ | ||
| 'name': name, | ||
| 'value': value, | ||
| 'domain': domain, | ||
| 'path': path | ||
| }; | ||
| } | ||
| } |
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
27 changes: 27 additions & 0 deletions
27
...w_flutter_platform_interface/test/src/platform_interface/webview_cookie_manager_test.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,27 @@ | ||
| // 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:flutter_test/flutter_test.dart'; | ||
| import 'package:webview_flutter_platform_interface/src/platform_interface/platform_interface.dart'; | ||
| import 'package:webview_flutter_platform_interface/src/types/webview_cookie.dart'; | ||
|
|
||
| void main() { | ||
| WebViewCookieManagerPlatform? cookieManager; | ||
|
|
||
| setUp(() { | ||
| cookieManager = TestWebViewCookieManagerPlatform(); | ||
| }); | ||
|
|
||
| test('clearCookies should throw UnimplementedError', () { | ||
| expect(() => cookieManager!.clearCookies(), throwsUnimplementedError); | ||
| }); | ||
|
|
||
| test('setCookie should throw UnimplementedError', () { | ||
| const WebViewCookie cookie = | ||
| WebViewCookie(domain: 'flutter.dev', name: 'foo', value: 'bar'); | ||
| expect(() => cookieManager!.setCookie(cookie), throwsUnimplementedError); | ||
| }); | ||
| } | ||
|
|
||
| class TestWebViewCookieManagerPlatform extends WebViewCookieManagerPlatform {} |
21 changes: 21 additions & 0 deletions
21
...ebview_flutter/webview_flutter_platform_interface/test/src/types/webview_cookie_test.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,21 @@ | ||
| // 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:flutter_test/flutter_test.dart'; | ||
| import 'package:webview_flutter_platform_interface/src/types/types.dart'; | ||
|
|
||
| void main() { | ||
| test('WebViewCookie should serialize correctly', () { | ||
| WebViewCookie cookie; | ||
| Map<String, String> serializedCookie; | ||
| // Test serialization | ||
| cookie = const WebViewCookie( | ||
| name: 'foo', value: 'bar', domain: 'example.com', path: '/test'); | ||
| serializedCookie = cookie.toJson(); | ||
| expect(serializedCookie['name'], 'foo'); | ||
| expect(serializedCookie['value'], 'bar'); | ||
| expect(serializedCookie['domain'], 'example.com'); | ||
| expect(serializedCookie['path'], '/test'); | ||
| }); | ||
| } |
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.
@ reviewer: Just want to double check if it's ok to deprecate platform interface methods like this?
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.
You can't deprecate methods we're still using; it breaks the tree. (I should have tooling soon that will catch this kind of thing in CI.)
They can be commented as deprecated, and then actually deprecated later once the uses have been removed.
Unless you can fix the call sites right away, we need to revert this part, as this will close not only our tree, but the flutter/flutter tree as well.
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.
@stuartmorgan Alright, I'll quickly submit a PR that changes this annotation to a comment.